Skip to content

Commit

Permalink
feat: support multiple transaction types in transaction conversion
Browse files Browse the repository at this point in the history
Enhance transaction input and mined transaction conversion to support various Ethereum transaction types:
- Add support for EIP-2930, EIP-1559, EIP-4844, and EIP-7702 transaction types
- Improve transaction type handling in conversion logic
- Update receipt envelope generation to match transaction types
  • Loading branch information
gabriel-aranha-cw committed Feb 21, 2025
1 parent 69d157e commit 8c084b7
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 19 deletions.
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ e2e-importer-offline:

just _log "Compare blocks of stratus and importer-offline"
pip install -r utils/compare_block/requirements.txt
python utils/compare_block/main.py http://localhost:3000 http://localhost:3001 1 --ignore timestamp --ignore type
python utils/compare_block/main.py http://localhost:3000 http://localhost:3001 1 --ignore timestamp

just _log "Killing Stratus"
killport 3000 -s sigterm
Expand Down
110 changes: 95 additions & 15 deletions src/eth/primitives/transaction_input.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
use alloy_consensus::Signed;
use alloy_consensus::Transaction;
use alloy_consensus::TxEip1559;
use alloy_consensus::TxEip2930;
use alloy_consensus::TxEip4844;
use alloy_consensus::TxEip4844Variant;
use alloy_consensus::TxEip7702;
use alloy_consensus::TxEnvelope;
use alloy_consensus::TxLegacy;
use alloy_eips::eip2718::Decodable2718;
use alloy_primitives::PrimitiveSignature;
use alloy_primitives::TxKind;
use alloy_rpc_types_eth::AccessList;
use anyhow::anyhow;
use display_json::DebugAsJson;
use ethereum_types::U256;
Expand Down Expand Up @@ -177,22 +183,96 @@ fn try_from_alloy_transaction(value: alloy_rpc_types_eth::Transaction, compute_s

impl From<TransactionInput> for AlloyTransaction {
fn from(value: TransactionInput) -> Self {
let inner = TxEnvelope::Legacy(Signed::new_unchecked(
TxLegacy {
chain_id: value.chain_id.map(Into::into),
nonce: value.nonce.into(),
gas_price: value.gas_price.into(),
gas_limit: value.gas_limit.into(),
to: match value.to {
Some(addr) => TxKind::Call(addr.into()),
None => TxKind::Create,
let signature = PrimitiveSignature::new(SignatureComponent(value.r).into(), SignatureComponent(value.s).into(), value.v.as_u64() == 1);

let tx_type = value.tx_type.map(|t| t.as_u64()).unwrap_or(0);

let inner = match tx_type {
// EIP-2930
1 => TxEnvelope::Eip2930(Signed::new_unchecked(
TxEip2930 {
chain_id: value.chain_id.unwrap_or_default().into(),
nonce: value.nonce.into(),
gas_price: value.gas_price.into(),
gas_limit: value.gas_limit.into(),
to: value.to.map(|a| TxKind::Call(a.into())).unwrap_or(TxKind::Create),
value: value.value.into(),
input: value.input.clone().into(),
access_list: AccessList::default(),
},
signature,
value.hash.into(),
)),

// EIP-1559
2 => TxEnvelope::Eip1559(Signed::new_unchecked(
TxEip1559 {
chain_id: value.chain_id.unwrap_or_default().into(),
nonce: value.nonce.into(),
max_fee_per_gas: value.gas_price.into(),
max_priority_fee_per_gas: value.gas_price.into(),
gas_limit: value.gas_limit.into(),
to: value.to.map(|a| TxKind::Call(a.into())).unwrap_or(TxKind::Create),
value: value.value.into(),
input: value.input.clone().into(),
access_list: AccessList::default(),
},
signature,
value.hash.into(),
)),

// EIP-4844
3 => TxEnvelope::Eip4844(Signed::new_unchecked(
TxEip4844Variant::TxEip4844(TxEip4844 {
chain_id: value.chain_id.unwrap_or_default().into(),
nonce: value.nonce.into(),
max_fee_per_gas: value.gas_price.into(),
max_priority_fee_per_gas: value.gas_price.into(),
gas_limit: value.gas_limit.into(),
to: value.to.map(Into::into).unwrap_or_default(),
value: value.value.into(),
input: value.input.clone().into(),
access_list: AccessList::default(),
blob_versioned_hashes: Vec::new(),
max_fee_per_blob_gas: 0u64.into(),
}),
signature,
value.hash.into(),
)),

// EIP-7702
4 => TxEnvelope::Eip7702(Signed::new_unchecked(
TxEip7702 {
chain_id: value.chain_id.unwrap_or_default().into(),
nonce: value.nonce.into(),
gas_limit: value.gas_limit.into(),
max_fee_per_gas: value.gas_price.into(),
max_priority_fee_per_gas: value.gas_price.into(),
to: value.to.map(Into::into).unwrap_or_default(),
value: value.value.into(),
input: value.input.clone().into(),
access_list: AccessList::default(),
authorization_list: Vec::new(),
},
signature,
value.hash.into(),
)),

// Legacy (default)
_ => TxEnvelope::Legacy(Signed::new_unchecked(
TxLegacy {
chain_id: value.chain_id.map(Into::into),
nonce: value.nonce.into(),
gas_price: value.gas_price.into(),
gas_limit: value.gas_limit.into(),
to: value.to.map(|a| TxKind::Call(a.into())).unwrap_or(TxKind::Create),
value: value.value.into(),
input: value.input.clone().into(),
},
value: value.value.into(),
input: value.input.clone().into(),
},
PrimitiveSignature::new(SignatureComponent(value.r).into(), SignatureComponent(value.s).into(), value.v.as_u64() == 1),
value.hash.into(),
));
signature,
value.hash.into(),
)),
};

Self {
inner,
Expand Down
6 changes: 3 additions & 3 deletions src/eth/primitives/transaction_mined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ impl From<TransactionMined> for AlloyTransaction {
fn from(value: TransactionMined) -> Self {
let signer = value.input.signer;
let gas_price = value.input.gas_price;
let tx: AlloyTransaction = value.input.into();

let tx = AlloyTransaction::from(value.input);

Self {
inner: tx.inner,
Expand All @@ -128,12 +129,11 @@ impl From<TransactionMined> for AlloyReceipt {
};

let inner = match value.input.tx_type.map(|tx| tx.as_u64()) {
Some(0) | None => ReceiptEnvelope::Legacy(receipt_with_bloom),
Some(1) => ReceiptEnvelope::Eip2930(receipt_with_bloom),
Some(2) => ReceiptEnvelope::Eip1559(receipt_with_bloom),
Some(3) => ReceiptEnvelope::Eip4844(receipt_with_bloom),
Some(4) => ReceiptEnvelope::Eip7702(receipt_with_bloom),
Some(_) => ReceiptEnvelope::Legacy(receipt_with_bloom),
_ => ReceiptEnvelope::Legacy(receipt_with_bloom),
};

Self {
Expand Down

0 comments on commit 8c084b7

Please sign in to comment.