Skip to content

Commit

Permalink
feat(eip4844): add EIP4844 to the TxType enum (#3953)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored Jul 27, 2023
1 parent 465f0dc commit 369b9a7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion crates/primitives/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ impl Decodable for ReceiptWithBloom {
} else if receipt_type == 0x02 {
buf.advance(1);
Self::decode_receipt(buf, TxType::EIP1559)
} else if receipt_type == 0x03 {
buf.advance(1);
Self::decode_receipt(buf, TxType::EIP4844)
} else {
Err(reth_rlp::DecodeError::Custom("invalid receipt type"))
}
Expand Down Expand Up @@ -251,6 +254,9 @@ impl<'a> ReceiptWithBloomEncoder<'a> {
TxType::EIP1559 => {
out.put_u8(0x02);
}
TxType::EIP4844 => {
out.put_u8(0x03);
}
_ => unreachable!("legacy handled; qed."),
}
out.put_slice(payload.as_ref());
Expand All @@ -270,7 +276,7 @@ impl<'a> Encodable for ReceiptWithBloomEncoder<'a> {
fn length(&self) -> usize {
let mut payload_len = self.receipt_length();
// account for eip-2718 type prefix and set the list
if matches!(self.receipt.tx_type, TxType::EIP1559 | TxType::EIP2930) {
if matches!(self.receipt.tx_type, TxType::EIP1559 | TxType::EIP2930 | TxType::EIP4844) {
payload_len += 1;
// we include a string header for typed receipts, so include the length here
payload_len += length_of_length(payload_len);
Expand Down
7 changes: 6 additions & 1 deletion crates/primitives/src/transaction/tx_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub enum TxType {
EIP2930 = 1_isize,
/// Transaction with Priority fee
EIP1559 = 2_isize,
/// Shard Blob Transactions - EIP-4844
EIP4844 = 3_isize,
}

impl From<TxType> for u8 {
Expand All @@ -35,6 +37,7 @@ impl From<TxType> for u8 {
TxType::Legacy => LEGACY_TX_TYPE_ID,
TxType::EIP2930 => EIP2930_TX_TYPE_ID,
TxType::EIP1559 => EIP1559_TX_TYPE_ID,
TxType::EIP4844 => EIP4844_TX_TYPE_ID,
}
}
}
Expand All @@ -54,6 +57,7 @@ impl Compact for TxType {
TxType::Legacy => 0,
TxType::EIP2930 => 1,
TxType::EIP1559 => 2,
TxType::EIP4844 => 3,
}
}

Expand All @@ -62,7 +66,8 @@ impl Compact for TxType {
match identifier {
0 => TxType::Legacy,
1 => TxType::EIP2930,
_ => TxType::EIP1559,
2 => TxType::EIP1559,
_ => TxType::EIP4844,
},
buf,
)
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-types/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Transaction {
let (gas_price, max_fee_per_gas) = match signed_tx.tx_type() {
TxType::Legacy => (Some(U128::from(signed_tx.max_fee_per_gas())), None),
TxType::EIP2930 => (Some(U128::from(signed_tx.max_fee_per_gas())), None),
TxType::EIP1559 => {
TxType::EIP1559 | TxType::EIP4844 => {
// the gas price field for EIP1559 is set to `min(tip, gasFeeCap - baseFee) +
// baseFee`
let gas_price = base_fee
Expand Down

0 comments on commit 369b9a7

Please sign in to comment.