Skip to content

Commit 26b3851

Browse files
committed
graph,runtime: Support different block type inputs to call filters
1 parent eaf4b8c commit 26b3851

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

graph/src/components/ethereum/adapter.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,10 @@ fn parse_block_triggers(
843843
.iter()
844844
.filter(move |call| call_filter.matches(call))
845845
.map(move |call| {
846-
EthereumTrigger::Block(block_ptr, EthereumBlockTriggerType::WithCallTo(call.to))
846+
EthereumTrigger::Block(
847+
block_ptr,
848+
EthereumBlockTriggerType::WithCallTo(call.to, block_type),
849+
)
847850
})
848851
.collect::<Vec<EthereumTrigger>>()
849852
});
@@ -968,13 +971,14 @@ pub fn blocks_with_triggers(
968971
// To determine which blocks include a call to addresses
969972
// in the block filter, transform the `block_filter` into
970973
// a `call_filter` and run `blocks_with_calls`
974+
let block_type = block_filter.block_type.clone();
971975
let call_filter = EthereumCallFilter::from(block_filter);
972976
trigger_futs.push(Box::new(
973977
eth.calls_in_block_range(&logger, subgraph_metrics.clone(), from, to, call_filter)
974-
.map(|call| {
978+
.map(move |call| {
975979
EthereumTrigger::Block(
976980
EthereumBlockPointer::from(&call),
977-
EthereumBlockTriggerType::WithCallTo(call.to),
981+
EthereumBlockTriggerType::WithCallTo(call.to, block_type.clone()),
978982
)
979983
})
980984
.collect(),

graph/src/components/ethereum/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl Default for BlockType {
260260
#[derive(Clone, Debug, PartialEq, Eq)]
261261
pub enum EthereumBlockTriggerType {
262262
Every(BlockType),
263-
WithCallTo(Address),
263+
WithCallTo(Address, BlockType),
264264
}
265265

266266
impl EthereumTrigger {
@@ -892,7 +892,7 @@ mod test {
892892
number: 0,
893893
hash: H256::random(),
894894
},
895-
EthereumBlockTriggerType::WithCallTo(Address::random()),
895+
EthereumBlockTriggerType::WithCallTo(Address::random(), BlockType::Light),
896896
);
897897

898898
let mut call1 = EthereumCall::default();

runtime/wasm/src/host.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl RuntimeHost {
285285

286286
fn matches_block_trigger(&self, block_trigger_type: &EthereumBlockTriggerType) -> bool {
287287
let source_address_matches = match block_trigger_type {
288-
EthereumBlockTriggerType::WithCallTo(address) => {
288+
EthereumBlockTriggerType::WithCallTo(address, _block_type) => {
289289
self.data_source_contract
290290
.address
291291
// Do not match if this datasource has no address
@@ -347,7 +347,7 @@ impl RuntimeHost {
347347
trigger_type: &EthereumBlockTriggerType,
348348
) -> Result<MappingBlockHandler, anyhow::Error> {
349349
match trigger_type {
350-
EthereumBlockTriggerType::Every(_type) => self
350+
EthereumBlockTriggerType::Every(_block_type) => self
351351
.data_source_block_handlers
352352
.iter()
353353
.find(move |handler| handler.filter == None)
@@ -359,7 +359,7 @@ impl RuntimeHost {
359359
self.data_source_name,
360360
)
361361
}),
362-
EthereumBlockTriggerType::WithCallTo(_address) => self
362+
EthereumBlockTriggerType::WithCallTo(_address, _block_type) => self
363363
.data_source_block_handlers
364364
.iter()
365365
.find(move |handler| {
@@ -577,23 +577,20 @@ impl RuntimeHostTrait for RuntimeHost {
577577
) -> Result<BlockState, anyhow::Error> {
578578
let block_handler = self.handler_for_block(trigger_type)?;
579579
let mapping_block: EthereumBlockType = match trigger_type {
580-
EthereumBlockTriggerType::Every(BlockType::FullWithReceipts) => {
581-
match graph::block_on_allow_panic(
582-
future::lazy(move || {
583-
self.host_exports
584-
.ethereum_adapter
585-
.load_full_block(logger, block.light_block().clone())
586-
})
587-
.compat(),
588-
) {
589-
Ok(block) => Ok(EthereumBlockType::FullWithReceipts(block)),
590-
Err(e) => Err(anyhow::anyhow!(
591-
"Failed to load full block: {}, error: {}",
592-
&block.number().to_string(),
593-
e
594-
)),
595-
}?
596-
}
580+
EthereumBlockTriggerType::Every(BlockType::FullWithReceipts) => match self
581+
.host_exports
582+
.ethereum_adapter
583+
.load_full_block(logger, block.light_block().clone())
584+
.compat()
585+
.await
586+
{
587+
Ok(block) => Ok(EthereumBlockType::FullWithReceipts(block)),
588+
Err(e) => Err(anyhow::anyhow!(
589+
"Failed to load full block: {}, error: {}",
590+
&block.number().to_string(),
591+
e
592+
)),
593+
}?,
597594
EthereumBlockTriggerType::Every(BlockType::Full) => {
598595
EthereumBlockType::Full(block.light_block().clone())
599596
}

0 commit comments

Comments
 (0)