@@ -34,8 +34,9 @@ import (
34
34
// TestUnmanagedMiner is a miner that's not managed by the storage/infrastructure, all tasks must be manually executed, managed and scheduled by the test or test kit.
35
35
// Note: `TestUnmanagedMiner` is not thread safe and assumes linear access of it's methods
36
36
type TestUnmanagedMiner struct {
37
- t * testing.T
38
- options nodeOpts
37
+ t * testing.T
38
+ options nodeOpts
39
+ mockProofs bool
39
40
40
41
cacheDir string
41
42
unsealedSectorDir string
@@ -65,7 +66,7 @@ type WindowPostResp struct {
65
66
Error error
66
67
}
67
68
68
- func NewTestUnmanagedMiner (t * testing.T , full * TestFullNode , actorAddr address.Address , opts ... NodeOpt ) * TestUnmanagedMiner {
69
+ func NewTestUnmanagedMiner (t * testing.T , full * TestFullNode , actorAddr address.Address , mockProofs bool , opts ... NodeOpt ) * TestUnmanagedMiner {
69
70
require .NotNil (t , full , "full node required when instantiating miner" )
70
71
71
72
options := DefaultNodeOpts
@@ -94,6 +95,7 @@ func NewTestUnmanagedMiner(t *testing.T, full *TestFullNode, actorAddr address.A
94
95
tm := TestUnmanagedMiner {
95
96
t : t ,
96
97
options : options ,
98
+ mockProofs : mockProofs ,
97
99
cacheDir : cacheDir ,
98
100
unsealedSectorDir : unsealedSectorDir ,
99
101
sealedSectorDir : sealedSectorDir ,
@@ -222,7 +224,7 @@ func (tm *TestUnmanagedMiner) makeAndSaveCCSector(_ context.Context, sectorNumbe
222
224
tm .cacheDirPaths [sectorNumber ] = cacheDirPath
223
225
}
224
226
225
- func (tm * TestUnmanagedMiner ) OnboardSectorWithPiecesAndRealProofs (ctx context.Context , proofType abi.RegisteredSealProof ) (abi.SectorNumber , chan WindowPostResp ,
227
+ func (tm * TestUnmanagedMiner ) OnboardSectorWithPieces (ctx context.Context , proofType abi.RegisteredSealProof ) (abi.SectorNumber , chan WindowPostResp ,
226
228
context.CancelFunc ) {
227
229
req := require .New (tm .t )
228
230
sectorNumber := tm .currentSectorNum
@@ -232,10 +234,23 @@ func (tm *TestUnmanagedMiner) OnboardSectorWithPiecesAndRealProofs(ctx context.C
232
234
preCommitSealRand := tm .waitPreCommitSealRandomness (ctx , sectorNumber )
233
235
234
236
// Step 2: Build a sector with non 0 Pieces that we want to onboard
235
- pieces := tm .mkAndSavePiecesToOnboard (ctx , sectorNumber , proofType )
237
+ var pieces []abi.PieceInfo
238
+ if ! tm .mockProofs {
239
+ pieces = tm .mkAndSavePiecesToOnboard (ctx , sectorNumber , proofType )
240
+ } else {
241
+ pieces = []abi.PieceInfo {{
242
+ Size : abi .PaddedPieceSize (tm .options .sectorSize ),
243
+ PieceCID : cid .MustParse ("baga6ea4seaqjtovkwk4myyzj56eztkh5pzsk5upksan6f5outesy62bsvl4dsha" ),
244
+ }}
245
+ }
236
246
237
247
// Step 3: Generate a Pre-Commit for the CC sector -> this persists the proof on the `TestUnmanagedMiner` Miner State
238
- tm .generatePreCommit (ctx , sectorNumber , preCommitSealRand , proofType , pieces )
248
+ if ! tm .mockProofs {
249
+ tm .generatePreCommit (ctx , sectorNumber , preCommitSealRand , proofType , pieces )
250
+ } else {
251
+ tm .sealedCids [sectorNumber ] = cid .MustParse ("bagboea4b5abcatlxechwbp7kjpjguna6r6q7ejrhe6mdp3lf34pmswn27pkkiekz" )
252
+ tm .unsealedCids [sectorNumber ] = cid .MustParse ("baga6ea4seaqjtovkwk4myyzj56eztkh5pzsk5upksan6f5outesy62bsvl4dsha" )
253
+ }
239
254
240
255
// Step 4 : Submit the Pre-Commit to the network
241
256
unsealedCid := tm .unsealedCids [sectorNumber ]
@@ -255,75 +270,11 @@ func (tm *TestUnmanagedMiner) OnboardSectorWithPiecesAndRealProofs(ctx context.C
255
270
// Step 5: Generate a ProveCommit for the CC sector
256
271
waitSeedRandomness := tm .proveCommitWaitSeed (ctx , sectorNumber )
257
272
258
- proveCommit := tm .generateProveCommit (ctx , sectorNumber , proofType , waitSeedRandomness , pieces )
259
-
260
- // Step 6: Submit the ProveCommit to the network
261
- tm .t .Log ("Submitting ProveCommitSector ..." )
262
-
263
- var manifest []miner14.PieceActivationManifest
264
- for _ , piece := range pieces {
265
- manifest = append (manifest , miner14.PieceActivationManifest {
266
- CID : piece .PieceCID ,
267
- Size : piece .Size ,
268
- })
273
+ proveCommit := []byte {0xde , 0xad , 0xbe , 0xef } // mock prove commit
274
+ if ! tm .mockProofs {
275
+ proveCommit = tm .generateProveCommit (ctx , sectorNumber , proofType , waitSeedRandomness , pieces )
269
276
}
270
277
271
- r , err = tm .submitMessage (ctx , & miner14.ProveCommitSectors3Params {
272
- SectorActivations : []miner14.SectorActivationManifest {{SectorNumber : sectorNumber , Pieces : manifest }},
273
- SectorProofs : [][]byte {proveCommit },
274
- RequireActivationSuccess : true ,
275
- }, 1 , builtin .MethodsMiner .ProveCommitSectors3 )
276
- req .NoError (err )
277
- req .True (r .Receipt .ExitCode .IsSuccess ())
278
-
279
- tm .proofType [sectorNumber ] = proofType
280
-
281
- respCh := make (chan WindowPostResp , 1 )
282
-
283
- wdCtx , cancelF := context .WithCancel (ctx )
284
- go tm .wdPostLoop (wdCtx , sectorNumber , respCh , false , tm .sealedCids [sectorNumber ], tm .sealedSectorPaths [sectorNumber ], tm .cacheDirPaths [sectorNumber ])
285
-
286
- return sectorNumber , respCh , cancelF
287
- }
288
-
289
- func (tm * TestUnmanagedMiner ) OnboardSectorWithPiecesAndMockProofs (ctx context.Context , proofType abi.RegisteredSealProof ) (abi.SectorNumber , chan WindowPostResp ,
290
- context.CancelFunc ) {
291
- req := require .New (tm .t )
292
- sectorNumber := tm .currentSectorNum
293
- tm .currentSectorNum ++
294
-
295
- // Step 1: Wait for the pre-commitseal randomness to be available (we can only draw seal randomness from tipsets that have already achieved finality)
296
- preCommitSealRand := tm .waitPreCommitSealRandomness (ctx , sectorNumber )
297
-
298
- // Step 2: Build a sector with non 0 Pieces that we want to onboard
299
- pieces := []abi.PieceInfo {{
300
- Size : abi .PaddedPieceSize (tm .options .sectorSize ),
301
- PieceCID : cid .MustParse ("baga6ea4seaqjtovkwk4myyzj56eztkh5pzsk5upksan6f5outesy62bsvl4dsha" ),
302
- }}
303
-
304
- // Step 3: Generate a Pre-Commit for the CC sector -> this persists the proof on the `TestUnmanagedMiner` Miner State
305
- tm .sealedCids [sectorNumber ] = cid .MustParse ("bagboea4b5abcatlxechwbp7kjpjguna6r6q7ejrhe6mdp3lf34pmswn27pkkiekz" )
306
- tm .unsealedCids [sectorNumber ] = cid .MustParse ("baga6ea4seaqjtovkwk4myyzj56eztkh5pzsk5upksan6f5outesy62bsvl4dsha" )
307
-
308
- // Step 4 : Submit the Pre-Commit to the network
309
- unsealedCid := tm .unsealedCids [sectorNumber ]
310
- r , err := tm .submitMessage (ctx , & miner14.PreCommitSectorBatchParams2 {
311
- Sectors : []miner14.SectorPreCommitInfo {{
312
- Expiration : 2880 * 300 ,
313
- SectorNumber : sectorNumber ,
314
- SealProof : TestSpt ,
315
- SealedCID : tm .sealedCids [sectorNumber ],
316
- SealRandEpoch : preCommitSealRand ,
317
- UnsealedCid : & unsealedCid ,
318
- }},
319
- }, 1 , builtin .MethodsMiner .PreCommitSectorBatch2 )
320
- req .NoError (err )
321
- req .True (r .Receipt .ExitCode .IsSuccess ())
322
-
323
- // Step 5: Generate a ProveCommit for the CC sector
324
- _ = tm .proveCommitWaitSeed (ctx , sectorNumber )
325
- sectorProof := []byte {0xde , 0xad , 0xbe , 0xef }
326
-
327
278
// Step 6: Submit the ProveCommit to the network
328
279
tm .t .Log ("Submitting ProveCommitSector ..." )
329
280
@@ -337,7 +288,7 @@ func (tm *TestUnmanagedMiner) OnboardSectorWithPiecesAndMockProofs(ctx context.C
337
288
338
289
r , err = tm .submitMessage (ctx , & miner14.ProveCommitSectors3Params {
339
290
SectorActivations : []miner14.SectorActivationManifest {{SectorNumber : sectorNumber , Pieces : manifest }},
340
- SectorProofs : [][]byte {sectorProof },
291
+ SectorProofs : [][]byte {proveCommit },
341
292
RequireActivationSuccess : true ,
342
293
}, 1 , builtin .MethodsMiner .ProveCommitSectors3 )
343
294
req .NoError (err )
@@ -348,7 +299,7 @@ func (tm *TestUnmanagedMiner) OnboardSectorWithPiecesAndMockProofs(ctx context.C
348
299
respCh := make (chan WindowPostResp , 1 )
349
300
350
301
wdCtx , cancelF := context .WithCancel (ctx )
351
- go tm .wdPostLoop (wdCtx , sectorNumber , respCh , true , tm .sealedCids [sectorNumber ], tm .sealedSectorPaths [sectorNumber ], tm .cacheDirPaths [sectorNumber ])
302
+ go tm .wdPostLoop (wdCtx , sectorNumber , respCh , tm .sealedCids [sectorNumber ], tm .sealedSectorPaths [sectorNumber ], tm .cacheDirPaths [sectorNumber ])
352
303
353
304
return sectorNumber , respCh , cancelF
354
305
}
@@ -393,7 +344,11 @@ func (tm *TestUnmanagedMiner) mkStagedFileWithPieces(pt abi.RegisteredSealProof)
393
344
return publicPieces , unsealedSectorFile .Name ()
394
345
}
395
346
396
- func (tm * TestUnmanagedMiner ) SnapDealWithRealProofs (ctx context.Context , proofType abi.RegisteredSealProof , sectorNumber abi.SectorNumber ) {
347
+ func (tm * TestUnmanagedMiner ) SnapDeal (ctx context.Context , proofType abi.RegisteredSealProof , sectorNumber abi.SectorNumber ) {
348
+ if tm .mockProofs {
349
+ tm .t .Fatal ("snap deal with mock proofs currently not supported" )
350
+ }
351
+
397
352
// generate sector key
398
353
pieces , unsealedPath := tm .mkStagedFileWithPieces (proofType )
399
354
updateProofType := abi .SealProofInfos [proofType ].UpdateProof
@@ -489,56 +444,7 @@ func (tm *TestUnmanagedMiner) waitForMutableDeadline(ctx context.Context, sector
489
444
}
490
445
}
491
446
492
- func (tm * TestUnmanagedMiner ) OnboardCCSectorWithMockProofs (ctx context.Context , proofType abi.RegisteredSealProof ) (abi.SectorNumber , chan WindowPostResp ,
493
- context.CancelFunc ) {
494
- req := require .New (tm .t )
495
- sectorNumber := tm .currentSectorNum
496
- tm .currentSectorNum ++
497
-
498
- // Step 1: Wait for the pre-commitseal randomness to be available (we can only draw seal randomness from tipsets that have already achieved finality)
499
- preCommitSealRand := tm .waitPreCommitSealRandomness (ctx , sectorNumber )
500
-
501
- tm .sealedCids [sectorNumber ] = cid .MustParse ("bagboea4b5abcatlxechwbp7kjpjguna6r6q7ejrhe6mdp3lf34pmswn27pkkiekz" )
502
-
503
- // Step 4 : Submit the Pre-Commit to the network
504
- r , err := tm .submitMessage (ctx , & miner14.PreCommitSectorBatchParams2 {
505
- Sectors : []miner14.SectorPreCommitInfo {{
506
- Expiration : 2880 * 300 ,
507
- SectorNumber : sectorNumber ,
508
- SealProof : TestSpt ,
509
- SealedCID : tm .sealedCids [sectorNumber ],
510
- SealRandEpoch : preCommitSealRand ,
511
- }},
512
- }, 1 , builtin .MethodsMiner .PreCommitSectorBatch2 )
513
- req .NoError (err )
514
- req .True (r .Receipt .ExitCode .IsSuccess ())
515
-
516
- // Step 5: Generate a ProveCommit for the CC sector
517
- _ = tm .proveCommitWaitSeed (ctx , sectorNumber )
518
- sectorProof := []byte {0xde , 0xad , 0xbe , 0xef }
519
-
520
- // Step 6: Submit the ProveCommit to the network
521
- tm .t .Log ("Submitting ProveCommitSector ..." )
522
-
523
- r , err = tm .submitMessage (ctx , & miner14.ProveCommitSectors3Params {
524
- SectorActivations : []miner14.SectorActivationManifest {{SectorNumber : sectorNumber }},
525
- SectorProofs : [][]byte {sectorProof },
526
- RequireActivationSuccess : true ,
527
- }, 0 , builtin .MethodsMiner .ProveCommitSectors3 )
528
- req .NoError (err )
529
- req .True (r .Receipt .ExitCode .IsSuccess ())
530
-
531
- tm .proofType [sectorNumber ] = proofType
532
-
533
- respCh := make (chan WindowPostResp , 1 )
534
-
535
- wdCtx , cancelF := context .WithCancel (ctx )
536
- go tm .wdPostLoop (wdCtx , sectorNumber , respCh , true , tm .sealedCids [sectorNumber ], tm .sealedSectorPaths [sectorNumber ], tm .cacheDirPaths [sectorNumber ])
537
-
538
- return sectorNumber , respCh , cancelF
539
- }
540
-
541
- func (tm * TestUnmanagedMiner ) OnboardCCSectorWithRealProofs (ctx context.Context , proofType abi.RegisteredSealProof ) (abi.SectorNumber , chan WindowPostResp ,
447
+ func (tm * TestUnmanagedMiner ) OnboardCCSector (ctx context.Context , proofType abi.RegisteredSealProof ) (abi.SectorNumber , chan WindowPostResp ,
542
448
context.CancelFunc ) {
543
449
req := require .New (tm .t )
544
450
sectorNumber := tm .currentSectorNum
@@ -549,11 +455,16 @@ func (tm *TestUnmanagedMiner) OnboardCCSectorWithRealProofs(ctx context.Context,
549
455
// Step 1: Wait for the pre-commitseal randomness to be available (we can only draw seal randomness from tipsets that have already achieved finality)
550
456
preCommitSealRand := tm .waitPreCommitSealRandomness (ctx , sectorNumber )
551
457
552
- // Step 2: Write empty bytes that we want to seal i.e. create our CC sector
553
- tm .makeAndSaveCCSector (ctx , sectorNumber )
458
+ if ! tm .mockProofs {
459
+ // Step 2: Write empty bytes that we want to seal i.e. create our CC sector
460
+ tm .makeAndSaveCCSector (ctx , sectorNumber )
554
461
555
- // Step 3: Generate a Pre-Commit for the CC sector -> this persists the proof on the `TestUnmanagedMiner` Miner State
556
- tm .generatePreCommit (ctx , sectorNumber , preCommitSealRand , proofType , []abi.PieceInfo {})
462
+ // Step 3: Generate a Pre-Commit for the CC sector -> this persists the proof on the `TestUnmanagedMiner` Miner State
463
+ tm .generatePreCommit (ctx , sectorNumber , preCommitSealRand , proofType , []abi.PieceInfo {})
464
+ } else {
465
+ // skip the above steps and use a mock sealed CID
466
+ tm .sealedCids [sectorNumber ] = cid .MustParse ("bagboea4b5abcatlxechwbp7kjpjguna6r6q7ejrhe6mdp3lf34pmswn27pkkiekz" )
467
+ }
557
468
558
469
// Step 4 : Submit the Pre-Commit to the network
559
470
r , err := tm .submitMessage (ctx , & miner14.PreCommitSectorBatchParams2 {
@@ -571,7 +482,10 @@ func (tm *TestUnmanagedMiner) OnboardCCSectorWithRealProofs(ctx context.Context,
571
482
// Step 5: Generate a ProveCommit for the CC sector
572
483
waitSeedRandomness := tm .proveCommitWaitSeed (ctx , sectorNumber )
573
484
574
- proveCommit := tm .generateProveCommit (ctx , sectorNumber , proofType , waitSeedRandomness , []abi.PieceInfo {})
485
+ proveCommit := []byte {0xde , 0xad , 0xbe , 0xef } // mock prove commit
486
+ if ! tm .mockProofs {
487
+ proveCommit = tm .generateProveCommit (ctx , sectorNumber , proofType , waitSeedRandomness , []abi.PieceInfo {})
488
+ }
575
489
576
490
// Step 6: Submit the ProveCommit to the network
577
491
tm .t .Log ("Submitting ProveCommitSector ..." )
@@ -589,12 +503,12 @@ func (tm *TestUnmanagedMiner) OnboardCCSectorWithRealProofs(ctx context.Context,
589
503
respCh := make (chan WindowPostResp , 1 )
590
504
591
505
wdCtx , cancelF := context .WithCancel (ctx )
592
- go tm .wdPostLoop (wdCtx , sectorNumber , respCh , false , tm .sealedCids [sectorNumber ], tm .sealedSectorPaths [sectorNumber ], tm .cacheDirPaths [sectorNumber ])
506
+ go tm .wdPostLoop (wdCtx , sectorNumber , respCh , tm .sealedCids [sectorNumber ], tm .sealedSectorPaths [sectorNumber ], tm .cacheDirPaths [sectorNumber ])
593
507
594
508
return sectorNumber , respCh , cancelF
595
509
}
596
510
597
- func (tm * TestUnmanagedMiner ) wdPostLoop (ctx context.Context , sectorNumber abi.SectorNumber , respCh chan WindowPostResp , withMockProofs bool , sealedCid cid.Cid , sealedPath , cacheDir string ) {
511
+ func (tm * TestUnmanagedMiner ) wdPostLoop (ctx context.Context , sectorNumber abi.SectorNumber , respCh chan WindowPostResp , sealedCid cid.Cid , sealedPath , cacheDir string ) {
598
512
go func () {
599
513
var firstPost bool
600
514
@@ -635,7 +549,7 @@ func (tm *TestUnmanagedMiner) wdPostLoop(ctx context.Context, sectorNumber abi.S
635
549
}
636
550
}
637
551
638
- err = tm .submitWindowPost (ctx , sectorNumber , withMockProofs , sealedCid , sealedPath , cacheDir )
552
+ err = tm .submitWindowPost (ctx , sectorNumber , sealedCid , sealedPath , cacheDir )
639
553
writeRespF (err ) // send an error, or first post, or nothing if no error and this isn't the first post
640
554
postCount ++
641
555
tm .t .Logf ("Sector %d: WindowPoSt #%d submitted" , sectorNumber , postCount )
@@ -675,7 +589,7 @@ func (tm *TestUnmanagedMiner) SubmitPostDispute(ctx context.Context, sectorNumbe
675
589
return err
676
590
}
677
591
678
- func (tm * TestUnmanagedMiner ) submitWindowPost (ctx context.Context , sectorNumber abi.SectorNumber , withMockProofs bool , sealedCid cid.Cid , sealedPath , cacheDir string ) error {
592
+ func (tm * TestUnmanagedMiner ) submitWindowPost (ctx context.Context , sectorNumber abi.SectorNumber , sealedCid cid.Cid , sealedPath , cacheDir string ) error {
679
593
tm .t .Logf ("Miner(%s): WindowPoST(%d): Running WindowPoSt ...\n " , tm .ActorAddr , sectorNumber )
680
594
681
595
head , err := tm .FullNode .ChainHead (ctx )
@@ -698,7 +612,7 @@ func (tm *TestUnmanagedMiner) submitWindowPost(ctx context.Context, sectorNumber
698
612
}
699
613
700
614
var proofBytes []byte
701
- if withMockProofs {
615
+ if tm . mockProofs {
702
616
proofBytes = []byte {0xde , 0xad , 0xbe , 0xef }
703
617
} else {
704
618
proofBytes , err = tm .generateWindowPost (ctx , sectorNumber , sealedCid , sealedPath , cacheDir )
@@ -1070,3 +984,50 @@ func requireTempFile(t *testing.T, fileContentsReader io.Reader, size uint64) *o
1070
984
1071
985
return tempFile
1072
986
}
987
+
988
+ func (tm * TestUnmanagedMiner ) WaitTillActivatedAndAssertPower (
989
+ ctx context.Context ,
990
+ respCh chan WindowPostResp ,
991
+ sector abi.SectorNumber ,
992
+ ) {
993
+
994
+ // wait till sector is activated
995
+ select {
996
+ case resp := <- respCh :
997
+ require .NoError (tm .t , resp .Error )
998
+ require .True (tm .t , resp .Posted )
999
+ case <- ctx .Done ():
1000
+ tm .t .Fatal ("timed out waiting for sector activation" )
1001
+ }
1002
+
1003
+ // Fetch on-chain sector properties
1004
+ head , err := tm .FullNode .ChainHead (ctx )
1005
+ require .NoError (tm .t , err )
1006
+
1007
+ soi , err := tm .FullNode .StateSectorGetInfo (ctx , tm .ActorAddr , sector , head .Key ())
1008
+ require .NoError (tm .t , err )
1009
+ tm .t .Logf ("Miner %s SectorOnChainInfo %d: %+v" , tm .ActorAddr .String (), sector , soi )
1010
+
1011
+ _ = tm .FullNode .WaitTillChain (ctx , HeightAtLeast (head .Height ()+ 5 ))
1012
+
1013
+ tm .t .Log ("Checking power after PoSt ..." )
1014
+
1015
+ // Miner B should now have power
1016
+ tm .AssertPower (ctx , uint64 (tm .options .sectorSize ), uint64 (tm .options .sectorSize ))
1017
+
1018
+ if tm .mockProofs {
1019
+ // WindowPost Dispute should succeed as we are using mock proofs
1020
+ err := tm .SubmitPostDispute (ctx , sector )
1021
+ require .NoError (tm .t , err )
1022
+ } else {
1023
+ // WindowPost Dispute should fail
1024
+ tm .AssertDisputeFails (ctx , sector )
1025
+ }
1026
+ }
1027
+
1028
+ func (tm * TestUnmanagedMiner ) AssertDisputeFails (ctx context.Context , sector abi.SectorNumber ) {
1029
+ err := tm .SubmitPostDispute (ctx , sector )
1030
+ require .Error (tm .t , err )
1031
+ require .Contains (tm .t , err .Error (), "failed to dispute valid post" )
1032
+ require .Contains (tm .t , err .Error (), "(RetCode=16)" )
1033
+ }
0 commit comments