2021-05-17 12:28:09 +00:00
|
|
|
package itests
|
2020-07-01 14:49:17 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-05-18 21:01:10 +00:00
|
|
|
"github.com/filecoin-project/lotus/itests/kit"
|
2021-06-14 09:50:40 +00:00
|
|
|
"github.com/filecoin-project/lotus/itests/kit2"
|
2020-07-01 14:49:17 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-07-01 14:49:17 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
2021-05-18 20:32:10 +00:00
|
|
|
func TestCCUpgrade(t *testing.T) {
|
2021-06-14 09:50:40 +00:00
|
|
|
kit2.QuietMiningLogs()
|
2021-05-18 20:32:10 +00:00
|
|
|
|
2020-10-05 17:56:00 +00:00
|
|
|
for _, height := range []abi.ChainEpoch{
|
2021-06-14 09:50:40 +00:00
|
|
|
-1, // before
|
|
|
|
//162, // while sealing
|
|
|
|
//530, // after upgrade deal
|
|
|
|
//5000, // after
|
2020-10-05 17:56:00 +00:00
|
|
|
} {
|
2020-10-05 18:08:46 +00:00
|
|
|
height := height // make linters happy by copying
|
2020-10-05 17:56:00 +00:00
|
|
|
t.Run(fmt.Sprintf("upgrade-%d", height), func(t *testing.T) {
|
2021-06-14 09:50:40 +00:00
|
|
|
runTestCCUpgrade(t, height)
|
2020-10-05 17:56:00 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-14 09:50:40 +00:00
|
|
|
func runTestCCUpgrade(t *testing.T, upgradeHeight abi.ChainEpoch) {
|
2020-07-01 14:49:17 +00:00
|
|
|
ctx := context.Background()
|
2021-06-14 09:50:40 +00:00
|
|
|
blockTime := 5 * time.Millisecond
|
|
|
|
|
|
|
|
client, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(), kit2.LatestActorsAt(upgradeHeight))
|
|
|
|
ens.InterconnectAll().BeginMining(blockTime)
|
|
|
|
|
|
|
|
//b := kit.MockMinerBuilder
|
|
|
|
//n, sn := b(t, []kit.FullNodeOpts{kit.FullNodeWithLatestActorsAt(upgradeHeight)}, kit.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)
|
|
|
|
//}
|
|
|
|
//time.Sleep(time.Second)
|
|
|
|
//
|
|
|
|
//mine := int64(1)
|
|
|
|
//done := make(chan struct{})
|
|
|
|
//go func() {
|
|
|
|
// defer close(done)
|
|
|
|
// for atomic.LoadInt64(&mine) == 1 {
|
|
|
|
// time.Sleep(blocktime)
|
|
|
|
// if err := sn[0].MineOne(ctx, kit.MineNext); err != nil {
|
|
|
|
// t.Error(err)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}()
|
2020-07-01 14:49:17 +00:00
|
|
|
|
|
|
|
maddr, err := miner.ActorAddress(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-05-18 21:01:10 +00:00
|
|
|
CC := abi.SectorNumber(kit.GenesisPreseals + 1)
|
2020-07-01 14:49:17 +00:00
|
|
|
Upgraded := CC + 1
|
|
|
|
|
2021-06-14 09:50:40 +00:00
|
|
|
miner.PledgeSectors(ctx, 1, 0, nil)
|
2020-07-01 14:49:17 +00:00
|
|
|
|
|
|
|
sl, err := miner.SectorsList(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(sl) != 1 {
|
|
|
|
t.Fatal("expected 1 sector")
|
|
|
|
}
|
|
|
|
|
|
|
|
if sl[0] != CC {
|
|
|
|
t.Fatal("bad")
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
si, err := client.StateSectorGetInfo(ctx, maddr, CC, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Less(t, 50000, int(si.Expiration))
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := miner.SectorMarkForUpgrade(ctx, sl[0]); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-06-14 09:50:40 +00:00
|
|
|
dh := kit2.NewDealHarness(t, client, miner)
|
2021-05-20 15:12:42 +00:00
|
|
|
|
2021-06-14 09:50:40 +00:00
|
|
|
dh.MakeOnlineDeal(context.Background(), 6, false, 0)
|
2020-07-01 14:49:17 +00:00
|
|
|
|
|
|
|
// Validate upgrade
|
|
|
|
|
|
|
|
{
|
2020-07-16 15:24:41 +00:00
|
|
|
exp, err := client.StateSectorExpiration(ctx, maddr, CC, types.EmptyTSK)
|
2020-07-01 14:49:17 +00:00
|
|
|
require.NoError(t, err)
|
2020-09-18 05:12:45 +00:00
|
|
|
require.NotNil(t, exp)
|
2020-07-16 15:24:41 +00:00
|
|
|
require.Greater(t, 50000, int(exp.OnTime))
|
2020-07-01 14:49:17 +00:00
|
|
|
}
|
|
|
|
{
|
2020-07-16 15:24:41 +00:00
|
|
|
exp, err := client.StateSectorExpiration(ctx, maddr, Upgraded, types.EmptyTSK)
|
2020-07-01 14:49:17 +00:00
|
|
|
require.NoError(t, err)
|
2020-07-16 15:24:41 +00:00
|
|
|
require.Less(t, 50000, int(exp.OnTime))
|
2020-07-01 14:49:17 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 19:16:35 +00:00
|
|
|
dlInfo, err := client.StateMinerProvingDeadline(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Sector should expire.
|
|
|
|
for {
|
|
|
|
// Wait for the sector to expire.
|
|
|
|
status, err := miner.SectorsStatus(ctx, CC, true)
|
|
|
|
require.NoError(t, err)
|
|
|
|
if status.OnTime == 0 && status.Early == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
t.Log("waiting for sector to expire")
|
|
|
|
// wait one deadline per loop.
|
2021-06-14 09:50:40 +00:00
|
|
|
time.Sleep(time.Duration(dlInfo.WPoStChallengeWindow) * blockTime)
|
2020-09-25 19:16:35 +00:00
|
|
|
}
|
2020-07-01 14:49:17 +00:00
|
|
|
}
|