Skip to content

Commit

Permalink
fix: storage - move rand generation after proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc committed Sep 15, 2020
1 parent f0f15f8 commit db998e9
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions storage/wdpost_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ func (s *WindowPoStScheduler) doPost(ctx context.Context, deadline *dline.Info,

for i := range posts {
post := &posts[i]
sm, err := s.submitPost(ctx, &posts[i])
sm, err := s.submitPost(ctx, post)
if err != nil {
log.Errorf("submitPost failed: %+v", err)
s.failPost(err, deadline)
} else {
recordProofsEvent(post.Partitions, sm.Cid())
}
recordProofsEvent(post.Partitions, sm.Cid())
}

journal.J.RecordEvent(s.evtTypes[evtTypeWdPoStScheduler], func() interface{} {
Expand Down Expand Up @@ -412,6 +413,7 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty
return nil, err
}

// Generate proofs in batches
posts := make([]miner.SubmitWindowedPoStParams, 0, len(partitionBatches))
for batchIdx, batch := range partitionBatches {
batchPartitionStartIdx := 0
Expand All @@ -425,18 +427,12 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty
Proofs: nil,
}

//var sinfos []proof.SectorInfo
//sidToPart := map[abi.SectorNumber]uint64{}
//skipCount := uint64(0)

skipCount := uint64(0)
postSkipped := bitfield.New()
var postOut []proof.PoStProof
var sinfos []proof.SectorInfo

somethingToProve := true
for retries := 0; retries < 5; retries++ {
sinfos = make([]proof.SectorInfo, 0)

var sinfos []proof.SectorInfo
for partIdx, partition := range batch {
// TODO: Can do this in parallel
toProve, err := partition.ActiveSectors()
Expand Down Expand Up @@ -488,11 +484,12 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty
}

if len(sinfos) == 0 {
// nothing to prove..
//return nil, errNoPartitions
// nothing to prove for this batch
somethingToProve = false
break
}

// Generate proof
log.Infow("running windowPost",
"chain-random", rand,
"deadline", di,
Expand All @@ -513,9 +510,12 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty
log.Infow("computing window PoSt", "batch", batchIdx, "elapsed", elapsed)

if err == nil {
// Proof generation successful, stop retrying
break
}

// Proof generation failed, so retry

if len(ps) == 0 {
return nil, xerrors.Errorf("running post failed: %w", err)
}
Expand All @@ -528,7 +528,8 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty
}
}

if len(sinfos) == 0 {
// Nothing to prove for this batch, try the next batch
if !somethingToProve {
continue
}

Expand All @@ -541,10 +542,12 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty
posts = append(posts, params)
}

// Compute randomness after generating proofs so as to reduce the impact
// of chain reorgs (which change randomness)
commEpoch := di.Open
commRand, err := s.api.ChainGetRandomnessFromTickets(ctx, ts.Key(), crypto.DomainSeparationTag_PoStChainCommit, commEpoch, nil)
if err != nil {
return nil, xerrors.Errorf("failed to get chain randomness for windowPost (ts=%d; deadline=%d): %w", ts.Height(), di, err)
return nil, xerrors.Errorf("failed to get chain randomness for windowPost (ts=%d; deadline=%d): %w", ts.Height(), commEpoch, err)
}

for i := range posts {
Expand Down

0 comments on commit db998e9

Please sign in to comment.