Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

feat: support eip1559 when speeding up transactions #644

Merged
merged 2 commits into from
Dec 5, 2023

Conversation

rach-id
Copy link
Member

@rach-id rach-id commented Dec 5, 2023

Overview

Previously, we only supported speeding up legacy transactions. With this, we can also speed up EIP1559 ones.

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

Summary by CodeRabbit

  • New Features

    • Enhanced transaction handling with support for EIP-1559 dynamic fee transactions.
    • Ability to speed up transactions with updated gas pricing strategies.
  • Improvements

    • Improved waitForTransactionAndRetryIfNeeded function to handle different transaction types more effectively.

@rach-id rach-id added enhancement New feature or request relayer relayer related labels Dec 5, 2023
@rach-id rach-id self-assigned this Dec 5, 2023
@rach-id rach-id requested a review from evan-forbes as a code owner December 5, 2023 01:06
Copy link
Contributor

coderabbitai bot commented Dec 5, 2023

Walkthrough

The codebase has been updated to better handle Ethereum transactions, specifically by introducing new functions to manage the resubmission of transactions with increased gas fees. This includes separate handling for EIP-1559 dynamic fee transactions and legacy transactions, ensuring compatibility with the Ethereum network's evolving gas pricing mechanisms.

Changes

File(s) Change Summary
relayer/relayer.go Introduced functions for creating speeded-up transactions for both EIP-1559 and legacy types, and updated waitForTransactionAndRetryIfNeeded to handle resubmission with adjusted gas fees.

🐇✨
In the code's burrow, deep and wide,
New functions spring to life inside.
With swifter gas, transactions fly,
As CodeRabbit's work reaches the sky. 🚀🌌
🐇✨


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d3131ed and 77723d2.
Files selected for processing (1)
  • relayer/relayer.go (4 hunks)
Additional comments: 1
relayer/relayer.go (1)
  • 470-514: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [473-543]

The summary states that the new functions for creating and converting transactions are exported entities, but in the code, these functions (createSpeededUpDynamicTransaction, createSpeededUpLegacyTransaction, toDynamicTransaction, and toLegacyTransaction) are unexported (lowercase). If these functions are intended to be used by other packages, they should be exported (uppercase).

relayer/relayer.go Show resolved Hide resolved
@codecov-commenter
Copy link

Codecov Report

Attention: 86 lines in your changes are missing coverage. Please review.

Comparison is base (2aa4b32) 0.00% compared to head (2adb86d) 24.64%.

Files Patch % Lines
relayer/relayer.go 0.00% 86 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           main     #644       +/-   ##
=========================================
+ Coverage      0   24.64%   +24.64%     
=========================================
  Files         0       29       +29     
  Lines         0     3201     +3201     
=========================================
+ Hits          0      789      +789     
- Misses        0     2317     +2317     
- Partials      0       95       +95     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍

Comment on lines +413 to 456
var rawTx *coregethtypes.Transaction
if tx.GasPrice() != nil {
rawTx, err = createSpeededUpLegacyTransaction(ctx, ethClient, newTx)
if err != nil {
return err
}
if rawTx.GasPrice().Cmp(newTx.GasPrice()) <= 0 {
// no need to resend the transaction if the suggested gas price is lower than the original one
continue
}
} else if tx.GasTipCap() != nil && tx.GasFeeCap() != nil {
rawTx, err = createSpeededUpDynamicTransaction(ctx, ethClient, newTx)
if err != nil {
return err
}
if rawTx.GasFeeCap().Cmp(newTx.GasFeeCap()) <= 0 {
// no need to resend the transaction if the suggested gas price is lower than the original one
continue
}
} else {
// Only query for basefee if gasPrice not specified
if head, errHead := ethClient.HeaderByNumber(ctx, nil); errHead != nil {
return errHead
} else if head.BaseFee != nil {
rawTx, err = createSpeededUpDynamicTransaction(ctx, ethClient, newTx)
if err != nil {
return err
}
if rawTx.GasFeeCap().Cmp(newTx.GasFeeCap()) <= 0 {
// no need to resend the transaction if the suggested gas price is lower than the original one
continue
}
} else {
// Chain is not London ready -> use legacy transaction
rawTx, err = createSpeededUpLegacyTransaction(ctx, ethClient, newTx)
if err != nil {
return err
}
if rawTx.GasPrice().Cmp(newTx.GasPrice()) <= 0 {
// no need to resend the transaction if the suggested gas price is lower than the original one
continue
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think its necessarily worth changing, but it might be a good exercise to try and refactor this. Submitting a transaction is always really frustrating and some elaborate logic is unavoidable, I also haven't tried to so it might not be possible. However, my gut instinct is if there are this many if, if else, else, and continue statements there usually a way to rewrite it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, but I think that's the best we could do because we have multiple chain types so we need to speed up the transaction according to its type. This implementation is inspired from the geth implementation.

@rach-id rach-id merged commit b1c2b89 into celestiaorg:main Dec 5, 2023
18 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request relayer relayer related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants