From c55777c0c07e0dfcd7655a716511f4711371fc72 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Thu, 19 Sep 2024 20:30:42 +1000 Subject: [PATCH] chore(miner): tweaks to pledge api from feedback --- CHANGELOG.md | 2 +- api/api_full.go | 3 +- .../actors/builtin/verifreg/actor.go.template | 65 ++++++------------- chain/actors/builtin/verifreg/verifreg.go | 64 ++++++------------ itests/sector_miner_collateral_test.go | 2 +- 5 files changed, 45 insertions(+), 91 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cb61975f3f..16b888c9684 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ ## New features * Add `EthSendRawTransactionUntrusted` RPC method to be used for the gateway when accepting `EthSendRawTransaction` and `eth_sendRawTransaction`. Applies a tighter limit on the number of messages in the queue from a single sender and applies additional restrictions on nonce increments. ([filecoin-project/lotus#12431](https://github.com/filecoin-project/lotus/pull/12431)) -* [Checkpoint TipSets finalized by F3](https://github.com/filecoin-project/lotus/pull/12460): Once a decision is made by F3, the TipSet is check-pointed in `ChainStore`. As part of this change, any missing TipSets are asynchronously synced as required by the `ChainStore` checkpointing mechanism. +* [Checkpoint TipSets finalized by F3](https://github.com/filecoin-project/lotus/pull/12460): Once a decision is made by F3, the TipSet is check-pointed in `ChainStore`. As part of this change, any missing TipSets are asynchronously synced as required by the `ChainStore` checkpointing mechanism. * feat: Added `StateMinerInitialPledgeForSector` RPC method and deprecated existing `StateMinerInitialPledgeCollateral` method. Since ProveCommitSectors3 and ProveReplicaUpdates3, sector onboarding no longer includes an explicit notion of "deals", and precommit messages no longer contain deal information. This makes the existing `StateMinerInitialPledgeCollateral` unable to properly calculate pledge requirements with only the precommit. `StateMinerInitialPledgeForSector` is a new simplified calculator that simply takes duration, sector size, and verified size and estimates pledge based on current network conditions. ([filecoin-project/lotus#12384](https://github.com/filecoin-project/lotus/pull/12384) ## Improvements diff --git a/api/api_full.go b/api/api_full.go index 44a30a888ee..08e360e3ef5 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -419,7 +419,8 @@ type FullNode interface { StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error) //perm:read // StateMinerInitialPledgeForSector returns the initial pledge collateral for a given sector // duration, size, and combined size of any verified pieces within the sector. This calculation - // depends on current network conditions at the given tipset. + // depends on current network conditions (total power, total pledge and current rewards) at the + // given tipset. StateMinerInitialPledgeForSector(ctx context.Context, sectorDuration abi.ChainEpoch, sectorSize abi.SectorSize, verifiedSize uint64, tsk types.TipSetKey) (types.BigInt, error) //perm:read // StateMinerAvailableBalance returns the portion of a miner's balance that can be withdrawn or spent StateMinerAvailableBalance(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) //perm:read diff --git a/chain/actors/builtin/verifreg/actor.go.template b/chain/actors/builtin/verifreg/actor.go.template index bbda9be1240..75c99f2aaef 100644 --- a/chain/actors/builtin/verifreg/actor.go.template +++ b/chain/actors/builtin/verifreg/actor.go.template @@ -21,15 +21,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/types" verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg" - verifregtypes13 "github.com/filecoin-project/go-state-types/builtin/v14/verifreg" -) - -const ( - NoAllocationID = verifregtypes.NoAllocationID - MaximumVerifiedAllocationExpiration = verifregtypes.MaximumVerifiedAllocationExpiration - MinimumVerifiedAllocationTerm = verifregtypes.MinimumVerifiedAllocationTerm - MaximumVerifiedAllocationTerm = verifregtypes.MaximumVerifiedAllocationTerm - MinimumVerifiedAllocationSize = verifregtypes13.MinimumVerifiedAllocationSize + verifregtypes12 "github.com/filecoin-project/go-state-types/builtin/v12/verifreg" ) var ( @@ -37,41 +29,6 @@ var ( Methods = builtin{{.latestVersion}}.MethodsVerifiedRegistry ) -type ( - RemoveDataCapProposal = verifregtypes.RemoveDataCapProposal - RemoveDataCapRequest = verifregtypes.RemoveDataCapRequest - AddVerifierParams = verifregtypes.AddVerifierParams - AddVerifiedClientParams = verifregtypes.AddVerifiedClientParams - UseBytesParams = verifregtypes.UseBytesParams - RestoreBytesParams = verifregtypes.RestoreBytesParams - RemoveDataCapParams = verifregtypes.RemoveDataCapParams - RemoveDataCapReturn = verifregtypes.RemoveDataCapReturn - RemoveExpiredAllocationsParams = verifregtypes.RemoveExpiredAllocationsParams - RemoveExpiredAllocationsReturn = verifregtypes.RemoveExpiredAllocationsReturn - BatchReturn = verifregtypes.BatchReturn - AllocationId = verifregtypes.AllocationId - ClaimId = verifregtypes.ClaimId - ClaimAllocationsParams = verifregtypes.ClaimAllocationsParams - SectorAllocationClaims = verifregtypes13.SectorAllocationClaims - AllocationClaim = verifregtypes13.AllocationClaim - ClaimAllocationsReturn = verifregtypes.ClaimAllocationsReturn - GetClaimsParams = verifregtypes.GetClaimsParams - GetClaimsReturn = verifregtypes.GetClaimsReturn - Claim = verifregtypes.Claim - Allocation = verifregtypes.Allocation - UniversalReceiverParams = verifregtypes.UniversalReceiverParams - ReceiverType = verifregtypes.ReceiverType - AllocationsResponse = verifregtypes.AllocationsResponse - ExtendClaimTermsParams = verifregtypes.ExtendClaimTermsParams - ClaimTerm = verifregtypes.ClaimTerm - ExtendClaimTermsReturn = verifregtypes.ExtendClaimTermsReturn - RemoveExpiredClaimsParams = verifregtypes.RemoveExpiredClaimsParams - RemoveExpiredClaimsReturn = verifregtypes.RemoveExpiredClaimsReturn - AllocationRequest = verifregtypes.AllocationRequest - ClaimExtensionRequest = verifregtypes.ClaimExtensionRequest - AllocationRequests = verifregtypes.AllocationRequests -) - func Load(store adt.Store, act *types.Actor) (State, error) { if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { if name != manifest.VerifregKey { @@ -139,3 +96,23 @@ func AllCodes() []cid.Cid { {{- end}} } } + +type ( + Allocation = verifregtypes.Allocation + AllocationId = verifregtypes.AllocationId + Claim = verifregtypes.Claim + ClaimId = verifregtypes.ClaimId + AllocationRequest = verifregtypes12.AllocationRequest + AllocationRequests = verifregtypes12.AllocationRequests + RemoveExpiredAllocationsParams = verifregtypes12.RemoveExpiredAllocationsParams + AddVerifierParams = verifregtypes12.AddVerifierParams + AddVerifiedClientParams = verifregtypes12.AddVerifiedClientParams +) + +const ( + NoAllocationID = verifregtypes.NoAllocationID + MinimumVerifiedAllocationTerm = verifregtypes12.MinimumVerifiedAllocationTerm + MaximumVerifiedAllocationTerm = verifregtypes12.MaximumVerifiedAllocationTerm + MaximumVerifiedAllocationExpiration = verifregtypes12.MaximumVerifiedAllocationExpiration +) + diff --git a/chain/actors/builtin/verifreg/verifreg.go b/chain/actors/builtin/verifreg/verifreg.go index 36c9aad137e..02d8aa116fd 100644 --- a/chain/actors/builtin/verifreg/verifreg.go +++ b/chain/actors/builtin/verifreg/verifreg.go @@ -8,7 +8,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" actorstypes "github.com/filecoin-project/go-state-types/actors" builtin15 "github.com/filecoin-project/go-state-types/builtin" - verifregtypes13 "github.com/filecoin-project/go-state-types/builtin/v14/verifreg" + verifregtypes12 "github.com/filecoin-project/go-state-types/builtin/v12/verifreg" verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg" "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/manifest" @@ -25,54 +25,11 @@ import ( "github.com/filecoin-project/lotus/chain/types" ) -const ( - NoAllocationID = verifregtypes.NoAllocationID - MaximumVerifiedAllocationExpiration = verifregtypes.MaximumVerifiedAllocationExpiration - MinimumVerifiedAllocationTerm = verifregtypes.MinimumVerifiedAllocationTerm - MaximumVerifiedAllocationTerm = verifregtypes.MaximumVerifiedAllocationTerm - MinimumVerifiedAllocationSize = verifregtypes13.MinimumVerifiedAllocationSize -) - var ( Address = builtin15.VerifiedRegistryActorAddr Methods = builtin15.MethodsVerifiedRegistry ) -type ( - RemoveDataCapProposal = verifregtypes.RemoveDataCapProposal - RemoveDataCapRequest = verifregtypes.RemoveDataCapRequest - AddVerifierParams = verifregtypes.AddVerifierParams - AddVerifiedClientParams = verifregtypes.AddVerifiedClientParams - UseBytesParams = verifregtypes.UseBytesParams - RestoreBytesParams = verifregtypes.RestoreBytesParams - RemoveDataCapParams = verifregtypes.RemoveDataCapParams - RemoveDataCapReturn = verifregtypes.RemoveDataCapReturn - RemoveExpiredAllocationsParams = verifregtypes.RemoveExpiredAllocationsParams - RemoveExpiredAllocationsReturn = verifregtypes.RemoveExpiredAllocationsReturn - BatchReturn = verifregtypes.BatchReturn - AllocationId = verifregtypes.AllocationId - ClaimId = verifregtypes.ClaimId - ClaimAllocationsParams = verifregtypes.ClaimAllocationsParams - SectorAllocationClaims = verifregtypes13.SectorAllocationClaims - AllocationClaim = verifregtypes13.AllocationClaim - ClaimAllocationsReturn = verifregtypes.ClaimAllocationsReturn - GetClaimsParams = verifregtypes.GetClaimsParams - GetClaimsReturn = verifregtypes.GetClaimsReturn - Claim = verifregtypes.Claim - Allocation = verifregtypes.Allocation - UniversalReceiverParams = verifregtypes.UniversalReceiverParams - ReceiverType = verifregtypes.ReceiverType - AllocationsResponse = verifregtypes.AllocationsResponse - ExtendClaimTermsParams = verifregtypes.ExtendClaimTermsParams - ClaimTerm = verifregtypes.ClaimTerm - ExtendClaimTermsReturn = verifregtypes.ExtendClaimTermsReturn - RemoveExpiredClaimsParams = verifregtypes.RemoveExpiredClaimsParams - RemoveExpiredClaimsReturn = verifregtypes.RemoveExpiredClaimsReturn - AllocationRequest = verifregtypes.AllocationRequest - ClaimExtensionRequest = verifregtypes.ClaimExtensionRequest - AllocationRequests = verifregtypes.AllocationRequests -) - func Load(store adt.Store, act *types.Actor) (State, error) { if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { if name != manifest.VerifregKey { @@ -230,3 +187,22 @@ func AllCodes() []cid.Cid { (&state15{}).Code(), } } + +type ( + Allocation = verifregtypes.Allocation + AllocationId = verifregtypes.AllocationId + Claim = verifregtypes.Claim + ClaimId = verifregtypes.ClaimId + AllocationRequest = verifregtypes12.AllocationRequest + AllocationRequests = verifregtypes12.AllocationRequests + RemoveExpiredAllocationsParams = verifregtypes12.RemoveExpiredAllocationsParams + AddVerifierParams = verifregtypes12.AddVerifierParams + AddVerifiedClientParams = verifregtypes12.AddVerifiedClientParams +) + +const ( + NoAllocationID = verifregtypes.NoAllocationID + MinimumVerifiedAllocationTerm = verifregtypes12.MinimumVerifiedAllocationTerm + MaximumVerifiedAllocationTerm = verifregtypes12.MaximumVerifiedAllocationTerm + MaximumVerifiedAllocationExpiration = verifregtypes12.MaximumVerifiedAllocationExpiration +) diff --git a/itests/sector_miner_collateral_test.go b/itests/sector_miner_collateral_test.go index 7bb84c2ce11..a4df47dbd1c 100644 --- a/itests/sector_miner_collateral_test.go +++ b/itests/sector_miner_collateral_test.go @@ -444,7 +444,7 @@ func TestPledgeCalculations(t *testing.T) { require.NoError(t, err) require.Equal(t, exitcode.Ok, r.Receipt.ExitCode) - tsk := r.TipSet // we're going to perform all pledge calculations at this tipset so we have consistent power outputs + tsk := r.TipSet // we're going to perform all pledge calculations at this tipset so we have consistent power, pledge, reward outputs verifyPledge := func(sectorNumber abi.SectorNumber, verifiedSize uint64) big.Int { // Compare deprecated pledge calculation that uses PreCommit with Deal information with the