Skip to content

Commit 5fa50f9

Browse files
authored
chain/ethereum: RuntimeAdapter lazy EthAdapter (#4508)
1 parent 1280949 commit 5fa50f9

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

chain/ethereum/src/network.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ impl EthereumNetworks {
193193
}
194194
}
195195

196+
pub fn insert_empty(&mut self, name: String) {
197+
self.networks.entry(name).or_default();
198+
}
199+
196200
pub fn insert(
197201
&mut self,
198202
name: String,

chain/ethereum/src/runtime/runtime_adapter.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,17 @@ impl blockchain::RuntimeAdapter<Chain> for RuntimeAdapter {
4343
fn host_fns(&self, ds: &DataSource) -> Result<Vec<HostFn>, Error> {
4444
let abis = ds.mapping.abis.clone();
4545
let call_cache = self.call_cache.cheap_clone();
46-
// Ethereum calls should prioritise call-only adapters if one is available.
47-
let eth_adapter = self.eth_adapters.call_or_cheapest(Some(&NodeCapabilities {
48-
archive: ds.mapping.requires_archive()?,
49-
traces: false,
50-
}))?;
46+
let eth_adapters = self.eth_adapters.cheap_clone();
47+
let archive = ds.mapping.requires_archive()?;
5148

5249
let ethereum_call = HostFn {
5350
name: "ethereum.call",
5451
func: Arc::new(move |ctx, wasm_ptr| {
52+
// Ethereum calls should prioritise call-only adapters if one is available.
53+
let eth_adapter = eth_adapters.call_or_cheapest(Some(&NodeCapabilities {
54+
archive,
55+
traces: false,
56+
}))?;
5557
ethereum_call(&eth_adapter, call_cache.cheap_clone(), ctx, wasm_ptr, &abis)
5658
.map(|ptr| ptr.wasm_ptr())
5759
}),

node/src/chain.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,10 @@ pub async fn create_ethereum_networks_for_chain(
438438
let (web3, call_only) = match &provider.details {
439439
ProviderDetails::Web3Call(web3) => (web3, true),
440440
ProviderDetails::Web3(web3) => (web3, false),
441-
_ => continue,
441+
_ => {
442+
parsed_networks.insert_empty(network_name.to_string());
443+
continue;
444+
}
442445
};
443446

444447
let capabilities = web3.node_capabilities();

0 commit comments

Comments
 (0)