mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
When resending an eth tx, always increase gas price
Incrementing the gas price unconditionally avoids sending the exact same transaction, which geth will reject because that transaction already exists in the pool
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/hermeznetwork/hermez-node/common"
|
"github.com/hermeznetwork/hermez-node/common"
|
||||||
"github.com/hermeznetwork/hermez-node/eth"
|
"github.com/hermeznetwork/hermez-node/eth"
|
||||||
@@ -90,9 +91,9 @@ type BatchInfo struct {
|
|||||||
L2Txs []common.L2Tx
|
L2Txs []common.L2Tx
|
||||||
CoordIdxs []common.Idx
|
CoordIdxs []common.Idx
|
||||||
ForgeBatchArgs *eth.RollupForgeBatchArgs
|
ForgeBatchArgs *eth.RollupForgeBatchArgs
|
||||||
// FeesInfo
|
Auth *bind.TransactOpts `json:"-"`
|
||||||
EthTx *types.Transaction
|
EthTx *types.Transaction
|
||||||
EthTxErr error
|
EthTxErr error
|
||||||
// SendTimestamp the time of batch sent to ethereum
|
// SendTimestamp the time of batch sent to ethereum
|
||||||
SendTimestamp time.Time
|
SendTimestamp time.Time
|
||||||
Receipt *types.Receipt
|
Receipt *types.Receipt
|
||||||
|
|||||||
@@ -182,19 +182,29 @@ func addPerc(v *big.Int, p int64) *big.Int {
|
|||||||
r.Mul(r, big.NewInt(p))
|
r.Mul(r, big.NewInt(p))
|
||||||
// nolint reason: to calculate percentages we divide by 100
|
// nolint reason: to calculate percentages we divide by 100
|
||||||
r.Div(r, big.NewInt(100)) //nolit:gomnd
|
r.Div(r, big.NewInt(100)) //nolit:gomnd
|
||||||
|
// If the increase is 0, force it to be 1 so that a gas increase
|
||||||
|
// doesn't result in the same value, making the transaction to be equal
|
||||||
|
// than before.
|
||||||
|
if r.Cmp(big.NewInt(0)) == 0 {
|
||||||
|
r = big.NewInt(1)
|
||||||
|
}
|
||||||
return r.Add(v, r)
|
return r.Add(v, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TxManager) sendRollupForgeBatch(ctx context.Context, batchInfo *BatchInfo, resend bool) error {
|
func (t *TxManager) sendRollupForgeBatch(ctx context.Context, batchInfo *BatchInfo, resend bool) error {
|
||||||
var ethTx *types.Transaction
|
var ethTx *types.Transaction
|
||||||
var err error
|
var err error
|
||||||
auth, err := t.NewAuth(ctx, batchInfo)
|
var auth *bind.TransactOpts
|
||||||
if err != nil {
|
|
||||||
return tracerr.Wrap(err)
|
|
||||||
}
|
|
||||||
auth.Nonce = big.NewInt(int64(t.accNextNonce))
|
|
||||||
if resend {
|
if resend {
|
||||||
auth.Nonce = big.NewInt(int64(batchInfo.EthTx.Nonce()))
|
auth = batchInfo.Auth
|
||||||
|
auth.GasPrice = addPerc(auth.GasPrice, 10)
|
||||||
|
} else {
|
||||||
|
auth, err = t.NewAuth(ctx, batchInfo)
|
||||||
|
if err != nil {
|
||||||
|
return tracerr.Wrap(err)
|
||||||
|
}
|
||||||
|
batchInfo.Auth = auth
|
||||||
|
auth.Nonce = big.NewInt(int64(t.accNextNonce))
|
||||||
}
|
}
|
||||||
for attempt := 0; attempt < t.cfg.EthClientAttempts; attempt++ {
|
for attempt := 0; attempt < t.cfg.EthClientAttempts; attempt++ {
|
||||||
if auth.GasPrice.Cmp(t.cfg.MaxGasPrice) > 0 {
|
if auth.GasPrice.Cmp(t.cfg.MaxGasPrice) > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user