Skip to content

Commit

Permalink
fix: miner: Fix DDO pledge math
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Aug 5, 2024
1 parent d44dc15 commit 07f2060
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
18 changes: 13 additions & 5 deletions storage/pipeline/commit_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -54,17 +53,24 @@ 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
}

type CommitBatcher struct {
api CommitBatcherApi
pledgeApi PledgeApi
maddr address.Address
mctx context.Context
addrSel AddressSelector
Expand Down Expand Up @@ -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)
}
Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion storage/pipeline/pledge.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,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 {
if err == nil {
log.Errorw("failed to get allocation", "error", err)
}
w = big.Add(w, abi.NewStoragePower(int64(piece.Piece().Size)))
continue
}

vw = big.Add(vw, abi.NewStoragePower(int64(piece.Piece().Size)))
}

// load market actor
duration := expiration - ts.Height()
sectorWeight := builtin.QAPowerForWeight(ssize, duration, w, vw)

Expand Down
7 changes: 7 additions & 0 deletions storage/pipeline/states_replica_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 13 additions & 2 deletions storage/pipeline/states_sealing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 07f2060

Please sign in to comment.