2020-07-01 14:49:17 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"sync/atomic"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"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"
|
|
|
|
"github.com/filecoin-project/lotus/node/impl"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCCUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
|
|
|
_ = os.Setenv("BELLMAN_NO_GPU", "1")
|
|
|
|
|
|
|
|
ctx := context.Background()
|
2020-08-13 20:37:09 +00:00
|
|
|
n, sn := b(t, 1, OneMiner)
|
2020-07-01 14:49:17 +00:00
|
|
|
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)
|
2020-07-28 16:16:46 +00:00
|
|
|
if err := sn[0].MineOne(ctx, MineNext); err != nil {
|
2020-07-01 14:49:17 +00:00
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
maddr, err := miner.ActorAddress(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
CC := abi.SectorNumber(GenesisPreseals + 1)
|
|
|
|
Upgraded := CC + 1
|
|
|
|
|
2020-08-03 18:28:18 +00:00
|
|
|
pledgeSectors(t, ctx, miner, 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)
|
|
|
|
}
|
|
|
|
|
2020-07-08 18:35:55 +00:00
|
|
|
makeDeal(t, ctx, 6, client, miner, false, false)
|
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-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
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("shutting down mining")
|
|
|
|
atomic.AddInt64(&mine, -1)
|
|
|
|
<-done
|
|
|
|
}
|