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