From d8afd71f4c92b32097cfe1c128b4d094bf0a90b3 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 12 Nov 2020 14:43:27 -0800 Subject: [PATCH] add a test to demonstrate SDR upgrade while committing sectors --- api/test/test.go | 7 ++- api/test/window_post.go | 114 ++++++++++++++++++++++++++++++++-------- node/node_test.go | 16 ++++++ 3 files changed, 114 insertions(+), 23 deletions(-) diff --git a/api/test/test.go b/api/test/test.go index 95ad2a2a3..a1b82c590 100644 --- a/api/test/test.go +++ b/api/test/test.go @@ -122,7 +122,7 @@ var FullNodeWithActorsV2At = func(upgradeHeight abi.ChainEpoch) FullNodeOpts { } } -var FullNodeWithSDRAt = func(upgradeHeight abi.ChainEpoch) FullNodeOpts { +var FullNodeWithSDRAt = func(calico, persian abi.ChainEpoch) FullNodeOpts { return FullNodeOpts{ Opts: func(nodes []TestNode) node.Option { return node.Override(new(stmgr.UpgradeSchedule), stmgr.UpgradeSchedule{{ @@ -131,8 +131,11 @@ var FullNodeWithSDRAt = func(upgradeHeight abi.ChainEpoch) FullNodeOpts { Migration: stmgr.UpgradeActorsV2, }, { Network: network.Version7, - Height: upgradeHeight, + Height: calico, Migration: stmgr.UpgradeCalico, + }, { + Network: network.Version8, + Height: persian, }}) }, } diff --git a/api/test/window_post.go b/api/test/window_post.go index 95c5dfde1..ff107ae8d 100644 --- a/api/test/window_post.go +++ b/api/test/window_post.go @@ -3,16 +3,19 @@ package test import ( "context" "fmt" + "sort" "sync/atomic" "strings" "testing" "time" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/extern/sector-storage/mock" sealing "github.com/filecoin-project/lotus/extern/storage-sealing" "github.com/filecoin-project/specs-storage/storage" @@ -24,25 +27,95 @@ import ( "github.com/filecoin-project/lotus/node/impl" ) -func TestPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) { - for _, height := range []abi.ChainEpoch{ - 2, // before - 100, // while sealing - 4000, // after - } { - height := height // copy to satisfy lints - t.Run(fmt.Sprintf("sdr-%d", height), func(t *testing.T) { - testPledgeSector(t, b, blocktime, nSectors, height) - }) - } - -} - -func testPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int, sdrHeight abi.ChainEpoch) { +func TestSDRUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - n, sn := b(t, []FullNodeOpts{FullNodeWithSDRAt(sdrHeight)}, OneMiner) + n, sn := b(t, []FullNodeOpts{FullNodeWithSDRAt(500, 1000)}, OneMiner) + client := n[0].FullNode.(*impl.FullNodeAPI) + miner := sn[0] + + addrinfo, err := client.NetAddrsListen(ctx) + if err != nil { + t.Fatal(err) + } + + if err := miner.NetConnect(ctx, addrinfo); err != nil { + t.Fatal(err) + } + build.Clock.Sleep(time.Second) + + pledge := make(chan struct{}) + mine := int64(1) + done := make(chan struct{}) + go func() { + defer close(done) + round := 0 + for atomic.LoadInt64(&mine) != 0 { + build.Clock.Sleep(blocktime) + if err := sn[0].MineOne(ctx, bminer.MineReq{Done: func(bool, abi.ChainEpoch, error) { + + }}); err != nil { + t.Error(err) + } + + // 3 sealing rounds: before, during after. + if round >= 3 { + continue + } + + head, err := client.ChainHead(ctx) + assert.NoError(t, err) + + // rounds happen every 100 blocks, with a 50 block offset. + if head.Height() >= abi.ChainEpoch(round*500+50) { + round++ + pledge <- struct{}{} + + ver, err := client.StateNetworkVersion(ctx, head.Key()) + assert.NoError(t, err) + switch round { + case 1: + assert.Equal(t, network.Version6, ver) + case 2: + assert.Equal(t, network.Version7, ver) + case 3: + assert.Equal(t, network.Version8, ver) + } + } + + } + }() + + // before. + pledgeSectors(t, ctx, miner, 9, 0, pledge) + + s, err := miner.SectorsList(ctx) + require.NoError(t, err) + sort.Slice(s, func(i, j int) bool { + return s[i] < s[j] + }) + + for i, id := range s { + info, err := miner.SectorsStatus(ctx, id, true) + require.NoError(t, err) + expectProof := abi.RegisteredSealProof_StackedDrg2KiBV1 + if i >= 3 { + // after + expectProof = abi.RegisteredSealProof_StackedDrg2KiBV1_1 + } + assert.Equal(t, expectProof, info.SealProof, "sector %d, id %d", i, id) + } + + atomic.StoreInt64(&mine, 0) + <-done +} + +func TestPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + n, sn := b(t, OneFull, OneMiner) client := n[0].FullNode.(*impl.FullNodeAPI) miner := sn[0] @@ -70,9 +143,6 @@ func testPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSect } }() - // Wait for any initial upgrades. - build.Clock.Sleep(10 * blocktime) - pledgeSectors(t, ctx, miner, nSectors, 0, nil) atomic.StoreInt64(&mine, 0) @@ -81,11 +151,13 @@ func testPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSect func pledgeSectors(t *testing.T, ctx context.Context, miner TestStorageNode, n, existing int, blockNotif <-chan struct{}) { for i := 0; i < n; i++ { - err := miner.PledgeSector(ctx) - require.NoError(t, err) if i%3 == 0 && blockNotif != nil { <-blockNotif + log.Errorf("WAIT") } + log.Errorf("PLEDGING %d", i) + err := miner.PledgeSector(ctx) + require.NoError(t, err) } for { diff --git a/node/node_test.go b/node/node_test.go index e553e83b2..b8009aa78 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -93,6 +93,22 @@ func TestDealMining(t *testing.T) { test.TestDealMining(t, builder.MockSbBuilder, 50*time.Millisecond, false) } +func TestSDRUpgrade(t *testing.T) { + logging.SetLogLevel("miner", "ERROR") + logging.SetLogLevel("chainstore", "ERROR") + logging.SetLogLevel("chain", "ERROR") + logging.SetLogLevel("sub", "ERROR") + logging.SetLogLevel("storageminer", "ERROR") + + oldDelay := policy.GetPreCommitChallengeDelay() + policy.SetPreCommitChallengeDelay(5) + t.Cleanup(func() { + policy.SetPreCommitChallengeDelay(oldDelay) + }) + + test.TestSDRUpgrade(t, builder.MockSbBuilder, 50*time.Millisecond) +} + func TestPledgeSectors(t *testing.T) { logging.SetLogLevel("miner", "ERROR") logging.SetLogLevel("chainstore", "ERROR")