-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: add bal rpc methods #23330
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
Merged
Merged
feat: add bal rpc methods #23330
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
38c9794
feat: add bal rpc methods
Soubhik-10 a4fad4b
chore: fmt
Soubhik-10 a8a07b3
Merge branch 'main' into bal/eth-bal-endpoints
Soubhik-10 14c3308
chore: remove check
Soubhik-10 d234275
Merge branch 'main' into bal/eth-bal-endpoints
Soubhik-10 3e09a81
chore: used BlockId in place of block hash while fetching
Rimeeeeee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| //! Helpers for `eth_blockAccessList` RPC method. | ||
| use alloy_consensus::BlockHeader; | ||
| use alloy_eips::eip7928::BlockAccessList; | ||
| use alloy_rpc_types_eth::BlockId; | ||
| use reth_errors::RethError; | ||
| use reth_evm::{block::BlockExecutor, ConfigureEvm, Evm}; | ||
| use reth_revm::{database::StateProviderDatabase, State}; | ||
| use reth_rpc_eth_types::{ | ||
| cache::db::StateProviderTraitObjWrapper, error::FromEthApiError, EthApiError, | ||
| }; | ||
| use reth_storage_api::StateProviderFactory; | ||
|
|
||
| use crate::{ | ||
| helpers::{Call, LoadBlock, Trace}, | ||
| RpcNodeCore, | ||
| }; | ||
|
|
||
| /// Helper trait for `eth_blockAccessList` RPC method. | ||
| pub trait GetBlockAccessList: Trace + Call + LoadBlock { | ||
| /// Retrieves the block access list for a block identified by its hash. | ||
| fn get_block_access_list( | ||
| &self, | ||
| block_id: BlockId, | ||
| ) -> impl Future<Output = Result<Option<BlockAccessList>, Self::Error>> + Send { | ||
| async move { | ||
| let block = self | ||
| .recovered_block(block_id) | ||
| .await? | ||
| .ok_or_else(|| EthApiError::HeaderNotFound(block_id))?; | ||
|
|
||
| self.spawn_blocking_io(move |eth_api| { | ||
| let state = eth_api | ||
| .provider() | ||
| .state_by_block_id(block.parent_hash().into()) | ||
| .map_err(Self::Error::from_eth_err)?; | ||
|
|
||
| let mut db = State::builder() | ||
| .with_database(StateProviderDatabase::new(StateProviderTraitObjWrapper(state))) | ||
| .with_bal_builder() | ||
| .build(); | ||
|
|
||
| let block_txs = block.transactions_recovered(); | ||
| let mut executor = RpcNodeCore::evm_config(ð_api) | ||
| .executor_for_block(&mut db, block.sealed_block()) | ||
| .map_err(RethError::other) | ||
| .map_err(Self::Error::from_eth_err)?; | ||
|
|
||
| executor.apply_pre_execution_changes().map_err(Self::Error::from_eth_err)?; | ||
| executor.evm_mut().db_mut().bump_bal_index(); | ||
|
|
||
| // replay all transactions prior to the targeted transaction | ||
| for block_tx in block_txs { | ||
| executor.execute_transaction(block_tx).map_err(Self::Error::from_eth_err)?; | ||
| executor.evm_mut().db_mut().bump_bal_index(); | ||
| } | ||
|
|
||
| executor | ||
| .apply_post_execution_changes() | ||
| .map_err(|err| EthApiError::Internal(err.into()))?; | ||
|
|
||
| let bal = db.take_built_alloy_bal(); | ||
| Ok(bal) | ||
| }) | ||
| .await | ||
| } | ||
| } | ||
| } |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| //! Contains RPC handler implementations specific to block access lists. | ||
|
|
||
| use reth_rpc_convert::RpcConvert; | ||
| use reth_rpc_eth_api::{helpers::bal::GetBlockAccessList, FromEvmError, RpcNodeCore}; | ||
| use reth_rpc_eth_types::EthApiError; | ||
|
|
||
| use crate::EthApi; | ||
|
|
||
| impl<N, Rpc> GetBlockAccessList for EthApi<N, Rpc> | ||
| where | ||
| N: RpcNodeCore, | ||
| EthApiError: FromEvmError<N::Evm>, | ||
| Rpc: RpcConvert<Primitives = N::Primitives, Error = EthApiError, Evm = N::Evm>, | ||
| { | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ pub mod signer; | |
| pub mod sync_listener; | ||
| pub mod types; | ||
|
|
||
| mod bal; | ||
| mod block; | ||
| mod call; | ||
| mod fees; | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think returning value here makes sense for now, but it has some overhead because we then need to serialize this as string again.
but lets keep it for now