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

[Submitter] Do Not Bump if Out of Gas #1837

Open
trajan0x opened this issue Jan 11, 2024 · 1 comment
Open

[Submitter] Do Not Bump if Out of Gas #1837

trajan0x opened this issue Jan 11, 2024 · 1 comment

Comments

@trajan0x
Copy link
Contributor

Don't resubmit if out of gas

@trajan0x trajan0x changed the title [Submitter] Do Not Resubmit if Out of Gas [Submitter] Do Not Bump if Out of Gas Jan 11, 2024
@trajan0x trajan0x added the small label Jun 24, 2024
@trajan0x trajan0x reopened this Jun 24, 2024
@trajan0x trajan0x removed the small label Jun 24, 2024
Copy link

greptile-apps bot commented Jun 24, 2024

To address the issue of not resubmitting transactions if out of gas, modify the bumpTX function in ethergo/submitter/chain_queue.go as follows:

  1. Add a check for gas balance before attempting to bump the transaction.
  2. If the gas balance is insufficient, log the event and do not add the transaction to the reprocess queue.
func (c *chainQueue) bumpTX(parentCtx context.Context, ogTx db.TX) (err error) {
    if !c.isBumpIntervalElapsed(ogTx) {
        c.addToReprocessQueue(ogTx)
        return nil
    }

    gasBalance, err := c.client.BalanceAt(parentCtx, c.signer.Address(), nil)
    if err != nil {
        return fmt.Errorf("could not get gas balance: %w", err)
    }

    if ogTx.Cost().Cmp(gasBalance) > 0 {
        c.metrics.Tracer().Start(parentCtx, "chainPendingQueue.bumpTX").AddEvent("tx out of gas", trace.WithAttributes(txToAttributes(ogTx.Transaction, ogTx.UUID)...))
        return nil
    }

    // existing logic for copying and bumping the transaction
    tx, err := util.CopyTX(ogTx.Transaction, util.WithTxType(c.txTypeForChain(c.chainID)))
    if err != nil {
        return fmt.Errorf("could not copy tx: %w", err)
    }

    ctx, span := c.metrics.Tracer().Start(parentCtx, "chainPendingQueue.bumpTX", trace.WithAttributes(attribute.Stringer(metrics.TxHash, tx.Hash())))
    defer func() {
        metrics.EndSpanWithErr(span, err)
    }()

    newGasEstimate, err := c.getGasEstimate(ctx, c.client, c.chainIDInt(), tx)
    if err != nil {
        return fmt.Errorf("could not get gas estimate: %w", err)
    }

    transactor, err := c.signer.GetTransactor(ctx, c.chainID)
    if err != nil {
        return fmt.Errorf("could not get transactor: %w", err)
    }

    transactor.NoSend = true
    transactor.Nonce = new(big.Int).SetUint64(tx.Nonce())
    transactor.GasLimit = newGasEstimate

    err = c.setGasPrice(ctx, c.client, transactor, c.chainID, ogTx.Transaction)
    if err != nil {
        return fmt.Errorf("could not set gas price: %w", err)
    }

    switch tx.Type() {
    case types.LegacyTxType:
        tx = types.NewTx(&types.LegacyTx{
            Nonce:    tx.Nonce(),
            GasPrice: transactor.GasPrice,
            Gas:      transactor.GasLimit,
            To:       tx.To(),
            Value:    tx.Value(),
            Data:     tx.Data(),
        })
    case types.DynamicFeeTxType:
        tx = types.NewTx(&types.DynamicFeeTx{
            ChainID:   tx.ChainId(),
            Nonce:     tx.Nonce(),
            GasTipCap: core.CopyBigInt(transactor.GasTipCap),
            GasFeeCap: core.CopyBigInt(transactor.GasFeeCap),
            Gas:       transactor.GasLimit,
            To:        tx.To(),
            Value:     tx.Value(),
            Data:      tx.Data(),
        })
    default:
        return fmt.Errorf("unknown tx type: %v", ogTx.Type())
    }

    tx, err = transactor.Signer(transactor.From, tx)
    if err != nil {
        return fmt.Errorf("could not sign tx: %w", err)
    }

    span.AddEvent("add to reprocess queue")
    span.SetAttributes(txToAttributes(tx, ogTx.UUID)...) 

    c.addToReprocessQueue(db.TX{
        UUID:        ogTx.UUID,
        Transaction: tx,
        Status:      db.Stored,
    })

    registerErr := c.registerBumpTx(ctx, tx)
    if registerErr != nil {
        span.AddEvent("could not register bump tx", trace.WithAttributes(attribute.String("error", registerErr.Error())))
    }

    return nil
}

References

/ethergo/submitter/chain_queue.go
/ethergo/submitter

Ask Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant