mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: Merge system tx from address
This commit is contained in:
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -6648,7 +6648,6 @@ dependencies = [
|
|||||||
name = "reth"
|
name = "reth"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"alloy-chains",
|
|
||||||
"alloy-consensus",
|
"alloy-consensus",
|
||||||
"alloy-eips",
|
"alloy-eips",
|
||||||
"alloy-primitives",
|
"alloy-primitives",
|
||||||
@ -6717,7 +6716,6 @@ dependencies = [
|
|||||||
"reth-trie",
|
"reth-trie",
|
||||||
"reth-trie-db",
|
"reth-trie-db",
|
||||||
"rmp-serde",
|
"rmp-serde",
|
||||||
"rmpv",
|
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"similar-asserts",
|
"similar-asserts",
|
||||||
@ -10189,16 +10187,6 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rmpv"
|
|
||||||
version = "1.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "58450723cd9ee93273ce44a20b6ec4efe17f8ed2e3631474387bfdecf18bb2a9"
|
|
||||||
dependencies = [
|
|
||||||
"num-traits",
|
|
||||||
"rmp",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "roaring"
|
name = "roaring"
|
||||||
version = "0.10.10"
|
version = "0.10.10"
|
||||||
|
|||||||
@ -92,11 +92,9 @@ similar-asserts.workspace = true
|
|||||||
parking_lot.workspace = true
|
parking_lot.workspace = true
|
||||||
lz4_flex = "0.11.3"
|
lz4_flex = "0.11.3"
|
||||||
rmp-serde = "1.3.0"
|
rmp-serde = "1.3.0"
|
||||||
rmpv = "1.3.0"
|
|
||||||
serde = { workspace = true, features = ["derive"] }
|
serde = { workspace = true, features = ["derive"] }
|
||||||
reth-e2e-test-utils.workspace = true
|
reth-e2e-test-utils.workspace = true
|
||||||
once_cell.workspace = true
|
once_cell.workspace = true
|
||||||
alloy-chains.workspace = true
|
|
||||||
reth-ethereum-forks.workspace = true
|
reth-ethereum-forks.workspace = true
|
||||||
jsonrpsee.workspace = true
|
jsonrpsee.workspace = true
|
||||||
reth-rpc-layer.workspace = true
|
reth-rpc-layer.workspace = true
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use alloy_consensus::transaction::RlpEcdsaTx;
|
|
||||||
use alloy_consensus::{BlockBody, BlockHeader};
|
use alloy_consensus::{BlockBody, BlockHeader};
|
||||||
use alloy_eips::Typed2718;
|
use alloy_primitives::{Address, PrimitiveSignature, B256, U256};
|
||||||
use alloy_primitives::{address, Address, PrimitiveSignature, B256, U256};
|
|
||||||
use alloy_rpc_types::engine::{
|
use alloy_rpc_types::engine::{
|
||||||
ExecutionPayloadEnvelopeV3, ForkchoiceState, PayloadAttributes, PayloadStatusEnum,
|
ExecutionPayloadEnvelopeV3, ForkchoiceState, PayloadAttributes, PayloadStatusEnum,
|
||||||
};
|
};
|
||||||
@ -16,7 +14,7 @@ use reth_node_builder::EngineTypes;
|
|||||||
use reth_node_builder::NodeTypesWithEngine;
|
use reth_node_builder::NodeTypesWithEngine;
|
||||||
use reth_node_builder::{rpc::RethRpcAddOns, FullNode};
|
use reth_node_builder::{rpc::RethRpcAddOns, FullNode};
|
||||||
use reth_payload_builder::{EthBuiltPayload, EthPayloadBuilderAttributes, PayloadId};
|
use reth_payload_builder::{EthBuiltPayload, EthPayloadBuilderAttributes, PayloadId};
|
||||||
use reth_primitives::{Transaction, TransactionSigned};
|
use reth_primitives::TransactionSigned;
|
||||||
use reth_provider::{BlockHashReader, StageCheckpointReader};
|
use reth_provider::{BlockHashReader, StageCheckpointReader};
|
||||||
use reth_rpc_api::EngineApiClient;
|
use reth_rpc_api::EngineApiClient;
|
||||||
use reth_rpc_layer::AuthClientService;
|
use reth_rpc_layer::AuthClientService;
|
||||||
@ -53,23 +51,6 @@ async fn submit_payload<Engine: PayloadTypes + EngineTypes>(
|
|||||||
Ok(submission.latest_valid_hash.unwrap_or_default())
|
Ok(submission.latest_valid_hash.unwrap_or_default())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn impersonated_hash(
|
|
||||||
this: &Transaction,
|
|
||||||
sender: Address,
|
|
||||||
signature: &PrimitiveSignature,
|
|
||||||
) -> B256 {
|
|
||||||
let mut buffer = Vec::new();
|
|
||||||
let ty = this.ty();
|
|
||||||
match this {
|
|
||||||
Transaction::Legacy(tx) => tx.eip2718_encode_with_type(signature, ty, &mut buffer),
|
|
||||||
Transaction::Eip2930(tx) => tx.eip2718_encode_with_type(signature, ty, &mut buffer),
|
|
||||||
Transaction::Eip1559(tx) => tx.eip2718_encode_with_type(signature, ty, &mut buffer),
|
|
||||||
Transaction::Eip4844(tx) => tx.eip2718_encode_with_type(signature, ty, &mut buffer),
|
|
||||||
Transaction::Eip7702(tx) => tx.eip2718_encode_with_type(signature, ty, &mut buffer),
|
|
||||||
}
|
|
||||||
buffer.extend_from_slice(sender.as_ref());
|
|
||||||
B256::from_slice(alloy_primitives::utils::keccak256(&buffer).as_slice())
|
|
||||||
}
|
|
||||||
impl BlockIngest {
|
impl BlockIngest {
|
||||||
pub(crate) fn collect_block(&self, height: u64) -> Option<super::serialized::Block> {
|
pub(crate) fn collect_block(&self, height: u64) -> Option<super::serialized::Block> {
|
||||||
let f = ((height - 1) / 1_000_000) * 1_000_000;
|
let f = ((height - 1) / 1_000_000) * 1_000_000;
|
||||||
@ -126,7 +107,6 @@ impl BlockIngest {
|
|||||||
{
|
{
|
||||||
let BlockBody { transactions, ommers, withdrawals } =
|
let BlockBody { transactions, ommers, withdrawals } =
|
||||||
std::mem::take(block.body_mut());
|
std::mem::take(block.body_mut());
|
||||||
let signer = address!("2222222222222222222222222222222222222222");
|
|
||||||
let signature = PrimitiveSignature::new(
|
let signature = PrimitiveSignature::new(
|
||||||
// from anvil
|
// from anvil
|
||||||
U256::from(0x1),
|
U256::from(0x1),
|
||||||
@ -136,8 +116,11 @@ impl BlockIngest {
|
|||||||
let mut system_txs = vec![];
|
let mut system_txs = vec![];
|
||||||
for transaction in original_block.system_txs {
|
for transaction in original_block.system_txs {
|
||||||
let typed_transaction = transaction.tx.to_reth();
|
let typed_transaction = transaction.tx.to_reth();
|
||||||
let hash = impersonated_hash(&typed_transaction, signer, &signature);
|
let tx = TransactionSigned::new(
|
||||||
let tx = TransactionSigned::new(typed_transaction, signature, hash);
|
typed_transaction,
|
||||||
|
signature,
|
||||||
|
Default::default(),
|
||||||
|
);
|
||||||
system_txs.push(tx);
|
system_txs.push(tx);
|
||||||
}
|
}
|
||||||
let mut txs = vec![];
|
let mut txs = vec![];
|
||||||
|
|||||||
@ -8,7 +8,7 @@ use alloc::{boxed::Box, sync::Arc, vec::Vec};
|
|||||||
use alloy_consensus::{Header, Transaction};
|
use alloy_consensus::{Header, Transaction};
|
||||||
use alloy_eips::{eip4895::Withdrawals, eip6110, eip7685::Requests};
|
use alloy_eips::{eip4895::Withdrawals, eip6110, eip7685::Requests};
|
||||||
use alloy_evm::FromRecoveredTx;
|
use alloy_evm::FromRecoveredTx;
|
||||||
use alloy_primitives::{address, Address, B256};
|
use alloy_primitives::{Address, B256};
|
||||||
use reth_chainspec::{ChainSpec, EthereumHardfork, EthereumHardforks, MAINNET};
|
use reth_chainspec::{ChainSpec, EthereumHardfork, EthereumHardforks, MAINNET};
|
||||||
use reth_evm::{
|
use reth_evm::{
|
||||||
execute::{
|
execute::{
|
||||||
@ -23,7 +23,7 @@ use reth_execution_types::BlockExecutionResult;
|
|||||||
use reth_primitives::{
|
use reth_primitives::{
|
||||||
EthPrimitives, Receipt, Recovered, RecoveredBlock, SealedBlock, TransactionSigned,
|
EthPrimitives, Receipt, Recovered, RecoveredBlock, SealedBlock, TransactionSigned,
|
||||||
};
|
};
|
||||||
use reth_primitives_traits::NodePrimitives;
|
use reth_primitives_traits::{transaction::signed::HL_SYSTEM_TX_FROM_ADDR, NodePrimitives};
|
||||||
use reth_revm::{context_interface::result::ResultAndState, db::State, DatabaseCommit};
|
use reth_revm::{context_interface::result::ResultAndState, db::State, DatabaseCommit};
|
||||||
|
|
||||||
/// Factory for [`EthExecutionStrategy`].
|
/// Factory for [`EthExecutionStrategy`].
|
||||||
@ -190,10 +190,8 @@ where
|
|||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
const HL_SYSETM_TX_FROM_ADDR: Address = address!("2222222222222222222222222222222222222222");
|
|
||||||
|
|
||||||
let hash = tx.hash();
|
let hash = tx.hash();
|
||||||
let is_system_transaction = tx.signer() == HL_SYSETM_TX_FROM_ADDR;
|
let is_system_transaction = tx.signer() == HL_SYSTEM_TX_FROM_ADDR;
|
||||||
|
|
||||||
// Execute transaction.
|
// Execute transaction.
|
||||||
let result_and_state =
|
let result_and_state =
|
||||||
|
|||||||
@ -12,8 +12,7 @@ use alloy_eips::{
|
|||||||
};
|
};
|
||||||
use alloy_evm::FromRecoveredTx;
|
use alloy_evm::FromRecoveredTx;
|
||||||
use alloy_primitives::{
|
use alloy_primitives::{
|
||||||
address, keccak256, Address, Bytes, ChainId, PrimitiveSignature as Signature, TxHash, TxKind,
|
keccak256, Address, Bytes, ChainId, PrimitiveSignature as Signature, TxHash, TxKind, B256, U256,
|
||||||
B256, U256,
|
|
||||||
};
|
};
|
||||||
use alloy_rlp::{Decodable, Encodable};
|
use alloy_rlp::{Decodable, Encodable};
|
||||||
use core::hash::{Hash, Hasher};
|
use core::hash::{Hash, Hasher};
|
||||||
@ -22,7 +21,7 @@ use reth_primitives_traits::{
|
|||||||
sync::OnceLock,
|
sync::OnceLock,
|
||||||
transaction::{
|
transaction::{
|
||||||
error::TransactionConversionError,
|
error::TransactionConversionError,
|
||||||
signed::{is_impersonated_tx, RecoveryError},
|
signed::{is_impersonated_tx, RecoveryError, HL_SYSTEM_TX_FROM_ADDR},
|
||||||
},
|
},
|
||||||
InMemorySize, SignedTransaction,
|
InMemorySize, SignedTransaction,
|
||||||
};
|
};
|
||||||
@ -836,8 +835,6 @@ impl SignedTransaction for TransactionSigned {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn recover_signer(&self) -> Result<Address, RecoveryError> {
|
fn recover_signer(&self) -> Result<Address, RecoveryError> {
|
||||||
const HL_SYSTEM_TX_FROM_ADDR: Address =
|
|
||||||
address!("2222222222222222222222222222222222222222");
|
|
||||||
let signature = self.signature();
|
let signature = self.signature();
|
||||||
if is_impersonated_tx(signature, self.gas_price()) {
|
if is_impersonated_tx(signature, self.gas_price()) {
|
||||||
return Ok(HL_SYSTEM_TX_FROM_ADDR);
|
return Ok(HL_SYSTEM_TX_FROM_ADDR);
|
||||||
|
|||||||
@ -12,10 +12,10 @@ pub mod cancun;
|
|||||||
pub mod prague;
|
pub mod prague;
|
||||||
pub mod shanghai;
|
pub mod shanghai;
|
||||||
|
|
||||||
use alloy_primitives::{address, Address};
|
|
||||||
use alloy_rpc_types_engine::{ExecutionData, PayloadError};
|
use alloy_rpc_types_engine::{ExecutionData, PayloadError};
|
||||||
use reth_chainspec::EthereumHardforks;
|
use reth_chainspec::EthereumHardforks;
|
||||||
use reth_primitives::SealedBlock;
|
use reth_primitives::SealedBlock;
|
||||||
|
use reth_primitives_traits::transaction::signed::HL_SYSTEM_TX_FROM_ADDR;
|
||||||
use reth_primitives_traits::{Block, SignedTransaction};
|
use reth_primitives_traits::{Block, SignedTransaction};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -90,8 +90,6 @@ impl<ChainSpec: EthereumHardforks> ExecutionPayloadValidator<ChainSpec> {
|
|||||||
let expected_hash = payload.block_hash();
|
let expected_hash = payload.block_hash();
|
||||||
|
|
||||||
// First parse the block
|
// First parse the block
|
||||||
const HL_SYSTEM_TX_FROM_ADDR: Address =
|
|
||||||
address!("2222222222222222222222222222222222222222");
|
|
||||||
let transactions = payload.as_v1().transactions.clone();
|
let transactions = payload.as_v1().transactions.clone();
|
||||||
let (normal, system) = transactions.into_iter().partition(|tx| {
|
let (normal, system) = transactions.into_iter().partition(|tx| {
|
||||||
let tx = T::decode_2718(&mut tx.iter().as_slice());
|
let tx = T::decode_2718(&mut tx.iter().as_slice());
|
||||||
@ -107,8 +105,7 @@ impl<ChainSpec: EthereumHardforks> ExecutionPayloadValidator<ChainSpec> {
|
|||||||
block.body.transactions = system
|
block.body.transactions = system
|
||||||
.iter()
|
.iter()
|
||||||
.map(|tx| {
|
.map(|tx| {
|
||||||
T::decode_2718(&mut tx.iter().as_slice())
|
T::decode_2718(&mut tx.iter().as_slice()).expect("transaction should be valid")
|
||||||
.expect("transaction should be valid")
|
|
||||||
})
|
})
|
||||||
.chain(block.body.transactions)
|
.chain(block.body.transactions)
|
||||||
.collect();
|
.collect();
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
//! Block body abstraction.
|
//! Block body abstraction.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
transaction::signed::RecoveryError, BlockHeader, FullSignedTx, InMemorySize, MaybeSerde,
|
transaction::signed::{RecoveryError, HL_SYSTEM_TX_FROM_ADDR},
|
||||||
MaybeSerdeBincodeCompat, SignedTransaction,
|
BlockHeader, FullSignedTx, InMemorySize, MaybeSerde, MaybeSerdeBincodeCompat,
|
||||||
|
SignedTransaction,
|
||||||
};
|
};
|
||||||
use alloc::{fmt, vec::Vec};
|
use alloc::{fmt, vec::Vec};
|
||||||
use alloy_consensus::{Transaction, Typed2718};
|
use alloy_consensus::{Transaction, Typed2718};
|
||||||
use alloy_eips::{eip2718::Encodable2718, eip4895::Withdrawals};
|
use alloy_eips::{eip2718::Encodable2718, eip4895::Withdrawals};
|
||||||
use alloy_primitives::{Address, Bytes, B256};
|
use alloy_primitives::{Address, Bytes, B256};
|
||||||
use revm_primitives::address;
|
|
||||||
|
|
||||||
/// Helper trait that unifies all behaviour required by transaction to support full node operations.
|
/// Helper trait that unifies all behaviour required by transaction to support full node operations.
|
||||||
pub trait FullBlockBody: BlockBody<Transaction: FullSignedTx> + MaybeSerdeBincodeCompat {}
|
pub trait FullBlockBody: BlockBody<Transaction: FullSignedTx> + MaybeSerdeBincodeCompat {}
|
||||||
@ -82,12 +82,10 @@ pub trait BlockBody:
|
|||||||
|
|
||||||
/// Calculate the transaction root for the block body.
|
/// Calculate the transaction root for the block body.
|
||||||
fn calculate_tx_root(&self) -> B256 {
|
fn calculate_tx_root(&self) -> B256 {
|
||||||
const HL_SYSETM_TX_FROM_ADDR: Address =
|
|
||||||
address!("2222222222222222222222222222222222222222");
|
|
||||||
let transactions: Vec<Self::Transaction> = self
|
let transactions: Vec<Self::Transaction> = self
|
||||||
.transactions()
|
.transactions()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|tx| !matches!(tx.recover_signer(), Ok(address) if HL_SYSETM_TX_FROM_ADDR == address))
|
.filter(|tx| !matches!(tx.recover_signer(), Ok(address) if HL_SYSTEM_TX_FROM_ADDR == address))
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
alloy_consensus::proofs::calculate_transaction_root(transactions.as_slice())
|
alloy_consensus::proofs::calculate_transaction_root(transactions.as_slice())
|
||||||
|
|||||||
@ -18,6 +18,9 @@ use revm_primitives::{address, U256};
|
|||||||
pub trait FullSignedTx: SignedTransaction + MaybeCompact + MaybeSerdeBincodeCompat {}
|
pub trait FullSignedTx: SignedTransaction + MaybeCompact + MaybeSerdeBincodeCompat {}
|
||||||
impl<T> FullSignedTx for T where T: SignedTransaction + MaybeCompact + MaybeSerdeBincodeCompat {}
|
impl<T> FullSignedTx for T where T: SignedTransaction + MaybeCompact + MaybeSerdeBincodeCompat {}
|
||||||
|
|
||||||
|
/// Hyperliquid system transaction from address.
|
||||||
|
pub const HL_SYSTEM_TX_FROM_ADDR: Address = address!("2222222222222222222222222222222222222222");
|
||||||
|
|
||||||
/// Check if the transaction is impersonated.
|
/// Check if the transaction is impersonated.
|
||||||
/// Signature part is introduced in block_ingest, while the gas_price is trait of hyperliquid system transactions.
|
/// Signature part is introduced in block_ingest, while the gas_price is trait of hyperliquid system transactions.
|
||||||
pub fn is_impersonated_tx(signature: &Signature, gas_price: Option<u128>) -> bool {
|
pub fn is_impersonated_tx(signature: &Signature, gas_price: Option<u128>) -> bool {
|
||||||
@ -178,7 +181,7 @@ impl SignedTransaction for PooledTransaction {
|
|||||||
) -> Result<Address, RecoveryError> {
|
) -> Result<Address, RecoveryError> {
|
||||||
let signature = self.signature();
|
let signature = self.signature();
|
||||||
if is_impersonated_tx(signature, self.gas_price()) {
|
if is_impersonated_tx(signature, self.gas_price()) {
|
||||||
return Ok(address!("2222222222222222222222222222222222222222"));
|
return Ok(HL_SYSTEM_TX_FROM_ADDR);
|
||||||
}
|
}
|
||||||
match self {
|
match self {
|
||||||
Self::Legacy(tx) => tx.tx().encode_for_signing(buf),
|
Self::Legacy(tx) => tx.tx().encode_for_signing(buf),
|
||||||
|
|||||||
Reference in New Issue
Block a user