Skip to content

Commit

Permalink
Fund miners with the aggregate fee when ProveCommitting
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Jun 9, 2021
1 parent 4a321c6 commit 9a6f48a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion extern/storage-sealing/commit_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type CommitBatcherApi interface {
SendMsg(ctx context.Context, from, to address.Address, method abi.MethodNum, value, maxFee abi.TokenAmount, params []byte) (cid.Cid, error)
StateMinerInfo(context.Context, address.Address, TipSetToken) (miner.MinerInfo, error)
ChainHead(ctx context.Context) (TipSetToken, abi.ChainEpoch, error)
ChainBaseFee(context.Context, TipSetToken) (abi.TokenAmount, error)

StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok TipSetToken) (*miner.SectorPreCommitOnChainInfo, error)
StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, TipSetToken) (big.Int, error)
Expand Down Expand Up @@ -285,7 +286,14 @@ func (b *CommitBatcher) processBatch(cfg sealiface.Config) ([]sealiface.CommitBa
return []sealiface.CommitBatchRes{res}, xerrors.Errorf("couldn't get miner info: %w", err)
}

goodFunds := big.Add(b.feeCfg.MaxCommitGasFee, collateral)
bf, err := b.api.ChainBaseFee(b.mctx, tok)
if err != nil {
return []sealiface.CommitBatchRes{res}, xerrors.Errorf("couldn't get base fee: %w", err)
}

aggFee := miner5.AggregateNetworkFee(len(infos), bf)

goodFunds := big.Add(b.feeCfg.MaxCommitGasFee, big.Add(collateral, aggFee))

from, _, err := b.addrSel(b.mctx, mi, api.CommitAddr, goodFunds, collateral)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions extern/storage-sealing/sealing.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type SealingAPI interface {
StateMinerPartitions(ctx context.Context, m address.Address, dlIdx uint64, tok TipSetToken) ([]api.Partition, error)
SendMsg(ctx context.Context, from, to address.Address, method abi.MethodNum, value, maxFee abi.TokenAmount, params []byte) (cid.Cid, error)
ChainHead(ctx context.Context) (TipSetToken, abi.ChainEpoch, error)
ChainBaseFee(context.Context, TipSetToken) (abi.TokenAmount, error)
ChainGetMessage(ctx context.Context, mc cid.Cid) (*types.Message, error)
ChainGetRandomnessFromBeacon(ctx context.Context, tok TipSetToken, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) (abi.Randomness, error)
ChainGetRandomnessFromTickets(ctx context.Context, tok TipSetToken, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) (abi.Randomness, error)
Expand Down
14 changes: 14 additions & 0 deletions storage/adapter_storage_miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,20 @@ func (s SealingAPIAdapter) ChainHead(ctx context.Context) (sealing.TipSetToken,
return head.Key().Bytes(), head.Height(), nil
}

func (s SealingAPIAdapter) ChainBaseFee(ctx context.Context, tok sealing.TipSetToken) (abi.TokenAmount, error) {
tsk, err := types.TipSetKeyFromBytes(tok)
if err != nil {
return big.Zero(), err
}

ts, err := s.delegate.ChainGetTipSet(ctx, tsk)
if err != nil {
return big.Zero(), err
}

return ts.Blocks()[0].ParentBaseFee, nil
}

func (s SealingAPIAdapter) ChainGetMessage(ctx context.Context, mc cid.Cid) (*types.Message, error) {
return s.delegate.ChainGetMessage(ctx, mc)
}
Expand Down

0 comments on commit 9a6f48a

Please sign in to comment.