Skip to content

Commit 9475b5e

Browse files
committed
Fix block subscription issues when forking
1 parent e9ce1fe commit 9475b5e

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
@@ -1967,6 +1967,7 @@ async fn create_revive_rpc_client(
19671967
block_provider.clone(),
19681968
task_spawn_handle.clone(),
19691969
keep_latest_n_blocks,
1970+
in_fork_mode,
19701971
)
19711972
.await
19721973
{
@@ -1993,6 +1994,7 @@ async fn create_revive_rpc_client(
19931994
block_provider,
19941995
task_spawn_handle,
19951996
keep_latest_n_blocks,
1997+
in_fork_mode,
19961998
)
19971999
.await
19982000
.map(Some)
@@ -2005,6 +2007,7 @@ async fn create_revive_client_impl(
20052007
block_provider: SubxtBlockInfoProvider,
20062008
task_spawn_handle: SpawnTaskHandle,
20072009
keep_latest_n_blocks: Option<usize>,
2010+
in_fork_mode: bool,
20082011
) -> Result<EthRpcClient> {
20092012
let pool = SqlitePoolOptions::new()
20102013
.max_connections(1)
@@ -2038,18 +2041,28 @@ async fn create_revive_client_impl(
20382041

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

20542067
Ok(eth_rpc_client)
20552068
}

0 commit comments

Comments
 (0)