Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add GasOverPremium for gas estimate #5050

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion pkg/messagepool/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math"
stdbig "math/big"
"math/rand"
"sort"

Expand Down Expand Up @@ -312,6 +313,7 @@ func (mp *MessagePool) GasEstimateMessageGas(ctx context.Context, estimateMessag
if estimateMessage == nil || estimateMessage.Msg == nil {
return nil, fmt.Errorf("estimate message is nil")
}
log.Debugf("call GasEstimateMessageGas %v, send spec: %v", estimateMessage.Msg, estimateMessage.Spec)
if estimateMessage.Msg.GasLimit == 0 {
gasLimit, err := mp.GasEstimateGasLimit(ctx, estimateMessage.Msg, types.TipSetKey{})
if err != nil {
Expand All @@ -321,7 +323,6 @@ func (mp *MessagePool) GasEstimateMessageGas(ctx context.Context, estimateMessag
if estimateMessage.Spec != nil && estimateMessage.Spec.GasOverEstimation > 0 {
gasLimitOverestimation = estimateMessage.Spec.GasOverEstimation
}
log.Debugf("call GasEstimateMessageGas %v, spec: %v, config gasLimitOverestimation: %v", estimateMessage.Msg, estimateMessage.Spec, mp.GetConfig().GasLimitOverestimation)
estimateMessage.Msg.GasLimit = int64(float64(gasLimit) * gasLimitOverestimation)
}

Expand All @@ -330,6 +331,12 @@ func (mp *MessagePool) GasEstimateMessageGas(ctx context.Context, estimateMessag
if err != nil {
return nil, fmt.Errorf("estimating gas price: %w", err)
}
if estimateMessage.Spec != nil && estimateMessage.Spec.GasOverPremium > 0 {
olgGasPremium := gasPremium
newGasPremium, _ := new(stdbig.Float).Mul(new(stdbig.Float).SetInt(stdbig.NewInt(gasPremium.Int64())), stdbig.NewFloat(estimateMessage.Spec.GasOverPremium)).Int(nil)
gasPremium = big.NewFromGo(newGasPremium)
log.Debugf("call GasEstimateMessageGas old premium %v, new premium %v, premium ration %f", olgGasPremium, newGasPremium, estimateMessage.Spec.GasOverPremium)
}
estimateMessage.Msg.GasPremium = gasPremium
}

Expand Down Expand Up @@ -398,6 +405,12 @@ func (mp *MessagePool) GasBatchEstimateMessageGas(ctx context.Context, estimateM
})
continue
}
if estimateMessage.Spec != nil && estimateMessage.Spec.GasOverPremium > 0 {
olgGasPremium := gasPremium
newGasPremium, _ := new(stdbig.Float).Mul(new(stdbig.Float).SetInt(stdbig.NewInt(gasPremium.Int64())), stdbig.NewFloat(estimateMessage.Spec.GasOverPremium)).Int(nil)
gasPremium = big.NewFromGo(newGasPremium)
log.Debugf("call GasBatchEstimateMessageGas old premium %v, new premium %v, premium ration %f", olgGasPremium, newGasPremium, estimateMessage.Spec.GasOverPremium)
}
estimateMsg.GasPremium = gasPremium
}

