Skip to content

Commit d80ad5a

Browse files
committed
feat: ✨ update to ethereum crate v3 structs
1 parent 0442de2 commit d80ad5a

File tree

25 files changed

+137
-59
lines changed

25 files changed

+137
-59
lines changed

client/db/src/sql/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ where
520520
ethereum::ReceiptV3::Legacy(d)
521521
| ethereum::ReceiptV3::EIP2930(d)
522522
| ethereum::ReceiptV3::EIP1559(d) => &d.logs,
523+
ethereum::ReceiptV3::EIP7702(d) => &d.logs,
523524
};
524525
let transaction_index = transaction_index as i32;
525526
log_count += receipt_logs.len();

client/mapping-sync/src/sql/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ mod test {
525525
mix_hash: H256::default(),
526526
nonce: ethereum_types::H64::default(),
527527
};
528-
let ethereum_transactions: Vec<ethereum::TransactionV2> = vec![];
528+
let ethereum_transactions: Vec<ethereum::TransactionV3> = vec![];
529529
let ethereum_block = ethereum::Block::new(partial_header, ethereum_transactions, vec![]);
530530
DigestItem::Consensus(
531531
fp_consensus::FRONTIER_ENGINE_ID,

client/rpc-core/src/types/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mod work;
3838

3939
pub mod pubsub;
4040

41-
use ethereum::TransactionV2 as EthereumTransaction;
41+
use ethereum::TransactionV3 as EthereumTransaction;
4242
use ethereum_types::H160;
4343

4444
#[cfg(feature = "txpool")]

client/rpc-core/src/types/pubsub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use std::collections::BTreeMap;
2222

2323
use ethereum::{
24-
BlockV2 as EthereumBlock, ReceiptV3 as EthereumReceipt, TransactionV2 as EthereumTransaction,
24+
BlockV3 as EthereumBlock, ReceiptV3 as EthereumReceipt, TransactionV3 as EthereumTransaction,
2525
};
2626
use ethereum_types::{H256, U256};
2727
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};

client/rpc-core/src/types/transaction.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// You should have received a copy of the GNU General Public License
1717
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1818

19-
use ethereum::{AccessListItem, TransactionAction, TransactionV2 as EthereumTransaction};
19+
use ethereum::{AccessListItem, TransactionAction, TransactionV3 as EthereumTransaction};
2020
use ethereum_types::{H160, H256, U256, U64};
2121
use serde::{ser::SerializeStruct, Serialize, Serializer};
2222

@@ -164,6 +164,32 @@ impl BuildFrom for Transaction {
164164
r: U256::from_big_endian(t.r.as_bytes()),
165165
s: U256::from_big_endian(t.s.as_bytes()),
166166
},
167+
EthereumTransaction::EIP7702(t) => Self {
168+
transaction_type: U256::from(4),
169+
hash,
170+
nonce: t.nonce,
171+
block_hash: None,
172+
block_number: None,
173+
transaction_index: None,
174+
from,
175+
to: match t.destination {
176+
TransactionAction::Call(to) => Some(to),
177+
TransactionAction::Create => None,
178+
},
179+
value: t.value,
180+
gas: t.gas_limit,
181+
gas_price: Some(t.max_fee_per_gas),
182+
max_fee_per_gas: Some(t.max_fee_per_gas),
183+
max_priority_fee_per_gas: Some(t.max_priority_fee_per_gas),
184+
input: Bytes(t.data.clone()),
185+
creates: None,
186+
chain_id: Some(U64::from(t.chain_id)),
187+
access_list: Some(t.access_list.clone()),
188+
y_parity: Some(U256::from(t.odd_y_parity as u8)),
189+
v: Some(U256::from(t.odd_y_parity as u8)),
190+
r: U256::from_big_endian(t.r.as_bytes()),
191+
s: U256::from_big_endian(t.s.as_bytes()),
192+
},
167193
}
168194
}
169195
}

client/rpc-core/src/types/txpool.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
use std::collections::HashMap;
2020

21-
use ethereum::{TransactionAction, TransactionV2 as EthereumTransaction};
21+
use ethereum::{TransactionAction, TransactionV3 as EthereumTransaction};
2222
use ethereum_types::{H160, U256};
2323
use serde::{Serialize, Serializer};
2424

