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

fix: boost gas fee cap as well #3562

Merged
merged 1 commit into from Nov 17, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/storageincentives/redistribution/redistribution.go
Expand Up @@ -102,7 +102,7 @@ func (c *contract) Claim(ctx context.Context) error {
To: &c.incentivesContractAddress,
Data: callData,
GasPrice: sctx.GetGasPrice(ctx),
GasLimit: sctx.GetGasLimitWithDefault(ctx, 500_000),
GasLimit: sctx.GetGasLimitWithDefault(ctx, 1_000_000),
Value: big.NewInt(0),
Description: "claim win transaction",
}
Expand All @@ -124,7 +124,7 @@ func (c *contract) Commit(ctx context.Context, obfusHash []byte, round *big.Int)
To: &c.incentivesContractAddress,
Data: callData,
GasPrice: sctx.GetGasPrice(ctx),
GasLimit: sctx.GetGasLimitWithDefault(ctx, 500_000),
GasLimit: sctx.GetGasLimitWithDefault(ctx, 1_000_000),
Value: big.NewInt(0),
Description: "commit transaction",
}
Expand Down
15 changes: 8 additions & 7 deletions pkg/transaction/transaction.go
Expand Up @@ -141,7 +141,7 @@ func NewService(logger log.Logger, backend Backend, signer crypto.Signer, store
}

// Send creates and signs a transaction based on the request and sends it.
func (t *transactionService) Send(ctx context.Context, request *TxRequest, tipCapBoostPercent int) (txHash common.Hash, err error) {
func (t *transactionService) Send(ctx context.Context, request *TxRequest, boostPercent int) (txHash common.Hash, err error) {
loggerV1 := t.logger.V(1).Register()

t.lock.Lock()
Expand All @@ -152,7 +152,7 @@ func (t *transactionService) Send(ctx context.Context, request *TxRequest, tipCa
return common.Hash{}, err
}

tx, err := t.prepareTransaction(ctx, request, nonce, tipCapBoostPercent)
tx, err := t.prepareTransaction(ctx, request, nonce, boostPercent)
if err != nil {
return common.Hash{}, err
}
Expand Down Expand Up @@ -181,7 +181,7 @@ func (t *transactionService) Send(ctx context.Context, request *TxRequest, tipCa
Data: signedTx.Data(),
GasPrice: signedTx.GasPrice(),
GasLimit: signedTx.Gas(),
GasTipBoost: tipCapBoostPercent,
GasTipBoost: boostPercent,
GasTipCap: signedTx.GasTipCap(),
GasFeeCap: signedTx.GasFeeCap(),
Value: signedTx.Value(),
Expand Down Expand Up @@ -258,7 +258,7 @@ func (t *transactionService) StoredTransaction(txHash common.Hash) (*StoredTrans
}

// prepareTransaction creates a signable transaction based on a request.
func (t *transactionService) prepareTransaction(ctx context.Context, request *TxRequest, nonce uint64, tipBoostPercent int) (tx *types.Transaction, err error) {
func (t *transactionService) prepareTransaction(ctx context.Context, request *TxRequest, nonce uint64, boostPercent int) (tx *types.Transaction, err error) {
var gasLimit uint64
if request.GasLimit == 0 {
gasLimit, err = t.backend.EstimateGas(ctx, ethereum.CallMsg{
Expand Down Expand Up @@ -288,7 +288,7 @@ func (t *transactionService) prepareTransaction(ctx context.Context, request *Tx
notice that gas price does not exceed 20 as defined by max fee.
*/

gasFeeCap, gasTipCap, err := t.suggestedFeeAndTip(ctx, request.GasPrice, tipBoostPercent)
gasFeeCap, gasTipCap, err := t.suggestedFeeAndTip(ctx, request.GasPrice, boostPercent)
if err != nil {
return nil, err
}
Expand All @@ -305,7 +305,7 @@ func (t *transactionService) prepareTransaction(ctx context.Context, request *Tx
}), nil
}

func (t *transactionService) suggestedFeeAndTip(ctx context.Context, gasPrice *big.Int, tipBoostPercent int) (*big.Int, *big.Int, error) {
func (t *transactionService) suggestedFeeAndTip(ctx context.Context, gasPrice *big.Int, boostPercent int) (*big.Int, *big.Int, error) {
var err error

if gasPrice == nil {
Expand All @@ -320,7 +320,8 @@ func (t *transactionService) suggestedFeeAndTip(ctx context.Context, gasPrice *b
return nil, nil, err
}

gasTipCap = new(big.Int).Div(new(big.Int).Mul(big.NewInt(int64(tipBoostPercent)+100), gasTipCap), big.NewInt(100))
gasTipCap = new(big.Int).Div(new(big.Int).Mul(big.NewInt(int64(boostPercent)+100), gasTipCap), big.NewInt(100))
gasPrice = new(big.Int).Div(new(big.Int).Mul(big.NewInt(int64(boostPercent)+100), gasPrice), big.NewInt(100))
gasFeeCap := new(big.Int).Add(gasTipCap, gasPrice)

t.logger.Debug("prepare transaction", "gas_price", gasPrice, "gas_max_fee", gasFeeCap, "gas_max_tip", gasTipCap)
Expand Down
3 changes: 2 additions & 1 deletion pkg/transaction/transaction_test.go
Expand Up @@ -216,7 +216,8 @@ func TestTransactionSend(t *testing.T) {
t.Parallel()

tip := big.NewInt(0).Div(new(big.Int).Mul(suggestedGasTip, big.NewInt(15)), big.NewInt(10))
fee := new(big.Int).Add(tip, suggestedGasPrice)
fee := big.NewInt(0).Div(new(big.Int).Mul(suggestedGasPrice, big.NewInt(15)), big.NewInt(10))
fee = fee.Add(fee, tip)
// tip is the same as suggestedGasPrice and boost is 50%
// so final gas price will be 2.5x suggestedGasPrice

Expand Down