Expand Down
12 changes: 8 additions & 4 deletions venus-shared/api/chain/v0/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,8 @@ Inputs:
},
"Spec": {
"MaxFee": "0",
"GasOverEstimation": 12.3
"GasOverEstimation": 12.3,
"GasOverPremium": 12.3
}
}
],
Expand Down Expand Up @@ -1824,7 +1825,8 @@ Inputs:
},
{
"MaxFee": "0",
"GasOverEstimation": 12.3
"GasOverEstimation": 12.3,
"GasOverPremium": 12.3
},
[
{
Expand Down Expand Up @@ -1929,7 +1931,8 @@ Inputs:
],
{
"MaxFee": "0",
"GasOverEstimation": 12.3
"GasOverEstimation": 12.3,
"GasOverPremium": 12.3
}
]
```
Expand Down Expand Up @@ -2240,7 +2243,8 @@ Inputs:
},
{
"MaxFee": "0",
"GasOverEstimation": 12.3
"GasOverEstimation": 12.3,
"GasOverPremium": 12.3
}
]
```
Expand Down
12 changes: 8 additions & 4 deletions venus-shared/api/chain/v1/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,8 @@ Inputs:
},
"Spec": {
"MaxFee": "0",
"GasOverEstimation": 12.3
"GasOverEstimation": 12.3,
"GasOverPremium": 12.3
}
}
],
Expand Down Expand Up @@ -1869,7 +1870,8 @@ Inputs:
},
{
"MaxFee": "0",
"GasOverEstimation": 12.3
"GasOverEstimation": 12.3,
"GasOverPremium": 12.3
},
[
{
Expand Down Expand Up @@ -1974,7 +1976,8 @@ Inputs:
],
{
"MaxFee": "0",
"GasOverEstimation": 12.3
"GasOverEstimation": 12.3,
"GasOverPremium": 12.3
}
]
```
Expand Down Expand Up @@ -2416,7 +2419,8 @@ Inputs:
},
{
"MaxFee": "0",
"GasOverEstimation": 12.3
"GasOverEstimation": 12.3,
"GasOverPremium": 12.3
}
]
```
Expand Down
3 changes: 2 additions & 1 deletion venus-shared/api/market/client/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,8 @@ Inputs:
},
{
"MaxFee": "0",
"GasOverEstimation": 12.3
"GasOverEstimation": 12.3,
"GasOverPremium": 12.3
}
]
```
Expand Down
3 changes: 2 additions & 1 deletion venus-shared/api/market/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,8 @@ Inputs:
},
{
"MaxFee": "0",
"GasOverEstimation": 12.3
"GasOverEstimation": 12.3,
"GasOverPremium": 12.3
}
]
```
Expand Down
22 changes: 11 additions & 11 deletions venus-shared/api/messager/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ type IMessager interface {
MarkBadMessage(ctx context.Context, id string) error //perm:admin
RecoverFailedMsg(ctx context.Context, addr address.Address) ([]string, error) //perm:admin

GetAddress(ctx context.Context, addr address.Address) (*types.Address, error) //perm:admin
HasAddress(ctx context.Context, addr address.Address) (bool, error) //perm:read
WalletHas(ctx context.Context, addr address.Address) (bool, error) //perm:read
ListAddress(ctx context.Context) ([]*types.Address, error) //perm:admin
UpdateNonce(ctx context.Context, addr address.Address, nonce uint64) error //perm:admin
DeleteAddress(ctx context.Context, addr address.Address) error //perm:admin
ForbiddenAddress(ctx context.Context, addr address.Address) error //perm:admin
ActiveAddress(ctx context.Context, addr address.Address) error //perm:admin
SetSelectMsgNum(ctx context.Context, addr address.Address, num uint64) error //perm:admin
SetFeeParams(ctx context.Context, addr address.Address, gasOverEstimation float64, maxFee, maxFeeCap string) error //perm:admin
ClearUnFillMessage(ctx context.Context, addr address.Address) (int, error) //perm:admin
GetAddress(ctx context.Context, addr address.Address) (*types.Address, error) //perm:admin
HasAddress(ctx context.Context, addr address.Address) (bool, error) //perm:read
WalletHas(ctx context.Context, addr address.Address) (bool, error) //perm:read
ListAddress(ctx context.Context) ([]*types.Address, error) //perm:admin
UpdateNonce(ctx context.Context, addr address.Address, nonce uint64) error //perm:admin
DeleteAddress(ctx context.Context, addr address.Address) error //perm:admin
ForbiddenAddress(ctx context.Context, addr address.Address) error //perm:admin
ActiveAddress(ctx context.Context, addr address.Address) error //perm:admin
SetSelectMsgNum(ctx context.Context, addr address.Address, num uint64) error //perm:admin
SetFeeParams(ctx context.Context, addr address.Address, gasOverEstimation, gasOverPremium float64, maxFee, maxFeeCap string) error //perm:admin
ClearUnFillMessage(ctx context.Context, addr address.Address) (int, error) //perm:admin

GetSharedParams(ctx context.Context) (*types.SharedSpec, error) //perm:admin
SetSharedParams(ctx context.Context, params *types.SharedSpec) error //perm:admin
Expand Down
47 changes: 33 additions & 14 deletions venus-shared/api/messager/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ Inputs:
"expireEpoch": 10101,
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0"
"maxFeeCap": "0",
"gasOverPremium": 12.3
}
]
```
Expand Down Expand Up @@ -181,7 +182,8 @@ Inputs:
"expireEpoch": 10101,
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0"
"maxFeeCap": "0",
"gasOverPremium": 12.3
}
]
```
Expand Down Expand Up @@ -212,6 +214,7 @@ Response:
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0",
"gasOverPremium": 12.3,
"isDeleted": 123,
"createAt": "0001-01-01T00:00:00Z",
"updateAt": "0001-01-01T00:00:00Z"
Expand Down Expand Up @@ -274,7 +277,8 @@ Response:
"expireEpoch": 10101,
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0"
"maxFeeCap": "0",
"gasOverPremium": 12.3
},
"WalletName": "test",
"FromUser": "test",
Expand Down Expand Up @@ -341,7 +345,8 @@ Response:
"expireEpoch": 10101,
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0"
"maxFeeCap": "0",
"gasOverPremium": 12.3
},
"WalletName": "test",
"FromUser": "test",
Expand Down Expand Up @@ -406,7 +411,8 @@ Response:
"expireEpoch": 10101,
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0"
"maxFeeCap": "0",
"gasOverPremium": 12.3
},
"WalletName": "test",
"FromUser": "test",
Expand Down Expand Up @@ -473,7 +479,8 @@ Response:
"expireEpoch": 10101,
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0"
"maxFeeCap": "0",
"gasOverPremium": 12.3
},
"WalletName": "test",
"FromUser": "test",
Expand Down Expand Up @@ -520,6 +527,7 @@ Response:
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0",
"gasOverPremium": 12.3,
"selMsgNum": 42
}
```
Expand Down Expand Up @@ -586,6 +594,7 @@ Response:
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0",
"gasOverPremium": 12.3,
"isDeleted": 123,
"createAt": "0001-01-01T00:00:00Z",
"updateAt": "0001-01-01T00:00:00Z"
Expand Down Expand Up @@ -650,7 +659,8 @@ Response:
"expireEpoch": 10101,
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0"
"maxFeeCap": "0",
"gasOverPremium": 12.3
},
"WalletName": "test",
"FromUser": "test",
Expand Down Expand Up @@ -712,7 +722,8 @@ Response:
"expireEpoch": 10101,
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0"
"maxFeeCap": "0",
"gasOverPremium": 12.3
},
"WalletName": "test",
"FromUser": "test",
Expand Down Expand Up @@ -774,7 +785,8 @@ Response:
"expireEpoch": 10101,
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0"
"maxFeeCap": "0",
"gasOverPremium": 12.3
},
"WalletName": "test",
"FromUser": "test",
Expand Down Expand Up @@ -841,7 +853,8 @@ Response:
"expireEpoch": 10101,
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0"
"maxFeeCap": "0",
"gasOverPremium": 12.3
},
"WalletName": "test",
"FromUser": "test",
Expand Down Expand Up @@ -912,7 +925,8 @@ Response:
"expireEpoch": 10101,
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0"
"maxFeeCap": "0",
"gasOverPremium": 12.3
},
"WalletName": "test",
"FromUser": "test",
Expand Down Expand Up @@ -984,7 +998,8 @@ Inputs:
"expireEpoch": 10101,
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0"
"maxFeeCap": "0",
"gasOverPremium": 12.3
}
]
```
Expand Down Expand Up @@ -1019,7 +1034,8 @@ Inputs:
"expireEpoch": 10101,
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0"
"maxFeeCap": "0",
"gasOverPremium": 12.3
}
]
```
Expand Down Expand Up @@ -1147,6 +1163,7 @@ Inputs:
[
"f01234",
12.3,
12.3,
"string value",
"string value"
]
Expand Down Expand Up @@ -1196,6 +1213,7 @@ Inputs:
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0",
"gasOverPremium": 12.3,
"selMsgNum": 42
}
]
Expand Down Expand Up @@ -1312,7 +1330,8 @@ Response:
"expireEpoch": 10101,
"gasOverEstimation": 12.3,
"maxFee": "0",
"maxFeeCap": "0"
"maxFeeCap": "0",
"gasOverPremium": 12.3
},
"WalletName": "test",
"FromUser": "test",
Expand Down
8 changes: 4 additions & 4 deletions venus-shared/api/messager/mock/mock_imessager.go

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

Loading