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 5df2939
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 13 additions & 0 deletions storage/wdpost_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,19 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di dline.Info, ts *ty
posts[i].ChainCommitRand = commRand
}

// 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)
}

for i := range posts {
posts[i].ChainCommitEpoch = commEpoch
posts[i].ChainCommitRand = commRand
}

return posts, nil
}

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 5df2939

Please sign in to comment.