Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update block handler input data #1761

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6b0313c
core,graph,runtime: Create FullBlock struct and pass to mappings
fordN Jun 12, 2020
80d17f4
graph,runtime: Parse Block handler data type from the manifest
fordN Jun 19, 2020
f8e7ebf
core,graph,runtime: Update AscEthereumBlock struct
fordN Jun 23, 2020
5a4446e
graph,runtime: Support three data input structs for blockhandlers
fordN Jun 24, 2020
0105c58
core,graph,runtime: Pass EthereumBlockType into process_triggers()
fordN Jun 24, 2020
77b0495
graph: Update EthereumBlockFilter.extend() with block_type field
fordN Jun 24, 2020
a112e47
graph,runtime: Support different block type inputs to call filters
fordN Jun 24, 2020
2b98eaf
core,graph,runtime: Move BlockType out of EthereumBlockTriggerType
fordN Jul 6, 2020
8ec65f0
graph: Fix Ethereum Block handler from string and write to store
fordN Jul 6, 2020
2a8ec86
graph: Use Ord impl for EthereumBlockHandlerData and BlockType
fordN Jul 6, 2020
ad83da2
graph: Remove duplicate struct BlockHandlerData
fordN Jul 6, 2020
1bb1fac
graph/ethereum: Use the From<> impls to reduce code redundancy
fordN Jul 6, 2020
f5398c5
runtime/wasm: Impl and use From<Option<AscPtr<C>>> for AscPtr<C>
fordN Jul 6, 2020
daf740f
runtime/wasm: Do not clone block from context in handle_ethereum_block()
fordN Jul 6, 2020
e6288d1
graph,runtime: Remove root field on transaction receipt (no on Geth)
fordN Jul 13, 2020
9609561
core,graph: Ethereum struct improvements, impl copy, make clone explicit
fordN Jul 13, 2020
1a31f83
runtime: Reference the mapping context safely in handle_ethereum_block
fordN Jul 13, 2020
b053022
graph: Rename BlockHandler input -> blockFormat
fordN Jul 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions core/src/subgraph/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ where
async fn process_trigger(
&self,
logger: &Logger,
block: &Arc<LightEthereumBlock>,
block: &Arc<EthereumBlockType>,
trigger: EthereumTrigger,
state: BlockState,
proof_of_indexing: SharedProofOfIndexing,
Expand All @@ -154,7 +154,7 @@ where
async fn process_trigger_in_runtime_hosts(
logger: &Logger,
hosts: &[Arc<T::Host>],
block: &Arc<LightEthereumBlock>,
block: &Arc<EthereumBlockType>,
trigger: EthereumTrigger,
mut state: BlockState,
proof_of_indexing: SharedProofOfIndexing,
Expand All @@ -165,12 +165,11 @@ where

let transaction = block
.transaction_for_log(&log)
.map(Arc::new)
.map(|tx| Arc::new(tx.clone()))
.context("Found no transaction for event")?;
let matching_hosts = hosts.iter().filter(|host| host.matches_log(&log));
// Process the log in each host in the same order the corresponding data
// sources appear in the subgraph manifest
let transaction = Arc::new(transaction);
for host in matching_hosts {
state = host
.process_log(
Expand All @@ -189,8 +188,8 @@ where

let transaction = block
.transaction_for_call(&call)
.map(|tx| Arc::new(tx.clone()))
.context("Found no transaction for call")?;
let transaction = Arc::new(transaction);
let matching_hosts = hosts.iter().filter(|host| host.matches_call(&call));

for host in matching_hosts {
Expand All @@ -206,16 +205,16 @@ where
.await?;
}
}
EthereumTrigger::Block(ptr, trigger_type) => {
EthereumTrigger::Block(ptr, block_trigger_) => {
let matching_hosts = hosts
.iter()
.filter(|host| host.matches_block(&trigger_type, ptr.number));
.filter(|host| host.matches_block(&block_trigger_.trigger_type, ptr.number));
for host in matching_hosts {
state = host
.process_block(
logger,
block,
&trigger_type,
&block_trigger_,
state,
proof_of_indexing.cheap_clone(),
)
Expand Down
4 changes: 2 additions & 2 deletions core/src/subgraph/instance_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ where
}

// Obtain current and new block pointer (after this block is processed)
let light_block = Arc::new(block.light_block());
let light_block = Arc::new(EthereumBlockType::Light(block.light_block()));
let block_ptr_after = EthereumBlockPointer::from(&block);
let block_ptr_for_new_data_sources = block_ptr_after.clone();

Expand Down Expand Up @@ -879,7 +879,7 @@ async fn process_triggers<B: BlockStreamBuilder, T: RuntimeHostBuilder, S: Send
mut block_state: BlockState,
proof_of_indexing: SharedProofOfIndexing,
ctx: IndexingContext<B, T, S>,
block: &Arc<LightEthereumBlock>,
block: &Arc<EthereumBlockType>,
triggers: Vec<EthereumTrigger>,
) -> Result<(IndexingContext<B, T, S>, BlockState), CancelableError<Error>> {
for trigger in triggers.into_iter() {
Expand Down
51 changes: 42 additions & 9 deletions graph/src/components/ethereum/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ impl From<EthereumBlockFilter> for EthereumCallFilter {
pub struct EthereumBlockFilter {
pub contract_addresses: HashSet<(u64, Address)>,
pub trigger_every_block: bool,
pub block_type: BlockType,
}

impl EthereumBlockFilter {
Expand All @@ -421,8 +422,7 @@ impl EthereumBlockFilter {
let has_block_handler_with_call_filter = data_source
.mapping
.block_handlers
.clone()
.into_iter()
.iter()
.any(|block_handler| match block_handler.filter {
Some(ref filter) if *filter == BlockHandlerFilter::Call => return true,
_ => return false,
Expand All @@ -431,12 +431,21 @@ impl EthereumBlockFilter {
let has_block_handler_without_filter = data_source
.mapping
.block_handlers
.clone()
.into_iter()
.iter()
That3Percent marked this conversation as resolved.
Show resolved Hide resolved
.any(|block_handler| block_handler.filter.is_none());

let block_type = data_source
.mapping
.block_handlers
.iter()
.map(|handler| handler.block_format)
.max()
.unwrap_or(EthereumBlockHandlerData::Block)
.into();

filter_opt.extend(Self {
trigger_every_block: has_block_handler_without_filter,
block_type,
contract_addresses: if has_block_handler_with_call_filter {
vec![(
data_source.source.start_block,
Expand All @@ -454,6 +463,8 @@ impl EthereumBlockFilter {

pub fn extend(&mut self, other: EthereumBlockFilter) {
self.trigger_every_block = self.trigger_every_block || other.trigger_every_block;
self.block_type = self.block_type.max(other.block_type);

self.contract_addresses = self.contract_addresses.iter().cloned().fold(
HashSet::new(),
|mut addresses, (start_block, address)| {
Expand Down Expand Up @@ -803,20 +814,30 @@ fn parse_block_triggers(
) -> Vec<EthereumTrigger> {
let block_ptr = EthereumBlockPointer::from(&block.ethereum_block);
let trigger_every_block = block_filter.trigger_every_block;
let block_type = block_filter.block_type;
let call_filter = EthereumCallFilter::from(block_filter);
let mut triggers = block.calls.as_ref().map_or(vec![], |calls| {
calls
.iter()
.filter(move |call| call_filter.matches(call))
.map(move |call| {
EthereumTrigger::Block(block_ptr, EthereumBlockTriggerType::WithCallTo(call.to))
EthereumTrigger::Block(
block_ptr,
EthereumBlockTrigger {
block_type,
trigger_type: EthereumBlockTriggerType::WithCallTo(call.to),
},
)
})
.collect::<Vec<EthereumTrigger>>()
});
if trigger_every_block {
triggers.push(EthereumTrigger::Block(
block_ptr,
EthereumBlockTriggerType::Every,
EthereumBlockTrigger {
block_type,
trigger_type: EthereumBlockTriggerType::Every,
},
));
}
triggers
Expand Down Expand Up @@ -921,21 +942,33 @@ pub fn blocks_with_triggers(
.block_range_to_ptrs(logger.clone(), from, to)
.map(move |ptrs| {
ptrs.into_iter()
.map(|ptr| EthereumTrigger::Block(ptr, EthereumBlockTriggerType::Every))
.map(|ptr| {
EthereumTrigger::Block(
ptr,
EthereumBlockTrigger {
block_type: block_filter.block_type,
trigger_type: EthereumBlockTriggerType::Every,
},
)
})
.collect()
}),
))
} else if !block_filter.contract_addresses.is_empty() {
// To determine which blocks include a call to addresses
// in the block filter, transform the `block_filter` into
// a `call_filter` and run `blocks_with_calls`
let block_type = block_filter.block_type;
let call_filter = EthereumCallFilter::from(block_filter);
trigger_futs.push(Box::new(
eth.calls_in_block_range(&logger, subgraph_metrics.clone(), from, to, call_filter)
.map(|call| {
.map(move |call| {
EthereumTrigger::Block(
EthereumBlockPointer::from(&call),
EthereumBlockTriggerType::WithCallTo(call.to),
EthereumBlockTrigger {
block_type,
trigger_type: EthereumBlockTriggerType::WithCallTo(call.to),
},
)
})
.collect(),
Expand Down
10 changes: 6 additions & 4 deletions graph/src/components/ethereum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ pub use self::adapter::{
pub use self::listener::{ChainHeadUpdate, ChainHeadUpdateListener, ChainHeadUpdateStream};
pub use self::stream::{BlockStream, BlockStreamBuilder, BlockStreamEvent};
pub use self::types::{
BlockFinality, EthereumBlock, EthereumBlockData, EthereumBlockPointer,
EthereumBlockTriggerType, EthereumBlockWithCalls, EthereumBlockWithTriggers, EthereumCall,
EthereumCallData, EthereumEventData, EthereumTransactionData, EthereumTrigger,
LightEthereumBlock, LightEthereumBlockExt,
BlockFinality, BlockType, EthereumBlock, EthereumBlockData, EthereumBlockPointer,
EthereumBlockTrigger, EthereumBlockTriggerType, EthereumBlockType, EthereumBlockWithCalls,
EthereumBlockWithTriggers, EthereumCall, EthereumCallData, EthereumEventData,
EthereumTransactionData, EthereumTransactionReceiptData, EthereumTrigger,
FullEthereumBlockData, FullEthereumBlockDataWithReceipts, LightEthereumBlock,
LightEthereumBlockExt,
};
Loading