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:
@ -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