@@ -70,6 +70,9 @@ impl BuildFrom for Summary {
7070
EthereumTransaction::Legacy(t) => (t.action, t.value, t.gas_price, t.gas_limit),
7171
EthereumTransaction::EIP2930(t) => (t.action, t.value, t.gas_price, t.gas_limit),
7272
EthereumTransaction::EIP1559(t) => (t.action, t.value, t.max_fee_per_gas, t.gas_limit),
73+
EthereumTransaction::EIP7702(t) => {
74+
(t.destination, t.value, t.max_fee_per_gas, t.gas_limit)
75+
}
7376
};
7477
Self {
7578
to: match action {

client/rpc/src/cache/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::{
2424
sync::{Arc, Mutex},
2525
};
2626

27-
use ethereum::BlockV2 as EthereumBlock;
27+
use ethereum::BlockV3 as EthereumBlock;
2828
use ethereum_types::U256;
2929
use futures::StreamExt;
3030
use tokio::sync::{mpsc, oneshot};
@@ -334,16 +334,21 @@ where
334334
.enumerate()
335335
.map(|(i, receipt)| TransactionHelper {
336336
gas_used: match receipt {
337-
ethereum::ReceiptV3::Legacy(d) | ethereum::ReceiptV3::EIP2930(d) | ethereum::ReceiptV3::EIP1559(d) => used_gas(d.used_gas, &mut previous_cumulative_gas),
337+
ethereum::ReceiptV3::Legacy(d) | ethereum::ReceiptV3::EIP2930(d) | ethereum::ReceiptV3::EIP1559(d) | ethereum::ReceiptV3::EIP7702(d) => used_gas(d.used_gas, &mut previous_cumulative_gas),
338338
},
339339
effective_reward: match block.transactions.get(i) {
340-
Some(ethereum::TransactionV2::Legacy(t)) => {
340+
Some(ethereum::TransactionV3::Legacy(t)) => {
341341
UniqueSaturatedInto::<u64>::unique_saturated_into(t.gas_price.saturating_sub(base_fee))
342342
}
343-
Some(ethereum::TransactionV2::EIP2930(t)) => {
343+
Some(ethereum::TransactionV3::EIP2930(t)) => {
344344
UniqueSaturatedInto::<u64>::unique_saturated_into(t.gas_price.saturating_sub(base_fee))
345345
}
346-
Some(ethereum::TransactionV2::EIP1559(t)) => UniqueSaturatedInto::<u64>::unique_saturated_into(
346+
Some(ethereum::TransactionV3::EIP1559(t)) => UniqueSaturatedInto::<u64>::unique_saturated_into(
347+
t
348+
.max_priority_fee_per_gas
349+
.min(t.max_fee_per_gas.saturating_sub(base_fee))
350+
),
351+
Some(ethereum::TransactionV3::EIP7702(t)) => UniqueSaturatedInto::<u64>::unique_saturated_into(
347352
t
348353
.max_priority_fee_per_gas
349354
.min(t.max_fee_per_gas.saturating_sub(base_fee))

client/rpc/src/debug.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<B: BlockT, C, BE> Debug<B, C, BE> {
5959
}
6060
}
6161

62-
async fn block_by(&self, number: BlockNumberOrHash) -> RpcResult<Option<ethereum::BlockV2>>
62+
async fn block_by(&self, number: BlockNumberOrHash) -> RpcResult<Option<ethereum::BlockV3>>
6363
where
6464
C: HeaderBackend<B> + StorageProvider<B, BE> + 'static,
6565
BE: Backend<B>,
@@ -86,7 +86,7 @@ impl<B: BlockT, C, BE> Debug<B, C, BE> {
8686
async fn transaction_by(
8787
&self,
8888
transaction_hash: H256,
89-
) -> RpcResult<Option<ethereum::TransactionV2>>
89+
) -> RpcResult<Option<ethereum::TransactionV3>>
9090
where
9191
C: HeaderBackend<B> + StorageProvider<B, BE> + 'static,
9292
BE: Backend<B>,

client/rpc/src/eth/filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::{
2323
time::{Duration, Instant},
2424
};
2525

26-
use ethereum::BlockV2 as EthereumBlock;
26+
use ethereum::BlockV3 as EthereumBlock;
2727
use ethereum_types::{H256, U256};
2828
use jsonrpsee::core::{async_trait, RpcResult};
2929
// Substrate

client/rpc/src/eth/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ mod transaction;
3030

3131
use std::{collections::BTreeMap, marker::PhantomData, sync::Arc};
3232

33-
use ethereum::{BlockV2 as EthereumBlock, TransactionV2 as EthereumTransaction};
33+
use ethereum::{BlockV3 as EthereumBlock, TransactionV3 as EthereumTransaction};
3434
use ethereum_types::{H160, H256, H64, U256, U64};
3535
use jsonrpsee::core::{async_trait, RpcResult};
3636
// Substrate

client/rpc/src/eth/submit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ where
160160
return Err(internal_err("transaction data is empty"));
161161
}
162162

163-
let transaction: ethereum::TransactionV2 =
163+
let transaction: ethereum::TransactionV3 =
164164
match ethereum::EnvelopedDecodable::decode(&bytes) {
165165
Ok(transaction) => transaction,
166166
Err(_) => return Err(internal_err("decode transaction failed")),
@@ -237,7 +237,7 @@ where
237237
fn convert_transaction(
238238
&self,
239239
block_hash: B::Hash,
240-
transaction: ethereum::TransactionV2,
240+
transaction: ethereum::TransactionV3,
241241
) -> RpcResult<B::Extrinsic> {
242242
let api_version = match self
243243
.client
@@ -258,7 +258,7 @@ where
258258
Err(_) => Err(internal_err("cannot access `ConvertTransactionRuntimeApi`")),
259259
},
260260
Some(1) => {
261-
if let ethereum::TransactionV2::Legacy(legacy_transaction) = transaction {
261+
if let ethereum::TransactionV3::Legacy(legacy_transaction) = transaction {
262262
// To be compatible with runtimes that do not support transactions v2
263263
#[allow(deprecated)]
264264
match self

client/rpc/src/eth/transaction.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
use std::sync::Arc;
2020

21-
use ethereum::TransactionV2 as EthereumTransaction;
21+
use ethereum::TransactionV3 as EthereumTransaction;
2222
use ethereum_types::{H256, U256, U64};
2323
use jsonrpsee::core::RpcResult;
2424
// Substrate
@@ -253,14 +253,16 @@ where
253253
match receipt {
254254
ethereum::ReceiptV3::Legacy(ref d)
255255
| ethereum::ReceiptV3::EIP2930(ref d)
256-
| ethereum::ReceiptV3::EIP1559(ref d) => {
256+
| ethereum::ReceiptV3::EIP1559(ref d)
257+
| ethereum::ReceiptV3::EIP7702(ref d) => {
257258
let cumulative_gas = d.used_gas;
258259
let gas_used = if index > 0 {
259260
let previous_receipt = receipts[index - 1].clone();
260261
let previous_gas_used = match previous_receipt {
261262
ethereum::ReceiptV3::Legacy(d)
262263
| ethereum::ReceiptV3::EIP2930(d)
263-
| ethereum::ReceiptV3::EIP1559(d) => d.used_gas,
264+
| ethereum::ReceiptV3::EIP1559(d)
265+
| ethereum::ReceiptV3::EIP7702(d) => d.used_gas,
264266
};
265267
cumulative_gas.saturating_sub(previous_gas_used)
266268
} else {
@@ -301,6 +303,31 @@ where
301303
))?
302304
};
303305

306+
self.client
307+
.runtime_api()
308+
.gas_price(base_fee_block_substrate_hash)
309+
.unwrap_or_default()
310+
.checked_add(t.max_priority_fee_per_gas)
311+
.unwrap_or_else(U256::max_value)
312+
.min(t.max_fee_per_gas)
313+
}
314+
EthereumTransaction::EIP7702(t) => {
315+
let parent_eth_hash = block.header.parent_hash;
316+
let base_fee_block_substrate_hash = if parent_eth_hash.is_zero() {
317+
substrate_hash
318+
} else {
319+
frontier_backend_client::load_hash::<B, C>(
320+
self.client.as_ref(),
321+
self.backend.as_ref(),
322+
parent_eth_hash,
323+
)
324+
.await
325+
.map_err(|err| internal_err(format!("{:?}", err)))?
326+
.ok_or(internal_err(
327+
"Failed to retrieve substrate parent block hash",
328+
))?
329+
};
330+
304331
self.client
305332
.runtime_api()
306333
.gas_price(base_fee_block_substrate_hash)
@@ -331,7 +358,8 @@ where
331358
.map(|r| match r {
332359
ethereum::ReceiptV3::Legacy(d)
333360
| ethereum::ReceiptV3::EIP2930(d)
334-
| ethereum::ReceiptV3::EIP1559(d) => d.logs.len() as u32,
361+
| ethereum::ReceiptV3::EIP1559(d)
362+
| ethereum::ReceiptV3::EIP7702(d) => d.logs.len() as u32,
335363
})
336364
.sum::<u32>(),
337365
);
@@ -362,6 +390,7 @@ where
362390
ethereum::ReceiptV3::Legacy(_) => U256::from(0),
363391
ethereum::ReceiptV3::EIP2930(_) => U256::from(1),
364392
ethereum::ReceiptV3::EIP1559(_) => U256::from(2),
393+
ethereum::ReceiptV3::EIP7702(_) => U256::from(4),
365394
},
366395
}));
367396
}

client/rpc/src/eth_pubsub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
use std::{marker::PhantomData, sync::Arc};
2020

21-
use ethereum::TransactionV2 as EthereumTransaction;
21+
use ethereum::TransactionV3 as EthereumTransaction;
2222
use futures::{future, FutureExt as _, StreamExt as _};
2323
use jsonrpsee::{core::traits::IdProvider, server::PendingSubscriptionSink};
2424
// Substrate

client/rpc/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub use self::{
4747
signer::{EthDevSigner, EthSigner},
4848
web3::Web3,
4949
};
50-
pub use ethereum::TransactionV2 as EthereumTransaction;
50+
pub use ethereum::TransactionV3 as EthereumTransaction;
5151
#[cfg(feature = "txpool")]
5252
pub use fc_rpc_core::TxPoolApiServer;
5353
pub use fc_rpc_core::{
@@ -342,6 +342,12 @@ pub fn public_key(transaction: &EthereumTransaction) -> Result<[u8; 64], sp_io::
342342
sig[64] = t.odd_y_parity as u8;
343343
msg.copy_from_slice(&ethereum::EIP1559TransactionMessage::from(t.clone()).hash()[..]);
344344
}
345+
EthereumTransaction::EIP7702(t) => {
346+
sig[0..32].copy_from_slice(&t.r[..]);
347+
sig[32..64].copy_from_slice(&t.s[..]);
348+
sig[64] = t.odd_y_parity as u8;
349+
msg.copy_from_slice(&ethereum::EIP7702TransactionMessage::from(t.clone()).hash()[..]);
350+
}
345351
}
346352
sp_io::crypto::secp256k1_ecdsa_recover(&sig, &msg)
347353
}

client/rpc/src/signer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// You should have received a copy of the GNU General Public License
1717
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1818

19-
use ethereum::TransactionV2 as EthereumTransaction;
19+
use ethereum::TransactionV3 as EthereumTransaction;
2020
use ethereum_types::{H160, H256};
2121
use jsonrpsee::types::ErrorObjectOwned;
2222
// Substrate

client/rpc/src/txpool.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
use std::{marker::PhantomData, sync::Arc};
2020

21-
use ethereum::TransactionV2 as EthereumTransaction;
21+
use ethereum::TransactionV3 as EthereumTransaction;
2222
use ethereum_types::{H160, H256, U256};
2323
use jsonrpsee::core::RpcResult;
2424
use serde::Serialize;
@@ -88,6 +88,7 @@ where
8888
EthereumTransaction::Legacy(t) => t.nonce,
8989
EthereumTransaction::EIP2930(t) => t.nonce,
9090
EthereumTransaction::EIP1559(t) => t.nonce,
91+
EthereumTransaction::EIP7702(t) => t.nonce,
9192
};
9293
let from = match public_key(txn) {
9394
Ok(pk) => H160::from(H256::from(keccak_256(&pk))),

client/storage/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub mod overrides;
2222

2323
use std::sync::Arc;
2424

25-
use ethereum::{BlockV2, ReceiptV3};
25+
use ethereum::{BlockV3, ReceiptV3};
2626
use ethereum_types::{Address, H256, U256};
2727
// Substrate
2828
use sc_client_api::{backend::Backend, StorageProvider};
@@ -91,7 +91,7 @@ where
9191
}
9292
}
9393

94-
fn current_block(&self, at: B::Hash) -> Option<BlockV2> {
94+
fn current_block(&self, at: B::Hash) -> Option<BlockV3> {
9595
match self.querier.storage_schema(at) {
9696
Some(EthereumStorageSchema::V1) => {
9797
SchemaV1StorageOverrideRef::new(&self.querier).current_block(at)

client/storage/src/overrides/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub trait StorageOverride<Block: BlockT>: Send + Sync {
5858
fn account_storage_at(&self, at: Block::Hash, address: Address, index: U256) -> Option<H256>;
5959

6060
/// Return the current ethereum block.
61-
fn current_block(&self, at: Block::Hash) -> Option<ethereum::BlockV2>;
61+
fn current_block(&self, at: Block::Hash) -> Option<ethereum::BlockV3>;
6262
/// Return the current ethereum transaction receipt.
6363
fn current_receipts(&self, at: Block::Hash) -> Option<Vec<ethereum::ReceiptV3>>;
6464
/// Return the current ethereum transaction status.

client/storage/src/overrides/runtime_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ where
8282
.ok()
8383
}
8484

85-
fn current_block(&self, block_hash: B::Hash) -> Option<ethereum::BlockV2> {
85+
fn current_block(&self, block_hash: B::Hash) -> Option<ethereum::BlockV3> {
8686
let api = self.client.runtime_api();
8787

8888
let api_version = Self::api_version(&api, block_hash)?;

0 commit comments

Comments
 (0)