2021-05-18 20:32:10 +00:00
|
|
|
package itests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-06-07 22:17:44 +00:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
2021-05-18 20:32:10 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-06-18 18:45:29 +00:00
|
|
|
"github.com/filecoin-project/lotus/itests/kit"
|
2021-06-17 07:37:35 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2021-06-07 22:17:44 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2021-05-18 20:32:10 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
2021-06-07 22:17:44 +00:00
|
|
|
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
|
2021-05-18 20:32:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPledgeSectors(t *testing.T) {
|
2021-06-18 18:45:29 +00:00
|
|
|
kit.QuietMiningLogs()
|
2021-06-17 07:37:35 +00:00
|
|
|
|
|
|
|
blockTime := 50 * time.Millisecond
|
2021-05-18 20:32:10 +00:00
|
|
|
|
2021-06-17 07:37:35 +00:00
|
|
|
runTest := func(t *testing.T, nSectors int) {
|
2021-06-07 22:17:44 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2021-06-18 18:45:29 +00:00
|
|
|
_, miner, ens := kit.EnsembleMinimal(t, kit.MockProofs())
|
2021-06-17 07:37:35 +00:00
|
|
|
ens.InterconnectAll().BeginMining(blockTime)
|
2021-06-07 22:17:44 +00:00
|
|
|
|
2021-06-17 07:37:35 +00:00
|
|
|
miner.PledgeSectors(ctx, nSectors, 0, nil)
|
2021-06-07 22:17:44 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 20:32:10 +00:00
|
|
|
t.Run("1", func(t *testing.T) {
|
2021-06-17 07:37:35 +00:00
|
|
|
runTest(t, 1)
|
2021-05-18 20:32:10 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("100", func(t *testing.T) {
|
2021-06-17 07:37:35 +00:00
|
|
|
runTest(t, 100)
|
2021-05-18 20:32:10 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("1000", func(t *testing.T) {
|
|
|
|
if testing.Short() { // takes ~16s
|
|
|
|
t.Skip("skipping test in short mode")
|
|
|
|
}
|
|
|
|
|
2021-06-17 07:37:35 +00:00
|
|
|
runTest(t, 1000)
|
2021-05-18 20:32:10 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-06-07 22:17:44 +00:00
|
|
|
func TestPledgeBatching(t *testing.T) {
|
2021-06-17 07:37:35 +00:00
|
|
|
blockTime := 50 * time.Millisecond
|
|
|
|
|
|
|
|
runTest := func(t *testing.T, nSectors int) {
|
2021-06-07 22:17:44 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2021-05-18 20:32:10 +00:00
|
|
|
|
2021-06-18 18:45:29 +00:00
|
|
|
opts := kit.ConstructorOpts(kit.LatestActorsAt(-1))
|
|
|
|
client, miner, ens := kit.EnsembleMinimal(t, kit.MockProofs(), opts)
|
2021-06-17 07:37:35 +00:00
|
|
|
ens.InterconnectAll().BeginMining(blockTime)
|
2021-05-18 20:32:10 +00:00
|
|
|
|
2021-06-18 18:45:29 +00:00
|
|
|
client.WaitTillChain(ctx, kit.HeightAtLeast(10))
|
2021-06-07 22:17:44 +00:00
|
|
|
|
2021-06-17 07:37:35 +00:00
|
|
|
toCheck := miner.StartPledge(ctx, nSectors, 0, nil)
|
2021-06-07 22:17:44 +00:00
|
|
|
|
|
|
|
for len(toCheck) > 0 {
|
|
|
|
states := map[api.SectorState]int{}
|
|
|
|
|
|
|
|
for n := range toCheck {
|
|
|
|
st, err := miner.SectorsStatus(ctx, n, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
states[st.State]++
|
|
|
|
if st.State == api.SectorState(sealing.Proving) {
|
|
|
|
delete(toCheck, n)
|
|
|
|
}
|
|
|
|
if strings.Contains(string(st.State), "Fail") {
|
|
|
|
t.Fatal("sector in a failed state", st.State)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if states[api.SectorState(sealing.SubmitPreCommitBatch)] == nSectors ||
|
|
|
|
(states[api.SectorState(sealing.SubmitPreCommitBatch)] > 0 && states[api.SectorState(sealing.PreCommit1)] == 0 && states[api.SectorState(sealing.PreCommit2)] == 0) {
|
|
|
|
pcb, err := miner.SectorPreCommitFlush(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
if pcb != nil {
|
|
|
|
fmt.Printf("PRECOMMIT BATCH: %+v\n", pcb)
|
|
|
|
}
|
|
|
|
}
|
2021-05-18 20:32:10 +00:00
|
|
|
|
2021-06-07 22:17:44 +00:00
|
|
|
if states[api.SectorState(sealing.SubmitCommitAggregate)] == nSectors ||
|
|
|
|
(states[api.SectorState(sealing.SubmitCommitAggregate)] > 0 && states[api.SectorState(sealing.WaitSeed)] == 0 && states[api.SectorState(sealing.Committing)] == 0) {
|
|
|
|
cb, err := miner.SectorCommitFlush(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
if cb != nil {
|
|
|
|
fmt.Printf("COMMIT BATCH: %+v\n", cb)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
build.Clock.Sleep(100 * time.Millisecond)
|
|
|
|
fmt.Printf("WaitSeal: %d %+v\n", len(toCheck), states)
|
|
|
|
}
|
2021-05-18 20:32:10 +00:00
|
|
|
}
|
2021-06-07 22:17:44 +00:00
|
|
|
|
|
|
|
t.Run("100", func(t *testing.T) {
|
2021-06-17 07:37:35 +00:00
|
|
|
runTest(t, 100)
|
2021-06-07 22:17:44 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPledgeBeforeNv13(t *testing.T) {
|
2021-06-17 07:37:35 +00:00
|
|
|
blocktime := 50 * time.Millisecond
|
|
|
|
|
|
|
|
runTest := func(t *testing.T, nSectors int) {
|
2021-06-07 22:17:44 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2021-06-18 18:45:29 +00:00
|
|
|
opts := kit.ConstructorOpts(kit.LatestActorsAt(1000000000))
|
|
|
|
client, miner, ens := kit.EnsembleMinimal(t, kit.MockProofs(), opts)
|
2021-06-17 07:37:35 +00:00
|
|
|
ens.InterconnectAll().BeginMining(blocktime)
|
2021-06-07 22:17:44 +00:00
|
|
|
|
2021-06-18 18:45:29 +00:00
|
|
|
client.WaitTillChain(ctx, kit.HeightAtLeast(10))
|
2021-06-07 22:17:44 +00:00
|
|
|
|
2021-06-17 07:37:35 +00:00
|
|
|
toCheck := miner.StartPledge(ctx, nSectors, 0, nil)
|
2021-06-07 22:17:44 +00:00
|
|
|
|
|
|
|
for len(toCheck) > 0 {
|
|
|
|
states := map[api.SectorState]int{}
|
2021-05-18 20:32:10 +00:00
|
|
|
|
2021-06-07 22:17:44 +00:00
|
|
|
for n := range toCheck {
|
|
|
|
st, err := miner.SectorsStatus(ctx, n, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
states[st.State]++
|
|
|
|
if st.State == api.SectorState(sealing.Proving) {
|
|
|
|
delete(toCheck, n)
|
|
|
|
}
|
|
|
|
if strings.Contains(string(st.State), "Fail") {
|
|
|
|
t.Fatal("sector in a failed state", st.State)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
build.Clock.Sleep(100 * time.Millisecond)
|
|
|
|
fmt.Printf("WaitSeal: %d %+v\n", len(toCheck), states)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("100-before-nv13", func(t *testing.T) {
|
2021-06-17 07:37:35 +00:00
|
|
|
runTest(t, 100)
|
2021-06-07 22:17:44 +00:00
|
|
|
})
|
2021-05-18 20:32:10 +00:00
|
|
|
}
|