From 6ba52440bedd245df2126fb47e47423ea0bf9709 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 22 Jan 2021 13:02:54 -0800 Subject: [PATCH] retry proofs if we generate an incorrect one --- node/modules/storageminer.go | 2 +- storage/wdpost_run.go | 16 ++++++++++++++++ storage/wdpost_sched.go | 5 ++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index 2a0b3f8b205..97a89a816ed 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -218,7 +218,7 @@ func StorageMiner(fc config.MinerFeeConfig) func(params StorageMinerParams) (*st ctx := helpers.LifecycleCtx(mctx, lc) - fps, err := storage.NewWindowedPoStScheduler(api, fc, as, sealer, sealer, j, maddr) + fps, err := storage.NewWindowedPoStScheduler(api, fc, as, sealer, verif, sealer, j, maddr) if err != nil { return nil, err } diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index 346ffc38d87..4dfa6f63597 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -20,6 +20,7 @@ import ( "golang.org/x/xerrors" proof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof" + "github.com/filecoin-project/specs-actors/v3/actors/runtime/proof" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" @@ -594,10 +595,25 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty log.Infow("computing window post", "batch", batchIdx, "elapsed", elapsed) if err == nil { + // If we proved nothing, something is very wrong. if len(postOut) == 0 { return nil, xerrors.Errorf("received no proofs back from generate window post") } + // If we generated an incorrect proof, try again. + if correct, err := s.verifier.VerifyWindowPoSt(ctx, proof.WindowPoStVerifyInfo{ + Randomness: abi.PoStRandomness(rand), + Proofs: postOut, + ChallengedSectors: sinfos, + Prover: abi.ActorID(mid), + }); err != nil { + log.Errorw("window post verification failed", "post", postOut, "error", err) + continue + } else if !correct { + log.Errorw("generated incorrect window post proof", "post", postOut, "error", err) + continue + } + // Proof generation successful, stop retrying somethingToProve = true params.Partitions = partitions diff --git a/storage/wdpost_sched.go b/storage/wdpost_sched.go index 3d6073a63a4..8c24a551658 100644 --- a/storage/wdpost_sched.go +++ b/storage/wdpost_sched.go @@ -16,6 +16,7 @@ import ( "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage" + "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/lotus/journal" "github.com/filecoin-project/lotus/node/config" @@ -27,6 +28,7 @@ type WindowPoStScheduler struct { feeCfg config.MinerFeeConfig addrSel *AddressSelector prover storage.Prover + verifier ffiwrapper.Verifier faultTracker sectorstorage.FaultTracker proofType abi.RegisteredPoStProof partitionSectors uint64 @@ -41,7 +43,7 @@ type WindowPoStScheduler struct { // failLk sync.Mutex } -func NewWindowedPoStScheduler(api storageMinerApi, fc config.MinerFeeConfig, as *AddressSelector, sb storage.Prover, ft sectorstorage.FaultTracker, j journal.Journal, actor address.Address) (*WindowPoStScheduler, error) { +func NewWindowedPoStScheduler(api storageMinerApi, fc config.MinerFeeConfig, as *AddressSelector, sb storage.Prover, verif ffiwrapper.Verifier, ft sectorstorage.FaultTracker, j journal.Journal, actor address.Address) (*WindowPoStScheduler, error) { mi, err := api.StateMinerInfo(context.TODO(), actor, types.EmptyTSK) if err != nil { return nil, xerrors.Errorf("getting sector size: %w", err) @@ -52,6 +54,7 @@ func NewWindowedPoStScheduler(api storageMinerApi, fc config.MinerFeeConfig, as feeCfg: fc, addrSel: as, prover: sb, + verifier: verif, faultTracker: ft, proofType: mi.WindowPoStProofType, partitionSectors: mi.WindowPoStPartitionSectors,