From ee9d79f11eab441c740c5313521532f5f2d43744 Mon Sep 17 00:00:00 2001 From: istae <14264581+istae@users.noreply.github.com> Date: Thu, 17 Nov 2022 17:44:23 +0300 Subject: [PATCH] fix: boost gas fee cap as well --- .../redistribution/redistribution.go | 4 ++-- pkg/transaction/transaction.go | 15 ++++++++------- pkg/transaction/transaction_test.go | 3 ++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pkg/storageincentives/redistribution/redistribution.go b/pkg/storageincentives/redistribution/redistribution.go index 173732ee174..94ec9cba51a 100644 --- a/pkg/storageincentives/redistribution/redistribution.go +++ b/pkg/storageincentives/redistribution/redistribution.go @@ -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", } @@ -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", } diff --git a/pkg/transaction/transaction.go b/pkg/transaction/transaction.go index 137c9009d6c..09232b2ffd0 100644 --- a/pkg/transaction/transaction.go +++ b/pkg/transaction/transaction.go @@ -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() @@ -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 } @@ -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(), @@ -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{ @@ -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 } @@ -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 { @@ -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) diff --git a/pkg/transaction/transaction_test.go b/pkg/transaction/transaction_test.go index 92e696db2e8..ec99d4a448e 100644 --- a/pkg/transaction/transaction_test.go +++ b/pkg/transaction/transaction_test.go @@ -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