Skip to content

Commit

Permalink
Merge pull request #5764 from filecoin-project/fix/wait-for-proof
Browse files Browse the repository at this point in the history
fix: wait a bit before starting to compute window post proofs
  • Loading branch information
magik6k authored Mar 10, 2021
2 parents 5125aa0 + a0d7604 commit 4abb333
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
7 changes: 5 additions & 2 deletions storage/wdpost_changehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import (
"github.com/filecoin-project/lotus/chain/types"
)

const SubmitConfidence = 4
const (
SubmitConfidence = 4
ChallengeConfidence = 10
)

type CompleteGeneratePoSTCb func(posts []miner.SubmitWindowedPoStParams, err error)
type CompleteSubmitPoSTCb func(err error)
Expand Down Expand Up @@ -230,7 +233,7 @@ func (p *proveHandler) processHeadChange(ctx context.Context, newTS *types.TipSe
}

// Check if the chain is above the Challenge height for the post window
if newTS.Height() < di.Challenge {
if newTS.Height() < di.Challenge+ChallengeConfidence {
return
}

Expand Down
12 changes: 6 additions & 6 deletions storage/wdpost_changehandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func TestChangeHandlerStartProvingNextDeadline(t *testing.T) {

// Trigger a head change
currentEpoch := abi.ChainEpoch(1)
go triggerHeadAdvance(t, s, currentEpoch)
go triggerHeadAdvance(t, s, currentEpoch+ChallengeConfidence)

// Should start proving
<-s.ch.proveHdlr.processedHeadChanges
Expand All @@ -405,7 +405,7 @@ func TestChangeHandlerStartProvingNextDeadline(t *testing.T) {
// Trigger a head change that advances the chain beyond the submit
// confidence
currentEpoch = 1 + SubmitConfidence
go triggerHeadAdvance(t, s, currentEpoch)
go triggerHeadAdvance(t, s, currentEpoch+ChallengeConfidence)

// Should be no change to state yet
<-s.ch.proveHdlr.processedHeadChanges
Expand All @@ -424,7 +424,7 @@ func TestChangeHandlerStartProvingNextDeadline(t *testing.T) {
// the next deadline
go func() {
di = nextDeadline(di)
currentEpoch = di.Challenge
currentEpoch = di.Challenge + ChallengeConfidence
triggerHeadAdvance(t, s, currentEpoch)
}()

Expand All @@ -446,7 +446,7 @@ func TestChangeHandlerProvingRounds(t *testing.T) {
for currentEpoch := abi.ChainEpoch(1); currentEpoch < miner.WPoStChallengeWindow*5; currentEpoch++ {
// Trigger a head change
di := mock.getDeadline(currentEpoch)
go triggerHeadAdvance(t, s, currentEpoch)
go triggerHeadAdvance(t, s, currentEpoch+ChallengeConfidence)

// Wait for prover to process head change
<-s.ch.proveHdlr.processedHeadChanges
Expand Down Expand Up @@ -913,7 +913,7 @@ func TestChangeHandlerSubmitRevertTwoEpochs(t *testing.T) {

// Move to the challenge epoch for the next deadline
diE2 := nextDeadline(diE1)
currentEpoch = diE2.Challenge
currentEpoch = diE2.Challenge + ChallengeConfidence
go triggerHeadAdvance(t, s, currentEpoch)

// Should move to submitting state for epoch 1
Expand Down Expand Up @@ -1014,7 +1014,7 @@ func TestChangeHandlerSubmitRevertAdvanceLess(t *testing.T) {

// Move to the challenge epoch for the next deadline
diE2 := nextDeadline(diE1)
currentEpoch = diE2.Challenge
currentEpoch = diE2.Challenge + ChallengeConfidence
go triggerHeadAdvance(t, s, currentEpoch)

// Should move to submitting state for epoch 1
Expand Down
16 changes: 15 additions & 1 deletion storage/wdpost_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,23 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty
return nil, xerrors.Errorf("received no proofs back from generate window post")
}

headTs, err := s.api.ChainHead(ctx)
if err != nil {
return nil, xerrors.Errorf("getting current head: %w", err)
}

checkRand, err := s.api.ChainGetRandomnessFromBeacon(ctx, headTs.Key(), crypto.DomainSeparationTag_WindowedPoStChallengeSeed, di.Challenge, buf.Bytes())
if err != nil {
return nil, xerrors.Errorf("failed to get chain randomness from beacon for window post (ts=%d; deadline=%d): %w", ts.Height(), di, err)
}

if !bytes.Equal(checkRand, rand) {
log.Warnw("windowpost randomness changed", "old", rand, "new", checkRand, "ts-height", ts.Height(), "challenge-height", di.Challenge, "tsk", ts.Key())
}

// If we generated an incorrect proof, try again.
if correct, err := s.verifier.VerifyWindowPoSt(ctx, proof.WindowPoStVerifyInfo{
Randomness: abi.PoStRandomness(rand),
Randomness: abi.PoStRandomness(checkRand),
Proofs: postOut,
ChallengedSectors: sinfos,
Prover: abi.ActorID(mid),
Expand Down
2 changes: 1 addition & 1 deletion storage/wdpost_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (m *mockStorageMinerAPI) GasEstimateMessageGas(ctx context.Context, message
}

func (m *mockStorageMinerAPI) ChainHead(ctx context.Context) (*types.TipSet, error) {
panic("implement me")
return nil, nil
}

func (m *mockStorageMinerAPI) ChainNotify(ctx context.Context) (<-chan []*api.HeadChange, error) {
Expand Down

0 comments on commit 4abb333

Please sign in to comment.