From 1c0386285476cb6e51a451c5114f640688cd4c91 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 28 Sep 2020 17:28:16 -0700 Subject: [PATCH] fix policy for specs-actors update --- api/test/paych.go | 2 +- build/params_shared_vals.go | 13 ++++-------- build/params_testground.go | 9 ++++---- chain/actors/policy/policy.go | 27 ++++++++++++++++++++++++ chain/actors/policy/policy_test.go | 11 ++++++++++ extern/storage-sealing/checks.go | 16 ++++---------- extern/storage-sealing/constants.go | 7 ------ extern/storage-sealing/states_sealing.go | 13 +++--------- 8 files changed, 54 insertions(+), 44 deletions(-) diff --git a/api/test/paych.go b/api/test/paych.go index 4c3bdba1b..c13303593 100644 --- a/api/test/paych.go +++ b/api/test/paych.go @@ -169,7 +169,7 @@ func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) { return true, nil }, func(ctx context.Context, ts *types.TipSet) error { return nil - }, int(build.MessageConfidence)+1, build.SealRandomnessLookbackLimit, func(oldTs, newTs *types.TipSet) (bool, events.StateChange, error) { + }, int(build.MessageConfidence)+1, build.Finality, func(oldTs, newTs *types.TipSet) (bool, events.StateChange, error) { return preds.OnPaymentChannelActorChanged(channel, preds.OnToSendAmountChanges())(ctx, oldTs.Key(), newTs.Key()) }) if err != nil { diff --git a/build/params_shared_vals.go b/build/params_shared_vals.go index 9655711fb..4734a15ed 100644 --- a/build/params_shared_vals.go +++ b/build/params_shared_vals.go @@ -7,12 +7,12 @@ import ( "os" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/specs-actors/actors/builtin" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) // ///// @@ -35,7 +35,7 @@ const ForkLengthThreshold = Finality var BlocksPerEpoch = uint64(builtin.ExpectedLeadersPerEpoch) // Epochs -const Finality = miner0.ChainFinality +const Finality = policy.ChainFinality const MessageConfidence = uint64(5) // constants for Weight calculation @@ -47,13 +47,8 @@ const WRatioDen = uint64(2) // Proofs // Epochs -const SealRandomnessLookback = Finality - -// Epochs -const SealRandomnessLookbackLimit = SealRandomnessLookback + 2000 // TODO: Get from spec specs-actors - -// Maximum lookback that randomness can be sourced from for a seal proof submission -const MaxSealLookback = SealRandomnessLookbackLimit + 2000 // TODO: Get from specs-actors +// TODO: unused +const SealRandomnessLookback = policy.SealRandomnessLookback // ///// // Mining diff --git a/build/params_testground.go b/build/params_testground.go index 718e21d68..975c26599 100644 --- a/build/params_testground.go +++ b/build/params_testground.go @@ -13,7 +13,8 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/specs-actors/actors/builtin" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + + "github.com/filecoin-project/lotus/chain/actors/policy" ) var ( @@ -32,7 +33,7 @@ var ( AllowableClockDriftSecs = uint64(1) - Finality = miner0.ChainFinality + Finality = policy.ChainFinality ForkLengthThreshold = Finality SlashablePowerDelay = 20 @@ -47,9 +48,7 @@ var ( BlsSignatureCacheSize = 40000 VerifSigCacheSize = 32000 - SealRandomnessLookback = Finality - SealRandomnessLookbackLimit = SealRandomnessLookback + 2000 - MaxSealLookback = SealRandomnessLookbackLimit + 2000 + SealRandomnessLookback = policy.SealRandomnessLookback TicketRandomnessLookback = abi.ChainEpoch(1) WinningPoStSectorSetLookback = abi.ChainEpoch(10) diff --git a/chain/actors/policy/policy.go b/chain/actors/policy/policy.go index b8205177e..2101cfdcf 100644 --- a/chain/actors/policy/policy.go +++ b/chain/actors/policy/policy.go @@ -2,10 +2,19 @@ package policy import ( "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lotus/chain/actors" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" + verifreg2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/verifreg" +) + +const ( + ChainFinality = miner0.ChainFinality + SealRandomnessLookback = ChainFinality ) // SetSupportedProofTypes sets supported proof types, across all actor versions. @@ -17,6 +26,7 @@ func SetSupportedProofTypes(types ...abi.RegisteredSealProof) { } // Set for all miner versions. miner0.SupportedProofTypes = newTypes + miner2.SupportedProofTypes = newTypes } // AddSupportedProofTypes sets supported proof types, across all actor versions. @@ -25,6 +35,7 @@ func AddSupportedProofTypes(types ...abi.RegisteredSealProof) { for _, t := range types { // Set for all miner versions. miner0.SupportedProofTypes[t] = struct{}{} + miner2.SupportedProofTypes[t] = struct{}{} } } @@ -33,6 +44,7 @@ func AddSupportedProofTypes(types ...abi.RegisteredSealProof) { func SetPreCommitChallengeDelay(delay abi.ChainEpoch) { // Set for all miner versions. miner0.PreCommitChallengeDelay = delay + miner2.PreCommitChallengeDelay = delay } // TODO: this function shouldn't really exist. Instead, the API should expose the precommit delay. @@ -45,10 +57,25 @@ func GetPreCommitChallengeDelay() abi.ChainEpoch { // for testing. func SetConsensusMinerMinPower(p abi.StoragePower) { power0.ConsensusMinerMinPower = p + for _, policy := range builtin2.SealProofPolicies { + policy.ConsensusMinerMinPower = p + } } // SetMinVerifiedDealSize sets the minimum size of a verified deal. This should // only be used for testing. func SetMinVerifiedDealSize(size abi.StoragePower) { verifreg0.MinVerifiedDealSize = size + verifreg2.MinVerifiedDealSize = size +} + +func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) abi.ChainEpoch { + switch ver { + case actors.Version0: + return miner0.MaxSealDuration[t] + case actors.Version2: + return miner2.MaxProveCommitDuration[t] + default: + panic("unsupported actors version") + } } diff --git a/chain/actors/policy/policy_test.go b/chain/actors/policy/policy_test.go index be64362a2..9ba5b4030 100644 --- a/chain/actors/policy/policy_test.go +++ b/chain/actors/policy/policy_test.go @@ -7,6 +7,9 @@ import ( "github.com/filecoin-project/go-state-types/abi" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" + verifreg2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/verifreg" ) func TestSupportedProofTypes(t *testing.T) { @@ -34,3 +37,11 @@ func TestSupportedProofTypes(t *testing.T) { }, ) } + +// Tests assumptions about policies being the same between actor versions. +func TestAssumptions(t *testing.T) { + require.EqualValues(t, miner0.SupportedProofTypes, miner2.SupportedProofTypes) + require.Equal(t, miner0.PreCommitChallengeDelay, miner2.PreCommitChallengeDelay) + require.Equal(t, miner0.ChainFinality, miner2.ChainFinality) + require.Equal(t, verifreg0.MinVerifiedDealSize, verifreg2.MinVerifiedDealSize) +} diff --git a/extern/storage-sealing/checks.go b/extern/storage-sealing/checks.go index 49994024f..1010d31b2 100644 --- a/extern/storage-sealing/checks.go +++ b/extern/storage-sealing/checks.go @@ -4,11 +4,9 @@ import ( "bytes" "context" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/policy" - "github.com/filecoin-project/lotus/build" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - proof0 "github.com/filecoin-project/specs-actors/actors/runtime/proof" "golang.org/x/xerrors" @@ -102,16 +100,10 @@ func checkPrecommit(ctx context.Context, maddr address.Address, si SectorInfo, t return &ErrApi{xerrors.Errorf("calling StateNetworkVersion: %w", err)} } - var msd abi.ChainEpoch - if nv < build.ActorUpgradeNetworkVersion { - msd = miner0.MaxSealDuration[si.SectorType] - } else { - // TODO: ActorUpgrade(use MaxProveCommitDuration) - msd = 0 - } + msd := policy.GetMaxProveCommitDuration(actors.VersionForNetwork(nv), si.SectorType) - if height-(si.TicketEpoch+SealRandomnessLookback) > msd { - return &ErrExpiredTicket{xerrors.Errorf("ticket expired: seal height: %d, head: %d", si.TicketEpoch+SealRandomnessLookback, height)} + if height-(si.TicketEpoch+policy.SealRandomnessLookback) > msd { + return &ErrExpiredTicket{xerrors.Errorf("ticket expired: seal height: %d, head: %d", si.TicketEpoch+policy.SealRandomnessLookback, height)} } pci, err := api.StateSectorPreCommitInfo(ctx, maddr, si.SectorNumber, tok) diff --git a/extern/storage-sealing/constants.go b/extern/storage-sealing/constants.go index 8c7fa5abc..d6aba1814 100644 --- a/extern/storage-sealing/constants.go +++ b/extern/storage-sealing/constants.go @@ -1,11 +1,4 @@ package sealing -import ( - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" -) - -// Epochs -const SealRandomnessLookback = miner0.ChainFinality - // Epochs const InteractivePoRepConfidence = 6 diff --git a/extern/storage-sealing/states_sealing.go b/extern/storage-sealing/states_sealing.go index a4e852454..96589bcd2 100644 --- a/extern/storage-sealing/states_sealing.go +++ b/extern/storage-sealing/states_sealing.go @@ -4,10 +4,9 @@ import ( "bytes" "context" - "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/policy" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "golang.org/x/xerrors" @@ -60,7 +59,7 @@ func (m *Sealing) getTicket(ctx statemachine.Context, sector SectorInfo) (abi.Se return nil, 0, nil } - ticketEpoch := epoch - SealRandomnessLookback + ticketEpoch := epoch - policy.SealRandomnessLookback buf := new(bytes.Buffer) if err := m.maddr.MarshalCBOR(buf); err != nil { return nil, 0, err @@ -189,13 +188,7 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf return ctx.Send(SectorSealPreCommit1Failed{xerrors.Errorf("failed to get network version: %w", err)}) } - var msd abi.ChainEpoch - if nv < build.ActorUpgradeNetworkVersion { - msd = miner0.MaxSealDuration[sector.SectorType] - } else { - // TODO: ActorUpgrade(use MaxProveCommitDuration) - msd = 0 - } + msd := policy.GetMaxProveCommitDuration(actors.VersionForNetwork(nv), sector.SectorType) if minExpiration := height + msd + miner.MinSectorExpiration + 10; expiration < minExpiration { expiration = minExpiration