lotus/itests/sector_miner_collateral_test.go

146 lines
4.5 KiB
Go
Raw Normal View History

2022-08-29 14:25:30 +00:00
// stm: #integration
2021-06-29 16:17:08 +00:00
package itests
import (
"context"
"strings"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/itests/kit"
"github.com/filecoin-project/lotus/node"
"github.com/filecoin-project/lotus/node/config"
"github.com/filecoin-project/lotus/node/modules"
2021-06-29 16:17:08 +00:00
"github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/filecoin-project/lotus/node/repo"
sealing "github.com/filecoin-project/lotus/storage/pipeline"
"github.com/filecoin-project/lotus/storage/pipeline/sealiface"
2021-06-29 16:17:08 +00:00
)
func TestMinerBalanceCollateral(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-15 14:30:42 +00:00
//stm: @MINER_SECTOR_LIST_001
2021-06-29 16:17:08 +00:00
kit.QuietMiningLogs()
blockTime := 5 * time.Millisecond
runTest := func(t *testing.T, enabled bool, nSectors int, batching bool) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
opts := kit.ConstructorOpts(
node.ApplyIf(node.IsType(repo.StorageMiner), node.Override(new(dtypes.GetSealingConfigFunc), func() (dtypes.GetSealingConfigFunc, error) {
2021-06-29 16:17:08 +00:00
return func() (sealiface.Config, error) {
2022-03-18 11:18:00 +00:00
cfg := config.DefaultStorageMiner()
sc := modules.ToSealingConfig(cfg.Dealmaking, cfg.Sealing)
2021-06-29 16:17:08 +00:00
sc.MaxWaitDealsSectors = 4
sc.MaxSealingSectors = 4
sc.MaxSealingSectorsForDeals = 4
sc.AlwaysKeepUnsealedCopy = true
sc.WaitDealsDelay = time.Hour
2021-06-29 16:17:08 +00:00
sc.AggregateCommits = batching
2021-06-29 16:17:08 +00:00
sc.PreCommitBatchWait = time.Hour
sc.CommitBatchWait = time.Hour
2021-06-29 16:17:08 +00:00
sc.MinCommitBatch = nSectors
sc.MaxPreCommitBatch = nSectors
sc.MaxCommitBatch = nSectors
sc.CollateralFromMinerBalance = enabled
sc.AvailableBalanceBuffer = big.Zero()
sc.DisableCollateralFallback = false
sc.AggregateAboveBaseFee = big.Zero()
sc.BatchPreCommitAboveBaseFee = big.Zero()
return sc, nil
2021-06-29 16:17:08 +00:00
}, nil
})),
)
full, miner, ens := kit.EnsembleMinimal(t, kit.MockProofs(), opts)
2021-06-29 16:17:08 +00:00
ens.InterconnectAll().BeginMining(blockTime)
full.WaitTillChain(ctx, kit.HeightAtLeast(10))
toCheck := miner.StartPledge(ctx, nSectors, 0, nil)
for len(toCheck) > 0 {
states := map[api.SectorState]int{}
for n := range toCheck {
st, err := miner.StorageMiner.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)
}
// check that sector messages had zero value set
sl, err := miner.SectorsListNonGenesis(ctx)
2021-06-29 16:17:08 +00:00
require.NoError(t, err)
for _, number := range sl {
si, err := miner.SectorsStatus(ctx, number, false)
require.NoError(t, err)
require.NotNil(t, si.PreCommitMsg)
pc, err := full.ChainGetMessage(ctx, *si.PreCommitMsg)
require.NoError(t, err)
if enabled {
require.Equal(t, big.Zero(), pc.Value)
} else {
require.NotEqual(t, big.Zero(), pc.Value)
}
require.NotNil(t, si.CommitMsg)
c, err := full.ChainGetMessage(ctx, *si.CommitMsg)
require.NoError(t, err)
if enabled {
require.Equal(t, big.Zero(), c.Value)
}
// commit value might be zero even with !enabled because in test devnets
// precommit deposit tends to be greater than collateral required at
// commit time.
}
}
t.Run("nobatch", func(t *testing.T) {
runTest(t, true, 1, false)
})
t.Run("batch-1", func(t *testing.T) {
runTest(t, true, 1, true) // individual commit instead of aggregate
})
t.Run("batch-4", func(t *testing.T) {
runTest(t, true, 4, true)
})
t.Run("nobatch-frombalance-disabled", func(t *testing.T) {
runTest(t, false, 1, false)
})
t.Run("batch-1-frombalance-disabled", func(t *testing.T) {
runTest(t, false, 1, true) // individual commit instead of aggregate
})
t.Run("batch-4-frombalance-disabled", func(t *testing.T) {
runTest(t, false, 4, true)
})
}