refactor: Merge system tx from address

This commit is contained in:
sprites0
2025-03-01 17:10:15 +00:00
parent 7a81e16702
commit 5d779a66a0
8 changed files with 22 additions and 60 deletions

View File

@ -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())

View File

@ -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),