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

chore: enforce window #11540

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions crates/rpc/rpc-eth-api/src/helpers/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,26 @@ pub trait EthState: LoadState + SpawnBlocking {
&self,
address: Address,
block_id: BlockId,
) -> impl Future<Output = Result<Option<Account>, Self::Error>> + Send {
) -> impl Future<Output = Result<Option<Account>, Self::Error>> + Send
where
Self: EthApiSpec,
{
self.spawn_blocking_io(move |this| {
let state = this.state_at_block_id(block_id)?;

let account = state.basic_account(address).map_err(Self::Error::from_eth_err)?;
let Some(account) = account else { return Ok(None) };

// Check whether the distance to the block exceeds the maximum configured proof window.
let chain_info = this.chain_info().map_err(Self::Error::from_eth_err)?;
let block_number = LoadState::provider(&this)
.block_number_for_id(block_id)
.map_err(Self::Error::from_eth_err)?
.ok_or(EthApiError::HeaderNotFound(block_id))?;
let max_window = this.max_proof_window();
if chain_info.best_number.saturating_sub(block_number) > max_window {
return Err(EthApiError::ExceedsMaxProofWindow.into())
}

let balance = account.balance;
let nonce = account.nonce;
let code_hash = account.bytecode_hash.unwrap_or(KECCAK_EMPTY);
Expand Down
Loading