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 11, 2020
1 parent 2f24ee1 commit 85ee7ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
26 changes: 14 additions & 12 deletions storage/wdpost_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,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 @@ -346,18 +347,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 @@ -409,11 +404,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 @@ -434,9 +430,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 @@ -449,7 +448,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 @@ -462,10 +462,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
6 changes: 4 additions & 2 deletions storage/wdpost_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
"github.com/filecoin-project/specs-actors/actors/runtime/proof"

"github.com/filecoin-project/go-state-types/dline"

"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/crypto"
tutils "github.com/filecoin-project/specs-actors/support/testing"
Expand Down Expand Up @@ -154,7 +156,7 @@ func TestWDPostDoPost(t *testing.T) {
worker: workerAct,
}

di := &miner.DeadlineInfo{}
di := &dline.Info{}
ts := mockTipSet(t)
scheduler.doPost(ctx, di, ts)

Expand Down Expand Up @@ -218,7 +220,7 @@ func (m *mockStorageMinerAPI) StateSectorPartition(ctx context.Context, maddr ad
panic("implement me")
}

func (m *mockStorageMinerAPI) StateMinerProvingDeadline(ctx context.Context, address address.Address, key types.TipSetKey) (*miner.DeadlineInfo, error) {
func (m *mockStorageMinerAPI) StateMinerProvingDeadline(ctx context.Context, address address.Address, key types.TipSetKey) (*dline.Info, error) {
panic("implement me")
}

Expand Down

0 comments on commit 85ee7ff

Please sign in to comment.