Skip to content

Commit cb82efd

Browse files
committed
core,graph,runtime: Update AscEthereumBlock struct
1 parent f13fcec commit cb82efd

File tree

7 files changed

+85
-25
lines changed

7 files changed

+85
-25
lines changed

core/src/subgraph/instance_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ async fn process_triggers<B: BlockStreamBuilder, T: RuntimeHostBuilder, S: Send
879879
mut block_state: BlockState,
880880
proof_of_indexing: SharedProofOfIndexing,
881881
ctx: IndexingContext<B, T, S>,
882-
block: &Arc<EthereumBlock>,
882+
block: &Arc<LightEthereumBlock>,
883883
triggers: Vec<EthereumTrigger>,
884884
) -> Result<(IndexingContext<B, T, S>, BlockState), CancelableError<Error>> {
885885
for trigger in triggers.into_iter() {

graph/src/components/ethereum/adapter.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,10 @@ fn parse_block_triggers(
813813
) -> Vec<EthereumTrigger> {
814814
let block_ptr = EthereumBlockPointer::from(&block.ethereum_block);
815815
let trigger_every_block = block_filter.trigger_every_block;
816+
let block_type = match block_filter.full_block {
817+
true => BlockType::Full,
818+
false => BlockType::Light,
819+
};
816820
let call_filter = EthereumCallFilter::from(block_filter);
817821
let mut triggers = block.calls.as_ref().map_or(vec![], |calls| {
818822
calls
@@ -826,7 +830,7 @@ fn parse_block_triggers(
826830
if trigger_every_block {
827831
triggers.push(EthereumTrigger::Block(
828832
block_ptr,
829-
EthereumBlockTriggerType::Every(BlockType::Full),
833+
EthereumBlockTriggerType::Every(block_type),
830834
));
831835
}
832836
triggers
@@ -934,7 +938,9 @@ pub fn blocks_with_triggers(
934938
.map(|ptr| {
935939
EthereumTrigger::Block(
936940
ptr,
937-
EthereumBlockTriggerType::Every(BlockType::Full),
941+
EthereumBlockTriggerType::Every(BlockType::from(
942+
block_filter.full_block,
943+
)),
938944
)
939945
})
940946
.collect()

graph/src/components/ethereum/mod.rs

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

graph/src/components/ethereum/types.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,6 @@ impl PartialEq for EthereumTrigger {
203203

204204
impl Eq for EthereumTrigger {}
205205

206-
/// This is used in `EthereumAdapter::triggers_in_block`, called when re-processing a block for
207-
/// newly created data sources. This allows the re-processing to be reorg safe without having to
208-
/// always fetch the full block data.
209206
#[derive(Clone, Debug)]
210207
pub enum EthereumBlockType {
211208
Light(LightEthereumBlock),
@@ -303,8 +300,8 @@ impl PartialOrd for EthereumTrigger {
303300

304301
pub struct EthereumTransactionReceiptData {
305302
// from receipts
306-
pub transaction_hash: H256,
307-
pub transaction_index: Index,
303+
pub hash: H256,
304+
pub index: Index,
308305
pub cumulative_gas_used: U256,
309306
pub gas_used: Option<U256>,
310307
pub contract_address: Option<H160>,
@@ -360,8 +357,8 @@ impl<'a> TryFrom<&'a EthereumBlockType> for FullEthereumBlockData {
360357
transaction_and_receipt.1.transaction_hash
361358
);
362359
EthereumTransactionReceiptData {
363-
transaction_hash: transaction_and_receipt.0.hash,
364-
transaction_index: transaction_and_receipt.1.transaction_index,
360+
hash: transaction_and_receipt.0.hash,
361+
index: transaction_and_receipt.1.transaction_index,
365362
cumulative_gas_used: transaction_and_receipt.1.cumulative_gas_used,
366363
gas_used: transaction_and_receipt.1.gas_used,
367364
contract_address: transaction_and_receipt.1.contract_address,
@@ -413,8 +410,8 @@ impl<'a> From<&'a EthereumBlock> for FullEthereumBlockData {
413410
transaction_and_receipt.1.transaction_hash
414411
);
415412
EthereumTransactionReceiptData {
416-
transaction_hash: transaction_and_receipt.0.hash,
417-
transaction_index: transaction_and_receipt.1.transaction_index,
413+
hash: transaction_and_receipt.0.hash,
414+
index: transaction_and_receipt.1.transaction_index,
418415
cumulative_gas_used: transaction_and_receipt.1.cumulative_gas_used,
419416
gas_used: transaction_and_receipt.1.gas_used,
420417
contract_address: transaction_and_receipt.1.contract_address,
@@ -470,10 +467,11 @@ pub struct EthereumBlockData {
470467
pub difficulty: U256,
471468
pub total_difficulty: U256,
472469
pub size: Option<U256>,
470+
pub transactions: Vec<EthereumTransactionData>,
473471
}
474472

475-
impl<'a, T> From<&'a Block<T>> for EthereumBlockData {
476-
fn from(block: &'a Block<T>) -> EthereumBlockData {
473+
impl<'a> From<&'a LightEthereumBlock> for EthereumBlockData {
474+
fn from(block: &'a LightEthereumBlock) -> EthereumBlockData {
477475
EthereumBlockData {
478476
hash: block.hash.unwrap(),
479477
parent_hash: block.parent_hash,
@@ -489,6 +487,11 @@ impl<'a, T> From<&'a Block<T>> for EthereumBlockData {
489487
difficulty: block.difficulty,
490488
total_difficulty: block.total_difficulty.unwrap_or_default(),
491489
size: block.size,
490+
transactions: block
491+
.transactions
492+
.iter()
493+
.map(|tx| EthereumTransactionData::from(tx))
494+
.collect(),
492495
}
493496
}
494497
}
@@ -515,6 +518,11 @@ impl<'a> From<&'a EthereumBlockType> for EthereumBlockData {
515518
difficulty: block.difficulty,
516519
total_difficulty: block.total_difficulty.unwrap_or_default(),
517520
size: block.size,
521+
transactions: block
522+
.transactions
523+
.iter()
524+
.map(|tx| EthereumTransactionData::from(tx))
525+
.collect(),
518526
}
519527
}
520528
}

runtime/wasm/src/asc_abi/class.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,26 @@ pub(crate) struct AscEthereumBlock {
418418
pub size: AscPtr<AscBigInt>,
419419
}
420420

421+
#[repr(C)]
422+
#[derive(AscType)]
423+
pub(crate) struct AscEthereumBlock_0_0_5 {
424+
pub hash: AscPtr<AscH256>,
425+
pub parent_hash: AscPtr<AscH256>,
426+
pub uncles_hash: AscPtr<AscH256>,
427+
pub author: AscPtr<AscH160>,
428+
pub state_root: AscPtr<AscH256>,
429+
pub transactions_root: AscPtr<AscH256>,
430+
pub receipts_root: AscPtr<AscH256>,
431+
pub number: AscPtr<AscBigInt>,
432+
pub gas_used: AscPtr<AscBigInt>,
433+
pub gas_limit: AscPtr<AscBigInt>,
434+
pub timestamp: AscPtr<AscBigInt>,
435+
pub difficulty: AscPtr<AscBigInt>,
436+
pub total_difficulty: AscPtr<AscBigInt>,
437+
pub size: AscPtr<AscBigInt>,
438+
pub transactions: AscPtr<Array<AscPtr<AscEthereumTransaction_0_0_2>>>,
439+
}
440+
421441
#[repr(C)]
422442
#[derive(AscType)]
423443
pub(crate) struct AscFullEthereumBlock {
@@ -453,8 +473,8 @@ pub(crate) struct AscEthereumTransaction {
453473
#[repr(C)]
454474
#[derive(AscType)]
455475
pub(crate) struct AscEthereumTransactionReceipt {
456-
pub transaction_hash: AscPtr<AscH256>,
457-
pub transaction_index: AscPtr<AscBigInt>,
476+
pub hash: AscPtr<AscH256>,
477+
pub index: AscPtr<AscBigInt>,
458478
pub cumulative_gas_used: AscPtr<AscBigInt>,
459479
pub gas_used: AscPtr<AscBigInt>,
460480
pub contract_address: AscPtr<AscH160>,

runtime/wasm/src/host.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ impl RuntimeHostTrait for RuntimeHost {
576576
proof_of_indexing: SharedProofOfIndexing,
577577
) -> Result<BlockState, anyhow::Error> {
578578
let block_handler = self.handler_for_block(trigger_type)?;
579-
let theblock: EthereumBlockType = match dbg!(trigger_type) {
579+
let mapping_block: EthereumBlockType = match trigger_type {
580580
EthereumBlockTriggerType::Every(BlockType::Full) => match graph::block_on_allow_panic(
581581
future::lazy(move || {
582582
self.host_exports
@@ -585,7 +585,7 @@ impl RuntimeHostTrait for RuntimeHost {
585585
})
586586
.compat(),
587587
) {
588-
Ok(block) => Ok(EthereumBlockType::Full(dbg!(block))),
588+
Ok(block) => Ok(EthereumBlockType::Full(block)),
589589
Err(e) => Err(anyhow::anyhow!(
590590
"Failed to load full block: {}, error: {}",
591591
&block.number.unwrap().to_string(),
@@ -606,7 +606,7 @@ impl RuntimeHostTrait for RuntimeHost {
606606
MappingTrigger::Block {
607607
handler: block_handler.clone(),
608608
},
609-
&Arc::new(dbg!(theblock)),
609+
&Arc::new(mapping_block),
610610
proof_of_indexing,
611611
)
612612
.await

runtime/wasm/src/to_from/external.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,31 @@ impl ToAscObj<AscEthereumBlock> for EthereumBlockData {
325325
}
326326
}
327327

328+
impl ToAscObj<AscEthereumBlock_0_0_5> for EthereumBlockData {
329+
fn to_asc_obj<H: AscHeap>(&self, heap: &mut H) -> AscEthereumBlock_0_0_5 {
330+
AscEthereumBlock_0_0_5 {
331+
hash: heap.asc_new(&self.hash),
332+
parent_hash: heap.asc_new(&self.parent_hash),
333+
uncles_hash: heap.asc_new(&self.uncles_hash),
334+
author: heap.asc_new(&self.author),
335+
state_root: heap.asc_new(&self.state_root),
336+
transactions_root: heap.asc_new(&self.transactions_root),
337+
receipts_root: heap.asc_new(&self.receipts_root),
338+
number: heap.asc_new(&BigInt::from(self.number)),
339+
gas_used: heap.asc_new(&BigInt::from_unsigned_u256(&self.gas_used)),
340+
gas_limit: heap.asc_new(&BigInt::from_unsigned_u256(&self.gas_limit)),
341+
timestamp: heap.asc_new(&BigInt::from_unsigned_u256(&self.timestamp)),
342+
difficulty: heap.asc_new(&BigInt::from_unsigned_u256(&self.difficulty)),
343+
total_difficulty: heap.asc_new(&BigInt::from_unsigned_u256(&self.total_difficulty)),
344+
size: self
345+
.size
346+
.map(|size| heap.asc_new(&BigInt::from_unsigned_u256(&size)))
347+
.unwrap_or_else(|| AscPtr::null()),
348+
transactions: heap.asc_new(self.transactions.as_slice()),
349+
}
350+
}
351+
}
352+
328353
impl ToAscObj<AscFullEthereumBlock> for FullEthereumBlockData {
329354
fn to_asc_obj<H: AscHeap>(&self, heap: &mut H) -> AscFullEthereumBlock {
330355
AscFullEthereumBlock {
@@ -354,8 +379,8 @@ impl ToAscObj<AscEthereumTransactionReceipt> for EthereumTransactionReceiptData
354379
fn to_asc_obj<H: AscHeap>(&self, heap: &mut H) -> AscEthereumTransactionReceipt {
355380
AscEthereumTransactionReceipt {
356381
//from receipts
357-
transaction_hash: heap.asc_new(&self.transaction_hash),
358-
transaction_index: heap.asc_new(&BigInt::from(self.transaction_index)),
382+
hash: heap.asc_new(&self.hash),
383+
index: heap.asc_new(&BigInt::from(self.index)),
359384
cumulative_gas_used: heap
360385
.asc_new(&BigInt::from_unsigned_u256(&self.cumulative_gas_used)),
361386
gas_used: self

0 commit comments

Comments
 (0)