diff --git a/.circleci/config.yml b/.circleci/config.yml index ea585f05b..fc94bb81b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -76,6 +76,7 @@ jobs: make test-coverage mkdir -p /tmp/artifacts mv coverage.out /tmp/artifacts/coverage.out + make test-migration - codecov/upload: file: /tmp/artifacts/coverage.out - store_artifacts: diff --git a/Makefile b/Makefile index 911abc141..99e717317 100644 --- a/Makefile +++ b/Makefile @@ -8,11 +8,9 @@ build: test: $(GO_BIN) test ./... - $(GO_BIN) test -race ./actors/migration/nv12/test .PHONY: test test-migration: - $(GO_BIN) test -race ./actors/migration/nv12/test .PHONY: test-migration test-coverage: diff --git a/actors/builtin/account/account_actor.go b/actors/builtin/account/account_actor.go index 9a9853127..ae0199cca 100644 --- a/actors/builtin/account/account_actor.go +++ b/actors/builtin/account/account_actor.go @@ -7,8 +7,8 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" "github.com/ipfs/go-cid" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" ) type Actor struct{} diff --git a/actors/builtin/account/account_test.go b/actors/builtin/account/account_test.go index 262ebac7f..38b19c908 100644 --- a/actors/builtin/account/account_test.go +++ b/actors/builtin/account/account_test.go @@ -9,10 +9,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/account" - "github.com/filecoin-project/specs-actors/v4/support/mock" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/account" + "github.com/filecoin-project/specs-actors/v5/support/mock" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" ) type constructorTestCase struct { diff --git a/actors/builtin/account/testing.go b/actors/builtin/account/testing.go index 3b2c84917..d1b801688 100644 --- a/actors/builtin/account/testing.go +++ b/actors/builtin/account/testing.go @@ -3,7 +3,7 @@ package account import ( "github.com/filecoin-project/go-address" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" ) type StateSummary struct { diff --git a/actors/builtin/cron/cron_actor.go b/actors/builtin/cron/cron_actor.go index 8feac97fa..a17525a8c 100644 --- a/actors/builtin/cron/cron_actor.go +++ b/actors/builtin/cron/cron_actor.go @@ -6,8 +6,8 @@ import ( cron0 "github.com/filecoin-project/specs-actors/actors/builtin/cron" "github.com/ipfs/go-cid" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" ) // The cron actor is a built-in singleton that sends messages to other registered actors at the end of each epoch. diff --git a/actors/builtin/cron/cron_state.go b/actors/builtin/cron/cron_state.go index 63a59b350..f7bec64e7 100644 --- a/actors/builtin/cron/cron_state.go +++ b/actors/builtin/cron/cron_state.go @@ -4,7 +4,7 @@ import ( addr "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" ) type State struct { diff --git a/actors/builtin/cron/cron_test.go b/actors/builtin/cron/cron_test.go index cd7ad7696..541ace649 100644 --- a/actors/builtin/cron/cron_test.go +++ b/actors/builtin/cron/cron_test.go @@ -8,10 +8,10 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" "github.com/stretchr/testify/assert" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/cron" - "github.com/filecoin-project/specs-actors/v4/support/mock" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/cron" + "github.com/filecoin-project/specs-actors/v5/support/mock" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" ) func TestExports(t *testing.T) { diff --git a/actors/builtin/cron/testing.go b/actors/builtin/cron/testing.go index 3eda003d7..e91a28197 100644 --- a/actors/builtin/cron/testing.go +++ b/actors/builtin/cron/testing.go @@ -2,8 +2,8 @@ package cron import ( "github.com/filecoin-project/go-address" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) type StateSummary struct { diff --git a/actors/builtin/exported/actors.go b/actors/builtin/exported/actors.go index e28e3f597..5dc3a3ee1 100644 --- a/actors/builtin/exported/actors.go +++ b/actors/builtin/exported/actors.go @@ -1,18 +1,18 @@ package exported import ( - "github.com/filecoin-project/specs-actors/v4/actors/builtin/account" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/cron" - init_ "github.com/filecoin-project/specs-actors/v4/actors/builtin/init" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/multisig" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/paych" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/system" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/account" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/cron" + init_ "github.com/filecoin-project/specs-actors/v5/actors/builtin/init" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/multisig" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/paych" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/reward" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/system" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/verifreg" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" ) func BuiltinActors() []runtime.VMActor { diff --git a/actors/builtin/exported/actors_test.go b/actors/builtin/exported/actors_test.go index dad7dc388..462bb48ea 100644 --- a/actors/builtin/exported/actors_test.go +++ b/actors/builtin/exported/actors_test.go @@ -7,19 +7,19 @@ import ( "testing" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/account" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/cron" - init_ "github.com/filecoin-project/specs-actors/v4/actors/builtin/init" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/multisig" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/paych" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/system" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/account" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/cron" + init_ "github.com/filecoin-project/specs-actors/v5/actors/builtin/init" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/multisig" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/paych" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/reward" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/system" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/verifreg" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" "github.com/ipfs/go-cid" "github.com/stretchr/testify/require" diff --git a/actors/builtin/init/init_actor.go b/actors/builtin/init/init_actor.go index 9e3a55e59..211e333a4 100644 --- a/actors/builtin/init/init_actor.go +++ b/actors/builtin/init/init_actor.go @@ -8,9 +8,9 @@ import ( init0 "github.com/filecoin-project/specs-actors/actors/builtin/init" cid "github.com/ipfs/go-cid" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) // The init actor uniquely has the power to create new actors. diff --git a/actors/builtin/init/init_actor_state.go b/actors/builtin/init/init_actor_state.go index 1907128c5..3bf7e214d 100644 --- a/actors/builtin/init/init_actor_state.go +++ b/actors/builtin/init/init_actor_state.go @@ -7,8 +7,8 @@ import ( cbg "github.com/whyrusleeping/cbor-gen" xerrors "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) type State struct { diff --git a/actors/builtin/init/init_test.go b/actors/builtin/init/init_test.go index 8fd013eb8..90803783e 100644 --- a/actors/builtin/init/init_test.go +++ b/actors/builtin/init/init_test.go @@ -11,11 +11,11 @@ import ( cid "github.com/ipfs/go-cid" assert "github.com/stretchr/testify/assert" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - init_ "github.com/filecoin-project/specs-actors/v4/actors/builtin/init" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/mock" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + init_ "github.com/filecoin-project/specs-actors/v5/actors/builtin/init" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/mock" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" ) func TestExports(t *testing.T) { diff --git a/actors/builtin/init/testing.go b/actors/builtin/init/testing.go index 57eabf940..c2f68d643 100644 --- a/actors/builtin/init/testing.go +++ b/actors/builtin/init/testing.go @@ -5,8 +5,8 @@ import ( "github.com/filecoin-project/go-state-types/abi" cbg "github.com/whyrusleeping/cbor-gen" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) type StateSummary struct { diff --git a/actors/builtin/market/market_actor.go b/actors/builtin/market/market_actor.go index 70f0873e0..eb8d37648 100644 --- a/actors/builtin/market/market_actor.go +++ b/actors/builtin/market/market_actor.go @@ -17,12 +17,12 @@ import ( cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/reward" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/verifreg" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) type Actor struct{} diff --git a/actors/builtin/market/market_state.go b/actors/builtin/market/market_state.go index 36816fda8..56ec7de18 100644 --- a/actors/builtin/market/market_state.go +++ b/actors/builtin/market/market_state.go @@ -9,8 +9,8 @@ import ( "github.com/ipfs/go-cid" xerrors "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) const epochUndefined = abi.ChainEpoch(-1) diff --git a/actors/builtin/market/market_test.go b/actors/builtin/market/market_test.go index f54ee149e..da3a86136 100644 --- a/actors/builtin/market/market_test.go +++ b/actors/builtin/market/market_test.go @@ -16,15 +16,15 @@ import ( cid "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/mock" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/reward" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/verifreg" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/mock" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/actors/builtin/market/policy.go b/actors/builtin/market/policy.go index 774123445..1d797d48f 100644 --- a/actors/builtin/market/policy.go +++ b/actors/builtin/market/policy.go @@ -4,7 +4,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" ) // The number of epochs between payment and other state processing for deals. diff --git a/actors/builtin/market/set_multimap.go b/actors/builtin/market/set_multimap.go index 0747e0820..c21058fd1 100644 --- a/actors/builtin/market/set_multimap.go +++ b/actors/builtin/market/set_multimap.go @@ -9,7 +9,7 @@ import ( cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) type SetMultimap struct { diff --git a/actors/builtin/market/testing.go b/actors/builtin/market/testing.go index d8b459e4f..8a5b4d15c 100644 --- a/actors/builtin/market/testing.go +++ b/actors/builtin/market/testing.go @@ -12,8 +12,8 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) type DealSummary struct { diff --git a/actors/builtin/market/types.go b/actors/builtin/market/types.go index 12bc4c754..5fb38c4d8 100644 --- a/actors/builtin/market/types.go +++ b/actors/builtin/market/types.go @@ -2,7 +2,7 @@ package market import ( "github.com/filecoin-project/go-state-types/abi" - . "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + . "github.com/filecoin-project/specs-actors/v5/actors/util/adt" "github.com/ipfs/go-cid" ) diff --git a/actors/builtin/miner/bitfield_queue.go b/actors/builtin/miner/bitfield_queue.go index 50c021a16..c6cf845ae 100644 --- a/actors/builtin/miner/bitfield_queue.go +++ b/actors/builtin/miner/bitfield_queue.go @@ -9,7 +9,7 @@ import ( "github.com/ipfs/go-cid" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) // Wrapper for working with an AMT[ChainEpoch]*Bitfield functioning as a queue, bucketed by epoch. diff --git a/actors/builtin/miner/bitfield_queue_test.go b/actors/builtin/miner/bitfield_queue_test.go index 374932843..7e96cfc76 100644 --- a/actors/builtin/miner/bitfield_queue_test.go +++ b/actors/builtin/miner/bitfield_queue_test.go @@ -9,9 +9,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/mock" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/mock" ) const testAmtBitwidth = 3 diff --git a/actors/builtin/miner/deadline_state.go b/actors/builtin/miner/deadline_state.go index 3eb2a823f..4176a7cfb 100644 --- a/actors/builtin/miner/deadline_state.go +++ b/actors/builtin/miner/deadline_state.go @@ -12,8 +12,8 @@ import ( cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v4/actors/runtime/proof" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) // Deadlines contains Deadline objects, describing the sectors due at the given diff --git a/actors/builtin/miner/deadline_state_test.go b/actors/builtin/miner/deadline_state_test.go index ede6d4c18..3e27fd7c2 100644 --- a/actors/builtin/miner/deadline_state_test.go +++ b/actors/builtin/miner/deadline_state_test.go @@ -10,10 +10,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/ipld" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/ipld" ) func TestDeadlines(t *testing.T) { diff --git a/actors/builtin/miner/deadlines.go b/actors/builtin/miner/deadlines.go index 9ec98a545..969cb0f11 100644 --- a/actors/builtin/miner/deadlines.go +++ b/actors/builtin/miner/deadlines.go @@ -7,7 +7,7 @@ import ( "github.com/filecoin-project/go-state-types/dline" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) // Returns deadline-related calculations for a deadline in some proving period and the current epoch. diff --git a/actors/builtin/miner/deadlines_test.go b/actors/builtin/miner/deadlines_test.go index fa15c72db..88faf1ec9 100644 --- a/actors/builtin/miner/deadlines_test.go +++ b/actors/builtin/miner/deadlines_test.go @@ -6,7 +6,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/stretchr/testify/assert" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" ) func TestProvingPeriodDeadlines(t *testing.T) { diff --git a/actors/builtin/miner/expiration_queue.go b/actors/builtin/miner/expiration_queue.go index 8cf28258b..cdf4c05a7 100644 --- a/actors/builtin/miner/expiration_queue.go +++ b/actors/builtin/miner/expiration_queue.go @@ -10,8 +10,8 @@ import ( "github.com/ipfs/go-cid" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v4/actors/util" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/util" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) // ExpirationSet is a collection of sector numbers that are expiring, either due to diff --git a/actors/builtin/miner/expiration_queue_test.go b/actors/builtin/miner/expiration_queue_test.go index 67ea452b3..479011fbc 100644 --- a/actors/builtin/miner/expiration_queue_test.go +++ b/actors/builtin/miner/expiration_queue_test.go @@ -11,10 +11,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/mock" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/mock" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" ) func TestExpirationSet(t *testing.T) { diff --git a/actors/builtin/miner/miner_actor.go b/actors/builtin/miner/miner_actor.go index 0ebf4ce62..2a7823a3c 100644 --- a/actors/builtin/miner/miner_actor.go +++ b/actors/builtin/miner/miner_actor.go @@ -22,15 +22,15 @@ import ( cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" - "github.com/filecoin-project/specs-actors/v4/actors/runtime/proof" - . "github.com/filecoin-project/specs-actors/v4/actors/util" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/actors/util/smoothing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/reward" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" + . "github.com/filecoin-project/specs-actors/v5/actors/util" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/util/smoothing" ) type Runtime = runtime.Runtime @@ -1754,8 +1754,9 @@ func (a Actor) ReportConsensusFault(rt Runtime, params *ReportConsensusFaultPara rewardStats := requestCurrentEpochBlockReward(rt) // The policy amounts we should burn and send to reporter // These may differ from actual funds send when miner goes into fee debt - faultPenalty := ConsensusFaultPenalty(rewardStats.ThisEpochRewardSmoothed.Estimate()) - slasherReward := RewardForConsensusSlashReport(faultAge, faultPenalty) + thisEpochReward := rewardStats.ThisEpochRewardSmoothed.Estimate() + faultPenalty := ConsensusFaultPenalty(thisEpochReward) + slasherReward := RewardForConsensusSlashReport(thisEpochReward) pledgeDelta := big.Zero() // The amounts actually sent to burnt funds and reporter @@ -1933,7 +1934,7 @@ func processEarlyTerminations(rt Runtime) (more bool) { // TODO: We're using the current power+epoch reward. Technically, we // should use the power/reward at the time of termination. - // https://github.com/filecoin-project/specs-actors/v4/pull/648 + // https://github.com/filecoin-project/specs-actors/v5/pull/648 rewardStats := requestCurrentEpochBlockReward(rt) pwrTotal := requestCurrentTotalPower(rt) diff --git a/actors/builtin/miner/miner_internal_test.go b/actors/builtin/miner/miner_internal_test.go index 3f83a19b6..b226dea05 100644 --- a/actors/builtin/miner/miner_internal_test.go +++ b/actors/builtin/miner/miner_internal_test.go @@ -8,9 +8,9 @@ import ( "github.com/minio/blake2b-simd" "github.com/stretchr/testify/assert" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/smoothing" - tutils "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/smoothing" + tutils "github.com/filecoin-project/specs-actors/v5/support/testing" ) func TestAssignProvingPeriodBoundary(t *testing.T) { diff --git a/actors/builtin/miner/miner_state.go b/actors/builtin/miner/miner_state.go index 87866263f..ab89ceddb 100644 --- a/actors/builtin/miner/miner_state.go +++ b/actors/builtin/miner/miner_state.go @@ -15,8 +15,8 @@ import ( errors "github.com/pkg/errors" xerrors "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) // Balance of Miner Actor should be greater than or equal to diff --git a/actors/builtin/miner/miner_state_test.go b/actors/builtin/miner/miner_state_test.go index c28104675..aecc1c752 100644 --- a/actors/builtin/miner/miner_state_test.go +++ b/actors/builtin/miner/miner_state_test.go @@ -14,11 +14,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/ipld" - tutils "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/ipld" + tutils "github.com/filecoin-project/specs-actors/v5/support/testing" ) func TestPrecommittedSectorsStore(t *testing.T) { diff --git a/actors/builtin/miner/miner_test.go b/actors/builtin/miner/miner_test.go index 0ee319ea0..9b5e85310 100644 --- a/actors/builtin/miner/miner_test.go +++ b/actors/builtin/miner/miner_test.go @@ -22,17 +22,17 @@ import ( "github.com/stretchr/testify/require" cbg "github.com/whyrusleeping/cbor-gen" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" - "github.com/filecoin-project/specs-actors/v4/actors/runtime/proof" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/actors/util/smoothing" - "github.com/filecoin-project/specs-actors/v4/support/mock" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/reward" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/util/smoothing" + "github.com/filecoin-project/specs-actors/v5/support/mock" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" ) var testPid abi.PeerID @@ -5995,13 +5995,13 @@ func (h *actorHarness) reportConsensusFault(rt *mock.Runtime, from addr.Address, } rt.ExpectSend(builtin.RewardActorAddr, builtin.MethodsReward.ThisEpochReward, nil, big.Zero(), ¤tReward, exitcode.Ok) - penaltyTotal := miner.ConsensusFaultPenalty(h.epochRewardSmooth.Estimate()) - // slash reward - rwd := miner.RewardForConsensusSlashReport(1, penaltyTotal) - rt.ExpectSend(from, builtin.MethodSend, nil, rwd, nil, exitcode.Ok) + thisEpochReward := h.epochRewardSmooth.Estimate() + penaltyTotal := miner.ConsensusFaultPenalty(thisEpochReward) + rewardTotal := miner.RewardForConsensusSlashReport(thisEpochReward) + rt.ExpectSend(from, builtin.MethodSend, nil, rewardTotal, nil, exitcode.Ok) // pay fault fee - toBurn := big.Sub(penaltyTotal, rwd) + toBurn := big.Sub(penaltyTotal, rewardTotal) rt.ExpectSend(builtin.BurntFundsActorAddr, builtin.MethodSend, nil, toBurn, nil, exitcode.Ok) rt.Call(h.a.ReportConsensusFault, params) diff --git a/actors/builtin/miner/monies.go b/actors/builtin/miner/monies.go index 4f546ff56..987d2af8b 100644 --- a/actors/builtin/miner/monies.go +++ b/actors/builtin/miner/monies.go @@ -5,9 +5,9 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/exitcode" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/math" - "github.com/filecoin-project/specs-actors/v4/actors/util/smoothing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/math" + "github.com/filecoin-project/specs-actors/v5/actors/util/smoothing" ) // Projection period of expected sector block reward for deposit required to pre-commit a sector. diff --git a/actors/builtin/miner/monies_test.go b/actors/builtin/miner/monies_test.go index a694ed2ad..4a73d958c 100644 --- a/actors/builtin/miner/monies_test.go +++ b/actors/builtin/miner/monies_test.go @@ -7,9 +7,9 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/stretchr/testify/assert" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/util/smoothing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/util/smoothing" ) // Test termination fee diff --git a/actors/builtin/miner/partition_state.go b/actors/builtin/miner/partition_state.go index c8b52bf86..73c96c0e9 100644 --- a/actors/builtin/miner/partition_state.go +++ b/actors/builtin/miner/partition_state.go @@ -10,8 +10,8 @@ import ( "github.com/ipfs/go-cid" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v4/actors/util" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/util" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) type Partition struct { diff --git a/actors/builtin/miner/partition_state_test.go b/actors/builtin/miner/partition_state_test.go index 682947773..25f0315f8 100644 --- a/actors/builtin/miner/partition_state_test.go +++ b/actors/builtin/miner/partition_state_test.go @@ -14,10 +14,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/ipld" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/ipld" ) func TestPartitions(t *testing.T) { diff --git a/actors/builtin/miner/policy.go b/actors/builtin/miner/policy.go index e98846f82..155c7af55 100644 --- a/actors/builtin/miner/policy.go +++ b/actors/builtin/miner/policy.go @@ -9,7 +9,7 @@ import ( "github.com/ipfs/go-cid" mh "github.com/multiformats/go-multihash" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" ) // The period over which a miner's active sectors are expected to be proven via WindowPoSt. @@ -273,25 +273,9 @@ func SectorDealsMax(size abi.SectorSize) uint64 { return max64(256, uint64(size/DealLimitDenominator)) } -// Initial share of consensus fault penalty allocated as reward to the reporter. -var consensusFaultReporterInitialShare = builtin.BigFrac{ - Numerator: big.NewInt(1), // PARAM_SPEC - Denominator: big.NewInt(1000), -} - -// Per-epoch growth rate of the consensus fault reporter reward. -// consensusFaultReporterInitialShare*consensusFaultReporterShareGrowthRate^consensusFaultGrowthDuration ~= consensusFaultReporterMaxShare -// consensusFaultGrowthDuration = 500 epochs -var consensusFaultReporterShareGrowthRate = builtin.BigFrac{ - Numerator: big.NewInt(100785473384), // PARAM_SPEC - Denominator: big.NewInt(100000000000), -} - -// Maximum share of consensus fault penalty allocated as reporter reward. -var consensusFaultMaxReporterShare = builtin.BigFrac{ - Numerator: big.NewInt(1), // PARAM_SPEC - Denominator: big.NewInt(20), -} +// Default share of block reward allocated as reward to the consensus fault reporter. +// Applied as epochReward / (expectedLeadersPerEpoch * consensusFaultReporterDefaultShare) +const consensusFaultReporterDefaultShare int64 = 4 // Specification for a linear vesting schedule. type VestSpec struct { @@ -310,37 +294,11 @@ var RewardVestingSpec = VestSpec{ // PARAM_SPEC } // When an actor reports a consensus fault, they earn a share of the penalty paid by the miner. -// This amount is: Min(initialShare * growthRate^elapsed, maxReporterShare) * collateral -// The reward grows over time until a maximum, forming an auction for the report. -func RewardForConsensusSlashReport(elapsedEpoch abi.ChainEpoch, collateral abi.TokenAmount) abi.TokenAmount { - // High level description - // var growthRate = SLASHER_SHARE_GROWTH_RATE_NUM / SLASHER_SHARE_GROWTH_RATE_DENOM - // var multiplier = growthRate^elapsedEpoch - // var slasherProportion = min(INITIAL_SLASHER_SHARE * multiplier, 0.05) - // return collateral * slasherProportion - - // BigInt Operation - // NUM = SLASHER_SHARE_GROWTH_RATE_NUM^elapsedEpoch * INITIAL_SLASHER_SHARE_NUM * collateral - // DENOM = SLASHER_SHARE_GROWTH_RATE_DENOM^elapsedEpoch * INITIAL_SLASHER_SHARE_DENOM - // slasher_amount = min(NUM/DENOM, collateral) - elapsed := big.NewInt(int64(elapsedEpoch)) - - // The following is equivalent to: slasherShare = growthRate^elapsed - // slasherShareNumerator = growthRateNumerator^elapsed - slasherShareNumerator := big.Exp(consensusFaultReporterShareGrowthRate.Numerator, elapsed) - // slasherShareDenominator = growthRateDenominator^elapsed - slasherShareDenominator := big.Exp(consensusFaultReporterShareGrowthRate.Denominator, elapsed) - - // The following is equivalent to: reward = slasherShare * initialShare * collateral - // num = slasherShareNumerator * initialShareNumerator * collateral - num := big.Mul(big.Mul(slasherShareNumerator, consensusFaultReporterInitialShare.Numerator), collateral) - // denom = slasherShareDenominator * initialShareDenominator - denom := big.Mul(slasherShareDenominator, consensusFaultReporterInitialShare.Denominator) - - // The following is equivalent to: Min(reward, collateral * maxReporterShare) - // Min(rewardNum/rewardDenom, maxReporterShareNum/maxReporterShareDen*collateral) - return big.Min(big.Div(num, denom), big.Div(big.Mul(collateral, consensusFaultMaxReporterShare.Numerator), - consensusFaultMaxReporterShare.Denominator)) +func RewardForConsensusSlashReport(epochReward abi.TokenAmount) abi.TokenAmount { + return big.Div(epochReward, + big.Mul(big.NewInt(builtin.ExpectedLeadersPerEpoch), + big.NewInt(consensusFaultReporterDefaultShare)), + ) } // The reward given for successfully disputing a window post. diff --git a/actors/builtin/miner/policy_test.go b/actors/builtin/miner/policy_test.go index 3d13a7f45..022df5509 100644 --- a/actors/builtin/miner/policy_test.go +++ b/actors/builtin/miner/policy_test.go @@ -7,8 +7,8 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/stretchr/testify/assert" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" ) func TestQuality(t *testing.T) { diff --git a/actors/builtin/miner/sector_map_test.go b/actors/builtin/miner/sector_map_test.go index 0842e9a17..17b553961 100644 --- a/actors/builtin/miner/sector_map_test.go +++ b/actors/builtin/miner/sector_map_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" ) func TestDeadlineSectorMap(t *testing.T) { diff --git a/actors/builtin/miner/sectors.go b/actors/builtin/miner/sectors.go index ca1c51e7e..15aa57a8a 100644 --- a/actors/builtin/miner/sectors.go +++ b/actors/builtin/miner/sectors.go @@ -9,7 +9,7 @@ import ( "github.com/ipfs/go-cid" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) func LoadSectors(store adt.Store, root cid.Cid) (Sectors, error) { diff --git a/actors/builtin/miner/sectors_test.go b/actors/builtin/miner/sectors_test.go index f57f84a0e..a30e89439 100644 --- a/actors/builtin/miner/sectors_test.go +++ b/actors/builtin/miner/sectors_test.go @@ -9,10 +9,10 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/ipld" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/ipld" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" ) func sectorsArr(t *testing.T, store adt.Store, sectors []*miner.SectorOnChainInfo) miner.Sectors { diff --git a/actors/builtin/miner/termination_test.go b/actors/builtin/miner/termination_test.go index df54601c1..bf22328fb 100644 --- a/actors/builtin/miner/termination_test.go +++ b/actors/builtin/miner/termination_test.go @@ -7,7 +7,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" ) func TestTerminationResult(t *testing.T) { diff --git a/actors/builtin/miner/testing.go b/actors/builtin/miner/testing.go index c14def750..f553f29a8 100644 --- a/actors/builtin/miner/testing.go +++ b/actors/builtin/miner/testing.go @@ -6,9 +6,9 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) type DealSummary struct { diff --git a/actors/builtin/multisig/multisig_actor.go b/actors/builtin/multisig/multisig_actor.go index 1ec830578..761b79a83 100644 --- a/actors/builtin/multisig/multisig_actor.go +++ b/actors/builtin/multisig/multisig_actor.go @@ -14,9 +14,9 @@ import ( "github.com/ipfs/go-cid" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) type TxnID = multisig0.TxnID diff --git a/actors/builtin/multisig/multisig_state.go b/actors/builtin/multisig/multisig_state.go index 099acb986..ff9affb3a 100644 --- a/actors/builtin/multisig/multisig_state.go +++ b/actors/builtin/multisig/multisig_state.go @@ -7,8 +7,8 @@ import ( cid "github.com/ipfs/go-cid" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) type State struct { diff --git a/actors/builtin/multisig/multisig_test.go b/actors/builtin/multisig/multisig_test.go index 4fea8c3da..23e2e2cad 100644 --- a/actors/builtin/multisig/multisig_test.go +++ b/actors/builtin/multisig/multisig_test.go @@ -14,12 +14,12 @@ import ( assert "github.com/stretchr/testify/assert" require "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/multisig" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/mock" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/multisig" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/mock" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" ) func TestExports(t *testing.T) { diff --git a/actors/builtin/multisig/testing.go b/actors/builtin/multisig/testing.go index a5619633a..c4ad15983 100644 --- a/actors/builtin/multisig/testing.go +++ b/actors/builtin/multisig/testing.go @@ -4,8 +4,8 @@ import ( "bytes" "encoding/binary" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) type StateSummary struct { diff --git a/actors/builtin/paych/paych_actor.go b/actors/builtin/paych/paych_actor.go index 06754ac9e..be3ff4a56 100644 --- a/actors/builtin/paych/paych_actor.go +++ b/actors/builtin/paych/paych_actor.go @@ -13,9 +13,9 @@ import ( "github.com/ipfs/go-cid" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) const ( diff --git a/actors/builtin/paych/paych_test.go b/actors/builtin/paych/paych_test.go index 94a903b40..c6481335d 100644 --- a/actors/builtin/paych/paych_test.go +++ b/actors/builtin/paych/paych_test.go @@ -17,11 +17,11 @@ import ( "github.com/stretchr/testify/require" cbg "github.com/whyrusleeping/cbor-gen" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - . "github.com/filecoin-project/specs-actors/v4/actors/builtin/paych" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/mock" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + . "github.com/filecoin-project/specs-actors/v5/actors/builtin/paych" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/mock" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" ) func TestExports(t *testing.T) { diff --git a/actors/builtin/paych/policy.go b/actors/builtin/paych/policy.go index fc76049fe..857772651 100644 --- a/actors/builtin/paych/policy.go +++ b/actors/builtin/paych/policy.go @@ -3,7 +3,7 @@ package paych import ( "math" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" ) // Maximum number of lanes in a channel. diff --git a/actors/builtin/paych/testing.go b/actors/builtin/paych/testing.go index bcf546878..b634d5538 100644 --- a/actors/builtin/paych/testing.go +++ b/actors/builtin/paych/testing.go @@ -4,8 +4,8 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) type StateSummary struct { diff --git a/actors/builtin/power/power_actor.go b/actors/builtin/power/power_actor.go index 16d74f92b..1449a1c52 100644 --- a/actors/builtin/power/power_actor.go +++ b/actors/builtin/power/power_actor.go @@ -12,12 +12,12 @@ import ( power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/ipfs/go-cid" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - initact "github.com/filecoin-project/specs-actors/v4/actors/builtin/init" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" - "github.com/filecoin-project/specs-actors/v4/actors/runtime/proof" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/actors/util/smoothing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + initact "github.com/filecoin-project/specs-actors/v5/actors/builtin/init" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/util/smoothing" ) type Runtime = runtime.Runtime diff --git a/actors/builtin/power/power_state.go b/actors/builtin/power/power_state.go index b3b01d413..03baaa2de 100644 --- a/actors/builtin/power/power_state.go +++ b/actors/builtin/power/power_state.go @@ -12,9 +12,9 @@ import ( errors "github.com/pkg/errors" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/actors/util/smoothing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/util/smoothing" ) // genesis power in bytes = 750,000 GiB diff --git a/actors/builtin/power/power_test.go b/actors/builtin/power/power_test.go index 582672626..f30fe12c3 100644 --- a/actors/builtin/power/power_test.go +++ b/actors/builtin/power/power_test.go @@ -16,15 +16,15 @@ import ( assert "github.com/stretchr/testify/assert" require "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - initact "github.com/filecoin-project/specs-actors/v4/actors/builtin/init" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - mineract "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/runtime/proof" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/mock" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + initact "github.com/filecoin-project/specs-actors/v5/actors/builtin/init" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" + mineract "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/mock" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" ) func TestExports(t *testing.T) { diff --git a/actors/builtin/power/testing.go b/actors/builtin/power/testing.go index 6ccb07aa9..0c424637e 100644 --- a/actors/builtin/power/testing.go +++ b/actors/builtin/power/testing.go @@ -5,9 +5,9 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/runtime/proof" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) type MinerCronEvent struct { diff --git a/actors/builtin/reward/reward_actor.go b/actors/builtin/reward/reward_actor.go index c700d0263..de5200eb0 100644 --- a/actors/builtin/reward/reward_actor.go +++ b/actors/builtin/reward/reward_actor.go @@ -9,9 +9,9 @@ import ( reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/ipfs/go-cid" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" - "github.com/filecoin-project/specs-actors/v4/actors/util/smoothing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/util/smoothing" ) // PenaltyMultiplier is the factor miner penaltys are scaled up by diff --git a/actors/builtin/reward/reward_logic.go b/actors/builtin/reward/reward_logic.go index d8d1cc601..5899869e1 100644 --- a/actors/builtin/reward/reward_logic.go +++ b/actors/builtin/reward/reward_logic.go @@ -4,7 +4,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/v4/actors/util/math" + "github.com/filecoin-project/specs-actors/v5/actors/util/math" ) // Baseline function = BaselineInitialValue * (BaselineExponent) ^(t), t in epochs diff --git a/actors/builtin/reward/reward_logic_test.go b/actors/builtin/reward/reward_logic_test.go index e77719200..835b80298 100644 --- a/actors/builtin/reward/reward_logic_test.go +++ b/actors/builtin/reward/reward_logic_test.go @@ -11,8 +11,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/xorcare/golden" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/math" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/math" ) func q128ToF(x big.Int) float64 { diff --git a/actors/builtin/reward/reward_state.go b/actors/builtin/reward/reward_state.go index 21c93eb71..e1a49a45f 100644 --- a/actors/builtin/reward/reward_state.go +++ b/actors/builtin/reward/reward_state.go @@ -4,7 +4,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/v4/actors/util/smoothing" + "github.com/filecoin-project/specs-actors/v5/actors/util/smoothing" ) // A quantity of space * time (in byte-epochs) representing power committed to the network for some duration. diff --git a/actors/builtin/reward/reward_test.go b/actors/builtin/reward/reward_test.go index d2c1c9a5c..5aebc3ec3 100644 --- a/actors/builtin/reward/reward_test.go +++ b/actors/builtin/reward/reward_test.go @@ -10,10 +10,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward" - "github.com/filecoin-project/specs-actors/v4/support/mock" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/reward" + "github.com/filecoin-project/specs-actors/v5/support/mock" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" ) func TestExports(t *testing.T) { diff --git a/actors/builtin/reward/testing.go b/actors/builtin/reward/testing.go index 21efb46c2..9891e6515 100644 --- a/actors/builtin/reward/testing.go +++ b/actors/builtin/reward/testing.go @@ -3,8 +3,8 @@ package reward import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) type StateSummary struct{} diff --git a/actors/builtin/shared.go b/actors/builtin/shared.go index 9c6fecebf..aee13a42a 100644 --- a/actors/builtin/shared.go +++ b/actors/builtin/shared.go @@ -12,7 +12,7 @@ import ( builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" ) ///// Code shared by multiple built-in actors. ///// diff --git a/actors/builtin/system/system_actor.go b/actors/builtin/system/system_actor.go index 249f74b43..225926e94 100644 --- a/actors/builtin/system/system_actor.go +++ b/actors/builtin/system/system_actor.go @@ -5,8 +5,8 @@ import ( "github.com/filecoin-project/go-state-types/cbor" "github.com/ipfs/go-cid" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" ) type Actor struct{} diff --git a/actors/builtin/system/system_test.go b/actors/builtin/system/system_test.go index c9ae30b6d..9ac0f5a0d 100644 --- a/actors/builtin/system/system_test.go +++ b/actors/builtin/system/system_test.go @@ -5,9 +5,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/system" - "github.com/filecoin-project/specs-actors/v4/support/mock" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/system" + "github.com/filecoin-project/specs-actors/v5/support/mock" ) func TestExports(t *testing.T) { diff --git a/actors/builtin/testing_test.go b/actors/builtin/testing_test.go index 113b1a2ec..62dad24e2 100644 --- a/actors/builtin/testing_test.go +++ b/actors/builtin/testing_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" ) func TestMessageAccumulator(t *testing.T) { diff --git a/actors/builtin/verifreg/testing.go b/actors/builtin/verifreg/testing.go index f68e3bbaf..fd4d1911d 100644 --- a/actors/builtin/verifreg/testing.go +++ b/actors/builtin/verifreg/testing.go @@ -5,8 +5,8 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) type StateSummary struct { diff --git a/actors/builtin/verifreg/verified_registry_actor.go b/actors/builtin/verifreg/verified_registry_actor.go index d599a6a3a..405f8535c 100644 --- a/actors/builtin/verifreg/verified_registry_actor.go +++ b/actors/builtin/verifreg/verified_registry_actor.go @@ -10,9 +10,9 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) type Actor struct{} @@ -182,18 +182,19 @@ func (a Actor) AddVerifiedClient(rt runtime.Runtime, params *AddVerifiedClientPa err = verifiers.Put(abi.AddrKey(verifier), &newVerifierCap) builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "failed to update new verifier cap (%d) for %v", newVerifierCap, verifier) - // This is a one-time, upfront allocation. - // This allowance cannot be changed by calls to AddVerifiedClient as long as the client has not been removed. - // If parties need more allowance, they need to create a new verified client or use up the the current allowance - // and then create a new verified client. - found, err = verifiedClients.Get(abi.AddrKey(client), nil) + var clientCap DataCap + found, err = verifiedClients.Get(abi.AddrKey(client), &clientCap) builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "failed to get verified client %v", client) + + // if verified client exists, add allowance to existing cap + // otherwise, create new client with allownace if found { - rt.Abortf(exitcode.ErrIllegalArgument, "verified client already exists: %v", client) + clientCap = big.Add(clientCap, params.Allowance) + } else { + clientCap = params.Allowance } - - err = verifiedClients.Put(abi.AddrKey(client), ¶ms.Allowance) - builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "failed to add verified client %v with cap %d", client, params.Allowance) + err = verifiedClients.Put(abi.AddrKey(client), &clientCap) + builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "failed to add verified client %v with cap %d", client, clientCap) st.Verifiers, err = verifiers.Root() builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "failed to flush verifiers") diff --git a/actors/builtin/verifreg/verified_registry_state.go b/actors/builtin/verifreg/verified_registry_state.go index 7512556e3..9e8958908 100644 --- a/actors/builtin/verifreg/verified_registry_state.go +++ b/actors/builtin/verifreg/verified_registry_state.go @@ -6,8 +6,8 @@ import ( cid "github.com/ipfs/go-cid" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) // DataCap is an integer number of bytes. diff --git a/actors/builtin/verifreg/verified_registry_test.go b/actors/builtin/verifreg/verified_registry_test.go index 5006a78dd..0ad16d405 100644 --- a/actors/builtin/verifreg/verified_registry_test.go +++ b/actors/builtin/verifreg/verified_registry_test.go @@ -11,11 +11,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/mock" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/verifreg" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/mock" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" ) func TestExports(t *testing.T) { @@ -251,12 +251,12 @@ func TestAddVerifiedClient(t *testing.T) { ac.addVerifier(rt, verifier2.Address, verifier2.Allowance) // add client 1 & 2 - ac.addVerifiedClient(rt, verifier.Address, c1.Address, c1.Allowance) - ac.addVerifiedClient(rt, verifier.Address, c2.Address, c2.Allowance) + ac.addVerifiedClient(rt, verifier.Address, c1.Address, c1.Allowance, c1.Allowance) + ac.addVerifiedClient(rt, verifier.Address, c2.Address, c2.Allowance, c2.Allowance) // add clients 3 & 4 - ac.addVerifiedClient(rt, verifier2.Address, c3.Address, c3.Allowance) - ac.addVerifiedClient(rt, verifier2.Address, c4.Address, c4.Allowance) + ac.addVerifiedClient(rt, verifier2.Address, c3.Address, c3.Allowance, c3.Allowance) + ac.addVerifiedClient(rt, verifier2.Address, c4.Address, c4.Allowance, c4.Allowance) // all clients should exist and verifiers should have no more allowance left assert.EqualValues(t, c1.Allowance, ac.getClientCap(rt, c1.Address)) @@ -281,7 +281,7 @@ func TestAddVerifiedClient(t *testing.T) { ac.addVerifier(rt, verifier.Address, verifier.Allowance) // add client 1 works - ac.addVerifiedClient(rt, verifier.Address, c1.Address, c1.Allowance) + ac.addVerifiedClient(rt, verifier.Address, c1.Address, c1.Allowance, c1.Allowance) // add client 2 fails rt.SetCaller(verifier.Address, builtin.VerifiedRegistryActorCodeID) @@ -308,18 +308,18 @@ func TestAddVerifiedClient(t *testing.T) { verifier := mkVerifierParams(verifierAddr, allowance) ac.addVerifier(rt, verifier.Address, verifier.Allowance) - ac.addVerifiedClient(rt, verifier.Address, c1.Address, c1.Allowance) + ac.addVerifiedClient(rt, verifier.Address, c1.Address, c1.Allowance, c1.Allowance) assert.EqualValues(t, clientAllowance, ac.getClientCap(rt, clientIdAddr)) - // adding another verified client with the same ID address now fails + // adding another verified client with the same ID address increments + // the data cap which has already been granted c2 := mkClientParams(clientIdAddr, clientAllowance) verifier = mkVerifierParams(verifierAddr, allowance) ac.addVerifier(rt, verifier.Address, verifier.Allowance) - rt.ExpectAbort(exitcode.ErrIllegalArgument, func() { - ac.addVerifiedClient(rt, verifier.Address, c2.Address, c2.Allowance) - }) + expectedAllowance := big.Add(c1.Allowance, c2.Allowance) + ac.addVerifiedClient(rt, verifier.Address, c2.Address, c2.Allowance, expectedAllowance) ac.checkState(rt) }) @@ -333,7 +333,7 @@ func TestAddVerifiedClient(t *testing.T) { ac.addVerifier(rt, verifier.Address, verifier.Allowance) // add client works - ac.addVerifiedClient(rt, verifier.Address, c1.Address, c1.Allowance) + ac.addVerifiedClient(rt, verifier.Address, c1.Address, c1.Allowance, c1.Allowance) ac.checkState(rt) }) @@ -349,7 +349,7 @@ func TestAddVerifiedClient(t *testing.T) { rt.ExpectSend(clientNonIdAddr, builtin.MethodSend, nil, abi.NewTokenAmount(0), nil, exitcode.Ok) rt.ExpectAbort(exitcode.ErrIllegalState, func() { - ac.addVerifiedClient(rt, verifier.Address, c1.Address, c1.Allowance) + ac.addVerifiedClient(rt, verifier.Address, c1.Address, c1.Allowance, c1.Allowance) }) ac.checkState(rt) }) @@ -397,24 +397,6 @@ func TestAddVerifiedClient(t *testing.T) { ac.checkState(rt) }) - t.Run("fails when verified client already exists", func(t *testing.T) { - rt, ac := basicVerifRegSetup(t, root) - - // add verified client with caller 1 - verifier := ac.addNewVerifier(rt, verifierAddr, allowance) - client := mkClientParams(clientAddr, clientAllowance) - ac.addVerifiedClient(rt, verifier.Address, client.Address, client.Allowance) - - // add verified client with caller 2 - verifier2 := ac.addNewVerifier(rt, verifierAddr, allowance) - rt.SetCaller(verifier2.Address, builtin.VerifiedRegistryActorCodeID) - rt.ExpectValidateCallerAny() - rt.ExpectAbort(exitcode.ErrIllegalArgument, func() { - rt.Call(ac.AddVerifiedClient, client) - }) - ac.checkState(rt) - }) - t.Run("fails when root is added as a verified client", func(t *testing.T) { rt, ac := basicVerifRegSetup(t, root) @@ -422,7 +404,7 @@ func TestAddVerifiedClient(t *testing.T) { client := mkClientParams(root, clientAllowance) rt.ExpectAbort(exitcode.ErrIllegalArgument, func() { - ac.addVerifiedClient(rt, verifier.Address, client.Address, client.Allowance) + ac.addVerifiedClient(rt, verifier.Address, client.Address, client.Allowance, client.Allowance) }) ac.checkState(rt) }) @@ -822,20 +804,20 @@ func (h *verifRegActorTestHarness) generateAndAddVerifierAndVerifiedClient(rt *m // add client client := mkClientParams(clientAddr, clientAllowance) client.Allowance = clientAllowance - h.addVerifiedClient(rt, verifier.Address, client.Address, client.Allowance) + h.addVerifiedClient(rt, verifier.Address, client.Address, client.Allowance, client.Allowance) } -func (h *verifRegActorTestHarness) addVerifiedClient(rt *mock.Runtime, verifier, client address.Address, allowance verifreg.DataCap) { +func (h *verifRegActorTestHarness) addVerifiedClient(rt *mock.Runtime, verifier, client address.Address, allowanceAdded, totalAllowance verifreg.DataCap) { rt.SetCaller(verifier, builtin.VerifiedRegistryActorCodeID) rt.ExpectValidateCallerAny() - params := &verifreg.AddVerifiedClientParams{Address: client, Allowance: allowance} + params := &verifreg.AddVerifiedClientParams{Address: client, Allowance: allowanceAdded} rt.Call(h.AddVerifiedClient, params) rt.Verify() clientIdAddr, found := rt.GetIdAddr(client) require.True(h.t, found) - assert.EqualValues(h.t, allowance, h.getClientCap(rt, clientIdAddr)) + assert.EqualValues(h.t, totalAllowance, h.getClientCap(rt, clientIdAddr)) } func (h *verifRegActorTestHarness) addVerifier(rt *mock.Runtime, verifier address.Address, datacap verifreg.DataCap) { diff --git a/actors/migration/nv10/init.go b/actors/migration/nv10/init.go deleted file mode 100644 index 0c5eb9c1e..000000000 --- a/actors/migration/nv10/init.go +++ /dev/null @@ -1,41 +0,0 @@ -package nv10 - -import ( - "context" - - init2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/init" - cid "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" - - builtin3 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - init3 "github.com/filecoin-project/specs-actors/v4/actors/builtin/init" -) - -type initMigrator struct{} - -func (m initMigrator) migrateState(ctx context.Context, store cbor.IpldStore, in actorMigrationInput) (*actorMigrationResult, error) { - var inState init2.State - if err := store.Get(ctx, in.head, &inState); err != nil { - return nil, err - } - - addressMapOut, err := migrateHAMTRaw(ctx, store, inState.AddressMap, builtin3.DefaultHamtBitwidth) - if err != nil { - return nil, err - } - - outState := init3.State{ - AddressMap: addressMapOut, - NextID: inState.NextID, - NetworkName: inState.NetworkName, - } - newHead, err := store.Put(ctx, &outState) - return &actorMigrationResult{ - newCodeCID: m.migratedCodeCID(), - newHead: newHead, - }, err -} - -func (m initMigrator) migratedCodeCID() cid.Cid { - return builtin3.InitActorCodeID -} diff --git a/actors/migration/nv10/market.go b/actors/migration/nv10/market.go deleted file mode 100644 index dea783b17..000000000 --- a/actors/migration/nv10/market.go +++ /dev/null @@ -1,106 +0,0 @@ -package nv10 - -import ( - "context" - - cid "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" - - market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" - adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" - - builtin3 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - market3 "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - adt3 "github.com/filecoin-project/specs-actors/v4/actors/util/adt" -) - -type marketMigrator struct{} - -func (m marketMigrator) migrateState(ctx context.Context, store cbor.IpldStore, in actorMigrationInput) (*actorMigrationResult, error) { - var inState market2.State - if err := store.Get(ctx, in.head, &inState); err != nil { - return nil, err - } - - pendingProposalsCidOut, err := m.MapPendingProposals(ctx, store, inState.PendingProposals) - if err != nil { - return nil, err - } - proposalsCidOut, err := migrateAMTRaw(ctx, store, inState.Proposals, market3.ProposalsAmtBitwidth) - if err != nil { - return nil, err - } - statesCidOut, err := migrateAMTRaw(ctx, store, inState.States, market3.StatesAmtBitwidth) - if err != nil { - return nil, err - } - escrowTableCidOut, err := migrateHAMTRaw(ctx, store, inState.EscrowTable, adt3.BalanceTableBitwidth) - if err != nil { - return nil, err - } - lockedTableCidOut, err := migrateHAMTRaw(ctx, store, inState.LockedTable, adt3.BalanceTableBitwidth) - if err != nil { - return nil, err - } - dobeCidOut, err := migrateHAMTHAMTRaw(ctx, store, inState.DealOpsByEpoch, builtin3.DefaultHamtBitwidth, builtin3.DefaultHamtBitwidth) - if err != nil { - return nil, err - } - - outState := market3.State{ - Proposals: proposalsCidOut, - States: statesCidOut, - PendingProposals: pendingProposalsCidOut, - EscrowTable: escrowTableCidOut, - LockedTable: lockedTableCidOut, - NextID: inState.NextID, - DealOpsByEpoch: dobeCidOut, - LastCron: inState.LastCron, - TotalClientLockedCollateral: inState.TotalClientLockedCollateral, - TotalProviderLockedCollateral: inState.TotalProviderLockedCollateral, - TotalClientStorageFee: inState.TotalClientStorageFee, - } - - newHead, err := store.Put(ctx, &outState) - return &actorMigrationResult{ - newCodeCID: m.migratedCodeCID(), - newHead: newHead, - }, err -} - -func (m marketMigrator) migratedCodeCID() cid.Cid { - return builtin3.StorageMarketActorCodeID -} - -func (a marketMigrator) MapPendingProposals(ctx context.Context, store cbor.IpldStore, pendingProposalsRoot cid.Cid) (cid.Cid, error) { - oldPendingProposals, err := adt2.AsMap(adt2.WrapStore(ctx, store), pendingProposalsRoot) - if err != nil { - return cid.Undef, err - } - - newPendingProposals, err := adt3.MakeEmptySet(adt3.WrapStore(ctx, store), builtin3.DefaultHamtBitwidth) - if err != nil { - return cid.Undef, err - } - - err = oldPendingProposals.ForEach(nil, func(key string) error { - return newPendingProposals.Put(StringKey(key)) - }) - if err != nil { - return cid.Undef, err - } - - newPendingProposalsCid, err := newPendingProposals.Root() - if err != nil { - return cid.Undef, err - } - - return newPendingProposalsCid, nil -} - -// An adt.Map key that just preserves the underlying string. -type StringKey string - -func (k StringKey) Key() string { - return string(k) -} diff --git a/actors/migration/nv10/miner.go b/actors/migration/nv10/miner.go deleted file mode 100644 index 474b30655..000000000 --- a/actors/migration/nv10/miner.go +++ /dev/null @@ -1,228 +0,0 @@ -package nv10 - -import ( - "context" - - "github.com/filecoin-project/go-bitfield" - cid "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" - "golang.org/x/xerrors" - - miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" - adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" - - builtin3 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - miner3 "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - adt3 "github.com/filecoin-project/specs-actors/v4/actors/util/adt" -) - -type minerMigrator struct{} - -func (m minerMigrator) migrateState(ctx context.Context, store cbor.IpldStore, in actorMigrationInput) (*actorMigrationResult, error) { - var inState miner2.State - if err := store.Get(ctx, in.head, &inState); err != nil { - return nil, err - } - - infoOut, err := m.migrateInfo(ctx, store, inState.Info) - if err != nil { - return nil, err - } - preCommittedSectorsOut, err := migrateHAMTRaw(ctx, store, inState.PreCommittedSectors, builtin3.DefaultHamtBitwidth) - if err != nil { - return nil, err - } - preCommittedSectorsExpiryOut, err := migrateAMTRaw(ctx, store, inState.PreCommittedSectorsExpiry, miner3.PrecommitExpiryAmtBitwidth) - if err != nil { - return nil, err - } - - sectorsOut, err := in.cache.Load(SectorsRootKey(inState.Sectors), func() (cid.Cid, error) { - return migrateAMTRaw(ctx, store, inState.Sectors, miner3.SectorsAmtBitwidth) - }) - if err != nil { - return nil, err - } - - deadlinesOut, err := m.migrateDeadlines(ctx, store, in.cache, inState.Deadlines) - if err != nil { - return nil, err - } - - outState := miner3.State{ - Info: infoOut, - PreCommitDeposits: inState.PreCommitDeposits, - LockedFunds: inState.LockedFunds, - VestingFunds: inState.VestingFunds, - FeeDebt: inState.FeeDebt, - InitialPledge: inState.InitialPledge, - PreCommittedSectors: preCommittedSectorsOut, - PreCommittedSectorsExpiry: preCommittedSectorsExpiryOut, - AllocatedSectors: inState.AllocatedSectors, - Sectors: sectorsOut, - ProvingPeriodStart: inState.ProvingPeriodStart, - CurrentDeadline: inState.CurrentDeadline, - Deadlines: deadlinesOut, - EarlyTerminations: inState.EarlyTerminations, - } - newHead, err := store.Put(ctx, &outState) - return &actorMigrationResult{ - newCodeCID: m.migratedCodeCID(), - newHead: newHead, - }, err -} - -func (m minerMigrator) migratedCodeCID() cid.Cid { - return builtin3.StorageMinerActorCodeID -} - -func (m *minerMigrator) migrateInfo(ctx context.Context, store cbor.IpldStore, c cid.Cid) (cid.Cid, error) { - var oldInfo miner2.MinerInfo - err := store.Get(ctx, c, &oldInfo) - if err != nil { - return cid.Undef, err - } - - var newWorkerKeyChange *miner3.WorkerKeyChange - if oldInfo.PendingWorkerKey != nil { - newWorkerKeyChange = &miner3.WorkerKeyChange{ - NewWorker: oldInfo.PendingWorkerKey.NewWorker, - EffectiveAt: oldInfo.PendingWorkerKey.EffectiveAt, - } - } - - windowPoStProof, err := oldInfo.SealProofType.RegisteredWindowPoStProof() - if err != nil { - return cid.Undef, err - } - - newInfo := miner3.MinerInfo{ - Owner: oldInfo.Owner, - Worker: oldInfo.Worker, - ControlAddresses: oldInfo.ControlAddresses, - PendingWorkerKey: newWorkerKeyChange, - PeerId: oldInfo.PeerId, - Multiaddrs: oldInfo.Multiaddrs, - WindowPoStProofType: windowPoStProof, - SectorSize: oldInfo.SectorSize, - WindowPoStPartitionSectors: oldInfo.WindowPoStPartitionSectors, - ConsensusFaultElapsed: oldInfo.ConsensusFaultElapsed, - PendingOwnerAddress: oldInfo.PendingOwnerAddress, - } - return store.Put(ctx, &newInfo) -} - -func (m *minerMigrator) migrateDeadlines(ctx context.Context, store cbor.IpldStore, cache MigrationCache, deadlines cid.Cid) (cid.Cid, error) { - var inDeadlines miner2.Deadlines - err := store.Get(ctx, deadlines, &inDeadlines) - if err != nil { - return cid.Undef, err - } - - if miner2.WPoStPeriodDeadlines != miner3.WPoStPeriodDeadlines { - return cid.Undef, xerrors.Errorf("unexpected WPoStPeriodDeadlines changed from %d to %d", - miner2.WPoStPeriodDeadlines, miner3.WPoStPeriodDeadlines) - } - - outDeadlines := miner3.Deadlines{Due: [miner3.WPoStPeriodDeadlines]cid.Cid{}} - - // Start from an empty template to zero-initialize new fields. - deadlineTemplate, err := miner3.ConstructDeadline(adt3.WrapStore(ctx, store)) - if err != nil { - return cid.Undef, xerrors.Errorf("failed to construct new deadline template") - } - - for i, c := range inDeadlines.Due { - outDlCid, err := cache.Load(DeadlineKey(c), func() (cid.Cid, error) { - var inDeadline miner2.Deadline - if err = store.Get(ctx, c, &inDeadline); err != nil { - return cid.Undef, err - } - - partitions, err := m.migratePartitions(ctx, store, inDeadline.Partitions) - if err != nil { - return cid.Undef, xerrors.Errorf("partitions: %w", err) - } - - expirationEpochs, err := migrateAMTRaw(ctx, store, inDeadline.ExpirationsEpochs, miner3.DeadlineExpirationAmtBitwidth) - if err != nil { - return cid.Undef, xerrors.Errorf("bitfield queue: %w", err) - } - - outDeadline := *deadlineTemplate - outDeadline.Partitions = partitions - outDeadline.ExpirationsEpochs = expirationEpochs - outDeadline.PartitionsPoSted = inDeadline.PostSubmissions - outDeadline.EarlyTerminations = inDeadline.EarlyTerminations - outDeadline.LiveSectors = inDeadline.LiveSectors - outDeadline.TotalSectors = inDeadline.TotalSectors - outDeadline.FaultyPower = miner3.PowerPair(inDeadline.FaultyPower) - - // If there are no live sectors in this partition, zero out the "partitions - // posted" bitfield. This corrects a state issue where: - // 1. A proof is submitted and a partition is marked as proven. - // 2. All sectors in a deadline are terminated during the challenge window. - // 3. The end of deadline logic is skipped because there are no live sectors. - // This bug has been fixed in actors v3 (no terminations allowed during the - // challenge window) but the state still needs to be fixed. - // See: https://github.com/filecoin-project/specs-actors/issues/1348 - if outDeadline.LiveSectors == 0 { - outDeadline.PartitionsPoSted = bitfield.New() - } - - return store.Put(ctx, &outDeadline) - }) - if err != nil { - return cid.Undef, err - } - - outDeadlines.Due[i] = outDlCid - } - - return store.Put(ctx, &outDeadlines) -} - -func (m *minerMigrator) migratePartitions(ctx context.Context, store cbor.IpldStore, root cid.Cid) (cid.Cid, error) { - // AMT[PartitionNumber]Partition - inArray, err := adt2.AsArray(adt2.WrapStore(ctx, store), root) - if err != nil { - return cid.Undef, err - } - outArray, err := adt3.MakeEmptyArray(adt2.WrapStore(ctx, store), miner3.DeadlinePartitionsAmtBitwidth) - if err != nil { - return cid.Undef, err - } - - var inPartition miner2.Partition - if err = inArray.ForEach(&inPartition, func(i int64) error { - expirationEpochs, err := migrateAMTRaw(ctx, store, inPartition.ExpirationsEpochs, miner3.PartitionExpirationAmtBitwidth) - if err != nil { - return xerrors.Errorf("expiration queue: %w", err) - } - - earlyTerminated, err := migrateAMTRaw(ctx, store, inPartition.EarlyTerminated, miner3.PartitionEarlyTerminationArrayAmtBitwidth) - if err != nil { - return xerrors.Errorf("early termination queue: %w", err) - } - - outPartition := miner3.Partition{ - Sectors: inPartition.Sectors, - Unproven: inPartition.Unproven, - Faults: inPartition.Faults, - Recoveries: inPartition.Recoveries, - Terminated: inPartition.Terminated, - ExpirationsEpochs: expirationEpochs, - EarlyTerminated: earlyTerminated, - LivePower: miner3.PowerPair(inPartition.LivePower), - UnprovenPower: miner3.PowerPair(inPartition.UnprovenPower), - FaultyPower: miner3.PowerPair(inPartition.FaultyPower), - RecoveringPower: miner3.PowerPair(inPartition.RecoveringPower), - } - - return outArray.Set(uint64(i), &outPartition) - }); err != nil { - return cid.Undef, err - } - - return outArray.Root() -} diff --git a/actors/migration/nv10/multisig.go b/actors/migration/nv10/multisig.go deleted file mode 100644 index 855714bb1..000000000 --- a/actors/migration/nv10/multisig.go +++ /dev/null @@ -1,45 +0,0 @@ -package nv10 - -import ( - "context" - - multisig2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/multisig" - cid "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" - - builtin3 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - multisig3 "github.com/filecoin-project/specs-actors/v4/actors/builtin/multisig" -) - -type multisigMigrator struct{} - -func (m multisigMigrator) migrateState(ctx context.Context, store cbor.IpldStore, in actorMigrationInput) (*actorMigrationResult, error) { - var inState multisig2.State - if err := store.Get(ctx, in.head, &inState); err != nil { - return nil, err - } - - pendingTxnsOut, err := migrateHAMTRaw(ctx, store, inState.PendingTxns, builtin3.DefaultHamtBitwidth) - if err != nil { - return nil, err - } - - outState := multisig3.State{ - Signers: inState.Signers, - NumApprovalsThreshold: inState.NumApprovalsThreshold, - NextTxnID: inState.NextTxnID, - InitialBalance: inState.InitialBalance, - StartEpoch: inState.StartEpoch, - UnlockDuration: inState.UnlockDuration, - PendingTxns: pendingTxnsOut, - } - newHead, err := store.Put(ctx, &outState) - return &actorMigrationResult{ - newCodeCID: m.migratedCodeCID(), - newHead: newHead, - }, err -} - -func (m multisigMigrator) migratedCodeCID() cid.Cid { - return builtin3.MultisigActorCodeID -} diff --git a/actors/migration/nv10/paych.go b/actors/migration/nv10/paych.go deleted file mode 100644 index cf04fce3b..000000000 --- a/actors/migration/nv10/paych.go +++ /dev/null @@ -1,44 +0,0 @@ -package nv10 - -import ( - "context" - - paych2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/paych" - cid "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" - - builtin3 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - paych3 "github.com/filecoin-project/specs-actors/v4/actors/builtin/paych" -) - -type paychMigrator struct{} - -func (m paychMigrator) migrateState(ctx context.Context, store cbor.IpldStore, in actorMigrationInput) (*actorMigrationResult, error) { - var inState paych2.State - if err := store.Get(ctx, in.head, &inState); err != nil { - return nil, err - } - - laneStatesOut, err := migrateAMTRaw(ctx, store, inState.LaneStates, paych3.LaneStatesAmtBitwidth) - if err != nil { - return nil, err - } - - outState := paych3.State{ - From: inState.From, - To: inState.To, - ToSend: inState.ToSend, - SettlingAt: inState.SettlingAt, - MinSettleHeight: inState.MinSettleHeight, - LaneStates: laneStatesOut, - } - newHead, err := store.Put(ctx, &outState) - return &actorMigrationResult{ - newCodeCID: m.migratedCodeCID(), - newHead: newHead, - }, err -} - -func (m paychMigrator) migratedCodeCID() cid.Cid { - return builtin3.PaymentChannelActorCodeID -} diff --git a/actors/migration/nv10/power.go b/actors/migration/nv10/power.go deleted file mode 100644 index e2dd79a06..000000000 --- a/actors/migration/nv10/power.go +++ /dev/null @@ -1,99 +0,0 @@ -package nv10 - -import ( - "context" - - adt2 "github.com/filecoin-project/specs-actors/actors/util/adt" - power2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/power" - cid "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" - - builtin3 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - power3 "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - adt3 "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - smoothing3 "github.com/filecoin-project/specs-actors/v4/actors/util/smoothing" -) - -type powerMigrator struct{} - -func (m powerMigrator) migrateState(ctx context.Context, store cbor.IpldStore, in actorMigrationInput) (*actorMigrationResult, error) { - var inState power2.State - if err := store.Get(ctx, in.head, &inState); err != nil { - return nil, err - } - - var proofValidationBatchOut *cid.Cid - if inState.ProofValidationBatch != nil { - proofValidationBatchOutCID, err := migrateHAMTAMTRaw(ctx, store, *inState.ProofValidationBatch, builtin3.DefaultHamtBitwidth, power3.ProofValidationBatchAmtBitwidth) - if err != nil { - return nil, err - } - proofValidationBatchOut = &proofValidationBatchOutCID - } - - claimsOut, err := m.migrateClaims(ctx, store, inState.Claims) - if err != nil { - return nil, err - } - - cronEventQueueOut, err := migrateHAMTAMTRaw(ctx, store, inState.CronEventQueue, power3.CronQueueHamtBitwidth, power3.CronQueueAmtBitwidth) - if err != nil { - return nil, err - } - - outState := power3.State{ - TotalRawBytePower: inState.TotalRawBytePower, - TotalBytesCommitted: inState.TotalBytesCommitted, - TotalQualityAdjPower: inState.TotalQualityAdjPower, - TotalQABytesCommitted: inState.TotalQABytesCommitted, - TotalPledgeCollateral: inState.TotalPledgeCollateral, - ThisEpochRawBytePower: inState.ThisEpochRawBytePower, - ThisEpochQualityAdjPower: inState.ThisEpochQualityAdjPower, - ThisEpochPledgeCollateral: inState.ThisEpochPledgeCollateral, - ThisEpochQAPowerSmoothed: smoothing3.FilterEstimate(inState.ThisEpochQAPowerSmoothed), - MinerCount: inState.MinerCount, - MinerAboveMinPowerCount: inState.MinerAboveMinPowerCount, - CronEventQueue: cronEventQueueOut, - FirstCronEpoch: inState.FirstCronEpoch, - Claims: claimsOut, - ProofValidationBatch: proofValidationBatchOut, - } - newHead, err := store.Put(ctx, &outState) - return &actorMigrationResult{ - newCodeCID: m.migratedCodeCID(), - newHead: newHead, - }, err -} - -func (m powerMigrator) migratedCodeCID() cid.Cid { - return builtin3.StoragePowerActorCodeID -} - -func (m powerMigrator) migrateClaims(ctx context.Context, store cbor.IpldStore, root cid.Cid) (cid.Cid, error) { - astore := adt3.WrapStore(ctx, store) - inClaims, err := adt2.AsMap(astore, root) - if err != nil { - return cid.Undef, err - } - outClaims, err := adt3.MakeEmptyMap(astore, builtin3.DefaultHamtBitwidth) - if err != nil { - return cid.Undef, err - } - - var inClaim power2.Claim - if err = inClaims.ForEach(&inClaim, func(key string) error { - postProof, err := inClaim.SealProofType.RegisteredWindowPoStProof() - if err != nil { - return err - } - outClaim := power3.Claim{ - WindowPoStProofType: postProof, - RawBytePower: inClaim.RawBytePower, - QualityAdjPower: inClaim.QualityAdjPower, - } - return outClaims.Put(StringKey(key), &outClaim) - }); err != nil { - return cid.Undef, err - } - return outClaims.Root() -} diff --git a/actors/migration/nv10/test/modify_pending_proposals_test.go b/actors/migration/nv10/test/modify_pending_proposals_test.go deleted file mode 100644 index e10bd7416..000000000 --- a/actors/migration/nv10/test/modify_pending_proposals_test.go +++ /dev/null @@ -1,231 +0,0 @@ -package test_test - -import ( - "context" - "fmt" - "strings" - "testing" - - addr "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/go-state-types/crypto" - "github.com/filecoin-project/go-state-types/exitcode" - "github.com/filecoin-project/go-state-types/rt" - "github.com/ipfs/go-cid" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" - market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" - power2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/power" - ipld2 "github.com/filecoin-project/specs-actors/v2/support/ipld" - vm2 "github.com/filecoin-project/specs-actors/v2/support/vm" - - builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" - exported3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/exported" - market3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/market" - miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v3/actors/migration/nv10" - states3 "github.com/filecoin-project/specs-actors/v3/actors/states" - tutil "github.com/filecoin-project/specs-actors/v3/support/testing" - vm3 "github.com/filecoin-project/specs-actors/v3/support/vm" -) - -func TestUpdatePendingDealsMigration(t *testing.T) { - ctx := context.Background() - log := nv10.TestLogger{TB: t} - v := vm2.NewVMWithSingletons(ctx, t, ipld2.NewSyncBlockStoreInMemory()) - addrs := vm2.CreateAccounts(ctx, t, v, 10, big.Mul(big.NewInt(100_000), vm2.FIL), 93837778) - worker := addrs[0] - - minerBalance := big.Mul(big.NewInt(10_000), vm2.FIL) - - // create miner - params := power2.CreateMinerParams{ - Owner: worker, - Worker: worker, - SealProofType: abi.RegisteredSealProof_StackedDrg32GiBV1_1, - Peer: abi.PeerID("not really a peer id"), - } - ret := vm2.ApplyOk(t, v, addrs[0], builtin2.StoragePowerActorAddr, minerBalance, builtin2.MethodsPower.CreateMiner, ¶ms) - - minerAddrs, ok := ret.(*power2.CreateMinerReturn) - require.True(t, ok) - - // add market collateral for clients and miner - for i := 0; i < 9; i++ { - collateral := big.Mul(big.NewInt(30), vm2.FIL) - vm2.ApplyOk(t, v, addrs[i+1], builtin2.StorageMarketActorAddr, collateral, builtin2.MethodsMarket.AddBalance, &addrs[i+1]) - collateral = big.Mul(big.NewInt(64), vm2.FIL) - vm2.ApplyOk(t, v, worker, builtin2.StorageMarketActorAddr, collateral, builtin2.MethodsMarket.AddBalance, &minerAddrs.IDAddress) - } - - // create 100 deals over 100 epochs to fill pending proposals structure - dealStart := abi.ChainEpoch(252) - var deals []*market2.PublishStorageDealsReturn - for i := 0; i < 100; i++ { - var err error - v, err = v.WithEpoch(v.GetEpoch() + 1) - require.NoError(t, err) - deals = append(deals, publishDeal(t, v, worker, addrs[1+i%9], minerAddrs.IDAddress, fmt.Sprintf("deal%d", i), - 1<<26, false, dealStart, 210*builtin2.EpochsInDay)) - } - - // run migration - nextRoot, err := nv10.MigrateStateTree(ctx, v.Store(), v.StateRoot(), v.GetEpoch(), nv10.Config{MaxWorkers: 1}, log, nv10.NewMemMigrationCache()) - require.NoError(t, err) - - lookup := map[cid.Cid]rt.VMActor{} - for _, ba := range exported3.BuiltinActors() { - lookup[ba.Code()] = ba - } - - v3, err := vm3.NewVMAtEpoch(ctx, lookup, v.Store(), nextRoot, v.GetEpoch()+1) - require.NoError(t, err) - - // add 10 more deals after migration - for i := 0; i < 10; i++ { - var err error - v3, err = v3.WithEpoch(v.GetEpoch() + 1) - require.NoError(t, err) - - deals = append(deals, publishV3Deal(t, v3, worker, addrs[1+i%9], minerAddrs.IDAddress, fmt.Sprintf("deal1%d", i), - 1<<26, false, dealStart, 210*builtin3.EpochsInDay)) - } - - // add even deals to a sector we will commit (to let the odd deals expire) - var dealIDs []abi.DealID - for i := 0; i < len(deals); i += 2 { - dealIDs = append(dealIDs, deals[i].IDs[0]) - } - - // precommit capacity upgrade sector with deals - sectorNumber := abi.SectorNumber(100) - sealedCid := tutil.MakeCID("100", &miner3.SealedCIDPrefix) - sealProof := abi.RegisteredSealProof_StackedDrg32GiBV1_1 - preCommitParams := miner3.PreCommitSectorParams{ - SealProof: sealProof, - SectorNumber: sectorNumber, - SealedCID: sealedCid, - SealRandEpoch: v.GetEpoch() - 1, - DealIDs: dealIDs, - Expiration: v.GetEpoch() + 220*builtin3.EpochsInDay, - } - vm3.ApplyOk(t, v3, addrs[0], minerAddrs.RobustAddress, big.Zero(), builtin3.MethodsMiner.PreCommitSector, &preCommitParams) - - // advance time to min seal duration - proveTime := v3.GetEpoch() + miner3.PreCommitChallengeDelay + 1 - v3, _ = vm3.AdvanceByDeadlineTillEpoch(t, v3, minerAddrs.IDAddress, proveTime) - - // Prove commit sector after max seal duration - v3, err = v3.WithEpoch(proveTime) - require.NoError(t, err) - proveCommitParams := miner3.ProveCommitSectorParams{ - SectorNumber: sectorNumber, - } - vm3.ApplyOk(t, v3, worker, minerAddrs.RobustAddress, big.Zero(), builtin3.MethodsMiner.ProveCommitSector, &proveCommitParams) - - // In the same epoch, trigger cron to validate prove commit - // This activates deals hitting the pending deals structure. - vm3.ApplyOk(t, v3, builtin3.SystemActorAddr, builtin3.CronActorAddr, big.Zero(), builtin3.MethodsCron.EpochTick, nil) - - // Run cron after deal start to expire pending deals - v3, err = v3.WithEpoch(dealStart + 1) - require.NoError(t, err) - vm3.ApplyOk(t, v3, builtin3.SystemActorAddr, builtin3.CronActorAddr, big.Zero(), builtin3.MethodsCron.EpochTick, nil) - - // Assert that no invariants are broken. CheckStateInvariants used to assert that Pending Proposal value cid - // matched its key, so this also checks that the market invariants have been corrected. - stateTree, err := v3.GetStateTree() - require.NoError(t, err) - totalBalance, err := v3.GetTotalActorBalance() - require.NoError(t, err) - msgs, err := states3.CheckStateInvariants(stateTree, totalBalance, v3.GetEpoch()) - require.NoError(t, err) - - assert.Equal(t, 0, len(msgs.Messages()), strings.Join(msgs.Messages(), "\n")) - -} - -func publishDeal(t *testing.T, v *vm2.VM, provider, dealClient, minerID addr.Address, dealLabel string, - pieceSize abi.PaddedPieceSize, verifiedDeal bool, dealStart abi.ChainEpoch, dealLifetime abi.ChainEpoch, -) *market2.PublishStorageDealsReturn { - deal := market2.DealProposal{ - PieceCID: tutil.MakeCID(dealLabel, &market2.PieceCIDPrefix), - PieceSize: pieceSize, - VerifiedDeal: verifiedDeal, - Client: dealClient, - Provider: minerID, - Label: dealLabel, - StartEpoch: dealStart, - EndEpoch: dealStart + dealLifetime, - StoragePricePerEpoch: abi.NewTokenAmount(1 << 20), - ProviderCollateral: big.Mul(big.NewInt(2), vm2.FIL), - ClientCollateral: big.Mul(big.NewInt(1), vm2.FIL), - } - - publishDealParams := market2.PublishStorageDealsParams{ - Deals: []market2.ClientDealProposal{{ - Proposal: deal, - ClientSignature: crypto.Signature{}, - }}, - } - ret, code := v.ApplyMessage(provider, builtin2.StorageMarketActorAddr, big.Zero(), builtin2.MethodsMarket.PublishStorageDeals, &publishDealParams) - require.Equal(t, exitcode.Ok, code) - - expectedPublishSubinvocations := []vm2.ExpectInvocation{ - {To: minerID, Method: builtin2.MethodsMiner.ControlAddresses, SubInvocations: []vm2.ExpectInvocation{}}, - {To: builtin2.RewardActorAddr, Method: builtin2.MethodsReward.ThisEpochReward, SubInvocations: []vm2.ExpectInvocation{}}, - {To: builtin2.StoragePowerActorAddr, Method: builtin2.MethodsPower.CurrentTotalPower, SubInvocations: []vm2.ExpectInvocation{}}, - } - - vm2.ExpectInvocation{ - To: builtin2.StorageMarketActorAddr, - Method: builtin2.MethodsMarket.PublishStorageDeals, - SubInvocations: expectedPublishSubinvocations, - }.Matches(t, v.LastInvocation()) - - return ret.(*market2.PublishStorageDealsReturn) -} - -func publishV3Deal(t *testing.T, v *vm3.VM, provider, dealClient, minerID addr.Address, dealLabel string, - pieceSize abi.PaddedPieceSize, verifiedDeal bool, dealStart abi.ChainEpoch, dealLifetime abi.ChainEpoch, -) *market2.PublishStorageDealsReturn { - deal := market3.DealProposal{ - PieceCID: tutil.MakeCID(dealLabel, &market2.PieceCIDPrefix), - PieceSize: pieceSize, - VerifiedDeal: verifiedDeal, - Client: dealClient, - Provider: minerID, - Label: dealLabel, - StartEpoch: dealStart, - EndEpoch: dealStart + dealLifetime, - StoragePricePerEpoch: abi.NewTokenAmount(1 << 20), - ProviderCollateral: big.Mul(big.NewInt(2), vm2.FIL), - ClientCollateral: big.Mul(big.NewInt(1), vm2.FIL), - } - - publishDealParams := market3.PublishStorageDealsParams{ - Deals: []market3.ClientDealProposal{{ - Proposal: deal, - ClientSignature: crypto.Signature{}, - }}, - } - ret, code := v.ApplyMessage(provider, builtin3.StorageMarketActorAddr, big.Zero(), builtin3.MethodsMarket.PublishStorageDeals, &publishDealParams) - require.Equal(t, exitcode.Ok, code) - - expectedPublishSubinvocations := []vm3.ExpectInvocation{ - {To: minerID, Method: builtin3.MethodsMiner.ControlAddresses, SubInvocations: []vm3.ExpectInvocation{}}, - {To: builtin3.RewardActorAddr, Method: builtin3.MethodsReward.ThisEpochReward, SubInvocations: []vm3.ExpectInvocation{}}, - {To: builtin3.StoragePowerActorAddr, Method: builtin3.MethodsPower.CurrentTotalPower, SubInvocations: []vm3.ExpectInvocation{}}, - } - - vm3.ExpectInvocation{ - To: builtin3.StorageMarketActorAddr, - Method: builtin3.MethodsMarket.PublishStorageDeals, - SubInvocations: expectedPublishSubinvocations, - }.Matches(t, v.LastInvocation()) - - return ret.(*market2.PublishStorageDealsReturn) -} diff --git a/actors/migration/nv10/test/parallel_migration_test.go b/actors/migration/nv10/test/parallel_migration_test.go deleted file mode 100644 index 8d46f7d35..000000000 --- a/actors/migration/nv10/test/parallel_migration_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package test_test - -import ( - "context" - "testing" - - "github.com/filecoin-project/go-state-types/abi" - adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" - ipld2 "github.com/filecoin-project/specs-actors/v2/support/ipld" - vm2 "github.com/filecoin-project/specs-actors/v2/support/vm" - cid "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "golang.org/x/sync/errgroup" - - "github.com/filecoin-project/specs-actors/v4/actors/migration/nv10" -) - -func TestParallelMigrationCalls(t *testing.T) { - // Construct simple prior state tree over a synchronized store - ctx := context.Background() - log := nv10.TestLogger{TB: t} - bs := ipld2.NewSyncBlockStoreInMemory() - vm := vm2.NewVMWithSingletons(ctx, t, bs) - - // Run migration - adtStore := adt2.WrapStore(ctx, cbor.NewCborStore(bs)) - startRoot := vm.StateRoot() - endRootSerial, err := nv10.MigrateStateTree(ctx, adtStore, startRoot, abi.ChainEpoch(0), nv10.Config{MaxWorkers: 1}, log, nv10.NewMemMigrationCache()) - require.NoError(t, err) - - // Migrate in parallel - var endRootParallel1, endRootParallel2 cid.Cid - grp, ctx := errgroup.WithContext(ctx) - grp.Go(func() error { - var err1 error - endRootParallel1, err1 = nv10.MigrateStateTree(ctx, adtStore, startRoot, abi.ChainEpoch(0), nv10.Config{MaxWorkers: 2}, log, nv10.NewMemMigrationCache()) - return err1 - }) - grp.Go(func() error { - var err2 error - endRootParallel2, err2 = nv10.MigrateStateTree(ctx, adtStore, startRoot, abi.ChainEpoch(0), nv10.Config{MaxWorkers: 2}, log, nv10.NewMemMigrationCache()) - return err2 - }) - require.NoError(t, grp.Wait()) - assert.Equal(t, endRootSerial, endRootParallel1) - assert.Equal(t, endRootParallel1, endRootParallel2) -} diff --git a/actors/migration/nv10/test/util_test.go b/actors/migration/nv10/test/util_test.go deleted file mode 100644 index f198db518..000000000 --- a/actors/migration/nv10/test/util_test.go +++ /dev/null @@ -1,15 +0,0 @@ -package test_test - -import ( - "testing" - - "github.com/filecoin-project/go-state-types/rt" -) - -type TestLogger struct { - TB testing.TB -} - -func (t TestLogger) Log(_ rt.LogLevel, msg string, args ...interface{}) { - t.TB.Logf(msg, args...) -} diff --git a/actors/migration/nv10/top.go b/actors/migration/nv10/top.go deleted file mode 100644 index 03529d6ec..000000000 --- a/actors/migration/nv10/top.go +++ /dev/null @@ -1,330 +0,0 @@ -package nv10 - -import ( - "context" - "fmt" - "sync" - "sync/atomic" - "time" - - address "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/rt" - cid "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" - "golang.org/x/sync/errgroup" - "golang.org/x/xerrors" - - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" - states2 "github.com/filecoin-project/specs-actors/v2/actors/states" - - builtin3 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - states3 "github.com/filecoin-project/specs-actors/v4/actors/states" - adt3 "github.com/filecoin-project/specs-actors/v4/actors/util/adt" -) - -// Config parameterizes a state tree migration -type Config struct { - // Number of migration worker goroutines to run. - // More workers enables higher CPU utilization doing migration computations (including state encoding) - MaxWorkers uint - // Capacity of the queue of jobs available to workers (zero for unbuffered). - // A queue length of hundreds to thousands improves throughput at the cost of memory. - JobQueueSize uint - // Capacity of the queue receiving migration results from workers, for persisting (zero for unbuffered). - // A queue length of tens to hundreds improves throughput at the cost of memory. - ResultQueueSize uint - // Time between progress logs to emit. - // Zero (the default) results in no progress logs. - ProgressLogPeriod time.Duration -} - -type Logger interface { - // This is the same logging interface provided by the Runtime. - Log(level rt.LogLevel, msg string, args ...interface{}) -} - -func ActorHeadKey(addr address.Address, head cid.Cid) string { - return addr.String() + "-h-" + head.String() -} - -func DeadlineKey(dlCid cid.Cid) string { - return "d-" + dlCid.String() -} - -func SectorsRootKey(sCid cid.Cid) string { - return "s-" + sCid.String() -} - -// MigrationCache stores and loads cached data. Its implementation must be threadsafe -type MigrationCache interface { - Write(key string, newCid cid.Cid) error - Read(key string) (bool, cid.Cid, error) - Load(key string, loadFunc func() (cid.Cid, error)) (cid.Cid, error) -} - -// Migrates the filecoin state tree starting from the global state tree and upgrading all actor state. -// The store must support concurrent writes (even if the configured worker count is 1). -func MigrateStateTree(ctx context.Context, store cbor.IpldStore, actorsRootIn cid.Cid, priorEpoch abi.ChainEpoch, cfg Config, log Logger, cache MigrationCache) (cid.Cid, error) { - if cfg.MaxWorkers <= 0 { - return cid.Undef, xerrors.Errorf("invalid migration config with %d workers", cfg.MaxWorkers) - } - - // Maps prior version code CIDs to migration functions. - var migrations = map[cid.Cid]actorMigration{ - builtin2.AccountActorCodeID: nilMigrator{builtin3.AccountActorCodeID}, - builtin2.CronActorCodeID: nilMigrator{builtin3.CronActorCodeID}, - builtin2.InitActorCodeID: cachedMigration(cache, initMigrator{}), - builtin2.MultisigActorCodeID: cachedMigration(cache, multisigMigrator{}), - builtin2.PaymentChannelActorCodeID: cachedMigration(cache, paychMigrator{}), - builtin2.RewardActorCodeID: nilMigrator{builtin3.RewardActorCodeID}, - builtin2.StorageMarketActorCodeID: cachedMigration(cache, marketMigrator{}), - builtin2.StorageMinerActorCodeID: cachedMigration(cache, minerMigrator{}), - builtin2.StoragePowerActorCodeID: cachedMigration(cache, powerMigrator{}), - builtin2.SystemActorCodeID: nilMigrator{builtin3.SystemActorCodeID}, - builtin2.VerifiedRegistryActorCodeID: cachedMigration(cache, verifregMigrator{}), - } - // Set of prior version code CIDs for actors to defer during iteration, for explicit migration afterwards. - var deferredCodeIDs = map[cid.Cid]struct{}{ - // None - } - if len(migrations)+len(deferredCodeIDs) != 11 { - panic(fmt.Sprintf("incomplete migration specification with %d code CIDs", len(migrations))) - } - startTime := time.Now() - - // Load input and output state trees - adtStore := adt3.WrapStore(ctx, store) - actorsIn, err := states2.LoadTree(adtStore, actorsRootIn) - if err != nil { - return cid.Undef, err - } - actorsOut, err := states3.NewTree(adtStore) - if err != nil { - return cid.Undef, err - } - - // Setup synchronization - grp, ctx := errgroup.WithContext(ctx) - // Input and output queues for workers. - jobCh := make(chan *migrationJob, cfg.JobQueueSize) - jobResultCh := make(chan *migrationJobResult, cfg.ResultQueueSize) - // Atomically-modified counters for logging progress - var jobCount uint32 - var doneCount uint32 - - // Iterate all actors in old state root to create migration jobs for each non-deferred actor. - grp.Go(func() error { - defer close(jobCh) - log.Log(rt.INFO, "Creating migration jobs for tree %s", actorsRootIn) - if err = actorsIn.ForEach(func(addr address.Address, actorIn *states2.Actor) error { - if _, ok := deferredCodeIDs[actorIn.Code]; ok { - return nil // Deferred for explicit migration later. - } - nextInput := &migrationJob{ - Address: addr, - Actor: *actorIn, // Must take a copy, the pointer is not stable. - cache: cache, - actorMigration: migrations[actorIn.Code], - } - select { - case jobCh <- nextInput: - case <-ctx.Done(): - return ctx.Err() - } - atomic.AddUint32(&jobCount, 1) - return nil - }); err != nil { - return err - } - log.Log(rt.INFO, "Done creating %d migration jobs for tree %s after %v", jobCount, actorsRootIn, time.Since(startTime)) - return nil - }) - - // Worker threads run jobs. - var workerWg sync.WaitGroup - for i := uint(0); i < cfg.MaxWorkers; i++ { - workerWg.Add(1) - workerId := i - grp.Go(func() error { - defer workerWg.Done() - for job := range jobCh { - result, err := job.run(ctx, store, priorEpoch) - if err != nil { - return err - } - select { - case jobResultCh <- result: - case <-ctx.Done(): - return ctx.Err() - } - atomic.AddUint32(&doneCount, 1) - } - log.Log(rt.INFO, "Worker %d done", workerId) - return nil - }) - } - log.Log(rt.INFO, "Started %d workers", cfg.MaxWorkers) - - // Monitor the job queue. This non-critical goroutine is outside the errgroup and exits when - // workersFinished is closed, or the context done. - workersFinished := make(chan struct{}) // Closed when waitgroup is emptied. - if cfg.ProgressLogPeriod > 0 { - go func() { - defer log.Log(rt.DEBUG, "Job queue monitor done") - for { - select { - case <-time.After(cfg.ProgressLogPeriod): - jobsNow := jobCount // Snapshot values to avoid incorrect-looking arithmetic if they change. - doneNow := doneCount - pendingNow := jobsNow - doneNow - elapsed := time.Since(startTime) - rate := float64(doneNow) / elapsed.Seconds() - log.Log(rt.INFO, "%d jobs created, %d done, %d pending after %v (%.0f/s)", - jobsNow, doneNow, pendingNow, elapsed, rate) - case <-workersFinished: - return - case <-ctx.Done(): - return - } - } - }() - } - - // Close result channel when workers are done sending to it. - grp.Go(func() error { - workerWg.Wait() - close(jobResultCh) - close(workersFinished) - log.Log(rt.INFO, "All workers done after %v", time.Since(startTime)) - return nil - }) - - // Insert migrated records in output state tree and accumulators. - grp.Go(func() error { - log.Log(rt.INFO, "Result writer started") - resultCount := 0 - for result := range jobResultCh { - if err := actorsOut.SetActor(result.Address, &result.Actor); err != nil { - return err - } - resultCount++ - } - log.Log(rt.INFO, "Result writer wrote %d results to state tree after %v", resultCount, time.Since(startTime)) - return nil - }) - - if err := grp.Wait(); err != nil { - return cid.Undef, err - } - - // Perform any deferred migrations explicitly here. - // Deferred migrations might depend on values accumulated through migration of other actors. - - elapsed := time.Since(startTime) - rate := float64(doneCount) / elapsed.Seconds() - log.Log(rt.INFO, "All %d done after %v (%.0f/s). Flushing state tree root.", doneCount, elapsed, rate) - return actorsOut.Flush() -} - -type actorMigrationInput struct { - address address.Address // actor's address - balance abi.TokenAmount // actor's balance - head cid.Cid // actor's state head CID - priorEpoch abi.ChainEpoch // epoch of last state transition prior to migration - cache MigrationCache // cache of existing cid -> cid migrations for this actor -} - -type actorMigrationResult struct { - newCodeCID cid.Cid - newHead cid.Cid -} - -type actorMigration interface { - // Loads an actor's state from an input store and writes new state to an output store. - // Returns the new state head CID. - migrateState(ctx context.Context, store cbor.IpldStore, input actorMigrationInput) (result *actorMigrationResult, err error) - migratedCodeCID() cid.Cid -} - -type migrationJob struct { - address.Address - states2.Actor - actorMigration - cache MigrationCache -} -type migrationJobResult struct { - address.Address - states3.Actor -} - -func (job *migrationJob) run(ctx context.Context, store cbor.IpldStore, priorEpoch abi.ChainEpoch) (*migrationJobResult, error) { - result, err := job.migrateState(ctx, store, actorMigrationInput{ - address: job.Address, - balance: job.Actor.Balance, - head: job.Actor.Head, - priorEpoch: priorEpoch, - cache: job.cache, - }) - if err != nil { - return nil, xerrors.Errorf("state migration failed for %s actor, addr %s: %w", - builtin2.ActorNameByCode(job.Actor.Code), job.Address, err) - } - - // Set up new actor record with the migrated state. - return &migrationJobResult{ - job.Address, // Unchanged - states3.Actor{ - Code: result.newCodeCID, - Head: result.newHead, - CallSeqNum: job.Actor.CallSeqNum, // Unchanged - Balance: job.Actor.Balance, // Unchanged - }, - }, nil -} - -// Migrator which preserves the head CID and provides a fixed result code CID. -type nilMigrator struct { - OutCodeCID cid.Cid -} - -func (n nilMigrator) migrateState(_ context.Context, _ cbor.IpldStore, in actorMigrationInput) (*actorMigrationResult, error) { - return &actorMigrationResult{ - newCodeCID: n.OutCodeCID, - newHead: in.head, - }, nil -} - -func (n nilMigrator) migratedCodeCID() cid.Cid { - return n.OutCodeCID -} - -// Migrator that uses cached transformation if it exists -type cachedMigrator struct { - cache MigrationCache - actorMigration -} - -func (c cachedMigrator) migrateState(ctx context.Context, store cbor.IpldStore, in actorMigrationInput) (*actorMigrationResult, error) { - newHead, err := c.cache.Load(ActorHeadKey(in.address, in.head), func() (cid.Cid, error) { - result, err := c.actorMigration.migrateState(ctx, store, in) - if err != nil { - return cid.Undef, err - } - return result.newHead, nil - }) - if err != nil { - return nil, err - } - return &actorMigrationResult{ - newCodeCID: c.migratedCodeCID(), - newHead: newHead, - }, nil -} - -func cachedMigration(cache MigrationCache, m actorMigration) actorMigration { - return cachedMigrator{ - actorMigration: m, - cache: cache, - } -} diff --git a/actors/migration/nv10/util.go b/actors/migration/nv10/util.go deleted file mode 100644 index ed56e6ea0..000000000 --- a/actors/migration/nv10/util.go +++ /dev/null @@ -1,199 +0,0 @@ -package nv10 - -import ( - "bytes" - "context" - "sync" - "testing" - - amt2 "github.com/filecoin-project/go-amt-ipld/v2" - amt3 "github.com/filecoin-project/go-amt-ipld/v3" - hamt2 "github.com/filecoin-project/go-hamt-ipld/v2" - hamt3 "github.com/filecoin-project/go-hamt-ipld/v3" - "github.com/filecoin-project/go-state-types/rt" - adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" - cid "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" - cbg "github.com/whyrusleeping/cbor-gen" - "golang.org/x/xerrors" - - adt3 "github.com/filecoin-project/specs-actors/v4/actors/util/adt" -) - -// Migrates a HAMT from v2 to v3 without re-encoding keys or values. -func migrateHAMTRaw(ctx context.Context, store cbor.IpldStore, root cid.Cid, newBitwidth int) (cid.Cid, error) { - inRootNode, err := hamt2.LoadNode(ctx, store, root, adt2.HamtOptions...) - if err != nil { - return cid.Undef, err - } - - newOpts := append(adt3.DefaultHamtOptions, hamt3.UseTreeBitWidth(newBitwidth)) - outRootNode, err := hamt3.NewNode(store, newOpts...) - if err != nil { - return cid.Undef, err - } - - if err = inRootNode.ForEach(ctx, func(k string, val interface{}) error { - return outRootNode.SetRaw(ctx, k, val.(*cbg.Deferred).Raw) - }); err != nil { - return cid.Undef, err - } - - err = outRootNode.Flush(ctx) - if err != nil { - return cid.Undef, err - } - return store.Put(ctx, outRootNode) -} - -// Migrates an AMT from v2 to v3 without re-encoding values. -func migrateAMTRaw(ctx context.Context, store cbor.IpldStore, root cid.Cid, newBitwidth int) (cid.Cid, error) { - inRootNode, err := amt2.LoadAMT(ctx, store, root) - if err != nil { - return cid.Undef, err - } - - newOpts := append(adt3.DefaultAmtOptions, amt3.UseTreeBitWidth(uint(newBitwidth))) - outRootNode, err := amt3.NewAMT(store, newOpts...) - if err != nil { - return cid.Undef, err - } - - if err = inRootNode.ForEach(ctx, func(k uint64, d *cbg.Deferred) error { - return outRootNode.Set(ctx, k, d) - }); err != nil { - return cid.Undef, err - } - - return outRootNode.Flush(ctx) -} - -// Migrates a HAMT of HAMTs from v2 to v3 without re-encoding leaf keys or values. -func migrateHAMTHAMTRaw(ctx context.Context, store cbor.IpldStore, root cid.Cid, newOuterBitwidth, newInnerBitwidth int) (cid.Cid, error) { - inRootNodeOuter, err := hamt2.LoadNode(ctx, store, root) - if err != nil { - return cid.Undef, err - } - - newOptsOuter := append(adt3.DefaultHamtOptions, hamt3.UseTreeBitWidth(newOuterBitwidth)) - outRootNodeOuter, err := hamt3.NewNode(store, newOptsOuter...) - if err != nil { - return cid.Undef, err - } - - if err = inRootNodeOuter.ForEach(ctx, func(k string, val interface{}) error { - var inInner cbg.CborCid - if err := inInner.UnmarshalCBOR(bytes.NewReader(val.(*cbg.Deferred).Raw)); err != nil { - return err - } - outInner, err := migrateHAMTRaw(ctx, store, cid.Cid(inInner), newInnerBitwidth) - if err != nil { - return err - } - c := cbg.CborCid(outInner) - return outRootNodeOuter.Set(ctx, k, &c) - }); err != nil { - return cid.Undef, err - } - - if err := outRootNodeOuter.Flush(ctx); err != nil { - return cid.Undef, err - } - return store.Put(ctx, outRootNodeOuter) -} - -// Migrates a HAMT of AMTs from v2 to v3 without re-encoding values. -func migrateHAMTAMTRaw(ctx context.Context, store cbor.IpldStore, root cid.Cid, newOuterBitwidth, newInnerBitwidth int) (cid.Cid, error) { - inRootNodeOuter, err := hamt2.LoadNode(ctx, store, root) - if err != nil { - return cid.Undef, err - } - newOptsOuter := append(adt3.DefaultHamtOptions, hamt3.UseTreeBitWidth(newOuterBitwidth)) - outRootNodeOuter, err := hamt3.NewNode(store, newOptsOuter...) - if err != nil { - return cid.Undef, err - } - - if err = inRootNodeOuter.ForEach(ctx, func(k string, val interface{}) error { - var inInner cbg.CborCid - if err := inInner.UnmarshalCBOR(bytes.NewReader(val.(*cbg.Deferred).Raw)); err != nil { - return err - } - outInner, err := migrateAMTRaw(ctx, store, cid.Cid(inInner), newInnerBitwidth) - if err != nil { - return err - } - c := cbg.CborCid(outInner) - return outRootNodeOuter.Set(ctx, k, &c) - }); err != nil { - return cid.Undef, err - } - - if err := outRootNodeOuter.Flush(ctx); err != nil { - return cid.Undef, err - } - return store.Put(ctx, outRootNodeOuter) -} - -type MemMigrationCache struct { - MigrationMap sync.Map -} - -func NewMemMigrationCache() *MemMigrationCache { - return new(MemMigrationCache) -} - -func (m *MemMigrationCache) Write(key string, c cid.Cid) error { - m.MigrationMap.Store(key, c) - return nil -} - -func (m *MemMigrationCache) Read(key string) (bool, cid.Cid, error) { - val, found := m.MigrationMap.Load(key) - if !found { - return false, cid.Undef, nil - } - c, ok := val.(cid.Cid) - if !ok { - return false, cid.Undef, xerrors.Errorf("non cid value in cache") - } - - return true, c, nil -} - -func (m *MemMigrationCache) Load(key string, loadFunc func() (cid.Cid, error)) (cid.Cid, error) { - found, c, err := m.Read(key) - if err != nil { - return cid.Undef, err - } - if found { - return c, nil - } - c, err = loadFunc() - if err != nil { - return cid.Undef, err - } - m.MigrationMap.Store(key, c) - return c, nil -} - -func (m *MemMigrationCache) Clone() *MemMigrationCache { - newCache := NewMemMigrationCache() - newCache.Update(m) - return newCache -} - -func (m *MemMigrationCache) Update(other *MemMigrationCache) { - other.MigrationMap.Range(func(key, value interface{}) bool { - m.MigrationMap.Store(key, value) - return true - }) -} - -type TestLogger struct { - TB testing.TB -} - -func (t TestLogger) Log(_ rt.LogLevel, msg string, args ...interface{}) { - t.TB.Logf(msg, args...) -} diff --git a/actors/migration/nv10/util_test.go b/actors/migration/nv10/util_test.go deleted file mode 100644 index d16216e58..000000000 --- a/actors/migration/nv10/util_test.go +++ /dev/null @@ -1,55 +0,0 @@ -package nv10_test - -import ( - "testing" - - "github.com/filecoin-project/specs-actors/v4/actors/migration/nv10" - atesting "github.com/filecoin-project/specs-actors/v4/support/testing" - "github.com/stretchr/testify/require" -) - -func TestMemMigrationCache(t *testing.T) { - cache := nv10.NewMemMigrationCache() - cid1 := atesting.MakeCID("foo", nil) - cid2 := atesting.MakeCID("bar", nil) - require.NoError(t, cache.Write("first", cid1)) - - // We see the key we wrote. - found, result, err := cache.Read("first") - require.True(t, found) - require.NoError(t, err) - require.Equal(t, cid1, result) - - // Make sure we can't find random keys. - found, _, err = cache.Read("other") - require.False(t, found) - require.NoError(t, err) - - newCache := cache.Clone() - require.NoError(t, newCache.Write("second", cid2)) - - // We see both keys. - found, result, err = newCache.Read("first") - require.True(t, found) - require.NoError(t, err) - require.Equal(t, cid1, result) - - found, result, err = newCache.Read("second") - require.True(t, found) - require.NoError(t, err) - require.Equal(t, cid2, result) - - // But the original cache was not updated. - found, _, err = cache.Read("second") - require.False(t, found) - require.NoError(t, err) - - // Now write back to the original cache. - cache.Update(newCache) - - // And make sure that worked. - found, result, err = cache.Read("second") - require.True(t, found) - require.NoError(t, err) - require.Equal(t, cid2, result) -} diff --git a/actors/migration/nv10/verifreg.go b/actors/migration/nv10/verifreg.go deleted file mode 100644 index 471605611..000000000 --- a/actors/migration/nv10/verifreg.go +++ /dev/null @@ -1,46 +0,0 @@ -package nv10 - -import ( - "context" - - verifreg2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/verifreg" - cid "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" - - builtin3 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - verifreg3 "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg" -) - -type verifregMigrator struct{} - -func (m verifregMigrator) migrateState(ctx context.Context, store cbor.IpldStore, in actorMigrationInput) (*actorMigrationResult, error) { - var inState verifreg2.State - if err := store.Get(ctx, in.head, &inState); err != nil { - return nil, err - } - - verifiersCIDOut, err := migrateHAMTRaw(ctx, store, inState.Verifiers, builtin3.DefaultHamtBitwidth) - if err != nil { - return nil, err - } - verifiedClientsCIDOut, err := migrateHAMTRaw(ctx, store, inState.VerifiedClients, builtin3.DefaultHamtBitwidth) - if err != nil { - return nil, err - } - - outState := verifreg3.State{ - RootKey: inState.RootKey, - Verifiers: verifiersCIDOut, - VerifiedClients: verifiedClientsCIDOut, - } - - newHead, err := store.Put(ctx, &outState) - return &actorMigrationResult{ - newCodeCID: m.migratedCodeCID(), - newHead: newHead, - }, err -} - -func (m verifregMigrator) migratedCodeCID() cid.Cid { - return builtin3.VerifiedRegistryActorCodeID -} diff --git a/actors/migration/nv12/miner.go b/actors/migration/nv12/miner.go deleted file mode 100644 index b5ef86383..000000000 --- a/actors/migration/nv12/miner.go +++ /dev/null @@ -1,49 +0,0 @@ -package nv12 - -import ( - "context" - - miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner" - builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - miner4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" -) - -type minerMigrator struct{} - -func (m minerMigrator) migrateState(ctx context.Context, store cbor.IpldStore, in actorMigrationInput) (*actorMigrationResult, error) { - var inState miner3.State - if err := store.Get(ctx, in.head, &inState); err != nil { - return nil, err - } - - outState := miner4.State{ - // No change - Info: inState.Info, - PreCommitDeposits: inState.PreCommitDeposits, - LockedFunds: inState.LockedFunds, - VestingFunds: inState.VestingFunds, - FeeDebt: inState.FeeDebt, - InitialPledge: inState.InitialPledge, - PreCommittedSectors: inState.PreCommittedSectors, - PreCommittedSectorsExpiry: inState.PreCommittedSectorsExpiry, - AllocatedSectors: inState.AllocatedSectors, - Sectors: inState.Sectors, - ProvingPeriodStart: inState.ProvingPeriodStart, - CurrentDeadline: inState.CurrentDeadline, - Deadlines: inState.Deadlines, - EarlyTerminations: inState.EarlyTerminations, - // Changed field - DeadlineCronActive: true, - } - newHead, err := store.Put(ctx, &outState) - return &actorMigrationResult{ - newCodeCID: m.migratedCodeCID(), - newHead: newHead, - }, err -} - -func (m minerMigrator) migratedCodeCID() cid.Cid { - return builtin4.StorageMinerActorCodeID -} diff --git a/actors/migration/nv12/test/miner_cron_test.go b/actors/migration/nv12/test/miner_cron_test.go deleted file mode 100644 index bc6b67e90..000000000 --- a/actors/migration/nv12/test/miner_cron_test.go +++ /dev/null @@ -1,134 +0,0 @@ -package test_test - -import ( - "context" - "strings" - "testing" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/go-state-types/exitcode" - "github.com/filecoin-project/go-state-types/rt" - ipld2 "github.com/filecoin-project/specs-actors/v2/support/ipld" - builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" - power3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/power" - vm3 "github.com/filecoin-project/specs-actors/v3/support/vm" - "github.com/ipfs/go-cid" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - builtin "github.com/filecoin-project/specs-actors/v4/actors/builtin" - exported "github.com/filecoin-project/specs-actors/v4/actors/builtin/exported" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/migration/nv12" - "github.com/filecoin-project/specs-actors/v4/actors/states" - vm "github.com/filecoin-project/specs-actors/v4/support/vm" -) - -func TestEmptyMinersStopCronAfterMigration(t *testing.T) { - ctx := context.Background() - log := nv12.TestLogger{TB: t} - v := vm3.NewVMWithSingletons(ctx, t, ipld2.NewSyncBlockStoreInMemory()) - addrs := vm3.CreateAccounts(ctx, t, v, 110, big.Mul(big.NewInt(100_000), vm3.FIL), 93837779) - - // create empty miners - minerAddrs := make([]address.Address, 100) - for i := 0; i < 100; i++ { - worker := addrs[i] - minerBalance := big.Mul(big.NewInt(10_000), vm3.FIL) - - params := power3.CreateMinerParams{ - Owner: worker, - Worker: worker, - WindowPoStProofType: abi.RegisteredPoStProof_StackedDrgWindow32GiBV1, - Peer: abi.PeerID("fake peer id"), - } - ret := vm3.ApplyOk(t, v, worker, builtin3.StoragePowerActorAddr, minerBalance, builtin3.MethodsPower.CreateMiner, ¶ms) - createRet, ok := ret.(*power3.CreateMinerReturn) - require.True(t, ok) - minerAddrs[i] = createRet.IDAddress - } - // run network for a few proving periods - stop := v.GetEpoch() + abi.ChainEpoch(10_000) - v = AdvanceToEpochWithCronV3(t, v, stop) - - // migrate - nextRoot, err := nv12.MigrateStateTree(ctx, v.Store(), v.StateRoot(), v.GetEpoch(), nv12.Config{MaxWorkers: 1}, log, nv12.NewMemMigrationCache()) - require.NoError(t, err) - - lookup := map[cid.Cid]rt.VMActor{} - for _, ba := range exported.BuiltinActors() { - lookup[ba.Code()] = ba - } - v4, err := vm.NewVMAtEpoch(ctx, lookup, v.Store(), nextRoot, v.GetEpoch()) - require.NoError(t, err) - - // check that all miners are cronning - stateTree, err := v4.GetStateTree() - require.NoError(t, err) - err = stateTree.ForEach(func(addr address.Address, act *states.Actor) error { - if act.Code.Equals(builtin.StorageMinerActorCodeID) { - var mSt miner.State - err := v4.GetState(addr, &mSt) - require.NoError(t, err) - assert.True(t, mSt.DeadlineCronActive) - } - return nil - }) - require.NoError(t, err) - - // empty miners stop cronning within 1 proving period - v4 = AdvanceToEpochWithCron(t, v4, v4.GetEpoch()+miner.WPoStProvingPeriod) - - // check invariants - stateTree, err = v4.GetStateTree() - require.NoError(t, err) - totalBalance, err := v4.GetTotalActorBalance() - require.NoError(t, err) - msgs, err := states.CheckStateInvariants(stateTree, totalBalance, v4.GetEpoch()-1) - require.NoError(t, err) - - assert.Equal(t, 0, len(msgs.Messages()), strings.Join(msgs.Messages(), "\n")) - - // check that no miners are cronning - err = stateTree.ForEach(func(addr address.Address, act *states.Actor) error { - if act.Code.Equals(builtin.StorageMinerActorCodeID) { - var mSt miner.State - err := v4.GetState(addr, &mSt) - require.NoError(t, err) - assert.False(t, mSt.DeadlineCronActive) - } - return nil - }) - require.NoError(t, err) -} - -// Advances to given epoch running cron for all epochs up to but not including this epoch. -// This utility didn't exist in v3 vm utils so copying here after the fact to handle migrations. -func AdvanceToEpochWithCronV3(t *testing.T, v *vm3.VM, stop abi.ChainEpoch) *vm3.VM { - currEpoch := v.GetEpoch() - var err error - for currEpoch < stop { - _, code := v.ApplyMessage(builtin3.SystemActorAddr, builtin3.CronActorAddr, big.Zero(), builtin3.MethodsCron.EpochTick, nil) - require.Equal(t, exitcode.Ok, code) - currEpoch += 1 - v, err = v.WithEpoch(currEpoch) - require.NoError(t, err) - } - return v -} - -// Advances to given epoch running cron for all epochs up to but not including this epoch. -func AdvanceToEpochWithCron(t *testing.T, v *vm.VM, stop abi.ChainEpoch) *vm.VM { - currEpoch := v.GetEpoch() - var err error - for currEpoch < stop { - _, code := v.ApplyMessage(builtin.SystemActorAddr, builtin.CronActorAddr, big.Zero(), builtin.MethodsCron.EpochTick, nil) - require.Equal(t, exitcode.Ok, code) - currEpoch += 1 - v, err = v.WithEpoch(currEpoch) - require.NoError(t, err) - } - return v -} diff --git a/actors/migration/nv12/test/parallel_migration_test.go b/actors/migration/nv12/test/parallel_migration_test.go deleted file mode 100644 index 3d0d73d52..000000000 --- a/actors/migration/nv12/test/parallel_migration_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package test_test - -import ( - "context" - "testing" - - "github.com/filecoin-project/go-state-types/abi" - ipld2 "github.com/filecoin-project/specs-actors/v2/support/ipld" - vm3 "github.com/filecoin-project/specs-actors/v3/support/vm" - "github.com/filecoin-project/specs-actors/v4/actors/migration/nv12" - adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - cbor "github.com/ipfs/go-ipld-cbor" - - "github.com/ipfs/go-cid" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "golang.org/x/sync/errgroup" -) - -func TestParallelMigrationCalls(t *testing.T) { - // Construct simple prior state tree over a synchronized store - ctx := context.Background() - log := nv12.TestLogger{TB: t} - bs := ipld2.NewSyncBlockStoreInMemory() - vm := vm3.NewVMWithSingletons(ctx, t, bs) - - // Run migration - adtStore := adt4.WrapStore(ctx, cbor.NewCborStore(bs)) - startRoot := vm.StateRoot() - endRootSerial, err := nv12.MigrateStateTree(ctx, adtStore, startRoot, abi.ChainEpoch(0), nv12.Config{MaxWorkers: 1}, log, nv12.NewMemMigrationCache()) - require.NoError(t, err) - - // Migrate in parallel - var endRootParallel1, endRootParallel2 cid.Cid - grp, ctx := errgroup.WithContext(ctx) - grp.Go(func() error { - var err1 error - endRootParallel1, err1 = nv12.MigrateStateTree(ctx, adtStore, startRoot, abi.ChainEpoch(0), nv12.Config{MaxWorkers: 2}, log, nv12.NewMemMigrationCache()) - return err1 - }) - grp.Go(func() error { - var err2 error - endRootParallel2, err2 = nv12.MigrateStateTree(ctx, adtStore, startRoot, abi.ChainEpoch(0), nv12.Config{MaxWorkers: 2}, log, nv12.NewMemMigrationCache()) - return err2 - }) - require.NoError(t, grp.Wait()) - assert.Equal(t, endRootSerial, endRootParallel1) - assert.Equal(t, endRootParallel1, endRootParallel2) -} diff --git a/actors/migration/nv12/top.go b/actors/migration/nv12/top.go deleted file mode 100644 index 044214fcb..000000000 --- a/actors/migration/nv12/top.go +++ /dev/null @@ -1,326 +0,0 @@ -package nv12 - -import ( - "context" - "fmt" - "sync" - "sync/atomic" - "time" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/rt" - builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" - states3 "github.com/filecoin-project/specs-actors/v3/actors/states" - builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - states4 "github.com/filecoin-project/specs-actors/v4/actors/states" - adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - - "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" - "golang.org/x/sync/errgroup" - "golang.org/x/xerrors" -) - -// Config parameterizes a state tree migration -type Config struct { - // Number of migration worker goroutines to run. - // More workers enables higher CPU utilization doing migration computations (including state encoding) - MaxWorkers uint - // Capacity of the queue of jobs available to workers (zero for unbuffered). - // A queue length of hundreds to thousands improves throughput at the cost of memory. - JobQueueSize uint - // Capacity of the queue receiving migration results from workers, for persisting (zero for unbuffered). - // A queue length of tens to hundreds improves throughput at the cost of memory. - ResultQueueSize uint - // Time between progress logs to emit. - // Zero (the default) results in no progress logs. - ProgressLogPeriod time.Duration -} - -type Logger interface { - // This is the same logging interface provided by the Runtime - Log(level rt.LogLevel, msg string, args ...interface{}) -} - -func ActorHeadKey(addr address.Address, head cid.Cid) string { - return addr.String() + "-h-" + head.String() -} - -// Migrates from v11 to v12 -// -// This migration updates all miner actor states to record their deadline cron status. -// In v12 miner actors defer scheduling deadline cron until beginning to prove storage -// and stop running deadline cron when they stop proving storage so this value can be false. -// All miner actors in v11 have active deadline crons so this field is set to true in migration. -// MigrationCache stores and loads cached data. Its implementation must be threadsafe -type MigrationCache interface { - Write(key string, newCid cid.Cid) error - Read(key string) (bool, cid.Cid, error) - Load(key string, loadFunc func() (cid.Cid, error)) (cid.Cid, error) -} - -// Migrates the filecoin state tree starting from the global state tree and upgrading all actor state. -// The store must support concurrent writes (even if the configured worker count is 1). -func MigrateStateTree(ctx context.Context, store cbor.IpldStore, actorsRootIn cid.Cid, priorEpoch abi.ChainEpoch, cfg Config, log Logger, cache MigrationCache) (cid.Cid, error) { - if cfg.MaxWorkers <= 0 { - return cid.Undef, xerrors.Errorf("invalid migration config with %d workers", cfg.MaxWorkers) - } - - // Maps prior version code CIDs to migration functions. - var migrations = map[cid.Cid]actorMigration{ - builtin3.AccountActorCodeID: nilMigrator{builtin4.AccountActorCodeID}, - builtin3.CronActorCodeID: nilMigrator{builtin4.CronActorCodeID}, - builtin3.InitActorCodeID: nilMigrator{builtin4.InitActorCodeID}, - builtin3.MultisigActorCodeID: nilMigrator{builtin4.MultisigActorCodeID}, - builtin3.PaymentChannelActorCodeID: nilMigrator{builtin4.PaymentChannelActorCodeID}, - builtin3.RewardActorCodeID: nilMigrator{builtin4.RewardActorCodeID}, - builtin3.StorageMarketActorCodeID: nilMigrator{builtin4.StorageMarketActorCodeID}, - builtin3.StorageMinerActorCodeID: cachedMigration(cache, minerMigrator{}), - builtin3.StoragePowerActorCodeID: nilMigrator{builtin4.StoragePowerActorCodeID}, - builtin3.SystemActorCodeID: nilMigrator{builtin4.SystemActorCodeID}, - builtin3.VerifiedRegistryActorCodeID: nilMigrator{builtin4.VerifiedRegistryActorCodeID}, - } - - // Set of prior version code CIDs for actors to defer during iteration, for explicit migration afterwards. - var deferredCodeIDs = map[cid.Cid]struct{}{ - // None - } - - if len(migrations)+len(deferredCodeIDs) != 11 { - panic(fmt.Sprintf("incomplete migration specification with %d code CIDs", len(migrations))) - } - startTime := time.Now() - - // Load input and output state trees - adtStore := adt4.WrapStore(ctx, store) - actorsIn, err := states3.LoadTree(adtStore, actorsRootIn) - if err != nil { - return cid.Undef, err - } - actorsOut, err := states4.NewTree(adtStore) - if err != nil { - return cid.Undef, err - } - - // Setup synchronization - grp, ctx := errgroup.WithContext(ctx) - // Input and output queues for workers. - jobCh := make(chan *migrationJob, cfg.JobQueueSize) - jobResultCh := make(chan *migrationJobResult, cfg.ResultQueueSize) - // Atomically-modified counters for logging progress - var jobCount uint32 - var doneCount uint32 - - // Iterate all actors in old state root to create migration jobs for each non-deferred actor. - grp.Go(func() error { - defer close(jobCh) - log.Log(rt.INFO, "Creating migration jobs for tree %s", actorsRootIn) - if err = actorsIn.ForEach(func(addr address.Address, actorIn *states3.Actor) error { - if _, ok := deferredCodeIDs[actorIn.Code]; ok { - return nil // Deferred for explicit migration later. - } - nextInput := &migrationJob{ - Address: addr, - Actor: *actorIn, // Must take a copy, the pointer is not stable. - cache: cache, - actorMigration: migrations[actorIn.Code], - } - select { - case jobCh <- nextInput: - case <-ctx.Done(): - return ctx.Err() - } - atomic.AddUint32(&jobCount, 1) - return nil - }); err != nil { - return err - } - log.Log(rt.INFO, "Done creating %d migration jobs for tree %s after %v", jobCount, actorsRootIn, time.Since(startTime)) - return nil - }) - - // Worker threads run jobs. - var workerWg sync.WaitGroup - for i := uint(0); i < cfg.MaxWorkers; i++ { - workerWg.Add(1) - workerId := i - grp.Go(func() error { - defer workerWg.Done() - for job := range jobCh { - result, err := job.run(ctx, store, priorEpoch) - if err != nil { - return err - } - select { - case jobResultCh <- result: - case <-ctx.Done(): - return ctx.Err() - } - atomic.AddUint32(&doneCount, 1) - } - log.Log(rt.INFO, "Worker %d done", workerId) - return nil - }) - } - log.Log(rt.INFO, "Started %d workers", cfg.MaxWorkers) - - // Monitor the job queue. This non-critical goroutine is outside the errgroup and exits when - // workersFinished is closed, or the context done. - workersFinished := make(chan struct{}) // Closed when waitgroup is emptied. - if cfg.ProgressLogPeriod > 0 { - go func() { - defer log.Log(rt.DEBUG, "Job queue monitor done") - for { - select { - case <-time.After(cfg.ProgressLogPeriod): - jobsNow := jobCount // Snapshot values to avoid incorrect-looking arithmetic if they change. - doneNow := doneCount - pendingNow := jobsNow - doneNow - elapsed := time.Since(startTime) - rate := float64(doneNow) / elapsed.Seconds() - log.Log(rt.INFO, "%d jobs created, %d done, %d pending after %v (%.0f/s)", - jobsNow, doneNow, pendingNow, elapsed, rate) - case <-workersFinished: - return - case <-ctx.Done(): - return - } - } - }() - } - - // Close result channel when workers are done sending to it. - grp.Go(func() error { - workerWg.Wait() - close(jobResultCh) - close(workersFinished) - log.Log(rt.INFO, "All workers done after %v", time.Since(startTime)) - return nil - }) - - // Insert migrated records in output state tree and accumulators. - grp.Go(func() error { - log.Log(rt.INFO, "Result writer started") - resultCount := 0 - for result := range jobResultCh { - if err := actorsOut.SetActor(result.Address, &result.Actor); err != nil { - return err - } - resultCount++ - } - log.Log(rt.INFO, "Result writer wrote %d results to state tree after %v", resultCount, time.Since(startTime)) - return nil - }) - - if err := grp.Wait(); err != nil { - return cid.Undef, err - } - - elapsed := time.Since(startTime) - rate := float64(doneCount) / elapsed.Seconds() - log.Log(rt.INFO, "All %d done after %v (%.0f/s). Flushing state tree root.", doneCount, elapsed, rate) - return actorsOut.Flush() -} - -type actorMigrationInput struct { - address address.Address // actor's address - balance abi.TokenAmount // actor's balance - head cid.Cid // actor's state head CID - priorEpoch abi.ChainEpoch // epoch of last state transition prior to migration - cache MigrationCache // cache of existing cid -> cid migrations for this actor -} - -type actorMigrationResult struct { - newCodeCID cid.Cid - newHead cid.Cid -} - -type actorMigration interface { - // Loads an actor's state from an input store and writes new state to an output store. - // Returns the new state head CID. - migrateState(ctx context.Context, store cbor.IpldStore, input actorMigrationInput) (result *actorMigrationResult, err error) - migratedCodeCID() cid.Cid -} - -type migrationJob struct { - address.Address - states3.Actor - actorMigration - cache MigrationCache -} -type migrationJobResult struct { - address.Address - states4.Actor -} - -func (job *migrationJob) run(ctx context.Context, store cbor.IpldStore, priorEpoch abi.ChainEpoch) (*migrationJobResult, error) { - result, err := job.migrateState(ctx, store, actorMigrationInput{ - address: job.Address, - balance: job.Actor.Balance, - head: job.Actor.Head, - priorEpoch: priorEpoch, - cache: job.cache, - }) - if err != nil { - return nil, xerrors.Errorf("state migration failed for %s actor, addr %s: %w", - builtin3.ActorNameByCode(job.Actor.Code), job.Address, err) - } - - // Set up new actor record with the migrated state. - return &migrationJobResult{ - job.Address, // Unchanged - states4.Actor{ - Code: result.newCodeCID, - Head: result.newHead, - CallSeqNum: job.Actor.CallSeqNum, // Unchanged - Balance: job.Actor.Balance, // Unchanged - }, - }, nil -} - -// Migrator which preserves the head CID and provides a fixed result code CID. -type nilMigrator struct { - OutCodeCID cid.Cid -} - -func (n nilMigrator) migrateState(_ context.Context, _ cbor.IpldStore, in actorMigrationInput) (*actorMigrationResult, error) { - return &actorMigrationResult{ - newCodeCID: n.OutCodeCID, - newHead: in.head, - }, nil -} - -func (n nilMigrator) migratedCodeCID() cid.Cid { - return n.OutCodeCID -} - -// Migrator that uses cached transformation if it exists -type cachedMigrator struct { - cache MigrationCache - actorMigration -} - -func (c cachedMigrator) migrateState(ctx context.Context, store cbor.IpldStore, in actorMigrationInput) (*actorMigrationResult, error) { - newHead, err := c.cache.Load(ActorHeadKey(in.address, in.head), func() (cid.Cid, error) { - result, err := c.actorMigration.migrateState(ctx, store, in) - if err != nil { - return cid.Undef, err - } - return result.newHead, nil - }) - if err != nil { - return nil, err - } - return &actorMigrationResult{ - newCodeCID: c.migratedCodeCID(), - newHead: newHead, - }, nil -} - -func cachedMigration(cache MigrationCache, m actorMigration) actorMigration { - return cachedMigrator{ - actorMigration: m, - cache: cache, - } -} diff --git a/actors/migration/nv12/util.go b/actors/migration/nv12/util.go deleted file mode 100644 index 91268dcd0..000000000 --- a/actors/migration/nv12/util.go +++ /dev/null @@ -1,73 +0,0 @@ -package nv12 - -import ( - "sync" - "testing" - - "github.com/filecoin-project/go-state-types/rt" - "github.com/ipfs/go-cid" - "golang.org/x/xerrors" -) - -type MemMigrationCache struct { - MigrationMap sync.Map -} - -func NewMemMigrationCache() *MemMigrationCache { - return new(MemMigrationCache) -} - -func (m *MemMigrationCache) Write(key string, c cid.Cid) error { - m.MigrationMap.Store(key, c) - return nil -} - -func (m *MemMigrationCache) Read(key string) (bool, cid.Cid, error) { - val, found := m.MigrationMap.Load(key) - if !found { - return false, cid.Undef, nil - } - c, ok := val.(cid.Cid) - if !ok { - return false, cid.Undef, xerrors.Errorf("non cid value in cache") - } - - return true, c, nil -} - -func (m *MemMigrationCache) Load(key string, loadFunc func() (cid.Cid, error)) (cid.Cid, error) { - found, c, err := m.Read(key) - if err != nil { - return cid.Undef, err - } - if found { - return c, nil - } - c, err = loadFunc() - if err != nil { - return cid.Undef, err - } - m.MigrationMap.Store(key, c) - return c, nil -} - -func (m *MemMigrationCache) Clone() *MemMigrationCache { - newCache := NewMemMigrationCache() - newCache.Update(m) - return newCache -} - -func (m *MemMigrationCache) Update(other *MemMigrationCache) { - other.MigrationMap.Range(func(key, value interface{}) bool { - m.MigrationMap.Store(key, value) - return true - }) -} - -type TestLogger struct { - TB testing.TB -} - -func (t TestLogger) Log(_ rt.LogLevel, msg string, args ...interface{}) { - t.TB.Logf(msg, args...) -} diff --git a/actors/runtime/runtime.go b/actors/runtime/runtime.go index 1c22378e5..97591535a 100644 --- a/actors/runtime/runtime.go +++ b/actors/runtime/runtime.go @@ -12,7 +12,7 @@ import ( "github.com/filecoin-project/go-state-types/rt" cid "github.com/ipfs/go-cid" - "github.com/filecoin-project/specs-actors/v4/actors/runtime/proof" + "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" ) // Interfaces for the runtime. diff --git a/actors/states/check.go b/actors/states/check.go index 2399d5eaf..3ec5e6b41 100644 --- a/actors/states/check.go +++ b/actors/states/check.go @@ -8,18 +8,18 @@ import ( "github.com/filecoin-project/go-state-types/big" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/account" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/cron" - init_ "github.com/filecoin-project/specs-actors/v4/actors/builtin/init" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/multisig" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/paych" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/account" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/cron" + init_ "github.com/filecoin-project/specs-actors/v5/actors/builtin/init" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/multisig" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/paych" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/reward" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/verifreg" ) // Within this code, Go errors are not expected, but are often converted to messages so that execution diff --git a/actors/states/election.go b/actors/states/election.go index 5fd714dd4..0a5597dda 100644 --- a/actors/states/election.go +++ b/actors/states/election.go @@ -5,9 +5,9 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) // Checks for miner election eligibility. diff --git a/actors/states/election_test.go b/actors/states/election_test.go index 23b8eb573..a148201d5 100644 --- a/actors/states/election_test.go +++ b/actors/states/election_test.go @@ -10,13 +10,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/states" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/ipld" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/states" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/ipld" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" ) func TestMinerEligibleForElection(t *testing.T) { diff --git a/actors/states/tree.go b/actors/states/tree.go index c0b56bbe8..8d7e8fc9c 100644 --- a/actors/states/tree.go +++ b/actors/states/tree.go @@ -7,8 +7,8 @@ import ( "github.com/ipfs/go-cid" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) // Value type of the top level of the state tree. diff --git a/actors/states/tree_test.go b/actors/states/tree_test.go index 098003ac9..087b955bd 100644 --- a/actors/states/tree_test.go +++ b/actors/states/tree_test.go @@ -10,9 +10,9 @@ import ( "github.com/ipfs/go-cid" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/states" - "github.com/filecoin-project/specs-actors/v4/support/ipld" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/states" + "github.com/filecoin-project/specs-actors/v5/support/ipld" ) func BenchmarkStateTreeSet(b *testing.B) { diff --git a/actors/test/commit_post_test.go b/actors/test/commit_post_test.go index 65cf806e0..53d434e0c 100644 --- a/actors/test/commit_post_test.go +++ b/actors/test/commit_post_test.go @@ -12,14 +12,14 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/runtime/proof" - "github.com/filecoin-project/specs-actors/v4/actors/states" - "github.com/filecoin-project/specs-actors/v4/support/ipld" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" - vm "github.com/filecoin-project/specs-actors/v4/support/vm" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" + "github.com/filecoin-project/specs-actors/v5/actors/states" + "github.com/filecoin-project/specs-actors/v5/support/ipld" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" + vm "github.com/filecoin-project/specs-actors/v5/support/vm" ) func TestCommitPoStFlow(t *testing.T) { diff --git a/actors/test/committed_capacity_scenario_test.go b/actors/test/committed_capacity_scenario_test.go index 3526b3635..f3d501d69 100644 --- a/actors/test/committed_capacity_scenario_test.go +++ b/actors/test/committed_capacity_scenario_test.go @@ -10,15 +10,15 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg" - "github.com/filecoin-project/specs-actors/v4/actors/runtime/proof" - "github.com/filecoin-project/specs-actors/v4/support/ipld" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" - vm "github.com/filecoin-project/specs-actors/v4/support/vm" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/verifreg" + "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" + "github.com/filecoin-project/specs-actors/v5/support/ipld" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" + vm "github.com/filecoin-project/specs-actors/v5/support/vm" ) func TestReplaceCommittedCapacitySectorWithDealLadenSector(t *testing.T) { diff --git a/actors/test/common_test.go b/actors/test/common_test.go index b7f431b13..ffb94cbb4 100644 --- a/actors/test/common_test.go +++ b/actors/test/common_test.go @@ -10,10 +10,10 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" - vm "github.com/filecoin-project/specs-actors/v4/support/vm" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" + vm "github.com/filecoin-project/specs-actors/v5/support/vm" ) func publishDeal(t *testing.T, v *vm.VM, provider, dealClient, minerID addr.Address, dealLabel string, diff --git a/actors/test/cron_catches_expiries_scenario_test.go b/actors/test/cron_catches_expiries_scenario_test.go index 50ba9f8aa..e2fdd0ccd 100644 --- a/actors/test/cron_catches_expiries_scenario_test.go +++ b/actors/test/cron_catches_expiries_scenario_test.go @@ -10,13 +10,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/runtime/proof" - "github.com/filecoin-project/specs-actors/v4/support/ipld" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" - vm "github.com/filecoin-project/specs-actors/v4/support/vm" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" + "github.com/filecoin-project/specs-actors/v5/support/ipld" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" + vm "github.com/filecoin-project/specs-actors/v5/support/vm" ) var fakeChainRandomness = []byte("not really random") diff --git a/actors/test/market_withdrawal_test.go b/actors/test/market_withdrawal_test.go index c669c8e8e..04161ccb1 100644 --- a/actors/test/market_withdrawal_test.go +++ b/actors/test/market_withdrawal_test.go @@ -8,10 +8,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - "github.com/filecoin-project/specs-actors/v4/support/ipld" - vm "github.com/filecoin-project/specs-actors/v4/support/vm" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" + "github.com/filecoin-project/specs-actors/v5/support/ipld" + vm "github.com/filecoin-project/specs-actors/v5/support/vm" ) func TestMarketWithdraw(t *testing.T) { diff --git a/actors/test/multisig_delete_self_test.go b/actors/test/multisig_delete_self_test.go index 9d099aaaf..22f157fd6 100644 --- a/actors/test/multisig_delete_self_test.go +++ b/actors/test/multisig_delete_self_test.go @@ -11,11 +11,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - init_ "github.com/filecoin-project/specs-actors/v4/actors/builtin/init" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/multisig" - "github.com/filecoin-project/specs-actors/v4/support/ipld" - vm "github.com/filecoin-project/specs-actors/v4/support/vm" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + init_ "github.com/filecoin-project/specs-actors/v5/actors/builtin/init" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/multisig" + "github.com/filecoin-project/specs-actors/v5/support/ipld" + vm "github.com/filecoin-project/specs-actors/v5/support/vm" ) func TestMultisigDeleteSelf2Of3RemovedIsProposer(t *testing.T) { diff --git a/actors/test/power_scenario_test.go b/actors/test/power_scenario_test.go index 6fb62a9bc..d1c4a24a1 100644 --- a/actors/test/power_scenario_test.go +++ b/actors/test/power_scenario_test.go @@ -8,12 +8,12 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/support/ipld" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" - vm "github.com/filecoin-project/specs-actors/v4/support/vm" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/support/ipld" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" + vm "github.com/filecoin-project/specs-actors/v5/support/vm" ) func TestCreateMiner(t *testing.T) { diff --git a/actors/test/terminate_sectors_scenario_test.go b/actors/test/terminate_sectors_scenario_test.go index a4889b48f..83830e699 100644 --- a/actors/test/terminate_sectors_scenario_test.go +++ b/actors/test/terminate_sectors_scenario_test.go @@ -10,15 +10,15 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg" - "github.com/filecoin-project/specs-actors/v4/actors/runtime/proof" - "github.com/filecoin-project/specs-actors/v4/support/ipld" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" - vm "github.com/filecoin-project/specs-actors/v4/support/vm" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/verifreg" + "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" + "github.com/filecoin-project/specs-actors/v5/support/ipld" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" + vm "github.com/filecoin-project/specs-actors/v5/support/vm" ) // This scenario hits all Market Actor methods. diff --git a/actors/util/adt/array_test.go b/actors/util/adt/array_test.go index 60a90074b..27ca4e7ab 100644 --- a/actors/util/adt/array_test.go +++ b/actors/util/adt/array_test.go @@ -6,8 +6,8 @@ import ( "github.com/filecoin-project/go-address" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/mock" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/mock" ) func TestArrayNotFound(t *testing.T) { diff --git a/actors/util/adt/balancetable_test.go b/actors/util/adt/balancetable_test.go index ff70da29a..14221dbc9 100644 --- a/actors/util/adt/balancetable_test.go +++ b/actors/util/adt/balancetable_test.go @@ -9,10 +9,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/mock" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/mock" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" ) func TestBalanceTable(t *testing.T) { diff --git a/actors/util/adt/store.go b/actors/util/adt/store.go index b234b43a0..05a92b803 100644 --- a/actors/util/adt/store.go +++ b/actors/util/adt/store.go @@ -9,7 +9,7 @@ import ( cid "github.com/ipfs/go-cid" ipldcbor "github.com/ipfs/go-ipld-cbor" - vmr "github.com/filecoin-project/specs-actors/v4/actors/runtime" + vmr "github.com/filecoin-project/specs-actors/v5/actors/runtime" ) type Store = adt2.Store diff --git a/actors/util/bitfield_test.go b/actors/util/bitfield_test.go index 093489af3..4c051d5da 100644 --- a/actors/util/bitfield_test.go +++ b/actors/util/bitfield_test.go @@ -7,7 +7,7 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/stretchr/testify/assert" - "github.com/filecoin-project/specs-actors/v4/actors/util" + "github.com/filecoin-project/specs-actors/v5/actors/util" ) func TestBitFieldUnset(t *testing.T) { diff --git a/actors/util/math/exp_test.go b/actors/util/math/exp_test.go index dd160ef43..12bbc28b7 100644 --- a/actors/util/math/exp_test.go +++ b/actors/util/math/exp_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/v4/actors/util/math" + "github.com/filecoin-project/specs-actors/v5/actors/util/math" "github.com/stretchr/testify/assert" ) diff --git a/actors/util/math/expneg_test.go b/actors/util/math/expneg_test.go index 2305828d9..ca0f49687 100644 --- a/actors/util/math/expneg_test.go +++ b/actors/util/math/expneg_test.go @@ -8,7 +8,7 @@ import ( "github.com/xorcare/golden" - "github.com/filecoin-project/specs-actors/v4/actors/util/math" + "github.com/filecoin-project/specs-actors/v5/actors/util/math" ) var Res big.Word diff --git a/actors/util/math/ln_test.go b/actors/util/math/ln_test.go index ac07177fb..9f795bbbe 100644 --- a/actors/util/math/ln_test.go +++ b/actors/util/math/ln_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/v4/actors/util/math" + "github.com/filecoin-project/specs-actors/v5/actors/util/math" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/actors/util/smoothing/alpha_beta_filter.go b/actors/util/smoothing/alpha_beta_filter.go index df11ab68d..eaf68784e 100644 --- a/actors/util/smoothing/alpha_beta_filter.go +++ b/actors/util/smoothing/alpha_beta_filter.go @@ -4,7 +4,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/v4/actors/util/math" + "github.com/filecoin-project/specs-actors/v5/actors/util/math" ) var ( diff --git a/actors/util/smoothing/alpha_beta_filter_test.go b/actors/util/smoothing/alpha_beta_filter_test.go index 7e20cc27d..7efdbeb60 100644 --- a/actors/util/smoothing/alpha_beta_filter_test.go +++ b/actors/util/smoothing/alpha_beta_filter_test.go @@ -7,9 +7,9 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/stretchr/testify/assert" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/util/math" - "github.com/filecoin-project/specs-actors/v4/actors/util/smoothing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/util/math" + "github.com/filecoin-project/specs-actors/v5/actors/util/smoothing" ) // project of cumsum ratio is equal to cumsum of ratio of projections diff --git a/gen/gen.go b/gen/gen.go index bac12eae9..85fd2be87 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -3,19 +3,19 @@ package main import ( gen "github.com/whyrusleeping/cbor-gen" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/account" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/cron" - init_ "github.com/filecoin-project/specs-actors/v4/actors/builtin/init" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/multisig" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/paych" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/system" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg" - "github.com/filecoin-project/specs-actors/v4/actors/util/smoothing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/account" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/cron" + init_ "github.com/filecoin-project/specs-actors/v5/actors/builtin/init" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/multisig" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/paych" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/reward" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/system" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/verifreg" + "github.com/filecoin-project/specs-actors/v5/actors/util/smoothing" ) func main() { diff --git a/go.mod b/go.mod index a5553dd20..184dde9c7 100644 --- a/go.mod +++ b/go.mod @@ -1,18 +1,17 @@ -module github.com/filecoin-project/specs-actors/v4 +module github.com/filecoin-project/specs-actors/v5 -go 1.13 +go 1.16 require ( github.com/filecoin-project/go-address v0.0.5 - github.com/filecoin-project/go-amt-ipld/v2 v2.1.0 github.com/filecoin-project/go-amt-ipld/v3 v3.0.0 github.com/filecoin-project/go-bitfield v0.2.3 - github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0 github.com/filecoin-project/go-hamt-ipld/v3 v3.0.1 github.com/filecoin-project/go-state-types v0.1.0 github.com/filecoin-project/specs-actors v0.9.13 github.com/filecoin-project/specs-actors/v2 v2.3.5-0.20210114162132-5b58b773f4fb github.com/filecoin-project/specs-actors/v3 v3.1.0 + github.com/filecoin-project/specs-actors/v4 v4.0.0 github.com/ipfs/go-block-format v0.0.3 github.com/ipfs/go-cid v0.0.7 github.com/ipfs/go-ipld-cbor v0.0.5 @@ -23,6 +22,5 @@ require ( github.com/stretchr/testify v1.7.0 github.com/whyrusleeping/cbor-gen v0.0.0-20210118024343-169e9d70c0c2 github.com/xorcare/golden v0.6.0 - golang.org/x/sync v0.0.0-20190423024810-112230192c58 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 ) diff --git a/go.sum b/go.sum index ed5f4d874..e2eefe492 100644 --- a/go.sum +++ b/go.sum @@ -33,6 +33,8 @@ github.com/filecoin-project/specs-actors/v2 v2.3.5-0.20210114162132-5b58b773f4fb github.com/filecoin-project/specs-actors/v2 v2.3.5-0.20210114162132-5b58b773f4fb/go.mod h1:LljnY2Mn2homxZsmokJZCpRuhOPxfXhvcek5gWkmqAc= github.com/filecoin-project/specs-actors/v3 v3.1.0 h1:s4qiPw8pgypqBGAy853u/zdZJ7K9cTZdM1rTiSonHrg= github.com/filecoin-project/specs-actors/v3 v3.1.0/go.mod h1:mpynccOLlIRy0QnR008BwYBwT9fen+sPR13MA1VmMww= +github.com/filecoin-project/specs-actors/v4 v4.0.0 h1:vMALksY5G3J5rj3q9rbcyB+f4Tk1xrLqSgdB3jOok4s= +github.com/filecoin-project/specs-actors/v4 v4.0.0/go.mod h1:TkHXf/l7Wyw4ZejyXIPS2rK8bBO0rdwhTZyQQgaglng= github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -164,7 +166,6 @@ golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKG golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/support/agent/cases_test.go b/support/agent/cases_test.go index 66f4e048a..cac84c934 100644 --- a/support/agent/cases_test.go +++ b/support/agent/cases_test.go @@ -9,26 +9,16 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/go-state-types/rt" - power2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/power" - states2 "github.com/filecoin-project/specs-actors/v2/actors/states" - vm_test2 "github.com/filecoin-project/specs-actors/v2/support/vm" - states3 "github.com/filecoin-project/specs-actors/v3/actors/states" - vm_test3 "github.com/filecoin-project/specs-actors/v3/support/vm" - cid "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/exported" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/migration/nv10" - "github.com/filecoin-project/specs-actors/v4/actors/states" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/agent" - "github.com/filecoin-project/specs-actors/v4/support/ipld" - vm_test "github.com/filecoin-project/specs-actors/v4/support/vm" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/states" + "github.com/filecoin-project/specs-actors/v5/support/agent" + "github.com/filecoin-project/specs-actors/v5/support/ipld" + vm_test "github.com/filecoin-project/specs-actors/v5/support/vm" ) func TestCreate20Miners(t *testing.T) { @@ -39,7 +29,7 @@ func TestCreate20Miners(t *testing.T) { rnd := rand.New(rand.NewSource(42)) sim := agent.NewSim(ctx, t, newBlockStore, agent.SimConfig{Seed: rnd.Int63()}) - accounts := vm_test.CreateAccounts(ctx, t, getV3VM(t, sim), minerCount, initialBalance, rnd.Int63()) + accounts := vm_test.CreateAccounts(ctx, t, getV5VM(t, sim), minerCount, initialBalance, rnd.Int63()) sim.AddAgent(agent.NewMinerGenerator( accounts, agent.MinerAgentConfig{ @@ -92,7 +82,7 @@ func Test500Epochs(t *testing.T) { }) // create miners - workerAccounts := vm_test.CreateAccounts(ctx, t, getV3VM(t, sim), minerCount, initialBalance, rnd.Int63()) + workerAccounts := vm_test.CreateAccounts(ctx, t, getV5VM(t, sim), minerCount, initialBalance, rnd.Int63()) sim.AddAgent(agent.NewMinerGenerator( workerAccounts, agent.MinerAgentConfig{ @@ -109,7 +99,7 @@ func Test500Epochs(t *testing.T) { rnd.Int63(), )) - clientAccounts := vm_test.CreateAccounts(ctx, t, getV3VM(t, sim), clientCount, initialBalance, rnd.Int63()) + clientAccounts := vm_test.CreateAccounts(ctx, t, getV5VM(t, sim), clientCount, initialBalance, rnd.Int63()) dealAgents := agent.AddDealClientsForAccounts(sim, clientAccounts, rnd.Int63(), agent.DealClientConfig{ DealRate: .05, MinPieceSize: 1 << 29, @@ -132,10 +122,10 @@ func Test500Epochs(t *testing.T) { deals += da.DealCount } - stateTree, err := getV3VM(t, sim).GetStateTree() + stateTree, err := getV5VM(t, sim).GetStateTree() require.NoError(t, err) - totalBalance, err := getV3VM(t, sim).GetTotalActorBalance() + totalBalance, err := getV5VM(t, sim).GetTotalActorBalance() require.NoError(t, err) acc, err := states.CheckStateInvariants(stateTree, totalBalance, sim.GetVM().GetEpoch()-1) @@ -149,8 +139,8 @@ func Test500Epochs(t *testing.T) { fmt.Printf("Power at %d: raw: %v cmtRaw: %v cmtSecs: %d msgs: %d deals: %d gets: %d puts: %d write bytes: %d read bytes: %d\n", epoch, pwrSt.TotalRawBytePower, pwrSt.TotalBytesCommitted, sectorCount.Uint64(), - sim.MessageCount, deals, getV3VM(t, sim).StoreReads(), getV3VM(t, sim).StoreWrites(), - getV3VM(t, sim).StoreReadBytes(), getV3VM(t, sim).StoreWriteBytes()) + sim.MessageCount, deals, getV5VM(t, sim).StoreReads(), getV5VM(t, sim).StoreWrites(), + getV5VM(t, sim).StoreReadBytes(), getV5VM(t, sim).StoreWriteBytes()) } cumulativeStats.MergeAllStats(sim.GetCallStats()) @@ -165,7 +155,7 @@ func TestCommitPowerAndCheckInvariants(t *testing.T) { rnd := rand.New(rand.NewSource(42)) sim := agent.NewSim(ctx, t, newBlockStore, agent.SimConfig{Seed: rnd.Int63()}) - accounts := vm_test.CreateAccounts(ctx, t, getV3VM(t, sim), minerCount, initialBalance, rnd.Int63()) + accounts := vm_test.CreateAccounts(ctx, t, getV5VM(t, sim), minerCount, initialBalance, rnd.Int63()) sim.AddAgent(agent.NewMinerGenerator( accounts, agent.MinerAgentConfig{ @@ -187,10 +177,10 @@ func TestCommitPowerAndCheckInvariants(t *testing.T) { epoch := sim.GetVM().GetEpoch() if epoch%100 == 0 { - stateTree, err := getV3VM(t, sim).GetStateTree() + stateTree, err := getV5VM(t, sim).GetStateTree() require.NoError(t, err) - totalBalance, err := getV3VM(t, sim).GetTotalActorBalance() + totalBalance, err := getV5VM(t, sim).GetTotalActorBalance() require.NoError(t, err) acc, err := states.CheckStateInvariants(stateTree, totalBalance, sim.GetVM().GetEpoch()-1) @@ -209,151 +199,6 @@ func TestCommitPowerAndCheckInvariants(t *testing.T) { } } -func TestMigration(t *testing.T) { - t.Skip("slow") - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - initialBalance := big.Mul(big.NewInt(1e8), big.NewInt(1e18)) - minerCount := 10 - clientCount := 9 - - blkStore := newBlockStore() - v := vm_test2.NewVMWithSingletons(ctx, t, blkStore) - v2VMFactory := func(ctx context.Context, impl vm_test2.ActorImplLookup, store adt.Store, stateRoot cid.Cid, epoch abi.ChainEpoch) (agent.SimVM, error) { - return vm_test2.NewVMAtEpoch(ctx, impl, store, stateRoot, epoch) - } - v2MinerFactory := func(ctx context.Context, root cid.Cid) (agent.SimMinerState, error) { - return &agent.MinerStateV2{ - Ctx: ctx, - Root: root, - }, nil - } - - // set up sim - rnd := rand.New(rand.NewSource(42)) - sim := agent.NewSimWithVM(ctx, t, v, v2VMFactory, agent.ComputePowerTableV2, blkStore, newBlockStore, v2MinerFactory, agent.SimConfig{ - Seed: rnd.Int63(), - CheckpointEpochs: 1000, - }, agent.CreateMinerParamsV2) - - // create miners - workerAccounts := vm_test2.CreateAccounts(ctx, t, v, minerCount, initialBalance, rnd.Int63()) - sim.AddAgent(agent.NewMinerGenerator( - workerAccounts, - agent.MinerAgentConfig{ - PrecommitRate: 2.0, - FaultRate: 0.00001, - RecoveryRate: 0.0001, - UpgradeSectors: true, - ProofType: abi.RegisteredSealProof_StackedDrg32GiBV1_1, - StartingBalance: big.Div(initialBalance, big.NewInt(2)), - MinMarketBalance: big.NewInt(1e18), - MaxMarketBalance: big.NewInt(2e18), - }, - 1.0, // create miner probability of 1 means a new miner is created every tick - rnd.Int63(), - )) - - clientAccounts := vm_test2.CreateAccounts(ctx, t, v, clientCount, initialBalance, rnd.Int63()) - agent.AddDealClientsForAccounts(sim, clientAccounts, rnd.Int63(), agent.DealClientConfig{ - DealRate: .05, - MinPieceSize: 1 << 29, - MaxPieceSize: 32 << 30, - MinStoragePrice: big.Zero(), - MaxStoragePrice: abi.NewTokenAmount(200_000_000), - MinMarketBalance: big.NewInt(1e18), - MaxMarketBalance: big.NewInt(2e18), - }) - - // Run v2 for 5000 epochs - var pwrSt power2.State - for i := 0; i < 5000; i++ { - require.NoError(t, sim.Tick()) - epoch := sim.GetVM().GetEpoch() - if epoch%100 == 0 { - stateTree, err := states2.LoadTree(sim.GetVM().Store(), sim.GetVM().StateRoot()) - require.NoError(t, err) - - totalBalance, err := sim.GetVM().GetTotalActorBalance() - require.NoError(t, err) - - acc, err := states2.CheckStateInvariants(stateTree, totalBalance, sim.GetVM().GetEpoch()-1) - require.NoError(t, err) - require.True(t, acc.IsEmpty(), strings.Join(acc.Messages(), "\n")) - - require.NoError(t, sim.GetVM().GetState(builtin.StoragePowerActorAddr, &pwrSt)) - - // assume each sector is 32Gb - sectorCount := big.Div(pwrSt.TotalBytesCommitted, big.NewInt(32<<30)) - - fmt.Printf("Power at %d: raw: %v cmtRaw: %v cmtSecs: %d cnsMnrs: %d avgWins: %.3f msgs: %d\n", - epoch, pwrSt.TotalRawBytePower, pwrSt.TotalBytesCommitted, sectorCount.Uint64(), - pwrSt.MinerAboveMinPowerCount, float64(sim.WinCount)/float64(epoch), sim.MessageCount) - } - } - - // Migrate - v2 := sim.GetVM() - log := nv10.TestLogger{TB: t} - priorEpoch := v2.GetEpoch() - 1 // on tick sim internally creates new vm with epoch set to the next one - nextRoot, err := nv10.MigrateStateTree(ctx, v2.Store(), v2.StateRoot(), priorEpoch, nv10.Config{MaxWorkers: 1}, log, nv10.NewMemMigrationCache()) - require.NoError(t, err) - - lookup := map[cid.Cid]rt.VMActor{} - for _, ba := range exported.BuiltinActors() { - lookup[ba.Code()] = ba - } - - v3, err := vm_test3.NewVMAtEpoch(ctx, lookup, v2.Store(), nextRoot, priorEpoch+1) - require.NoError(t, err) - - stateTree, err := v3.GetStateTree() - require.NoError(t, err) - totalBalance, err := v3.GetTotalActorBalance() - require.NoError(t, err) - msgs, err := states3.CheckStateInvariants(stateTree, totalBalance, priorEpoch) - require.NoError(t, err) - assert.Zero(t, len(msgs.Messages()), strings.Join(msgs.Messages(), "\n")) - - v3VMFactory := func(ctx context.Context, impl vm_test2.ActorImplLookup, store adt.Store, stateRoot cid.Cid, epoch abi.ChainEpoch) (agent.SimVM, error) { - return vm_test.NewVMAtEpoch(ctx, vm_test.ActorImplLookup(impl), store, stateRoot, epoch) - } - v3MinerFactory := func(ctx context.Context, root cid.Cid) (agent.SimMinerState, error) { - return &agent.MinerStateV3{ - Ctx: ctx, - Root: root, - }, nil - } - sim.SwapVM(v3, agent.VMFactoryFunc(v3VMFactory), v3MinerFactory, agent.ComputePowerTableV3, agent.CreateMinerParamsV3) - - // Run v3 for 5000 epochs - for i := 0; i < 5000; i++ { - require.NoError(t, sim.Tick()) - epoch := sim.GetVM().GetEpoch() - if epoch%100 == 0 { - stateTree, err := states.LoadTree(sim.GetVM().Store(), sim.GetVM().StateRoot()) - require.NoError(t, err) - - totalBalance, err := sim.GetVM().GetTotalActorBalance() - require.NoError(t, err) - - acc, err := states.CheckStateInvariants(stateTree, totalBalance, sim.GetVM().GetEpoch()-1) - require.NoError(t, err) - require.True(t, acc.IsEmpty(), strings.Join(acc.Messages(), "\n")) - - require.NoError(t, sim.GetVM().GetState(builtin.StoragePowerActorAddr, &pwrSt)) - - // assume each sector is 32Gb - sectorCount := big.Div(pwrSt.TotalBytesCommitted, big.NewInt(32<<30)) - - fmt.Printf("Power at %d: raw: %v cmtRaw: %v cmtSecs: %d cnsMnrs: %d avgWins: %.3f msgs: %d\n", - epoch, pwrSt.TotalRawBytePower, pwrSt.TotalBytesCommitted, sectorCount.Uint64(), - pwrSt.MinerAboveMinPowerCount, float64(sim.WinCount)/float64(epoch), sim.MessageCount) - } - } - -} - func TestCommitAndCheckReadWriteStats(t *testing.T) { t.Skip("this is slow") ctx := context.Background() @@ -370,7 +215,7 @@ func TestCommitAndCheckReadWriteStats(t *testing.T) { }) // create miners - workerAccounts := vm_test.CreateAccounts(ctx, t, getV3VM(t, sim), minerCount, initialBalance, rnd.Int63()) + workerAccounts := vm_test.CreateAccounts(ctx, t, getV5VM(t, sim), minerCount, initialBalance, rnd.Int63()) sim.AddAgent(agent.NewMinerGenerator( workerAccounts, agent.MinerAgentConfig{ @@ -387,7 +232,7 @@ func TestCommitAndCheckReadWriteStats(t *testing.T) { rnd.Int63(), )) - clientAccounts := vm_test.CreateAccounts(ctx, t, getV3VM(t, sim), clientCount, initialBalance, rnd.Int63()) + clientAccounts := vm_test.CreateAccounts(ctx, t, getV5VM(t, sim), clientCount, initialBalance, rnd.Int63()) dealAgents := agent.AddDealClientsForAccounts(sim, clientAccounts, rnd.Int63(), agent.DealClientConfig{ DealRate: .05, MinPieceSize: 1 << 29, @@ -417,8 +262,8 @@ func TestCommitAndCheckReadWriteStats(t *testing.T) { fmt.Printf("Power at %d: raw: %v cmtRaw: %v cmtSecs: %d msgs: %d deals: %d gets: %d puts: %d write bytes: %d read bytes: %d\n", epoch, pwrSt.TotalRawBytePower, pwrSt.TotalBytesCommitted, sectorCount.Uint64(), - sim.MessageCount, deals, getV3VM(t, sim).StoreReads(), getV3VM(t, sim).StoreWrites(), - getV3VM(t, sim).StoreReadBytes(), getV3VM(t, sim).StoreWriteBytes()) + sim.MessageCount, deals, getV5VM(t, sim).StoreReads(), getV5VM(t, sim).StoreWrites(), + getV5VM(t, sim).StoreReadBytes(), getV5VM(t, sim).StoreWriteBytes()) } cumulativeStats.MergeAllStats(sim.GetCallStats()) @@ -444,7 +289,7 @@ func TestCreateDeals(t *testing.T) { sim := agent.NewSim(ctx, t, newBlockStore, agent.SimConfig{Seed: rnd.Int63()}) // create miners - workerAccounts := vm_test.CreateAccounts(ctx, t, getV3VM(t, sim), minerCount, initialBalance, rnd.Int63()) + workerAccounts := vm_test.CreateAccounts(ctx, t, getV5VM(t, sim), minerCount, initialBalance, rnd.Int63()) sim.AddAgent(agent.NewMinerGenerator( workerAccounts, agent.MinerAgentConfig{ @@ -460,7 +305,7 @@ func TestCreateDeals(t *testing.T) { rnd.Int63(), )) - clientAccounts := vm_test.CreateAccounts(ctx, t, getV3VM(t, sim), clientCount, initialBalance, rnd.Int63()) + clientAccounts := vm_test.CreateAccounts(ctx, t, getV5VM(t, sim), clientCount, initialBalance, rnd.Int63()) dealAgents := agent.AddDealClientsForAccounts(sim, clientAccounts, rnd.Int63(), agent.DealClientConfig{ DealRate: .01, MinPieceSize: 1 << 29, @@ -477,10 +322,10 @@ func TestCreateDeals(t *testing.T) { epoch := sim.GetVM().GetEpoch() if epoch%100 == 0 { - stateTree, err := getV3VM(t, sim).GetStateTree() + stateTree, err := getV5VM(t, sim).GetStateTree() require.NoError(t, err) - totalBalance, err := getV3VM(t, sim).GetTotalActorBalance() + totalBalance, err := getV5VM(t, sim).GetTotalActorBalance() require.NoError(t, err) acc, err := states.CheckStateInvariants(stateTree, totalBalance, sim.GetVM().GetEpoch()-1) @@ -517,7 +362,7 @@ func TestCCUpgrades(t *testing.T) { sim := agent.NewSim(ctx, t, newBlockStore, agent.SimConfig{Seed: rnd.Int63()}) // create miners - workerAccounts := vm_test.CreateAccounts(ctx, t, getV3VM(t, sim), minerCount, initialBalance, rnd.Int63()) + workerAccounts := vm_test.CreateAccounts(ctx, t, getV5VM(t, sim), minerCount, initialBalance, rnd.Int63()) sim.AddAgent(agent.NewMinerGenerator( workerAccounts, agent.MinerAgentConfig{ @@ -534,7 +379,7 @@ func TestCCUpgrades(t *testing.T) { rnd.Int63(), )) - clientAccounts := vm_test.CreateAccounts(ctx, t, getV3VM(t, sim), clientCount, initialBalance, rnd.Int63()) + clientAccounts := vm_test.CreateAccounts(ctx, t, getV5VM(t, sim), clientCount, initialBalance, rnd.Int63()) agent.AddDealClientsForAccounts(sim, clientAccounts, rnd.Int63(), agent.DealClientConfig{ DealRate: .01, MinPieceSize: 1 << 29, @@ -551,10 +396,10 @@ func TestCCUpgrades(t *testing.T) { epoch := sim.GetVM().GetEpoch() if epoch%100 == 0 { - stateTree, err := getV3VM(t, sim).GetStateTree() + stateTree, err := getV5VM(t, sim).GetStateTree() require.NoError(t, err) - totalBalance, err := getV3VM(t, sim).GetTotalActorBalance() + totalBalance, err := getV5VM(t, sim).GetTotalActorBalance() require.NoError(t, err) acc, err := states.CheckStateInvariants(stateTree, totalBalance, sim.GetVM().GetEpoch()-1) @@ -606,7 +451,7 @@ func printCallStats(method vm_test.MethodKey, stats *vm_test.CallStats, indent s } } -func getV3VM(t *testing.T, sim *agent.Sim) *vm_test.VM { +func getV5VM(t *testing.T, sim *agent.Sim) *vm_test.VM { vm, ok := sim.GetVM().(*vm_test.VM) require.True(t, ok) return vm diff --git a/support/agent/deal_client_agent.go b/support/agent/deal_client_agent.go index 43736cd71..700311a08 100644 --- a/support/agent/deal_client_agent.go +++ b/support/agent/deal_client_agent.go @@ -12,10 +12,10 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/crypto" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/reward" "github.com/ipfs/go-cid" ) diff --git a/support/agent/miner_agent.go b/support/agent/miner_agent.go index dd5ab60f3..afb54fcc7 100644 --- a/support/agent/miner_agent.go +++ b/support/agent/miner_agent.go @@ -16,10 +16,10 @@ import ( mh "github.com/multiformats/go-multihash" "github.com/pkg/errors" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/runtime/proof" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" ) type MinerAgentConfig struct { diff --git a/support/agent/miner_generator.go b/support/agent/miner_generator.go index 77861d6db..a364be516 100644 --- a/support/agent/miner_generator.go +++ b/support/agent/miner_generator.go @@ -7,10 +7,8 @@ import ( "github.com/filecoin-project/go-state-types/cbor" "github.com/pkg/errors" - power2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - power3 "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" ) // MinerGenerator adds miner agents to the simulation at a configured rate. @@ -75,14 +73,9 @@ func (mg *MinerGenerator) createMiner(owner address.Address, cfg MinerAgentConfi } var worker, owner address.Address - params, okV3 := msg.Params.(*power3.CreateMinerParams) - if !okV3 { - params, okV2 := msg.Params.(*power2.CreateMinerParams) - if !okV2 { - return errors.Errorf("create miner params has wrong type: %v", msg.Params) - } - worker = params.Worker - owner = params.Owner + params, ok := msg.Params.(*power.CreateMinerParams) + if !ok { + return errors.Errorf("create miner params has wrong type: %v", msg.Params) } else { worker = params.Worker owner = params.Owner diff --git a/support/agent/miner_state.go b/support/agent/miner_state.go index 50e7c49fc..031bb9167 100644 --- a/support/agent/miner_state.go +++ b/support/agent/miner_state.go @@ -7,21 +7,21 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/dline" - miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" - miner3 "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + miner4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" + miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" cid "github.com/ipfs/go-cid" ) -type MinerStateV2 struct { +type MinerStateV4 struct { Root cid.Cid Ctx context.Context - st *miner2.State + st *miner4.State } -func (m *MinerStateV2) state(store adt.Store) (*miner2.State, error) { +func (m *MinerStateV4) state(store adt.Store) (*miner4.State, error) { if m.st == nil { - var st miner2.State + var st miner4.State err := store.Get(m.Ctx, m.Root, &st) if err != nil { return nil, err @@ -31,7 +31,7 @@ func (m *MinerStateV2) state(store adt.Store) (*miner2.State, error) { return m.st, nil } -func (m *MinerStateV2) HasSectorNo(store adt.Store, sectorNo abi.SectorNumber) (bool, error) { +func (m *MinerStateV4) HasSectorNo(store adt.Store, sectorNo abi.SectorNumber) (bool, error) { st, err := m.state(store) if err != nil { return false, err @@ -39,7 +39,7 @@ func (m *MinerStateV2) HasSectorNo(store adt.Store, sectorNo abi.SectorNumber) ( return st.HasSectorNo(store, sectorNo) } -func (m *MinerStateV2) FindSector(store adt.Store, sectorNo abi.SectorNumber) (uint64, uint64, error) { +func (m *MinerStateV4) FindSector(store adt.Store, sectorNo abi.SectorNumber) (uint64, uint64, error) { st, err := m.state(store) if err != nil { return 0, 0, err @@ -47,7 +47,7 @@ func (m *MinerStateV2) FindSector(store adt.Store, sectorNo abi.SectorNumber) (u return st.FindSector(store, sectorNo) } -func (m *MinerStateV2) ProvingPeriodStart(store adt.Store) (abi.ChainEpoch, error) { +func (m *MinerStateV4) ProvingPeriodStart(store adt.Store) (abi.ChainEpoch, error) { st, err := m.state(store) if err != nil { return 0, err @@ -55,7 +55,7 @@ func (m *MinerStateV2) ProvingPeriodStart(store adt.Store) (abi.ChainEpoch, erro return st.ProvingPeriodStart, nil } -func (m *MinerStateV2) LoadSectorInfo(store adt.Store, sectorNo uint64) (SimSectorInfo, error) { +func (m *MinerStateV4) LoadSectorInfo(store adt.Store, sectorNo uint64) (SimSectorInfo, error) { st, err := m.state(store) if err != nil { return nil, err @@ -64,10 +64,10 @@ func (m *MinerStateV2) LoadSectorInfo(store adt.Store, sectorNo uint64) (SimSect if err != nil { return nil, err } - return &SectorInfoV2{info: sectors[0]}, nil + return &SectorInfoV4{info: sectors[0]}, nil } -func (m *MinerStateV2) DeadlineInfo(store adt.Store, currEpoch abi.ChainEpoch) (*dline.Info, error) { +func (m *MinerStateV4) DeadlineInfo(store adt.Store, currEpoch abi.ChainEpoch) (*dline.Info, error) { st, err := m.state(store) if err != nil { return nil, err @@ -75,7 +75,7 @@ func (m *MinerStateV2) DeadlineInfo(store adt.Store, currEpoch abi.ChainEpoch) ( return st.DeadlineInfo(currEpoch), nil } -func (m *MinerStateV2) FeeDebt(store adt.Store) (abi.TokenAmount, error) { +func (m *MinerStateV4) FeeDebt(store adt.Store) (abi.TokenAmount, error) { st, err := m.state(store) if err != nil { return big.Zero(), err @@ -83,7 +83,7 @@ func (m *MinerStateV2) FeeDebt(store adt.Store) (abi.TokenAmount, error) { return st.FeeDebt, nil } -func (m *MinerStateV2) LoadDeadlineState(store adt.Store, dlIdx uint64) (SimDeadlineState, error) { +func (m *MinerStateV4) LoadDeadlineState(store adt.Store, dlIdx uint64) (SimDeadlineState, error) { st, err := m.state(store) if err != nil { return nil, err @@ -96,46 +96,46 @@ func (m *MinerStateV2) LoadDeadlineState(store adt.Store, dlIdx uint64) (SimDead if err != nil { return nil, err } - return &DeadlineStateV2{deadline: dline}, nil + return &DeadlineStateV4{deadline: dline}, nil } -type DeadlineStateV2 struct { - deadline *miner2.Deadline +type DeadlineStateV4 struct { + deadline *miner4.Deadline } -func (d *DeadlineStateV2) LoadPartition(store adt.Store, partIdx uint64) (SimPartitionState, error) { +func (d *DeadlineStateV4) LoadPartition(store adt.Store, partIdx uint64) (SimPartitionState, error) { part, err := d.deadline.LoadPartition(store, partIdx) if err != nil { return nil, err } - return &PartitionStateV2{partition: part}, nil + return &PartitionStateV4{partition: part}, nil } -type PartitionStateV2 struct { - partition *miner2.Partition +type PartitionStateV4 struct { + partition *miner4.Partition } -func (p *PartitionStateV2) Terminated() bitfield.BitField { +func (p *PartitionStateV4) Terminated() bitfield.BitField { return p.partition.Terminated } -type SectorInfoV2 struct { - info *miner2.SectorOnChainInfo +type SectorInfoV4 struct { + info *miner4.SectorOnChainInfo } -func (s *SectorInfoV2) Expiration() abi.ChainEpoch { +func (s *SectorInfoV4) Expiration() abi.ChainEpoch { return s.info.Expiration } -type MinerStateV3 struct { +type MinerStateV5 struct { Root cid.Cid - st *miner3.State + st *miner5.State Ctx context.Context } -func (m *MinerStateV3) state(store adt.Store) (*miner3.State, error) { +func (m *MinerStateV5) state(store adt.Store) (*miner5.State, error) { if m.st == nil { - var st miner3.State + var st miner5.State err := store.Get(m.Ctx, m.Root, &st) if err != nil { return nil, err @@ -145,7 +145,7 @@ func (m *MinerStateV3) state(store adt.Store) (*miner3.State, error) { return m.st, nil } -func (m *MinerStateV3) HasSectorNo(store adt.Store, sectorNo abi.SectorNumber) (bool, error) { +func (m *MinerStateV5) HasSectorNo(store adt.Store, sectorNo abi.SectorNumber) (bool, error) { st, err := m.state(store) if err != nil { return false, err @@ -153,7 +153,7 @@ func (m *MinerStateV3) HasSectorNo(store adt.Store, sectorNo abi.SectorNumber) ( return st.HasSectorNo(store, sectorNo) } -func (m *MinerStateV3) FindSector(store adt.Store, sectorNo abi.SectorNumber) (uint64, uint64, error) { +func (m *MinerStateV5) FindSector(store adt.Store, sectorNo abi.SectorNumber) (uint64, uint64, error) { st, err := m.state(store) if err != nil { return 0, 0, err @@ -161,7 +161,7 @@ func (m *MinerStateV3) FindSector(store adt.Store, sectorNo abi.SectorNumber) (u return st.FindSector(store, sectorNo) } -func (m *MinerStateV3) ProvingPeriodStart(store adt.Store) (abi.ChainEpoch, error) { +func (m *MinerStateV5) ProvingPeriodStart(store adt.Store) (abi.ChainEpoch, error) { st, err := m.state(store) if err != nil { return 0, err @@ -169,7 +169,7 @@ func (m *MinerStateV3) ProvingPeriodStart(store adt.Store) (abi.ChainEpoch, erro return st.ProvingPeriodStart, nil } -func (m *MinerStateV3) LoadSectorInfo(store adt.Store, sectorNo uint64) (SimSectorInfo, error) { +func (m *MinerStateV5) LoadSectorInfo(store adt.Store, sectorNo uint64) (SimSectorInfo, error) { st, err := m.state(store) if err != nil { return nil, err @@ -178,10 +178,10 @@ func (m *MinerStateV3) LoadSectorInfo(store adt.Store, sectorNo uint64) (SimSect if err != nil { return nil, err } - return &SectorInfoV3{info: sectors[0]}, nil + return &SectorInfoV5{info: sectors[0]}, nil } -func (m *MinerStateV3) DeadlineInfo(store adt.Store, currEpoch abi.ChainEpoch) (*dline.Info, error) { +func (m *MinerStateV5) DeadlineInfo(store adt.Store, currEpoch abi.ChainEpoch) (*dline.Info, error) { st, err := m.state(store) if err != nil { return nil, err @@ -189,7 +189,7 @@ func (m *MinerStateV3) DeadlineInfo(store adt.Store, currEpoch abi.ChainEpoch) ( return st.DeadlineInfo(currEpoch), nil } -func (m *MinerStateV3) FeeDebt(store adt.Store) (abi.TokenAmount, error) { +func (m *MinerStateV5) FeeDebt(store adt.Store) (abi.TokenAmount, error) { st, err := m.state(store) if err != nil { return big.Zero(), err @@ -197,7 +197,7 @@ func (m *MinerStateV3) FeeDebt(store adt.Store) (abi.TokenAmount, error) { return st.FeeDebt, nil } -func (m *MinerStateV3) LoadDeadlineState(store adt.Store, dlIdx uint64) (SimDeadlineState, error) { +func (m *MinerStateV5) LoadDeadlineState(store adt.Store, dlIdx uint64) (SimDeadlineState, error) { st, err := m.state(store) if err != nil { return nil, err @@ -210,33 +210,33 @@ func (m *MinerStateV3) LoadDeadlineState(store adt.Store, dlIdx uint64) (SimDead if err != nil { return nil, err } - return &DeadlineStateV3{deadline: dline}, nil + return &DeadlineStateV5{deadline: dline}, nil } -type DeadlineStateV3 struct { - deadline *miner3.Deadline +type DeadlineStateV5 struct { + deadline *miner5.Deadline } -func (d *DeadlineStateV3) LoadPartition(store adt.Store, partIdx uint64) (SimPartitionState, error) { +func (d *DeadlineStateV5) LoadPartition(store adt.Store, partIdx uint64) (SimPartitionState, error) { part, err := d.deadline.LoadPartition(store, partIdx) if err != nil { return nil, err } - return &PartitionStateV3{partition: part}, nil + return &PartitionStateV5{partition: part}, nil } -type PartitionStateV3 struct { - partition *miner3.Partition +type PartitionStateV5 struct { + partition *miner5.Partition } -func (p *PartitionStateV3) Terminated() bitfield.BitField { +func (p *PartitionStateV5) Terminated() bitfield.BitField { return p.partition.Terminated } -type SectorInfoV3 struct { - info *miner3.SectorOnChainInfo +type SectorInfoV5 struct { + info *miner5.SectorOnChainInfo } -func (s *SectorInfoV3) Expiration() abi.ChainEpoch { +func (s *SectorInfoV5) Expiration() abi.ChainEpoch { return s.info.Expiration } diff --git a/support/agent/sim.go b/support/agent/sim.go index 268907fcf..549e519e7 100644 --- a/support/agent/sim.go +++ b/support/agent/sim.go @@ -15,8 +15,6 @@ import ( "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/go-state-types/rt" - power2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/power" - reward2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/reward" cid "github.com/ipfs/go-cid" ipldcbor "github.com/ipfs/go-ipld-cbor" "github.com/pkg/errors" @@ -24,15 +22,14 @@ import ( adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" vm2 "github.com/filecoin-project/specs-actors/v2/support/vm" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - power3 "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward" - "github.com/filecoin-project/specs-actors/v4/actors/states" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/ipld" - vm "github.com/filecoin-project/specs-actors/v4/support/vm" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/reward" + "github.com/filecoin-project/specs-actors/v5/actors/states" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/ipld" + vm "github.com/filecoin-project/specs-actors/v5/support/vm" ) // Sim is a simulation framework to exercise actor code in a network-like environment. @@ -45,13 +42,11 @@ import ( // * Messages will be shuffled to simulate network entropy. // * Messages will be applied and an new VM will be created from the resulting state tree for the next tick. type Sim struct { - Config SimConfig - Agents []Agent - DealProviders []DealProvider - WinCount uint64 - MessageCount uint64 - ComputePowerTable func(SimVM, []Agent) (PowerTable, error) - CreateMinerParamsFunc func(address.Address, address.Address, abi.RegisteredSealProof) (interface{}, error) + Config SimConfig + Agents []Agent + DealProviders []DealProvider + WinCount uint64 + MessageCount uint64 v SimVM vmFactory VMFactoryFunc @@ -75,61 +70,53 @@ func NewSim(ctx context.Context, t testing.TB, blockstoreFactory func() ipldcbor } v.SetStatsSource(metrics) minerStateFactory := func(ctx context.Context, root cid.Cid) (SimMinerState, error) { - return &MinerStateV3{ + return &MinerStateV5{ Ctx: ctx, Root: root, }, nil } return &Sim{ - Config: config, - Agents: []Agent{}, - DealProviders: []DealProvider{}, - ComputePowerTable: ComputePowerTableV3, - CreateMinerParamsFunc: CreateMinerParamsV3, - v: v, - vmFactory: vmFactory, - minerStateFactory: minerStateFactory, - rnd: rand.New(rand.NewSource(config.Seed)), - blkStore: blkStore, - blkStoreFactory: blockstoreFactory, - ctx: ctx, - t: t, + Config: config, + Agents: []Agent{}, + DealProviders: []DealProvider{}, + v: v, + vmFactory: vmFactory, + minerStateFactory: minerStateFactory, + rnd: rand.New(rand.NewSource(config.Seed)), + blkStore: blkStore, + blkStoreFactory: blockstoreFactory, + ctx: ctx, + t: t, } } func NewSimWithVM(ctx context.Context, t testing.TB, v SimVM, vmFactory VMFactoryFunc, - computePowerTable func(SimVM, []Agent) (PowerTable, error), blkStore ipldcbor.IpldBlockstore, - blockstoreFactory func() ipldcbor.IpldBlockstore, minerStateFactory func(context.Context, cid.Cid) (SimMinerState, error), - config SimConfig, createMinerParams func(address.Address, address.Address, abi.RegisteredSealProof) (interface{}, error), + blkStore ipldcbor.IpldBlockstore, blockstoreFactory func() ipldcbor.IpldBlockstore, + minerStateFactory func(context.Context, cid.Cid) (SimMinerState, error), config SimConfig, ) *Sim { metrics := ipld.NewMetricsBlockStore(blkStore) v.SetStatsSource(metrics) return &Sim{ - Config: config, - Agents: []Agent{}, - DealProviders: []DealProvider{}, - ComputePowerTable: computePowerTable, - CreateMinerParamsFunc: createMinerParams, - v: v, - vmFactory: vmFactory, - minerStateFactory: minerStateFactory, - rnd: rand.New(rand.NewSource(config.Seed)), - blkStore: blkStore, - blkStoreFactory: blockstoreFactory, - ctx: ctx, - t: t, + Config: config, + Agents: []Agent{}, + DealProviders: []DealProvider{}, + v: v, + vmFactory: vmFactory, + minerStateFactory: minerStateFactory, + rnd: rand.New(rand.NewSource(config.Seed)), + blkStore: blkStore, + blkStoreFactory: blockstoreFactory, + ctx: ctx, + t: t, } } func (s *Sim) SwapVM(v SimVM, vmFactory VMFactoryFunc, minerStateFactory func(context.Context, cid.Cid) (SimMinerState, error), - computePowerTable func(SimVM, []Agent) (PowerTable, error), createMinerParams func(address.Address, address.Address, abi.RegisteredSealProof) (interface{}, error), ) { s.v = v s.vmFactory = vmFactory s.minerStateFactory = minerStateFactory - s.ComputePowerTable = computePowerTable - s.CreateMinerParamsFunc = createMinerParams } ////////////////////////////////////////// @@ -142,7 +129,7 @@ func (s *Sim) Tick() error { var err error var blockMessages []message // compute power table before state transition to create block rewards at the end - powerTable, err := s.ComputePowerTable(s.v, s.Agents) + powerTable, err := s.computePowerTable(s.v, s.Agents) if err != nil { return err } @@ -297,8 +284,18 @@ func (s *Sim) NetworkCirculatingSupply() abi.TokenAmount { return s.v.GetCirculatingSupply() } -func (s *Sim) CreateMinerParams(worker, owner address.Address, sealProof abi.RegisteredSealProof) (interface{}, error) { - return s.CreateMinerParamsFunc(worker, owner, sealProof) +func (s *Sim) CreateMinerParams(worker, owner address.Address, sealProof abi.RegisteredSealProof) (*power.CreateMinerParams, error) { + wPoStProof, err := sealProof.RegisteredWindowPoStProof() + if err != nil { + return nil, err + } + + return &power.CreateMinerParams{ + Owner: owner, + Worker: worker, + WindowPoStProofType: wPoStProof, + }, nil + } ////////////////////////////////////////////////// @@ -325,7 +322,7 @@ func (s *Sim) rewardMiner(addr address.Address, wins uint64) error { return nil } -func ComputePowerTableV3(v SimVM, agents []Agent) (PowerTable, error) { +func (s *Sim) computePowerTable(v SimVM, agents []Agent) (PowerTable, error) { pt := PowerTable{} var rwst reward.State @@ -356,58 +353,6 @@ func ComputePowerTableV3(v SimVM, agents []Agent) (PowerTable, error) { return pt, nil } -func ComputePowerTableV2(v SimVM, agents []Agent) (PowerTable, error) { - pt := PowerTable{} - - var rwst reward2.State - if err := v.GetState(builtin.RewardActorAddr, &rwst); err != nil { - return PowerTable{}, err - } - pt.blockReward = rwst.ThisEpochReward - - var st power2.State - if err := v.GetState(builtin.StoragePowerActorAddr, &st); err != nil { - return PowerTable{}, err - } - pt.totalQAPower = st.TotalQualityAdjPower - - for _, agent := range agents { - if miner, ok := agent.(*MinerAgent); ok { - if claim, found, err := st.GetClaim(v.Store(), miner.IDAddress); err != nil { - return pt, err - } else if found { - if sufficient, err := st.MinerNominalPowerMeetsConsensusMinimum(v.Store(), miner.IDAddress); err != nil { - return pt, err - } else if sufficient { - pt.minerPower = append(pt.minerPower, minerPowerTable{miner.IDAddress, claim.QualityAdjPower}) - } - } - } - } - return pt, nil -} - -func CreateMinerParamsV2(worker, owner address.Address, sealProof abi.RegisteredSealProof) (interface{}, error) { - return &power2.CreateMinerParams{ - Owner: owner, - Worker: worker, - SealProofType: sealProof, - }, nil -} - -func CreateMinerParamsV3(worker, owner address.Address, sealProof abi.RegisteredSealProof) (interface{}, error) { - wPoStProof, err := sealProof.RegisteredWindowPoStProof() - if err != nil { - return nil, err - } - - return &power3.CreateMinerParams{ - Owner: owner, - Worker: worker, - WindowPoStProofType: wPoStProof, - }, nil -} - func computeCircSupply(v SimVM) error { // disbursed + reward.State.TotalStoragePowerReward - burnt.Balance - power.State.TotalPledgeCollateral var rewardSt reward.State @@ -446,7 +391,7 @@ type SimState interface { AddDealProvider(d DealProvider) NetworkCirculatingSupply() abi.TokenAmount MinerState(addr address.Address) (SimMinerState, error) - CreateMinerParams(worker, owner address.Address, sealProof abi.RegisteredSealProof) (interface{}, error) + CreateMinerParams(worker, owner address.Address, sealProof abi.RegisteredSealProof) (*power.CreateMinerParams, error) // randomly select an agent capable of making deals. // Returns nil if no providers exist. diff --git a/support/ipld/store.go b/support/ipld/store.go index 71824d1ef..b1791ce09 100644 --- a/support/ipld/store.go +++ b/support/ipld/store.go @@ -9,7 +9,7 @@ import ( "github.com/ipfs/go-cid" ipldcbor "github.com/ipfs/go-ipld-cbor" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) // Creates a new, empty, unsynchronized IPLD store in memory. diff --git a/support/mock/mockrt.go b/support/mock/mockrt.go index 4e2c0d79f..21ad048c4 100644 --- a/support/mock/mockrt.go +++ b/support/mock/mockrt.go @@ -21,12 +21,12 @@ import ( cid "github.com/ipfs/go-cid" mh "github.com/multiformats/go-multihash" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/exported" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" - "github.com/filecoin-project/specs-actors/v4/actors/runtime/proof" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/ipld" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/exported" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/ipld" ) // A mock runtime for unit testing of actors in isolation. diff --git a/support/mock/mockrt_state_test.go b/support/mock/mockrt_state_test.go index 5cd3df450..824afea0f 100644 --- a/support/mock/mockrt_state_test.go +++ b/support/mock/mockrt_state_test.go @@ -11,9 +11,9 @@ import ( mh "github.com/multiformats/go-multihash" cbg "github.com/whyrusleeping/cbor-gen" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" - tutil "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" + tutil "github.com/filecoin-project/specs-actors/v5/support/testing" ) type FakeActor struct{} diff --git a/support/tools/go.mod b/support/tools/go.mod index a4bb12e63..1efd2b93e 100644 --- a/support/tools/go.mod +++ b/support/tools/go.mod @@ -1,6 +1,6 @@ -module github.com/filecoin-project/specs-actors/v4/support/tools +module github.com/filecoin-project/specs-actors/v5/support/tools -go 1.13 +go 1.16 require ( github.com/Kubuxu/go-no-map-range v0.0.1 diff --git a/support/vm/invocation_context.go b/support/vm/invocation_context.go index 55805f8ed..3eb7de878 100644 --- a/support/vm/invocation_context.go +++ b/support/vm/invocation_context.go @@ -21,14 +21,14 @@ import ( "github.com/minio/blake2b-simd" "github.com/pkg/errors" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - init_ "github.com/filecoin-project/specs-actors/v4/actors/builtin/init" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" - "github.com/filecoin-project/specs-actors/v4/actors/runtime/proof" - "github.com/filecoin-project/specs-actors/v4/actors/states" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/support/ipld" - "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + init_ "github.com/filecoin-project/specs-actors/v5/actors/builtin/init" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" + "github.com/filecoin-project/specs-actors/v5/actors/states" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/support/ipld" + "github.com/filecoin-project/specs-actors/v5/support/testing" ) var EmptyObjectCid cid.Cid diff --git a/support/vm/testing.go b/support/vm/testing.go index b85e92981..f993f9bdb 100644 --- a/support/vm/testing.go +++ b/support/vm/testing.go @@ -17,22 +17,22 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/account" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/cron" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/exported" - initactor "github.com/filecoin-project/specs-actors/v4/actors/builtin/init" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/system" - "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" - "github.com/filecoin-project/specs-actors/v4/actors/states" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/specs-actors/v4/actors/util/smoothing" - actor_testing "github.com/filecoin-project/specs-actors/v4/support/testing" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/account" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/cron" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/exported" + initactor "github.com/filecoin-project/specs-actors/v5/actors/builtin/init" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/reward" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/system" + "github.com/filecoin-project/specs-actors/v5/actors/builtin/verifreg" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/states" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/util/smoothing" + actor_testing "github.com/filecoin-project/specs-actors/v5/support/testing" ) var FIL = big.NewInt(1e18) diff --git a/support/vm/vm.go b/support/vm/vm.go index 5960cafb0..eb9114b6d 100644 --- a/support/vm/vm.go +++ b/support/vm/vm.go @@ -15,11 +15,11 @@ import ( "github.com/ipfs/go-cid" "github.com/pkg/errors" - "github.com/filecoin-project/specs-actors/v4/actors/builtin" - init_ "github.com/filecoin-project/specs-actors/v4/actors/builtin/init" - "github.com/filecoin-project/specs-actors/v4/actors/runtime" - "github.com/filecoin-project/specs-actors/v4/actors/states" - "github.com/filecoin-project/specs-actors/v4/actors/util/adt" + "github.com/filecoin-project/specs-actors/v5/actors/builtin" + init_ "github.com/filecoin-project/specs-actors/v5/actors/builtin/init" + "github.com/filecoin-project/specs-actors/v5/actors/runtime" + "github.com/filecoin-project/specs-actors/v5/actors/states" + "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) // VM is a simplified message execution framework for the purposes of testing inter-actor communication.