Refactor EVM transaction handling for clarity and maintainability#703
Closed
seunlanlege wants to merge 1 commit intomainfrom
Closed
Refactor EVM transaction handling for clarity and maintainability#703seunlanlege wants to merge 1 commit intomainfrom
seunlanlege wants to merge 1 commit intomainfrom
Conversation
…ucing duplication - Extract `build_tx_request` to eliminate 3x duplicated TransactionRequest construction - Extract `gas_with_buffer` for repeated gas estimation + 5% buffer pattern - Extract `decode_mmr_proof_with_indices` for duplicated MMR proof decoding - Extract `build_solidity_proof` and `extract_state_machine_id` for proof construction - Extract `extract_event_commitments` from inline receipt log parsing - Break `wait_for_success` into `handle_missing_receipt`, `retry_consensus_message`, and `cancel_stuck_transaction` - Break `generate_contract_calls` message handling into `build_post_request_tx` and `build_post_response_tx` - Extract `resolve_gas_price` from inline gas price logic - Replace imperative loops in `handle_message_submission` with `collect_tx_receipts` using iterators - Remove excessive trace logging that cluttered the code https://claude.ai/code/session_01PdTZdbbn5tYByuC44jkSY5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR significantly refactors the EVM transaction handling code to improve readability, reduce duplication, and better organize the codebase. The changes extract common patterns into reusable helper functions and reorganize code into logical sections with clear separation of concerns.
Key Changes
Extracted helper functions to eliminate duplication:
build_tx_request(): ConstructsTransactionRequestwith optional gas pricegas_with_buffer(): Applies 5% buffer to gas estimates with fallback logicdecode_mmr_proof_with_indices(): Decodes MMR proofs and computes k_index/leaf_index pairsextract_state_machine_id(): Extracts numeric state machine ID from Polkadot/Kusama variantsbuild_solidity_proof(): Constructs solidityProofstructs from MMR proofsextract_event_commitments(): Extracts handled-event commitments from receiptsRefactored transaction lifecycle management:
wait_for_success()into focused functions:handle_missing_receipt(),retry_consensus_message(), andcancel_stuck_transaction()Simplified contract call generation:
resolve_gas_price()to handle gas price resolution with buffer applicationbuild_post_request_tx()andbuild_post_response_tx()to reduce duplication in message-to-transaction conversionReorganized code structure with clear section markers:
Improved
handle_message_submission():collect_tx_receipts()to match handled commitments against original messagesEnhanced code clarity:
Implementation Details
The refactoring maintains all existing functionality while improving code organization. Helper functions are designed to be composable and reusable across the transaction submission pipeline. The separation of concerns makes the code easier to test, maintain, and extend in the future.
https://claude.ai/code/session_01PdTZdbbn5tYByuC44jkSY5