From 526674cefafc15d6665726cb8ef60700aba54c7c Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 16 Jun 2021 16:39:23 -0700 Subject: [PATCH] fix: pick the correct partitions-per-post limit --- chain/actors/policy/policy.go | 6 +++--- chain/actors/policy/policy.go.template | 6 +++--- chain/actors/policy/policy_test.go | 10 ++++++++++ storage/wdpost_run.go | 2 +- storage/wdpost_run_test.go | 3 ++- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/chain/actors/policy/policy.go b/chain/actors/policy/policy.go index 22ec4c742..c159dc98f 100644 --- a/chain/actors/policy/policy.go +++ b/chain/actors/policy/policy.go @@ -278,13 +278,13 @@ func GetMaxSectorExpirationExtension() abi.ChainEpoch { return miner5.MaxSectorExpirationExtension } -// TODO: we'll probably need to abstract over this better in the future. -func GetMaxPoStPartitions(p abi.RegisteredPoStProof) (int, error) { +func GetMaxPoStPartitions(nv network.Version, p abi.RegisteredPoStProof) (int, error) { sectorsPerPart, err := builtin5.PoStProofWindowPoStPartitionSectors(p) if err != nil { return 0, err } - return int(miner5.AddressedSectorsMax / sectorsPerPart), nil + maxSectors := uint64(GetAddressedSectorsMax(nv)) + return int(maxSectors / sectorsPerPart), nil } func GetDefaultSectorSize() abi.SectorSize { diff --git a/chain/actors/policy/policy.go.template b/chain/actors/policy/policy.go.template index 5d8100675..e27aac6e8 100644 --- a/chain/actors/policy/policy.go.template +++ b/chain/actors/policy/policy.go.template @@ -182,13 +182,13 @@ func GetMaxSectorExpirationExtension() abi.ChainEpoch { return miner{{.latestVersion}}.MaxSectorExpirationExtension } -// TODO: we'll probably need to abstract over this better in the future. -func GetMaxPoStPartitions(p abi.RegisteredPoStProof) (int, error) { +func GetMaxPoStPartitions(nv network.Version, p abi.RegisteredPoStProof) (int, error) { sectorsPerPart, err := builtin{{.latestVersion}}.PoStProofWindowPoStPartitionSectors(p) if err != nil { return 0, err } - return int(miner{{.latestVersion}}.AddressedSectorsMax / sectorsPerPart), nil + maxSectors := uint64(GetAddressedSectorsMax(nv)) + return int(maxSectors / sectorsPerPart), nil } func GetDefaultSectorSize() abi.SectorSize { diff --git a/chain/actors/policy/policy_test.go b/chain/actors/policy/policy_test.go index 24e47aaa0..f40250fba 100644 --- a/chain/actors/policy/policy_test.go +++ b/chain/actors/policy/policy_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/network" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" @@ -68,3 +69,12 @@ func TestPartitionSizes(t *testing.T) { require.Equal(t, sizeOld, sizeNew) } } + +func TestPoStSize(t *testing.T) { + v12PoStSize, err := GetMaxPoStPartitions(network.Version12, abi.RegisteredPoStProof_StackedDrgWindow64GiBV1) + require.Equal(t, 4, v12PoStSize) + require.NoError(t, err) + v13PoStSize, err := GetMaxPoStPartitions(network.Version13, abi.RegisteredPoStProof_StackedDrgWindow64GiBV1) + require.NoError(t, err) + require.Equal(t, 10, v13PoStSize) +} diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index d590e3814..eeff94418 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -695,7 +695,7 @@ func (s *WindowPoStScheduler) batchPartitions(partitions []api.Partition, nv net // sectors per partition 3: ooo // partitions per message 2: oooOOO // <1><2> (3rd doesn't fit) - partitionsPerMsg, err := policy.GetMaxPoStPartitions(s.proofType) + partitionsPerMsg, err := policy.GetMaxPoStPartitions(nv, s.proofType) if err != nil { return nil, xerrors.Errorf("getting sectors per partition: %w", err) } diff --git a/storage/wdpost_run_test.go b/storage/wdpost_run_test.go index 916929724..3a009d5c7 100644 --- a/storage/wdpost_run_test.go +++ b/storage/wdpost_run_test.go @@ -31,6 +31,7 @@ import ( "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/actors/policy" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/extern/sector-storage/storiface" "github.com/filecoin-project/lotus/journal" @@ -185,8 +186,8 @@ func TestWDPostDoPost(t *testing.T) { // Work out the number of partitions that can be included in a message // without exceeding the message sector limit + partitionsPerMsg, err := policy.GetMaxPoStPartitions(network.Version13, proofType) require.NoError(t, err) - partitionsPerMsg := int(miner5.AddressedSectorsMax / sectorsPerPartition) if partitionsPerMsg > miner5.AddressedPartitionsMax { partitionsPerMsg = miner5.AddressedPartitionsMax }