diff --git a/storage/pipeline/commit_batch.go b/storage/pipeline/commit_batch.go index 5c04d97bb43..da9943714c5 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 @@ -606,7 +612,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 +622,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/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,