diff --git a/storage/pipeline/commit_batch.go b/storage/pipeline/commit_batch.go index 2e3f1a644dd..ad767fea1cc 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/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() diff --git a/storage/pipeline/pledge.go b/storage/pipeline/pledge.go index 04567fca1b2..7cdda9fa4cd 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,14 +104,16 @@ 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))) + if err == nil { + log.Errorw("failed to get allocation", "error", err) + } + 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 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 0c743f9db0a..f94c867c3e3 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 5d6928fba88..d166ee890d3 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,