Skip to content

Commit

Permalink
Merge pull request #9746 from filecoin-project/feat/maximize-feecap-cfg
Browse files Browse the repository at this point in the history
feat: mpool/wdpost: Maximize feecap config
  • Loading branch information
magik6k committed Oct 13, 2023
2 parents 2b36722 + 861134d commit 9fc3c33
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 17 deletions.
10 changes: 9 additions & 1 deletion api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,17 @@ type PubsubScore struct {
Score *pubsub.PeerScoreSnapshot
}

// MessageSendSpec contains optional fields which modify message sending behavior
type MessageSendSpec struct {
MaxFee abi.TokenAmount
// MaxFee specifies a cap on network fees related to this message
MaxFee abi.TokenAmount

// MsgUuid specifies a unique message identifier which can be used on node (or node cluster)
// level to prevent double-sends of messages even when nonce generation is not handled by sender
MsgUuid uuid.UUID

// MaximizeFeeCap makes message FeeCap be based entirely on MaxFee
MaximizeFeeCap bool
}

type MpoolMessageWhole struct {
Expand Down
Binary file modified build/openrpc/full.json.gz
Binary file not shown.
Binary file modified build/openrpc/gateway.json.gz
Binary file not shown.
13 changes: 6 additions & 7 deletions chain/messagepool/messagepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,10 @@ func ComputeRBF(curPrem abi.TokenAmount, replaceByFeeRatio types.Percent) abi.To

func CapGasFee(mff dtypes.DefaultMaxFeeFunc, msg *types.Message, sendSpec *api.MessageSendSpec) {
var maxFee abi.TokenAmount
var maximizeFeeCap bool
if sendSpec != nil {
maxFee = sendSpec.MaxFee
maximizeFeeCap = sendSpec.MaximizeFeeCap
}
if maxFee.Int == nil || maxFee.Equals(big.Zero()) {
mf, err := mff()
Expand All @@ -222,15 +224,12 @@ func CapGasFee(mff dtypes.DefaultMaxFeeFunc, msg *types.Message, sendSpec *api.M
maxFee = mf
}

gl := types.NewInt(uint64(msg.GasLimit))
totalFee := types.BigMul(msg.GasFeeCap, gl)

if totalFee.LessThanEqual(maxFee) {
msg.GasPremium = big.Min(msg.GasFeeCap, msg.GasPremium) // cap premium at FeeCap
return
gaslimit := types.NewInt(uint64(msg.GasLimit))
totalFee := types.BigMul(msg.GasFeeCap, gaslimit)
if maximizeFeeCap || totalFee.GreaterThan(maxFee) {
msg.GasFeeCap = big.Div(maxFee, gaslimit)
}

msg.GasFeeCap = big.Div(maxFee, gl)
msg.GasPremium = big.Min(msg.GasFeeCap, msg.GasPremium) // cap premium at FeeCap
}

Expand Down
9 changes: 6 additions & 3 deletions documentation/en/api-v0-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -2289,7 +2289,8 @@ Inputs:
},
{
"MaxFee": "0",
"MsgUuid": "07070707-0707-0707-0707-070707070707"
"MsgUuid": "07070707-0707-0707-0707-070707070707",
"MaximizeFeeCap": true
},
[
{
Expand Down Expand Up @@ -2766,7 +2767,8 @@ Inputs:
],
{
"MaxFee": "0",
"MsgUuid": "07070707-0707-0707-0707-070707070707"
"MsgUuid": "07070707-0707-0707-0707-070707070707",
"MaximizeFeeCap": true
}
]
```
Expand Down Expand Up @@ -3025,7 +3027,8 @@ Inputs:
},
{
"MaxFee": "0",
"MsgUuid": "07070707-0707-0707-0707-070707070707"
"MsgUuid": "07070707-0707-0707-0707-070707070707",
"MaximizeFeeCap": true
}
]
```
Expand Down
9 changes: 6 additions & 3 deletions documentation/en/api-v1-unstable-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -3357,7 +3357,8 @@ Inputs:
},
{
"MaxFee": "0",
"MsgUuid": "07070707-0707-0707-0707-070707070707"
"MsgUuid": "07070707-0707-0707-0707-070707070707",
"MaximizeFeeCap": true
},
[
{
Expand Down Expand Up @@ -3834,7 +3835,8 @@ Inputs:
],
{
"MaxFee": "0",
"MsgUuid": "07070707-0707-0707-0707-070707070707"
"MsgUuid": "07070707-0707-0707-0707-070707070707",
"MaximizeFeeCap": true
}
]
```
Expand Down Expand Up @@ -4226,7 +4228,8 @@ Inputs:
},
{
"MaxFee": "0",
"MsgUuid": "07070707-0707-0707-0707-070707070707"
"MsgUuid": "07070707-0707-0707-0707-070707070707",
"MaximizeFeeCap": true
}
]
```
Expand Down
4 changes: 4 additions & 0 deletions documentation/en/default-lotus-miner-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,10 @@
# env var: LOTUS_FEES_MAXMARKETBALANCEADDFEE
#MaxMarketBalanceAddFee = "0.007 FIL"

# type: bool
# env var: LOTUS_FEES_MAXIMIZEWINDOWPOSTFEECAP
#MaximizeWindowPoStFeeCap = true

[Fees.MaxPreCommitBatchGasFee]
# type: types.FIL
# env var: LOTUS_FEES_MAXPRECOMMITBATCHGASFEE_BASE
Expand Down
2 changes: 2 additions & 0 deletions node/config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ func DefaultStorageMiner() *StorageMiner {
MaxWindowPoStGasFee: types.MustParseFIL("5"),
MaxPublishDealsFee: types.MustParseFIL("0.05"),
MaxMarketBalanceAddFee: types.MustParseFIL("0.007"),

MaximizeWindowPoStFeeCap: true,
},

Addresses: MinerAddressConfig{
Expand Down
6 changes: 6 additions & 0 deletions node/config/doc_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions node/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ type MinerFeeConfig struct {
MaxWindowPoStGasFee types.FIL
MaxPublishDealsFee types.FIL
MaxMarketBalanceAddFee types.FIL

MaximizeWindowPoStFeeCap bool
}

type MinerAddressConfig struct {
Expand Down
2 changes: 1 addition & 1 deletion storage/wdpost/wdpost_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ func (s *WindowPoStScheduler) submitPoStMessage(ctx context.Context, proof *mine
Params: enc,
Value: types.NewInt(0),
}
spec := &api.MessageSendSpec{MaxFee: abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)}
spec := &api.MessageSendSpec{MaxFee: abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee), MaximizeFeeCap: s.feeCfg.MaximizeWindowPoStFeeCap}
if err := s.prepareMessage(ctx, msg, spec); err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions storage/wdpost/wdpost_run_faults.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ func (s *WindowPoStScheduler) declareRecoveries(ctx context.Context, dlIdx uint6
Params: enc,
Value: types.NewInt(0),
}
spec := &api.MessageSendSpec{MaxFee: abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)}
spec := &api.MessageSendSpec{MaxFee: abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee), MaximizeFeeCap: s.feeCfg.MaximizeWindowPoStFeeCap}
if err := s.prepareMessage(ctx, msg, spec); err != nil {
return nil, nil, err
}
sm, err := s.api.MpoolPushMessage(ctx, msg, &api.MessageSendSpec{MaxFee: abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)})
sm, err := s.api.MpoolPushMessage(ctx, msg, spec)
if err != nil {
return nil, nil, xerrors.Errorf("pushing message to mpool: %w", err)
}
Expand Down

0 comments on commit 9fc3c33

Please sign in to comment.