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

fix(api): Fix getting pending block #2186

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions core/node/api_server/src/web3/namespaces/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ impl DebugNamespace {
options: Option<TracerConfig>,
) -> Result<Vec<ResultDebugCall>, Web3Error> {
self.current_method().set_block_id(block_id);
if matches!(block_id, BlockId::Number(BlockNumber::Pending)) {
// See `EthNamespace::get_block_impl()` for an explanation why this check is needed.
return Ok(vec![]);
}

let only_top_call = options
.map(|options| options.tracer_config.only_top_call)
Expand Down
26 changes: 23 additions & 3 deletions core/node/api_server/src/web3/namespaces/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,15 @@ impl EthNamespace {
full_transactions: bool,
) -> Result<Option<Block<TransactionVariant>>, Web3Error> {
self.current_method().set_block_id(block_id);
let mut storage = self.state.acquire_connection().await?;
if matches!(block_id, BlockId::Number(BlockNumber::Pending)) {
// Shortcut here on a somewhat unlikely case of the client requesting a pending block.
// Otherwise, since we don't read DB data in a transaction,
// we might resolve a block number to a block that will be inserted to the DB immediately after,
// and return `Ok(Some(_))`.
return Ok(None);
}

let mut storage = self.state.acquire_connection().await?;
self.state
.start_info
.ensure_not_pruned(block_id, &mut storage)
Expand Down Expand Up @@ -288,8 +295,12 @@ impl EthNamespace {
block_id: BlockId,
) -> Result<Option<U256>, Web3Error> {
self.current_method().set_block_id(block_id);
let mut storage = self.state.acquire_connection().await?;
if matches!(block_id, BlockId::Number(BlockNumber::Pending)) {
// See `get_block_impl()` for an explanation why this check is needed.
return Ok(None);
}

let mut storage = self.state.acquire_connection().await?;
self.state
.start_info
.ensure_not_pruned(block_id, &mut storage)
Expand Down Expand Up @@ -319,8 +330,12 @@ impl EthNamespace {
block_id: BlockId,
) -> Result<Option<Vec<TransactionReceipt>>, Web3Error> {
self.current_method().set_block_id(block_id);
let mut storage = self.state.acquire_connection().await?;
if matches!(block_id, BlockId::Number(BlockNumber::Pending)) {
// See `get_block_impl()` for an explanation why this check is needed.
return Ok(None);
}

let mut storage = self.state.acquire_connection().await?;
self.state
.start_info
.ensure_not_pruned(block_id, &mut storage)
Expand Down Expand Up @@ -457,6 +472,11 @@ impl EthNamespace {
.map_err(DalError::generalize)?,

TransactionId::Block(block_id, idx) => {
if matches!(block_id, BlockId::Number(BlockNumber::Pending)) {
// See `get_block_impl()` for an explanation why this check is needed.
return Ok(None);
}

let Ok(idx) = u32::try_from(idx) else {
return Ok(None); // index overflow means no transaction
};
Expand Down
Loading