2022-01-14 13:11:04 +00:00
package itests
import (
"context"
"testing"
"time"
2022-01-18 10:37:15 +00:00
logging "github.com/ipfs/go-log/v2"
2022-01-14 13:11:04 +00:00
"github.com/stretchr/testify/require"
2022-01-18 10:37:15 +00:00
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types"
2022-01-14 13:11:04 +00:00
"github.com/filecoin-project/lotus/extern/sector-storage/sealtasks"
"github.com/filecoin-project/lotus/itests/kit"
2022-01-18 10:37:15 +00:00
"github.com/filecoin-project/lotus/storage"
2022-01-14 13:11:04 +00:00
)
func TestWorkerPledge ( t * testing . T ) {
ctx := context . Background ( )
_ , miner , worker , ens := kit . EnsembleWorker ( t , kit . WithAllSubsystems ( ) , kit . ThroughRPC ( ) , kit . WithNoLocalSealing ( true ) ,
kit . WithTaskTypes ( [ ] sealtasks . TaskType { sealtasks . TTFetch , sealtasks . TTCommit1 , sealtasks . TTFinalize , sealtasks . TTAddPiece , sealtasks . TTPreCommit1 , sealtasks . TTPreCommit2 , sealtasks . TTCommit2 , sealtasks . TTUnseal } ) ) // no mock proofs
ens . InterconnectAll ( ) . BeginMining ( 50 * time . Millisecond )
e , err := worker . Enabled ( ctx )
require . NoError ( t , err )
require . True ( t , e )
miner . PledgeSectors ( ctx , 1 , 0 , nil )
}
func TestWinningPostWorker ( t * testing . T ) {
prevIns := build . InsecurePoStValidation
build . InsecurePoStValidation = false
defer func ( ) {
build . InsecurePoStValidation = prevIns
} ( )
ctx := context . Background ( )
client , _ , worker , ens := kit . EnsembleWorker ( t , kit . WithAllSubsystems ( ) , kit . ThroughRPC ( ) ,
kit . WithTaskTypes ( [ ] sealtasks . TaskType { sealtasks . TTGenerateWinningPoSt } ) ) // no mock proofs
ens . InterconnectAll ( ) . BeginMining ( 50 * time . Millisecond )
e , err := worker . Enabled ( ctx )
require . NoError ( t , err )
require . True ( t , e )
client . WaitTillChain ( ctx , kit . HeightAtLeast ( 6 ) )
}
func TestWindowPostWorker ( t * testing . T ) {
ctx , cancel := context . WithCancel ( context . Background ( ) )
defer cancel ( )
_ = logging . SetLogLevel ( "storageminer" , "INFO" )
sectors := 2 * 48 * 2
client , miner , _ , ens := kit . EnsembleWorker ( t ,
kit . PresealSectors ( sectors ) , // 2 sectors per partition, 2 partitions in all 48 deadlines
kit . LatestActorsAt ( - 1 ) ,
kit . ThroughRPC ( ) ,
kit . WithTaskTypes ( [ ] sealtasks . TaskType { sealtasks . TTGenerateWindowPoSt } ) )
maddr , err := miner . ActorAddress ( ctx )
require . NoError ( t , err )
di , err := client . StateMinerProvingDeadline ( ctx , maddr , types . EmptyTSK )
require . NoError ( t , err )
bm := ens . InterconnectAll ( ) . BeginMining ( 2 * time . Millisecond ) [ 0 ]
di = di . NextNotElapsed ( )
t . Log ( "Running one proving period" )
waitUntil := di . Open + di . WPoStChallengeWindow * 2 + storage . SubmitConfidence
2022-01-18 11:11:59 +00:00
client . WaitTillChain ( ctx , kit . HeightAtLeast ( waitUntil ) )
2022-01-14 13:11:04 +00:00
t . Log ( "Waiting for post message" )
bm . Stop ( )
2022-01-18 14:53:13 +00:00
var lastPending [ ] * types . SignedMessage
2022-01-14 13:11:04 +00:00
for i := 0 ; i < 500 ; i ++ {
2022-01-18 14:53:13 +00:00
lastPending , err = client . MpoolPending ( ctx , types . EmptyTSK )
2022-01-14 13:11:04 +00:00
require . NoError ( t , err )
2022-01-18 14:53:13 +00:00
if len ( lastPending ) > 0 {
2022-01-14 13:11:04 +00:00
break
}
time . Sleep ( 40 * time . Millisecond )
}
2022-01-18 14:53:13 +00:00
require . Greater ( t , len ( lastPending ) , 0 )
2022-01-14 13:11:04 +00:00
t . Log ( "post message landed" )
bm . MineBlocks ( ctx , 2 * time . Millisecond )
waitUntil = di . Open + di . WPoStChallengeWindow * 3
t . Logf ( "End for head.Height > %d" , waitUntil )
2022-01-18 11:11:59 +00:00
ts := client . WaitTillChain ( ctx , kit . HeightAtLeast ( waitUntil ) )
2022-01-14 13:11:04 +00:00
t . Logf ( "Now head.Height = %d" , ts . Height ( ) )
p , err := client . StateMinerPower ( ctx , maddr , types . EmptyTSK )
require . NoError ( t , err )
ssz , err := miner . ActorSectorSize ( ctx , maddr )
require . NoError ( t , err )
require . Equal ( t , p . MinerPower , p . TotalPower )
require . Equal ( t , p . MinerPower . RawBytePower , types . NewInt ( uint64 ( ssz ) * uint64 ( sectors ) ) )
}