-
Notifications
You must be signed in to change notification settings - Fork 2
/
beta.5-import.patch
100 lines (88 loc) · 3.86 KB
/
beta.5-import.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
diff --git a/bin/reth/src/commands/import.rs b/bin/reth/src/commands/import.rs
index f59e9e149..5ef8273a7 100644
--- a/bin/reth/src/commands/import.rs
+++ b/bin/reth/src/commands/import.rs
@@ -20,7 +20,10 @@ use reth_downloaders::{
};
use reth_interfaces::consensus::Consensus;
use reth_node_core::{events::node::NodeEvent, init::init_genesis};
+#[cfg(not(feature = "optimism"))]
use reth_node_ethereum::EthEvmConfig;
+#[cfg(feature = "optimism")]
+use reth_node_optimism::OptimismEvmConfig;
use reth_primitives::{stage::StageId, ChainSpec, PruneModes, B256};
use reth_provider::{HeaderSyncMode, ProviderFactory, StageCheckpointReader};
use reth_stages::{
@@ -172,9 +175,14 @@ impl ImportCommand {
.into_task();
let (tip_tx, tip_rx) = watch::channel(B256::ZERO);
+ #[cfg(not(feature = "optimism"))]
let factory =
reth_revm::EvmProcessorFactory::new(self.chain.clone(), EthEvmConfig::default());
+ #[cfg(feature = "optimism")]
+ let factory =
+ reth_revm::EvmProcessorFactory::new(self.chain.clone(), OptimismEvmConfig::default());
+
let max_block = file_client.max_block().unwrap_or(0);
let mut pipeline = Pipeline::builder()
diff --git a/crates/net/downloaders/src/file_client.rs b/crates/net/downloaders/src/file_client.rs
index ebc5fe408..dc495eb6c 100644
--- a/crates/net/downloaders/src/file_client.rs
+++ b/crates/net/downloaders/src/file_client.rs
@@ -38,6 +38,9 @@ pub struct FileClient {
/// The buffered bodies retrieved when fetching new headers.
bodies: HashMap<BlockHash, BlockBody>,
+
+ /// Chain tip set based on highest incremental block hash
+ tip: Option<B256>,
}
/// An error that can occur when constructing and using a [`FileClient`].
@@ -72,6 +75,8 @@ impl FileClient {
let mut headers = HashMap::new();
let mut hash_to_number = HashMap::new();
let mut bodies = HashMap::new();
+ let mut max_bock = 0u64;
+ let mut tip = None;
// use with_capacity to make sure the internal buffer contains the entire file
let mut stream = FramedRead::with_capacity(&reader[..], BlockFileCodec, file_len as usize);
@@ -80,6 +85,11 @@ impl FileClient {
let block = block_res?;
let block_hash = block.header.hash_slow();
+ if block.number > max_bock {
+ max_bock = block.number;
+ tip = Some(block_hash);
+ }
+
// add to the internal maps
headers.insert(block.header.number, block.header.clone());
hash_to_number.insert(block_hash, block.header.number);
@@ -95,12 +105,12 @@ impl FileClient {
trace!(blocks = headers.len(), "Initialized file client");
- Ok(Self { headers, hash_to_number, bodies })
+ Ok(Self { headers, hash_to_number, bodies, tip })
}
/// Get the tip hash of the chain.
pub fn tip(&self) -> Option<B256> {
- self.headers.get(&(self.headers.len() as u64)).map(|h| h.hash_slow())
+ self.tip
}
/// Returns the highest block number of this client has or `None` if empty
diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs
index 817271ae3..81d59bea4 100644
--- a/crates/primitives/src/transaction/mod.rs
+++ b/crates/primitives/src/transaction/mod.rs
@@ -135,6 +135,15 @@ pub enum Transaction {
// === impl Transaction ===
impl Transaction {
+ /// Short-circuit signer for optimism deposit txs
+ pub fn signer(&self) -> Option<Address> {
+ #[cfg(feature = "optimism")]
+ if let Transaction::Deposit(TxDeposit { from, .. }) = self {
+ return Some(*from);
+ }
+ None
+ }
+
/// Heavy operation that return signature hash over rlp encoded transaction.
/// It is only for signature signing or signer recovery.
pub fn signature_hash(&self) -> B256 {