From 109b326ae2733725f172604503483890b8459a57 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 23 Oct 2020 12:32:07 -0700 Subject: [PATCH] Use older randomness for the PoSt commit on specs-actors version 2 After the upgrade, we're allowed to use randomness up to the challenge epoch. This safe-guards us against very large reorgs where a miner computes a PoSt very quickly. --- storage/wdpost_run.go | 9 +++++++++ storage/wdpost_run_test.go | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index 54d3d3dcc..fd3053a34 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -12,6 +12,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/dline" + "github.com/filecoin-project/go-state-types/network" "github.com/ipfs/go-cid" "go.opencensus.io/trace" @@ -151,7 +152,15 @@ func (s *WindowPoStScheduler) runSubmitPoST( defer span.End() // Get randomness from tickets + // use the challenge epoch if we've upgraded to network version 4 + // (actors version 2). We want to go back as far as possible to be safe. commEpoch := deadline.Open + if ver, err := s.api.StateNetworkVersion(ctx, types.EmptyTSK); err != nil { + log.Errorw("failed to get network version to determine PoSt epoch randomness lookback", "error", err) + } else if ver >= network.Version4 { + commEpoch = deadline.Challenge + } + commRand, err := s.api.ChainGetRandomnessFromTickets(ctx, ts.Key(), crypto.DomainSeparationTag_PoStChainCommit, commEpoch, nil) if err != nil { err = xerrors.Errorf("failed to get chain randomness from tickets for windowPost (ts=%d; deadline=%d): %w", ts.Height(), commEpoch, err) diff --git a/storage/wdpost_run_test.go b/storage/wdpost_run_test.go index bac86f022..4145a6e70 100644 --- a/storage/wdpost_run_test.go +++ b/storage/wdpost_run_test.go @@ -23,6 +23,7 @@ import ( tutils "github.com/filecoin-project/specs-actors/v2/support/testing" "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/journal" @@ -47,7 +48,7 @@ func (m *mockStorageMinerAPI) StateMinerInfo(ctx context.Context, a address.Addr } func (m *mockStorageMinerAPI) StateNetworkVersion(ctx context.Context, key types.TipSetKey) (network.Version, error) { - panic("implement me") + return build.NewestNetworkVersion, nil } func (m *mockStorageMinerAPI) ChainGetRandomnessFromTickets(ctx context.Context, tsk types.TipSetKey, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) (abi.Randomness, error) {