From ee21351aa0c80e5303ad6fb5645211a03c6bee1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 1 Jun 2021 21:16:01 +0200 Subject: [PATCH 1/5] statetree: Add missing version defs --- chain/state/statetree.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/chain/state/statetree.go b/chain/state/statetree.go index 81ab82e14..40955c48b 100644 --- a/chain/state/statetree.go +++ b/chain/state/statetree.go @@ -152,6 +152,8 @@ func VersionForNetwork(ver network.Version) (types.StateTreeVersion, error) { return types.StateTreeVersion2, nil case network.Version12: return types.StateTreeVersion3, nil + case network.Version13: + return types.StateTreeVersion4, nil default: panic(fmt.Sprintf("unsupported network version %d", ver)) } @@ -162,7 +164,7 @@ func NewStateTree(cst cbor.IpldStore, ver types.StateTreeVersion) (*StateTree, e switch ver { case types.StateTreeVersion0: // info is undefined - case types.StateTreeVersion1, types.StateTreeVersion2, types.StateTreeVersion3: + case types.StateTreeVersion1, types.StateTreeVersion2, types.StateTreeVersion3, types.StateTreeVersion4: var err error info, err = cst.Put(context.TODO(), new(types.StateInfo0)) if err != nil { From 2f0a9f6c407658499f68d3767fcf166c91924067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 1 Jun 2021 21:28:48 +0200 Subject: [PATCH 2/5] Improve AddVerifiedClient test --- api/test/test.go | 56 +++++++----- api/test/verifreg.go | 213 +++++++++++++++++++++++-------------------- 2 files changed, 148 insertions(+), 121 deletions(-) diff --git a/api/test/test.go b/api/test/test.go index 8f8d95100..11f0f41ea 100644 --- a/api/test/test.go +++ b/api/test/test.go @@ -122,31 +122,45 @@ var OneFull = DefaultFullOpts(1) var TwoFull = DefaultFullOpts(2) var FullNodeWithLatestActorsAt = func(upgradeHeight abi.ChainEpoch) FullNodeOpts { - if upgradeHeight == -1 { - // Attention: Update this when introducing new actor versions or your tests will be sad - upgradeHeight = 4 + // Attention: Update this when introducing new actor versions or your tests will be sad + return FullNodeWithActorsUpgradeAt(network.Version13, upgradeHeight) +} + +var FullNodeWithActorsUpgradeAt = func(version network.Version, upgradeHeight abi.ChainEpoch) FullNodeOpts { + fullSchedule := stmgr.UpgradeSchedule{{ + // prepare for upgrade. + Network: network.Version9, + Height: 1, + Migration: stmgr.UpgradeActorsV2, + }, { + Network: network.Version10, + Height: 2, + Migration: stmgr.UpgradeActorsV3, + }, { + Network: network.Version12, + Height: 3, + Migration: stmgr.UpgradeActorsV4, + }, { + Network: network.Version13, + Height: 4, + Migration: stmgr.UpgradeActorsV5, + }} + + schedule := stmgr.UpgradeSchedule{} + for _, upgrade := range fullSchedule { + if upgrade.Network > version { + break + } + + schedule = append(schedule, upgrade) } + if upgradeHeight > 0 { + schedule[len(schedule)-1].Height = upgradeHeight + } return FullNodeOpts{ Opts: func(nodes []TestNode) node.Option { - return node.Override(new(stmgr.UpgradeSchedule), stmgr.UpgradeSchedule{{ - // prepare for upgrade. - Network: network.Version9, - Height: 1, - Migration: stmgr.UpgradeActorsV2, - }, { - Network: network.Version10, - Height: 2, - Migration: stmgr.UpgradeActorsV3, - }, { - Network: network.Version12, - Height: 3, - Migration: stmgr.UpgradeActorsV4, - }, { - Network: network.Version13, - Height: upgradeHeight, - Migration: stmgr.UpgradeActorsV5, - }}) + return node.Override(new(stmgr.UpgradeSchedule), fullSchedule) }, } } diff --git a/api/test/verifreg.go b/api/test/verifreg.go index b66ca1a36..266bed190 100644 --- a/api/test/verifreg.go +++ b/api/test/verifreg.go @@ -2,6 +2,7 @@ package test import ( "context" + "github.com/filecoin-project/go-state-types/network" "strings" lapi "github.com/filecoin-project/lotus/api" @@ -19,108 +20,120 @@ import ( ) func AddVerifiedClient(t *testing.T, b APIBuilder) { + test := func(nv network.Version, shouldWork bool) func(*testing.T) { + return func(t *testing.T) { - nodes, miners := b(t, []FullNodeOpts{FullNodeWithLatestActorsAt(-1)}, OneMiner) - api := nodes[0].FullNode.(*impl.FullNodeAPI) - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() + nodes, miners := b(t, []FullNodeOpts{FullNodeWithActorsUpgradeAt(nv, -1)}, OneMiner) + api := nodes[0].FullNode.(*impl.FullNodeAPI) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() - //Get VRH - vrh, err := api.StateVerifiedRegistryRootKey(ctx, types.TipSetKey{}) - if err != nil { - t.Fatal(err) + //Get VRH + vrh, err := api.StateVerifiedRegistryRootKey(ctx, types.TipSetKey{}) + if err != nil { + t.Fatal(err) + } + + //Add verifier + verifier, err := api.WalletDefaultAddress(ctx) + if err != nil { + t.Fatal(err) + } + + params, err := actors.SerializeParams(&verifreg4.AddVerifierParams{Address: verifier, Allowance: big.NewInt(100000000000)}) + if err != nil { + t.Fatal(err) + } + msg := &types.Message{ + To: verifreg.Address, + From: vrh, + Method: verifreg.Methods.AddVerifier, + Params: params, + Value: big.Zero(), + } + + bm := NewBlockMiner(ctx, t, miners[0], 100*time.Millisecond) + bm.MineBlocks() + defer bm.Stop() + + sm, err := api.MpoolPushMessage(ctx, msg, nil) + if err != nil { + t.Fatal("AddVerifier failed: ", err) + } + res, err := api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true) + if err != nil { + t.Fatal(err) + } + if res.Receipt.ExitCode != 0 { + t.Fatal("did not successfully send message") + } + + //Assign datacap to a client + datacap := big.NewInt(10000) + clientAddress, err := api.WalletNew(ctx, types.KTBLS) + if err != nil { + t.Fatal(err) + } + + params, err = actors.SerializeParams(&verifreg4.AddVerifiedClientParams{Address: clientAddress, Allowance: datacap}) + if err != nil { + t.Fatal(err) + } + + msg = &types.Message{ + To: verifreg.Address, + From: verifier, + Method: verifreg.Methods.AddVerifiedClient, + Params: params, + Value: big.Zero(), + } + + sm, err = api.MpoolPushMessage(ctx, msg, nil) + if err != nil { + t.Fatal("AddVerifiedClient faield: ", err) + } + res, err = api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true) + if err != nil { + t.Fatal(err) + } + if res.Receipt.ExitCode != 0 { + t.Fatal("did not successfully send message") + } + + //check datacap balance + dcap, err := api.StateVerifiedClientStatus(ctx, clientAddress, types.EmptyTSK) + if err != nil { + t.Fatal(err) + } + if !dcap.Equals(datacap) { + t.Fatal("") + } + + //try to assign datacap to the same client should fail for actor v4 and below + params, err = actors.SerializeParams(&verifreg4.AddVerifiedClientParams{Address: clientAddress, Allowance: datacap}) + if err != nil { + t.Fatal(err) + } + + msg = &types.Message{ + To: verifreg.Address, + From: verifier, + Method: verifreg.Methods.AddVerifiedClient, + Params: params, + Value: big.Zero(), + } + + _, err = api.MpoolPushMessage(ctx, msg, nil) + if shouldWork && err != nil { + t.Fatal("expected nil err", err) + } + + if !shouldWork && err == nil || !strings.Contains(err.Error(), "verified client already exists") { + t.Fatal("Add datacap to an existing verified client should fail") + } + } } - //Add verifier - verifier, err := api.WalletDefaultAddress(ctx) - if err != nil { - t.Fatal(err) - } - - params, err := actors.SerializeParams(&verifreg4.AddVerifierParams{Address: verifier, Allowance: big.NewInt(100000000000)}) - if err != nil { - t.Fatal(err) - } - msg := &types.Message{ - To: verifreg.Address, - From: vrh, - Method: verifreg.Methods.AddVerifier, - Params: params, - Value: big.Zero(), - } - - bm := NewBlockMiner(ctx, t, miners[0], 100*time.Millisecond) - bm.MineBlocks() - defer bm.Stop() - - sm, err := api.MpoolPushMessage(ctx, msg, nil) - if err != nil { - t.Fatal("AddVerifier failed: ", err) - } - res, err := api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true) - if err != nil { - t.Fatal(err) - } - if res.Receipt.ExitCode != 0 { - t.Fatal("did not successfully send message") - } - - //Assign datacap to a client - datacap := big.NewInt(10000) - clientAddress, err := api.WalletNew(ctx, types.KTBLS) - if err != nil { - t.Fatal(err) - } - - params, err = actors.SerializeParams(&verifreg4.AddVerifiedClientParams{Address: clientAddress, Allowance: datacap}) - if err != nil { - t.Fatal(err) - } - - msg = &types.Message{ - To: verifreg.Address, - From: verifier, - Method: verifreg.Methods.AddVerifiedClient, - Params: params, - Value: big.Zero(), - } - - sm, err = api.MpoolPushMessage(ctx, msg, nil) - if err != nil { - t.Fatal("AddVerifiedClient faield: ", err) - } - res, err = api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true) - if err != nil { - t.Fatal(err) - } - if res.Receipt.ExitCode != 0 { - t.Fatal("did not successfully send message") - } - - //check datacap balance - dcap, err := api.StateVerifiedClientStatus(ctx, clientAddress, types.EmptyTSK) - if err != nil { - t.Fatal(err) - } - if !dcap.Equals(datacap) { - t.Fatal("") - } - - //try to assign datacap to the same client should fail for actor v4 and below - params, err = actors.SerializeParams(&verifreg4.AddVerifiedClientParams{Address: clientAddress, Allowance: datacap}) - if err != nil { - t.Fatal(err) - } - - msg = &types.Message{ - To: verifreg.Address, - From: verifier, - Method: verifreg.Methods.AddVerifiedClient, - Params: params, - Value: big.Zero(), - } - - if _, err = api.MpoolPushMessage(ctx, msg, nil); !strings.Contains(err.Error(), "verified client already exists") { - t.Fatal("Add datacap to an exist verified client should fail") - } + t.Run("nv12", test(network.Version12, false)) + t.Run("nv13", test(network.Version13, true)) } From f00cf70df078d594dfa6b0f8024490f003add1fc Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 1 Jun 2021 17:11:54 -0400 Subject: [PATCH 3/5] Magik shouldn't write code at midnight --- api/test/test.go | 7 ++++--- api/test/verifreg.go | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/api/test/test.go b/api/test/test.go index 11f0f41ea..7609d0702 100644 --- a/api/test/test.go +++ b/api/test/test.go @@ -123,10 +123,10 @@ var TwoFull = DefaultFullOpts(2) var FullNodeWithLatestActorsAt = func(upgradeHeight abi.ChainEpoch) FullNodeOpts { // Attention: Update this when introducing new actor versions or your tests will be sad - return FullNodeWithActorsUpgradeAt(network.Version13, upgradeHeight) + return FullNodeWithNetworkUpgradeAt(network.Version13, upgradeHeight) } -var FullNodeWithActorsUpgradeAt = func(version network.Version, upgradeHeight abi.ChainEpoch) FullNodeOpts { +var FullNodeWithNetworkUpgradeAt = func(version network.Version, upgradeHeight abi.ChainEpoch) FullNodeOpts { fullSchedule := stmgr.UpgradeSchedule{{ // prepare for upgrade. Network: network.Version9, @@ -158,9 +158,10 @@ var FullNodeWithActorsUpgradeAt = func(version network.Version, upgradeHeight ab if upgradeHeight > 0 { schedule[len(schedule)-1].Height = upgradeHeight } + return FullNodeOpts{ Opts: func(nodes []TestNode) node.Option { - return node.Override(new(stmgr.UpgradeSchedule), fullSchedule) + return node.Override(new(stmgr.UpgradeSchedule), schedule) }, } } diff --git a/api/test/verifreg.go b/api/test/verifreg.go index 266bed190..3fc1fb75a 100644 --- a/api/test/verifreg.go +++ b/api/test/verifreg.go @@ -2,9 +2,10 @@ package test import ( "context" - "github.com/filecoin-project/go-state-types/network" "strings" + "github.com/filecoin-project/go-state-types/network" + lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors" @@ -23,7 +24,7 @@ func AddVerifiedClient(t *testing.T, b APIBuilder) { test := func(nv network.Version, shouldWork bool) func(*testing.T) { return func(t *testing.T) { - nodes, miners := b(t, []FullNodeOpts{FullNodeWithActorsUpgradeAt(nv, -1)}, OneMiner) + nodes, miners := b(t, []FullNodeOpts{FullNodeWithNetworkUpgradeAt(nv, -1)}, OneMiner) api := nodes[0].FullNode.(*impl.FullNodeAPI) ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -128,7 +129,7 @@ func AddVerifiedClient(t *testing.T, b APIBuilder) { t.Fatal("expected nil err", err) } - if !shouldWork && err == nil || !strings.Contains(err.Error(), "verified client already exists") { + if !shouldWork && (err == nil || !strings.Contains(err.Error(), "verified client already exists")) { t.Fatal("Add datacap to an existing verified client should fail") } } From 964435a78c112a96306a63cceaccd92248103b26 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 1 Jun 2021 17:39:45 -0400 Subject: [PATCH 4/5] CLI docsgen --- documentation/en/cli-lotus-miner.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/documentation/en/cli-lotus-miner.md b/documentation/en/cli-lotus-miner.md index dfa9072c9..b4b245514 100644 --- a/documentation/en/cli-lotus-miner.md +++ b/documentation/en/cli-lotus-miner.md @@ -1533,9 +1533,9 @@ USAGE: lotus-miner sectors batching command [command options] [arguments...] COMMANDS: - pending-commit list sectors waiting in commit batch queue - pending-precommit list sectors waiting in precommit batch queue - help, h Shows a list of commands or help for one command + commit list sectors waiting in commit batch queue + precommit list sectors waiting in precommit batch queue + help, h Shows a list of commands or help for one command OPTIONS: --help, -h show help (default: false) @@ -1543,13 +1543,13 @@ OPTIONS: ``` -#### lotus-miner sectors batching pending-commit +#### lotus-miner sectors batching commit ``` NAME: - lotus-miner sectors batching pending-commit - list sectors waiting in commit batch queue + lotus-miner sectors batching commit - list sectors waiting in commit batch queue USAGE: - lotus-miner sectors batching pending-commit [command options] [arguments...] + lotus-miner sectors batching commit [command options] [arguments...] OPTIONS: --publish-now send a batch now (default: false) @@ -1557,13 +1557,13 @@ OPTIONS: ``` -#### lotus-miner sectors batching pending-precommit +#### lotus-miner sectors batching precommit ``` NAME: - lotus-miner sectors batching pending-precommit - list sectors waiting in precommit batch queue + lotus-miner sectors batching precommit - list sectors waiting in precommit batch queue USAGE: - lotus-miner sectors batching pending-precommit [command options] [arguments...] + lotus-miner sectors batching precommit [command options] [arguments...] OPTIONS: --publish-now send a batch now (default: false) From cf18709100779900ecbb9528d2e39a71fddf97b5 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 1 Jun 2021 17:50:06 -0400 Subject: [PATCH 5/5] Fix TestDeadlineToggling --- api/test/deadlines.go | 2 +- api/test/test.go | 25 ------------------------- 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/api/test/deadlines.go b/api/test/deadlines.go index 43fa731be..987bfb3ae 100644 --- a/api/test/deadlines.go +++ b/api/test/deadlines.go @@ -63,7 +63,7 @@ func TestDeadlineToggling(t *testing.T, b APIBuilder, blocktime time.Duration) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - n, sn := b(t, []FullNodeOpts{FullNodeWithLatestActorsAt(upgradeH)}, OneMiner) + n, sn := b(t, []FullNodeOpts{FullNodeWithNetworkUpgradeAt(network.Version12, upgradeH)}, OneMiner) client := n[0].FullNode.(*impl.FullNodeAPI) minerA := sn[0] diff --git a/api/test/test.go b/api/test/test.go index 7609d0702..64062e4ff 100644 --- a/api/test/test.go +++ b/api/test/test.go @@ -185,31 +185,6 @@ var FullNodeWithSDRAt = func(calico, persian abi.ChainEpoch) FullNodeOpts { } } -var FullNodeWithV4ActorsAt = func(upgradeHeight abi.ChainEpoch) FullNodeOpts { - if upgradeHeight == -1 { - upgradeHeight = 3 - } - - return FullNodeOpts{ - Opts: func(nodes []TestNode) node.Option { - return node.Override(new(stmgr.UpgradeSchedule), stmgr.UpgradeSchedule{{ - // prepare for upgrade. - Network: network.Version9, - Height: 1, - Migration: stmgr.UpgradeActorsV2, - }, { - Network: network.Version10, - Height: 2, - Migration: stmgr.UpgradeActorsV3, - }, { - Network: network.Version12, - Height: upgradeHeight, - Migration: stmgr.UpgradeActorsV4, - }}) - }, - } -} - var MineNext = miner.MineReq{ InjectNulls: 0, Done: func(bool, abi.ChainEpoch, error) {},