Skip to content

Commit 973f48e

Browse files
committed
use alloy block
1 parent 445dc99 commit 973f48e

File tree

9 files changed

+173
-133
lines changed

9 files changed

+173
-133
lines changed

chain/ethereum/src/codec.rs

Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ mod pbcodec;
44

55
use anyhow::format_err;
66
use graph::{
7+
alloy_todo,
78
blockchain::{
89
self, Block as BlockchainBlock, BlockPtr, BlockTime, ChainStoreBlock, ChainStoreData,
910
},
1011
prelude::{
11-
web3,
12-
web3::types::{Bytes, H160, H2048, H256, H64, U256, U64},
12+
web3::{
13+
self,
14+
types::{Bytes, H160, H2048, H256, U256, U64},
15+
},
1316
BlockNumber, Error, EthereumBlock, EthereumBlockWithCalls, EthereumCall,
1417
LightEthereumBlock,
1518
},
@@ -225,64 +228,65 @@ impl TryInto<EthereumBlockWithCalls> for &Block {
225228
format_err!("block header should always be present from gRPC Firehose")
226229
})?;
227230

228-
let web3_block = web3::types::Block {
229-
hash: Some(self.hash.try_decode_proto("block hash")?),
230-
number: Some(U64::from(self.number)),
231-
author: header.coinbase.try_decode_proto("author / coinbase")?,
232-
parent_hash: header.parent_hash.try_decode_proto("parent hash")?,
233-
uncles_hash: header.uncle_hash.try_decode_proto("uncle hash")?,
234-
state_root: header.state_root.try_decode_proto("state root")?,
235-
transactions_root: header
236-
.transactions_root
237-
.try_decode_proto("transactions root")?,
238-
receipts_root: header.receipt_root.try_decode_proto("receipt root")?,
239-
gas_used: U256::from(header.gas_used),
240-
gas_limit: U256::from(header.gas_limit),
241-
base_fee_per_gas: Some(
242-
header
243-
.base_fee_per_gas
244-
.as_ref()
245-
.map_or_else(U256::default, |v| v.into()),
246-
),
247-
extra_data: Bytes::from(header.extra_data.clone()),
248-
logs_bloom: match &header.logs_bloom.len() {
249-
0 => None,
250-
_ => Some(header.logs_bloom.try_decode_proto("logs bloom")?),
251-
},
252-
timestamp: header
253-
.timestamp
254-
.as_ref()
255-
.map_or_else(U256::default, |v| U256::from(v.seconds)),
256-
difficulty: header
257-
.difficulty
258-
.as_ref()
259-
.map_or_else(U256::default, |v| v.into()),
260-
total_difficulty: Some(
261-
header
262-
.total_difficulty
263-
.as_ref()
264-
.map_or_else(U256::default, |v| v.into()),
265-
),
266-
// FIXME (SF): Firehose does not have seal fields, are they really used? Might be required for POA chains only also, I've seen that stuff on xDai (is this important?)
267-
seal_fields: vec![],
268-
uncles: self
269-
.uncles
270-
.iter()
271-
.map(|u| u.hash.try_decode_proto("uncle hash"))
272-
.collect::<Result<Vec<H256>, _>>()?,
273-
transactions: self
274-
.transaction_traces
275-
.iter()
276-
.map(|t| TransactionTraceAt::new(t, self).try_into())
277-
.collect::<Result<Vec<web3::types::Transaction>, Error>>()?,
278-
size: Some(U256::from(self.size)),
279-
mix_hash: Some(header.mix_hash.try_decode_proto("mix hash")?),
280-
nonce: Some(H64::from_low_u64_be(header.nonce)),
281-
};
282-
231+
// let web3_block = web3::types::Block {
232+
// hash: Some(self.hash.try_decode_proto("block hash")?),
233+
// number: Some(U64::from(self.number)),
234+
// author: header.coinbase.try_decode_proto("author / coinbase")?,
235+
// parent_hash: header.parent_hash.try_decode_proto("parent hash")?,
236+
// uncles_hash: header.uncle_hash.try_decode_proto("uncle hash")?,
237+
// state_root: header.state_root.try_decode_proto("state root")?,
238+
// transactions_root: header
239+
// .transactions_root
240+
// .try_decode_proto("transactions root")?,
241+
// receipts_root: header.receipt_root.try_decode_proto("receipt root")?,
242+
// gas_used: U256::from(header.gas_used),
243+
// gas_limit: U256::from(header.gas_limit),
244+
// base_fee_per_gas: Some(
245+
// header
246+
// .base_fee_per_gas
247+
// .as_ref()
248+
// .map_or_else(U256::default, |v| v.into()),
249+
// ),
250+
// extra_data: Bytes::from(header.extra_data.clone()),
251+
// logs_bloom: match &header.logs_bloom.len() {
252+
// 0 => None,
253+
// _ => Some(header.logs_bloom.try_decode_proto("logs bloom")?),
254+
// },
255+
// timestamp: header
256+
// .timestamp
257+
// .as_ref()
258+
// .map_or_else(U256::default, |v| U256::from(v.seconds)),
259+
// difficulty: header
260+
// .difficulty
261+
// .as_ref()
262+
// .map_or_else(U256::default, |v| v.into()),
263+
// total_difficulty: Some(
264+
// header
265+
// .total_difficulty
266+
// .as_ref()
267+
// .map_or_else(U256::default, |v| v.into()),
268+
// ),
269+
// // FIXME (SF): Firehose does not have seal fields, are they really used? Might be required for POA chains only also, I've seen that stuff on xDai (is this important?)
270+
// seal_fields: vec![],
271+
// uncles: self
272+
// .uncles
273+
// .iter()
274+
// .map(|u| u.hash.try_decode_proto("uncle hash"))
275+
// .collect::<Result<Vec<H256>, _>>()?,
276+
// transactions: self
277+
// .transaction_traces
278+
// .iter()
279+
// .map(|t| TransactionTraceAt::new(t, self).try_into())
280+
// .collect::<Result<Vec<web3::types::Transaction>, Error>>()?,
281+
// size: Some(U256::from(self.size)),
282+
// mix_hash: Some(header.mix_hash.try_decode_proto("mix hash")?),
283+
// nonce: Some(H64::from_low_u64_be(header.nonce)),
284+
// };
285+
286+
#[allow(unreachable_code)]
283287
let block = EthereumBlockWithCalls {
284288
ethereum_block: EthereumBlock {
285-
block: Arc::new(LightEthereumBlock::new(web3_block)),
289+
block: Arc::new(LightEthereumBlock::new(alloy_todo!())),
286290
transaction_receipts: self
287291
.transaction_traces
288292
.iter()

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,14 +2624,13 @@ mod tests {
26242624
check_block_receipt_support, parse_block_triggers, EthereumBlock, EthereumBlockFilter,
26252625
EthereumBlockWithCalls,
26262626
};
2627+
use graph::alloy_todo;
26272628
use graph::blockchain::BlockPtr;
2628-
use graph::components::ethereum::Block;
2629+
use graph::components::ethereum::BlockWrapper;
26292630
use graph::prelude::alloy::primitives::B256;
26302631
use graph::prelude::alloy::providers::mock::Asserter;
26312632
use graph::prelude::alloy::providers::ProviderBuilder;
26322633
use graph::prelude::tokio::{self};
2633-
use graph::prelude::web3::types::Block as Web3Block;
2634-
use graph::prelude::web3::types::U64;
26352634
use graph::prelude::web3::types::{Address, Bytes, H256};
26362635
use graph::prelude::EthereumCall;
26372636
use jsonrpc_core::serde_json::{self, Value};
@@ -2641,15 +2640,17 @@ mod tests {
26412640

26422641
#[test]
26432642
fn parse_block_triggers_every_block() {
2644-
let web3_block = Web3Block {
2645-
hash: Some(hash(2)),
2646-
number: Some(U64::from(2)),
2647-
..Default::default()
2648-
};
2649-
2643+
// let web3_block = Web3Block {
2644+
// hash: Some(hash(2)),
2645+
// number: Some(U64::from(2)),
2646+
// ..Default::default()
2647+
// };
2648+
let web3_block = alloy_todo!();
2649+
2650+
#[allow(unreachable_code)]
26502651
let block = EthereumBlockWithCalls {
26512652
ethereum_block: EthereumBlock {
2652-
block: Arc::new(Block::new(web3_block)),
2653+
block: Arc::new(BlockWrapper::new(web3_block)),
26532654
..Default::default()
26542655
},
26552656
calls: Some(vec![EthereumCall {
@@ -2786,14 +2787,17 @@ mod tests {
27862787

27872788
#[test]
27882789
fn parse_block_triggers_specific_call_not_found() {
2789-
let web3_block = Web3Block {
2790-
hash: Some(hash(2)),
2791-
number: Some(U64::from(2)),
2792-
..Default::default()
2793-
};
2790+
// let web3_block = Web3Block {
2791+
// hash: Some(hash(2)),
2792+
// number: Some(U64::from(2)),
2793+
// ..Default::default()
2794+
// };
2795+
let web3_block = alloy_todo!();
2796+
2797+
#[allow(unreachable_code)]
27942798
let block = EthereumBlockWithCalls {
27952799
ethereum_block: EthereumBlock {
2796-
block: Arc::new(Block::new(web3_block)),
2800+
block: Arc::new(BlockWrapper::new(web3_block)),
27972801
..Default::default()
27982802
},
27992803
calls: Some(vec![EthereumCall {
@@ -2819,15 +2823,17 @@ mod tests {
28192823

28202824
#[test]
28212825
fn parse_block_triggers_specific_call_found() {
2822-
let web3_block = Web3Block {
2823-
hash: Some(hash(2)),
2824-
number: Some(U64::from(2)),
2825-
..Default::default()
2826-
};
2827-
2826+
// let web3_block = Web3Block {
2827+
// hash: Some(hash(2)),
2828+
// number: Some(U64::from(2)),
2829+
// ..Default::default()
2830+
// };
2831+
let web3_block = alloy_todo!();
2832+
2833+
#[allow(unreachable_code)]
28282834
let block = EthereumBlockWithCalls {
28292835
ethereum_block: EthereumBlock {
2830-
block: Arc::new(Block::new(web3_block)),
2836+
block: Arc::new(BlockWrapper::new(web3_block)),
28312837
..Default::default()
28322838
},
28332839
calls: Some(vec![EthereumCall {

chain/ethereum/src/tests.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use std::sync::Arc;
22

33
use graph::{
4+
alloy_todo,
45
blockchain::{block_stream::BlockWithTriggers, BlockPtr, Trigger},
5-
components::ethereum::Block,
6+
components::ethereum::BlockWrapper,
67
prelude::{
78
web3::{
89
self,
@@ -96,14 +97,17 @@ fn test_trigger_ordering() {
9697

9798
let logger = Logger::root(slog::Discard, o!());
9899

99-
let mut b: web3::types::Block<Transaction> = Default::default();
100+
// let mut b: web3::types::Block<Transaction> = Default::default();
100101

101-
// This is necessary because inside of BlockWithTriggers::new
102-
// there's a log for both fields. So just using Default above
103-
// gives None on them.
104-
b.number = Some(Default::default());
105-
b.hash = Some(Default::default());
106-
let b = Block::new(b);
102+
// // This is necessary because inside of BlockWithTriggers::new
103+
// // there's a log for both fields. So just using Default above
104+
// // gives None on them.
105+
// b.number = Some(Default::default());
106+
// b.hash = Some(Default::default());
107+
let b = alloy_todo!();
108+
109+
#[allow(unreachable_code)]
110+
let b = BlockWrapper::new(b);
107111

108112
// Test that `BlockWithTriggers` sorts the triggers.
109113
let block_with_triggers = BlockWithTriggers::<crate::Chain>::new(
@@ -202,7 +206,12 @@ fn test_trigger_dedup() {
202206
// gives None on them.
203207
b.number = Some(Default::default());
204208
b.hash = Some(Default::default());
205-
let b = Block::new(b);
209+
210+
#[allow(unused_variables)]
211+
let b = alloy_todo!();
212+
213+
#[allow(unreachable_code)]
214+
let b = BlockWrapper::new(b);
206215

207216
// Test that `BlockWithTriggers` sorts the triggers.
208217
let block_with_triggers = BlockWithTriggers::<crate::Chain>::new(

graph/src/blockchain/types.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::time::Duration;
1212
use std::{fmt, str::FromStr};
1313
use web3::types::{Block as Web3Block, H256, U256, U64};
1414

15-
use crate::components::ethereum::Block;
15+
use crate::components::ethereum::BlockWrapper;
1616

1717
use crate::cheap_clone::CheapClone;
1818
use crate::components::store::BlockNumber;
@@ -218,14 +218,14 @@ impl slog::Value for BlockPtr {
218218
}
219219
}
220220

221-
impl From<Block> for BlockPtr {
222-
fn from(b: Block) -> BlockPtr {
221+
impl From<BlockWrapper> for BlockPtr {
222+
fn from(b: BlockWrapper) -> BlockPtr {
223223
BlockPtr::from((b.hash_h256().unwrap(), b.number_u64().unwrap() as i32))
224224
}
225225
}
226226

227-
impl From<&Block> for BlockPtr {
228-
fn from(b: &Block) -> BlockPtr {
227+
impl From<&BlockWrapper> for BlockPtr {
228+
fn from(b: &BlockWrapper) -> BlockPtr {
229229
BlockPtr::from((b.hash_h256().unwrap(), b.number_u64().unwrap() as i32))
230230
}
231231
}

graph/src/components/ethereum/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mod types;
22

33
pub use self::types::{
4-
evaluate_transaction_status, Block, EthereumBlock, EthereumBlockWithCalls, EthereumCall,
4+
evaluate_transaction_status, BlockWrapper, EthereumBlock, EthereumBlockWithCalls, EthereumCall,
55
LightEthereumBlock, LightEthereumBlockExt,
66
};

graph/src/components/ethereum/types.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,45 @@ use crate::{
1414

1515
#[allow(dead_code)]
1616
#[derive(Debug, Default, Deserialize, Serialize)]
17-
pub struct Block(web3::types::Block<Transaction>);
17+
pub struct BlockWrapper(AlloyBlock);
1818

19-
impl Block {
20-
pub fn new(block: web3::types::Block<Transaction>) -> Self {
19+
impl BlockWrapper {
20+
pub fn new(block: AlloyBlock) -> Self {
2121
Self(block)
2222
}
2323

2424
pub fn hash_h256(&self) -> Option<H256> {
25-
self.0.hash
25+
alloy_todo!()
26+
// self.0.hash
2627
}
2728

2829
pub fn number_u64(&self) -> Option<u64> {
29-
self.0.number.map(|n| n.as_u64())
30+
alloy_todo!()
31+
// self.0.number.map(|n| n.as_u64())
3032
}
3133

3234
pub fn number_web3_u64(&self) -> Option<U64> {
33-
self.0.number
35+
alloy_todo!()
36+
// Some(u64_to_web3_u64(self.0.header.number))
3437
}
3538

3639
pub fn timestamp_u64(&self) -> u64 {
37-
self.0.timestamp.as_u64()
40+
alloy_todo!()
41+
// self.0.timestamp.as_u64()
3842
}
3943

4044
pub fn transactions(&self) -> &[Transaction] {
41-
&self.0.transactions
45+
alloy_todo!()
46+
// &self.0.transactions
4247
}
4348

4449
pub fn inner(&self) -> &web3::types::Block<Transaction> {
45-
&self.0
50+
alloy_todo!()
51+
// &self.0
4652
}
4753
}
4854

49-
pub type LightEthereumBlock = Block;
55+
pub type LightEthereumBlock = BlockWrapper;
5056

5157
pub trait LightEthereumBlockExt {
5258
fn number(&self) -> BlockNumber;

graph/src/util/conversions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::Arc;
22

33
use web3::types::Bytes;
44

5-
use crate::components::ethereum::Block;
5+
use crate::components::ethereum::BlockWrapper;
66
use crate::prelude::alloy::primitives::{Address as AlloyAddress, B256};
77
use crate::prelude::alloy::rpc::types::{
88
Block as AlloyBlock, Log as AlloyLog, TransactionReceipt as AlloyTransactionReceipt,
@@ -103,13 +103,13 @@ pub fn alloy_transaction_receipt_to_web3_transaction_receipt(
103103
}
104104

105105
/// Converts alloy Block to web3 Block
106-
pub fn alloy_block_to_block_arc(_block: Arc<AlloyBlock>) -> Arc<Block> {
106+
pub fn alloy_block_to_block_arc(_block: Arc<AlloyBlock>) -> Arc<BlockWrapper> {
107107
unimplemented!(
108108
"Block conversion from alloy to web3 not yet implemented - will be done when needed"
109109
)
110110
}
111111

112-
pub fn alloy_block_to_block(_block: AlloyBlock) -> Block {
112+
pub fn alloy_block_to_block(_block: AlloyBlock) -> BlockWrapper {
113113
unimplemented!(
114114
"Block conversion from alloy to web3 not yet implemented - will be done when needed"
115115
)

0 commit comments

Comments
 (0)