Skip to content

Commit 70f7803

Browse files
committed
core,graph,runtime: Move BlockType out of EthereumBlockTriggerType
1 parent 26b3851 commit 70f7803

File tree

7 files changed

+57
-38
lines changed

7 files changed

+57
-38
lines changed

core/src/subgraph/instance.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,16 @@ where
206206
.await?;
207207
}
208208
}
209-
EthereumTrigger::Block(ptr, trigger_type) => {
209+
EthereumTrigger::Block(ptr, block_trigger_) => {
210210
let matching_hosts = hosts
211211
.iter()
212-
.filter(|host| host.matches_block(&trigger_type, ptr.number));
212+
.filter(|host| host.matches_block(&block_trigger_.trigger_type, ptr.number));
213213
for host in matching_hosts {
214214
state = host
215215
.process_block(
216216
logger,
217217
block,
218-
&trigger_type,
218+
&block_trigger_,
219219
state,
220220
proof_of_indexing.cheap_clone(),
221221
)

graph/src/components/ethereum/adapter.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -845,16 +845,22 @@ fn parse_block_triggers(
845845
.map(move |call| {
846846
EthereumTrigger::Block(
847847
block_ptr,
848-
EthereumBlockTriggerType::WithCallTo(call.to, block_type),
848+
EthereumBlockTrigger {
849+
block_type,
850+
trigger_type: EthereumBlockTriggerType::WithCallTo(call.to),
851+
},
849852
)
850853
})
851854
.collect::<Vec<EthereumTrigger>>()
852855
});
853856
if trigger_every_block {
854-
triggers.push(dbg!(EthereumTrigger::Block(
857+
triggers.push(EthereumTrigger::Block(
855858
block_ptr,
856-
EthereumBlockTriggerType::Every(block_type),
857-
)));
859+
EthereumBlockTrigger {
860+
block_type,
861+
trigger_type: EthereumBlockTriggerType::Every,
862+
},
863+
));
858864
}
859865
triggers
860866
}
@@ -961,7 +967,10 @@ pub fn blocks_with_triggers(
961967
.map(|ptr| {
962968
EthereumTrigger::Block(
963969
ptr,
964-
EthereumBlockTriggerType::Every(block_filter.block_type),
970+
EthereumBlockTrigger {
971+
block_type: block_filter.block_type,
972+
trigger_type: EthereumBlockTriggerType::Every,
973+
},
965974
)
966975
})
967976
.collect()
@@ -971,14 +980,17 @@ pub fn blocks_with_triggers(
971980
// To determine which blocks include a call to addresses
972981
// in the block filter, transform the `block_filter` into
973982
// a `call_filter` and run `blocks_with_calls`
974-
let block_type = block_filter.block_type.clone();
983+
let block_type = block_filter.block_type;
975984
let call_filter = EthereumCallFilter::from(block_filter);
976985
trigger_futs.push(Box::new(
977986
eth.calls_in_block_range(&logger, subgraph_metrics.clone(), from, to, call_filter)
978987
.map(move |call| {
979988
EthereumTrigger::Block(
980989
EthereumBlockPointer::from(&call),
981-
EthereumBlockTriggerType::WithCallTo(call.to, block_type.clone()),
990+
EthereumBlockTrigger {
991+
block_type,
992+
trigger_type: EthereumBlockTriggerType::WithCallTo(call.to),
993+
},
982994
)
983995
})
984996
.collect(),

graph/src/components/ethereum/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ pub use self::listener::{ChainHeadUpdate, ChainHeadUpdateListener, ChainHeadUpda
1414
pub use self::stream::{BlockStream, BlockStreamBuilder, BlockStreamEvent};
1515
pub use self::types::{
1616
BlockFinality, BlockType, EthereumBlock, EthereumBlockData, EthereumBlockPointer,
17-
EthereumBlockTriggerType, EthereumBlockType, EthereumBlockWithCalls, EthereumBlockWithTriggers,
18-
EthereumCall, EthereumCallData, EthereumEventData, EthereumTransactionData,
19-
EthereumTransactionReceiptData, EthereumTrigger, FullEthereumBlockData,
20-
FullEthereumBlockDataWithReceipts, LightEthereumBlock, LightEthereumBlockExt,
17+
EthereumBlockTrigger, EthereumBlockTriggerType, EthereumBlockType, EthereumBlockWithCalls,
18+
EthereumBlockWithTriggers, EthereumCall, EthereumCallData, EthereumEventData,
19+
EthereumTransactionData, EthereumTransactionReceiptData, EthereumTrigger,
20+
FullEthereumBlockData, FullEthereumBlockDataWithReceipts, LightEthereumBlock,
21+
LightEthereumBlockExt,
2122
};

graph/src/components/ethereum/types.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl EthereumCall {
165165

166166
#[derive(Clone, Debug)]
167167
pub enum EthereumTrigger {
168-
Block(EthereumBlockPointer, EthereumBlockTriggerType),
168+
Block(EthereumBlockPointer, EthereumBlockTrigger),
169169
Call(EthereumCall),
170170
Log(Log),
171171
}
@@ -259,8 +259,8 @@ impl Default for BlockType {
259259

260260
#[derive(Clone, Debug, PartialEq, Eq)]
261261
pub enum EthereumBlockTriggerType {
262-
Every(BlockType),
263-
WithCallTo(Address, BlockType),
262+
Every,
263+
WithCallTo(Address),
264264
}
265265

266266
impl EthereumTrigger {
@@ -873,7 +873,8 @@ impl ToEntityKey for EthereumBlockPointer {
873873
#[cfg(test)]
874874
mod test {
875875
use super::{
876-
BlockType, EthereumBlockPointer, EthereumBlockTriggerType, EthereumCall, EthereumTrigger,
876+
BlockType, EthereumBlockPointer, EthereumBlockTrigger, EthereumBlockTriggerType,
877+
EthereumCall, EthereumTrigger,
877878
};
878879
use web3::types::*;
879880

@@ -884,15 +885,21 @@ mod test {
884885
number: 1,
885886
hash: H256::random(),
886887
},
887-
EthereumBlockTriggerType::Every(BlockType::Light),
888+
EthereumBlockTrigger {
889+
block_type: BlockType::Light,
890+
trigger_type: EthereumBlockTriggerType::Every,
891+
},
888892
);
889893

890894
let block2 = EthereumTrigger::Block(
891895
EthereumBlockPointer {
892896
number: 0,
893897
hash: H256::random(),
894898
},
895-
EthereumBlockTriggerType::WithCallTo(Address::random(), BlockType::Light),
899+
EthereumBlockTrigger {
900+
block_type: BlockType::Light,
901+
trigger_type: EthereumBlockTriggerType::WithCallTo(Address::random()),
902+
},
896903
);
897904

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

graph/src/components/subgraph/host.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub trait RuntimeHost: Send + Sync + Debug + 'static {
5050
&self,
5151
logger: &Logger,
5252
block: &Arc<EthereumBlockType>,
53-
trigger_type: &EthereumBlockTriggerType,
53+
trigger: &EthereumBlockTrigger,
5454
state: BlockState,
5555
proof_of_indexing: SharedProofOfIndexing,
5656
) -> Result<BlockState, anyhow::Error>;

graph/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ pub mod prelude {
7777
BlockFinality, BlockStream, BlockStreamBuilder, BlockStreamEvent, BlockStreamMetrics,
7878
ChainHeadUpdate, ChainHeadUpdateListener, ChainHeadUpdateStream, EthereumAdapter,
7979
EthereumAdapterError, EthereumBlock, EthereumBlockData, EthereumBlockFilter,
80-
EthereumBlockPointer, EthereumBlockTriggerType, EthereumBlockType, EthereumBlockWithCalls,
81-
EthereumBlockWithTriggers, EthereumCall, EthereumCallData, EthereumCallFilter,
82-
EthereumContractCall, EthereumContractCallError, EthereumEventData, EthereumLogFilter,
83-
EthereumNetworkIdentifier, EthereumTransactionData, EthereumTrigger, FullEthereumBlockData,
84-
LightEthereumBlock, LightEthereumBlockExt, ProviderEthRpcMetrics, SubgraphEthRpcMetrics,
80+
EthereumBlockPointer, EthereumBlockTrigger, EthereumBlockTriggerType, EthereumBlockType,
81+
EthereumBlockWithCalls, EthereumBlockWithTriggers, EthereumCall, EthereumCallData,
82+
EthereumCallFilter, EthereumContractCall, EthereumContractCallError, EthereumEventData,
83+
EthereumLogFilter, EthereumNetworkIdentifier, EthereumTransactionData, EthereumTrigger,
84+
FullEthereumBlockData, LightEthereumBlock, LightEthereumBlockExt, ProviderEthRpcMetrics,
85+
SubgraphEthRpcMetrics,
8586
};
8687
pub use crate::components::graphql::{
8788
GraphQlRunner, QueryResultFuture, SubscriptionResultFuture,

runtime/wasm/src/host.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,13 @@ 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, _block_type) => {
288+
EthereumBlockTriggerType::WithCallTo(address) => {
289289
self.data_source_contract
290290
.address
291291
// Do not match if this datasource has no address
292292
.map_or(false, |addr| addr == *address)
293293
}
294-
EthereumBlockTriggerType::Every(_) => true,
294+
EthereumBlockTriggerType::Every => true,
295295
};
296296
source_address_matches && self.handler_for_block(block_trigger_type).is_ok()
297297
}
@@ -347,7 +347,7 @@ impl RuntimeHost {
347347
trigger_type: &EthereumBlockTriggerType,
348348
) -> Result<MappingBlockHandler, anyhow::Error> {
349349
match trigger_type {
350-
EthereumBlockTriggerType::Every(_block_type) => self
350+
EthereumBlockTriggerType::Every => 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, _block_type) => self
362+
EthereumBlockTriggerType::WithCallTo(_address) => self
363363
.data_source_block_handlers
364364
.iter()
365365
.find(move |handler| {
@@ -571,13 +571,13 @@ impl RuntimeHostTrait for RuntimeHost {
571571
&self,
572572
logger: &Logger,
573573
block: &Arc<EthereumBlockType>,
574-
trigger_type: &EthereumBlockTriggerType,
574+
trigger: &EthereumBlockTrigger,
575575
state: BlockState,
576576
proof_of_indexing: SharedProofOfIndexing,
577577
) -> Result<BlockState, anyhow::Error> {
578-
let block_handler = self.handler_for_block(trigger_type)?;
579-
let mapping_block: EthereumBlockType = match trigger_type {
580-
EthereumBlockTriggerType::Every(BlockType::FullWithReceipts) => match self
578+
let block_handler = self.handler_for_block(&trigger.trigger_type)?;
579+
let mapping_block: EthereumBlockType = match trigger.block_type {
580+
BlockType::FullWithReceipts => match self
581581
.host_exports
582582
.ethereum_adapter
583583
.load_full_block(logger, block.light_block().clone())
@@ -591,10 +591,8 @@ impl RuntimeHostTrait for RuntimeHost {
591591
e
592592
)),
593593
}?,
594-
EthereumBlockTriggerType::Every(BlockType::Full) => {
595-
EthereumBlockType::Full(block.light_block().clone())
596-
}
597-
_ => block.as_ref().clone(),
594+
BlockType::Full => EthereumBlockType::Full(block.light_block().clone()),
595+
BlockType::Light => block.as_ref().clone(),
598596
};
599597

600598
self.send_mapping_request(

0 commit comments

Comments
 (0)