Skip to content

Commit d458e15

Browse files
committed
all: Defer parsing ABI for declared calls to handler resolution
The ahead-of-time parsing was unnecessarily complicated, and the map it produced was wrong since it was organized by the event name (`Owner`) rather than the event signature (`Owner(indexed address)`) which made parameter lookups fail at runtime. Since the handler has the event signature from the manifest, which is exactly in the form that is used for lookups, it's much easier to parse at that point.
1 parent ab59a92 commit d458e15

5 files changed

Lines changed: 186 additions & 208 deletions

File tree

chain/ethereum/src/data_source.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use graph::components::store::{EthereumCallCache, StoredDynamicDataSource};
66
use graph::components::subgraph::{HostMetrics, InstanceDSTemplateInfo, MappingError};
77
use graph::components::trigger_processor::RunnableTriggers;
88
use graph::data_source::common::{
9-
CallDecls, DeclaredCall, FindMappingABI, MappingABI, UnresolvedCallDecls, UnresolvedMappingABI,
9+
AbiJson, CallDecls, DeclaredCall, FindMappingABI, MappingABI, UnresolvedCallDecls,
10+
UnresolvedMappingABI,
1011
};
1112
use graph::data_source::{CausalityRegion, MappingTrigger as MappingTriggerType};
1213
use graph::env::ENV_VARS;
@@ -1379,9 +1380,7 @@ impl UnresolvedMapping {
13791380
// resolve each abi
13801381
abis.into_iter()
13811382
.map(|unresolved_abi| async {
1382-
Result::<_, Error>::Ok(Arc::new(
1383-
unresolved_abi.resolve(resolver, logger).await?,
1384-
))
1383+
Result::<_, Error>::Ok(unresolved_abi.resolve(resolver, logger).await?)
13851384
})
13861385
.collect::<FuturesOrdered<_>>()
13871386
.try_collect::<Vec<_>>(),
@@ -1398,24 +1397,27 @@ impl UnresolvedMapping {
13981397
.into_iter()
13991398
.map(|unresolved_handler| {
14001399
// Find the ABI for this event handler
1401-
let event_abi = abis.first().ok_or_else(|| {
1400+
let (_, abi_json) = abis.first().ok_or_else(|| {
14021401
anyhow!(
14031402
"No ABI found for event '{}' in event handler '{}'",
14041403
unresolved_handler.event,
14051404
unresolved_handler.handler
14061405
)
14071406
})?;
14081407

1409-
unresolved_handler.resolve(event_abi, &spec_version)
1408+
unresolved_handler.resolve(abi_json, &spec_version)
14101409
})
14111410
.collect::<Result<Vec<_>, anyhow::Error>>()?;
14121411

1412+
// Extract just the MappingABIs for the final Mapping struct
1413+
let mapping_abis = abis.into_iter().map(|(abi, _)| Arc::new(abi)).collect();
1414+
14131415
Ok(Mapping {
14141416
kind,
14151417
api_version,
14161418
language,
14171419
entities,
1418-
abis,
1420+
abis: mapping_abis,
14191421
block_handlers: block_handlers.clone(),
14201422
call_handlers: call_handlers.clone(),
14211423
event_handlers: resolved_event_handlers,
@@ -1482,12 +1484,12 @@ pub struct UnresolvedMappingEventHandler {
14821484
impl UnresolvedMappingEventHandler {
14831485
pub fn resolve(
14841486
self,
1485-
mapping: &MappingABI,
1487+
abi_json: &AbiJson,
14861488
spec_version: &semver::Version,
14871489
) -> Result<MappingEventHandler, anyhow::Error> {
14881490
let resolved_calls = self
14891491
.calls
1490-
.resolve(mapping, Some(&self.event), spec_version)?;
1492+
.resolve(abi_json, Some(&self.event), spec_version)?;
14911493

14921494
Ok(MappingEventHandler {
14931495
event: self.event,

0 commit comments

Comments
 (0)