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

Custom EthTxManager on agglayer #109

Merged
merged 8 commits into from
Apr 5, 2024
Merged

Conversation

goran-ethernal
Copy link
Contributor

@goran-ethernal goran-ethernal commented Mar 28, 2024

This PR copies ethTxManager implementation from zkevm-node to agglayer and implements custom logic the agglayer needs.

Since zkevm team does not want changes done to the original ethTxManager, the goal of this PR is to copy all the logic from it (including the fix from PR: 0xPolygonHermez/zkevm-node#3338 regarding the nonce hole issue), and add an extra feature of dropping monitored transactions that fail for a configured number of times. It also removed all the functions that agglayer does not use from ethTxManager, like Reorg.
We also needed to copy pgstorage.go since we can not use the one from zkevm-node since it uses the non-exposed monitoredTx struct.

Issue that we faced

During testing of the agglayer on testnet, an issue popped up where a transaction was repeated indefinitely even though for some reason, it constantly failed to be executed or it failed to estimate gas. This caused unnecessary traffic, load and logs, since that transaction was never going to be executed successfully, since it failed, 100s of times.

Fix

This PR introduces a new configuration parameter to the EthTxManager configuration on agglayer called MaxRetries. It represents a maximum number a transaction will be resent to the L1, or a maximum number of times it will try to estimate its gas until it drops it (updates the monitored transaction with the MonitoredTxStatusFailed status in the agglayer-db), meaning, it will not try to resend it again.

In order to know how many times a transaction was tried to be resent or estimated, a new column to the state.monitored_txs table needed to be added, called num_retries. That is why, a new migration file was added 0002.sql which alters given table, by adding the new column to it.

Tests

This PR copied the original ethTxManager tests, as well as tests for its postgress storage. Tests added:

  • monitoredtx_test.go - this is the same as in original ethTxManager, no need to review it.
  • pgstorage_test.go - this is the same as in original ethTxManager, no need to review it.
  • txmanager_test.go - this is the same as in original ethTxManager. Only need to review test TestTxRetry_MaxRetriesReached which tests the new logic.

How to review this PR

In order not to waste time reviewing the copy/pasted code this is what should be considered for reviewing:

  • main.go
  • config.go
  • default.go
  • 0002.sql
  • agglayer.toml
  • executor_test.go
  • executor.go
  • rpc_test.go
  • pgstorage.go - only changes regarding the num_retries column.
  • txmanager.go - parts of code where mtx.NumRetries and cfg.MaxRetries are mentioned. Other parts of code were left the same.
  • txmanager_test.go - only test TestTxRetry_MaxRetriesReached, other tests are just moved from original ethTxManager.
    -types/interfaces.go
  • Make file

@goran-ethernal goran-ethernal self-assigned this Mar 28, 2024
@goran-ethernal goran-ethernal marked this pull request as ready for review March 28, 2024 12:09
@goran-ethernal goran-ethernal requested a review from a team as a code owner March 28, 2024 12:09
types/interfaces.go Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Apr 5, 2024

@vcastellm vcastellm merged commit c0a88f1 into main Apr 5, 2024
6 checks passed
@vcastellm vcastellm deleted the CDK-142-nonce-hole-created branch April 5, 2024 10:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants