2021-12-10 10:33:29 +00:00
|
|
|
//stm: #integration
|
2021-05-18 20:32:10 +00:00
|
|
|
package itests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"sort"
|
|
|
|
"sync/atomic"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2021-05-18 20:32:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
2022-06-14 15:00:51 +00:00
|
|
|
|
2021-05-18 20:32:10 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
2021-06-18 18:45:29 +00:00
|
|
|
"github.com/filecoin-project/lotus/itests/kit"
|
2021-05-18 20:32:10 +00:00
|
|
|
bminer "github.com/filecoin-project/lotus/miner"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSDRUpgrade(t *testing.T) {
|
2021-12-13 12:41:04 +00:00
|
|
|
//stm: @CHAIN_SYNCER_LOAD_GENESIS_001, @CHAIN_SYNCER_FETCH_TIPSET_001,
|
|
|
|
//stm: @CHAIN_SYNCER_START_001, @CHAIN_SYNCER_SYNC_001, @BLOCKCHAIN_BEACON_VALIDATE_BLOCK_VALUES_01
|
|
|
|
//stm: @CHAIN_SYNCER_COLLECT_CHAIN_001, @CHAIN_SYNCER_COLLECT_HEADERS_001, @CHAIN_SYNCER_VALIDATE_TIPSET_001
|
|
|
|
//stm: @CHAIN_SYNCER_NEW_PEER_HEAD_001, @CHAIN_SYNCER_VALIDATE_MESSAGE_META_001, @CHAIN_SYNCER_STOP_001
|
2021-12-14 10:33:33 +00:00
|
|
|
|
|
|
|
//stm: @CHAIN_INCOMING_HANDLE_INCOMING_BLOCKS_001, @CHAIN_INCOMING_VALIDATE_BLOCK_PUBSUB_001, @CHAIN_INCOMING_VALIDATE_MESSAGE_PUBSUB_001
|
2021-12-10 15:08:25 +00:00
|
|
|
//stm: @CHAIN_STATE_NETWORK_VERSION_001
|
2021-12-15 14:30:42 +00:00
|
|
|
|
|
|
|
//stm: @MINER_SECTOR_LIST_001
|
2021-06-18 18:45:29 +00:00
|
|
|
kit.QuietMiningLogs()
|
2021-05-18 20:32:10 +00:00
|
|
|
|
2021-06-07 22:17:44 +00:00
|
|
|
// oldDelay := policy.GetPreCommitChallengeDelay()
|
|
|
|
// policy.SetPreCommitChallengeDelay(5)
|
|
|
|
// t.Cleanup(func() {
|
|
|
|
// policy.SetPreCommitChallengeDelay(oldDelay)
|
|
|
|
// })
|
2021-05-18 20:32:10 +00:00
|
|
|
|
|
|
|
blocktime := 50 * time.Millisecond
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2021-08-06 00:46:05 +00:00
|
|
|
client, miner, ens := kit.EnsembleMinimal(t,
|
|
|
|
kit.MockProofs(),
|
|
|
|
kit.SDRUpgradeAt(500, 1000),
|
|
|
|
)
|
2021-06-15 15:24:57 +00:00
|
|
|
ens.InterconnectAll()
|
2021-05-18 20:32:10 +00:00
|
|
|
|
|
|
|
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)
|
2021-06-15 15:24:57 +00:00
|
|
|
if err := miner.MineOne(ctx, bminer.MineReq{Done: func(bool, abi.ChainEpoch, error) {
|
2021-05-18 20:32:10 +00:00
|
|
|
|
|
|
|
}}); 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.
|
2021-06-15 15:24:57 +00:00
|
|
|
miner.PledgeSectors(ctx, 9, 0, pledge)
|
2021-05-18 20:32:10 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|