From ba78017d8198e349c18b2ff329a846eb4e8b750b Mon Sep 17 00:00:00 2001 From: zenground0 Date: Mon, 5 Aug 2024 09:39:52 -0600 Subject: [PATCH 1/4] Power is units of Space * Time so multiply by deal duration --- storage/pipeline/pledge.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/storage/pipeline/pledge.go b/storage/pipeline/pledge.go index 04567fca1b2..2b10d009717 100644 --- a/storage/pipeline/pledge.go +++ b/storage/pipeline/pledge.go @@ -91,6 +91,11 @@ func (m *Sealing) sectorWeight(ctx context.Context, sector SectorInfo, expiratio // get verified deal infos var w, vw = big.Zero(), big.Zero() + now, err := m.Api.ChainHead(ctx) + if err != nil { + return abi.NewStoragePower(0), err + } + sectorDuration := big.NewInt(int64(expiration - now.Height())) for _, piece := range sector.Pieces { if !piece.HasDealInfo() { // todo StateMinerInitialPledgeCollateral doesn't add cc/padding to non-verified weight, is that correct? @@ -99,11 +104,11 @@ func (m *Sealing) sectorWeight(ctx context.Context, sector SectorInfo, expiratio alloc, err := piece.GetAllocation(ctx, m.Api, ts.Key()) if err != nil || alloc == nil { - w = big.Add(w, abi.NewStoragePower(int64(piece.Piece().Size))) + w = big.Add(w, big.Mul(sectorDuration, abi.NewStoragePower(int64(piece.Piece().Size)))) continue } - vw = big.Add(vw, abi.NewStoragePower(int64(piece.Piece().Size))) + vw = big.Add(vw, big.Mul(sectorDuration, abi.NewStoragePower(int64(piece.Piece().Size)))) } // load market actor From 136d8519556355bd27d937a36adfc31c1ea3a669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 5 Aug 2024 17:35:54 +0200 Subject: [PATCH 2/4] fix: miner: Fix DDO pledge math --- storage/pipeline/commit_batch.go | 21 +++++++++++++++------ storage/pipeline/pledge.go | 4 +++- storage/pipeline/sealing.go | 2 +- storage/pipeline/states_replica_update.go | 7 +++++++ storage/pipeline/states_sealing.go | 15 +++++++++++++-- 5 files changed, 39 insertions(+), 10 deletions(-) diff --git a/storage/pipeline/commit_batch.go b/storage/pipeline/commit_batch.go index 5c04d97bb43..d14b7c00b6d 100644 --- a/storage/pipeline/commit_batch.go +++ b/storage/pipeline/commit_batch.go @@ -42,7 +42,6 @@ type CommitBatcherApi interface { ChainHead(ctx context.Context) (*types.TipSet, error) StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*miner.SectorPreCommitOnChainInfo, error) - StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (big.Int, error) StateNetworkVersion(ctx context.Context, tsk types.TipSetKey) (network.Version, error) StateMinerAvailableBalance(context.Context, address.Address, types.TipSetKey) (big.Int, error) StateGetAllocation(ctx context.Context, clientAddr address.Address, allocationId verifregtypes.AllocationId, tsk types.TipSetKey) (*verifregtypes.Allocation, error) @@ -54,10 +53,16 @@ type CommitBatcherApi interface { StateLookupID(context.Context, address.Address, types.TipSetKey) (address.Address, error) } +type PledgeApi interface { + sectorWeight(ctx context.Context, sector SectorInfo, expiration abi.ChainEpoch) (abi.StoragePower, error) + pledgeForPower(ctx context.Context, addedPower abi.StoragePower) (abi.TokenAmount, error) +} + type AggregateInput struct { - Spt abi.RegisteredSealProof - Info proof.AggregateSealVerifyInfo - Proof []byte + Spt abi.RegisteredSealProof + Info proof.AggregateSealVerifyInfo + Proof []byte + Weight abi.StoragePower ActivationManifest miner.SectorActivationManifest DealIDPrecommit bool @@ -65,6 +70,7 @@ type AggregateInput struct { type CommitBatcher struct { api CommitBatcherApi + pledgeApi PledgeApi maddr address.Address mctx context.Context addrSel AddressSelector @@ -81,7 +87,7 @@ type CommitBatcher struct { lk sync.Mutex } -func NewCommitBatcher(mctx context.Context, maddr address.Address, api CommitBatcherApi, addrSel AddressSelector, feeCfg config.MinerFeeConfig, getConfig dtypes.GetSealingConfigFunc, prov storiface.Prover) (*CommitBatcher, error) { +func NewCommitBatcher(mctx context.Context, maddr address.Address, api CommitBatcherApi, addrSel AddressSelector, feeCfg config.MinerFeeConfig, getConfig dtypes.GetSealingConfigFunc, prov storiface.Prover, pa PledgeApi) (*CommitBatcher, error) { b := &CommitBatcher{ api: api, maddr: maddr, @@ -90,6 +96,7 @@ func NewCommitBatcher(mctx context.Context, maddr address.Address, api CommitBat feeCfg: feeCfg, getConfig: getConfig, prover: prov, + pledgeApi: pa, cutoffs: map[abi.SectorNumber]time.Time{}, todo: map[abi.SectorNumber]AggregateInput{}, @@ -606,7 +613,7 @@ func (b *CommitBatcher) getSectorCollateral(sn abi.SectorNumber, tsk types.TipSe return big.Zero(), xerrors.Errorf("precommit info not found on chain") } - collateral, err := b.api.StateMinerInitialPledgeCollateral(b.mctx, b.maddr, pci.Info, tsk) + collateral, err := b.pledgeApi.pledgeForPower(b.mctx, b.todo[sn].Weight) // b.maddr, pci.Info, tsk if err != nil { return big.Zero(), xerrors.Errorf("getting initial pledge collateral: %w", err) } @@ -616,6 +623,8 @@ func (b *CommitBatcher) getSectorCollateral(sn abi.SectorNumber, tsk types.TipSe collateral = big.Zero() } + log.Infow("getSectorCollateral", "collateral", types.FIL(collateral), "sn", sn, "precommit", types.FIL(pci.PreCommitDeposit), "pledge", types.FIL(collateral), "weight", b.todo[sn].Weight) + return collateral, nil } func (b *CommitBatcher) aggregateProofType(nv network.Version) (abi.RegisteredAggregationProof, error) { diff --git a/storage/pipeline/pledge.go b/storage/pipeline/pledge.go index 04567fca1b2..1953d4e5e76 100644 --- a/storage/pipeline/pledge.go +++ b/storage/pipeline/pledge.go @@ -99,6 +99,9 @@ func (m *Sealing) sectorWeight(ctx context.Context, sector SectorInfo, expiratio alloc, err := piece.GetAllocation(ctx, m.Api, ts.Key()) if err != nil || alloc == nil { + if err == nil { + log.Errorw("failed to get allocation", "error", err) + } w = big.Add(w, abi.NewStoragePower(int64(piece.Piece().Size))) continue } @@ -106,7 +109,6 @@ func (m *Sealing) sectorWeight(ctx context.Context, sector SectorInfo, expiratio vw = big.Add(vw, abi.NewStoragePower(int64(piece.Piece().Size))) } - // load market actor duration := expiration - ts.Height() sectorWeight := builtin.QAPowerForWeight(ssize, duration, w, vw) diff --git a/storage/pipeline/sealing.go b/storage/pipeline/sealing.go index fe25e15e64b..4ef0323ff1f 100644 --- a/storage/pipeline/sealing.go +++ b/storage/pipeline/sealing.go @@ -273,7 +273,7 @@ func New(mctx context.Context, sapi SealingAPI, fc config.MinerFeeConfig, events } s.precommiter = pc - cc, err := NewCommitBatcher(mctx, maddr, sapi, addrSel, fc, gc, prov) + cc, err := NewCommitBatcher(mctx, maddr, sapi, addrSel, fc, gc, prov, s) if err != nil { return nil, err } diff --git a/storage/pipeline/states_replica_update.go b/storage/pipeline/states_replica_update.go index f0e43a5abc0..dd445b28bdc 100644 --- a/storage/pipeline/states_replica_update.go +++ b/storage/pipeline/states_replica_update.go @@ -143,6 +143,13 @@ func (m *Sealing) handleSubmitReplicaUpdate(ctx statemachine.Context, sector Sec return ctx.Send(SectorSubmitReplicaUpdateFailed{}) } + log.Infow("submitting replica update", + "sector", sector.SectorNumber, + "weight", types.FIL(weightUpdate), + "totalPledge", types.FIL(collateral), + "initialPledge", types.FIL(onChainInfo.InitialPledge), + "toPledge", types.FIL(big.Sub(collateral, onChainInfo.InitialPledge))) + collateral = big.Sub(collateral, onChainInfo.InitialPledge) if collateral.LessThan(big.Zero()) { collateral = big.Zero() diff --git a/storage/pipeline/states_sealing.go b/storage/pipeline/states_sealing.go index cc83f3753ee..ddcdd9befad 100644 --- a/storage/pipeline/states_sealing.go +++ b/storage/pipeline/states_sealing.go @@ -780,6 +780,16 @@ func (m *Sealing) handleSubmitCommitAggregate(ctx statemachine.Context, sector S return err } + pci, err := m.Api.StateSectorPreCommitInfo(ctx.Context(), m.maddr, sector.SectorNumber, types.EmptyTSK) + if err != nil { + return xerrors.Errorf("getting precommit info: %w", err) + } + + weight, err := m.sectorWeight(ctx.Context(), sector, pci.Info.Expiration) + if err != nil { + return xerrors.Errorf("getting sector weight: %w", err) + } + res, err := m.commiter.AddCommit(ctx.Context(), sector, AggregateInput{ Info: proof.AggregateSealVerifyInfo{ Number: sector.SectorNumber, @@ -788,8 +798,9 @@ func (m *Sealing) handleSubmitCommitAggregate(ctx statemachine.Context, sector S SealedCID: *sector.CommR, UnsealedCID: *sector.CommD, }, - Proof: sector.Proof, - Spt: sector.SectorType, + Proof: sector.Proof, + Spt: sector.SectorType, + Weight: weight, ActivationManifest: miner2.SectorActivationManifest{ SectorNumber: sector.SectorNumber, From 1bf0d1f6f7df8a4ca346784c479fe46f1b002e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 9 Aug 2024 17:55:44 +0200 Subject: [PATCH 3/4] appease the changelog checker --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c519d607778..64b8f4a393d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - https://github.com/filecoin-project/lotus/pull/12319: feat: `lotus send CLI`: allow sending to ETH addresses - https://github.com/filecoin-project/lotus/pull/12332: fix: ETH RPC: receipts: use correct txtype in receipts - https://github.com/filecoin-project/lotus/pull/12335: fix: lotus-shed: store processed tipset after backfilling events +- https://github.com/filecoin-project/lotus/pull/12341: fix: miner: Fix DDO pledge math ## New features From 7b29a3722fa99304aaa988065c494c38dd947021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 9 Aug 2024 18:05:32 +0200 Subject: [PATCH 4/4] Fix gen --- storage/pipeline/mocks/mock_commit_batcher.go | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/storage/pipeline/mocks/mock_commit_batcher.go b/storage/pipeline/mocks/mock_commit_batcher.go index e2fce1eca01..aad1c332fb9 100644 --- a/storage/pipeline/mocks/mock_commit_batcher.go +++ b/storage/pipeline/mocks/mock_commit_batcher.go @@ -164,21 +164,6 @@ func (mr *MockCommitBatcherApiMockRecorder) StateMinerInfo(arg0, arg1, arg2 inte return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateMinerInfo", reflect.TypeOf((*MockCommitBatcherApi)(nil).StateMinerInfo), arg0, arg1, arg2) } -// StateMinerInitialPledgeCollateral mocks base method. -func (m *MockCommitBatcherApi) StateMinerInitialPledgeCollateral(arg0 context.Context, arg1 address.Address, arg2 miner.SectorPreCommitInfo, arg3 types.TipSetKey) (big.Int, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StateMinerInitialPledgeCollateral", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].(big.Int) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// StateMinerInitialPledgeCollateral indicates an expected call of StateMinerInitialPledgeCollateral. -func (mr *MockCommitBatcherApiMockRecorder) StateMinerInitialPledgeCollateral(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateMinerInitialPledgeCollateral", reflect.TypeOf((*MockCommitBatcherApi)(nil).StateMinerInitialPledgeCollateral), arg0, arg1, arg2, arg3) -} - // StateNetworkVersion mocks base method. func (m *MockCommitBatcherApi) StateNetworkVersion(arg0 context.Context, arg1 types.TipSetKey) (network.Version, error) { m.ctrl.T.Helper()