Skip to content

Commit 4ab0e8c

Browse files
committed
Fix block subscription issues when forking
1 parent cfc962e commit 4ab0e8c

File tree

1 file changed

+25
-12
lines changed
  • crates/anvil-polkadot/src/api_server

1 file changed

+25
-12
lines changed

crates/anvil-polkadot/src/api_server/server.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,6 +1960,7 @@ async fn create_revive_rpc_client(
19601960
block_provider.clone(),
19611961
task_spawn_handle.clone(),
19621962
keep_latest_n_blocks,
1963+
in_fork_mode,
19631964
)
19641965
.await
19651966
{
@@ -1986,6 +1987,7 @@ async fn create_revive_rpc_client(
19861987
block_provider,
19871988
task_spawn_handle,
19881989
keep_latest_n_blocks,
1990+
in_fork_mode,
19891991
)
19901992
.await
19911993
.map(Some)
@@ -1998,6 +2000,7 @@ async fn create_revive_client_impl(
19982000
block_provider: SubxtBlockInfoProvider,
19992001
task_spawn_handle: SpawnTaskHandle,
20002002
keep_latest_n_blocks: Option<usize>,
2003+
in_fork_mode: bool,
20012004
) -> Result<EthRpcClient> {
20022005
let pool = SqlitePoolOptions::new()
20032006
.max_connections(1)
@@ -2031,18 +2034,28 @@ async fn create_revive_client_impl(
20312034

20322035
// Capacity is chosen using random.org
20332036
eth_rpc_client.set_block_notifier(Some(tokio::sync::broadcast::channel::<H256>(50).0));
2034-
let eth_rpc_client_clone = eth_rpc_client.clone();
2035-
task_spawn_handle.spawn("block-subscription", "None", async move {
2036-
let eth_rpc_client = eth_rpc_client_clone;
2037-
let best_future =
2038-
eth_rpc_client.subscribe_and_cache_new_blocks(SubscriptionType::BestBlocks);
2039-
let finalized_future =
2040-
eth_rpc_client.subscribe_and_cache_new_blocks(SubscriptionType::FinalizedBlocks);
2041-
let res = tokio::try_join!(best_future, finalized_future).map(|_| ());
2042-
if let Err(err) = res {
2043-
panic!("Block subscription task failed: {err:?}")
2044-
}
2045-
});
2037+
2038+
// In fork mode, skip block subscription to avoid ReceiptDataNotFound errors
2039+
// when processing blocks from the remote chain. In fork mode, we create our own
2040+
// local blocks using manual-seal, and don't need to subscribe to remote blocks.
2041+
if !in_fork_mode {
2042+
let eth_rpc_client_clone = eth_rpc_client.clone();
2043+
task_spawn_handle.spawn("block-subscription", "None", async move {
2044+
let eth_rpc_client = eth_rpc_client_clone;
2045+
let best_future =
2046+
eth_rpc_client.subscribe_and_cache_new_blocks(SubscriptionType::BestBlocks);
2047+
let finalized_future =
2048+
eth_rpc_client.subscribe_and_cache_new_blocks(SubscriptionType::FinalizedBlocks);
2049+
let res = tokio::try_join!(best_future, finalized_future).map(|_| ());
2050+
if let Err(err) = res {
2051+
panic!("Block subscription task failed: {err:?}")
2052+
}
2053+
});
2054+
} else {
2055+
tracing::info!(
2056+
"Skipping block subscription in fork mode - blocks will be created locally via manual-seal"
2057+
);
2058+
}
20462059

20472060
Ok(eth_rpc_client)
20482061
}

0 commit comments

Comments
 (0)