mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-06 21:15:27 -05:00
feat: use custom tx in custom-node (#16054)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
committed by
GitHub
parent
1dcb3dcfc0
commit
da95e5745e
@@ -1,8 +1,11 @@
|
||||
use crate::primitives::CustomHeader;
|
||||
use reth_op::OpTransactionSigned;
|
||||
|
||||
use super::{CustomTransactionEnvelope, ExtendedOpTxEnvelope};
|
||||
|
||||
/// The Block type of this node
|
||||
pub type Block = alloy_consensus::Block<OpTransactionSigned, CustomHeader>;
|
||||
pub type Block =
|
||||
alloy_consensus::Block<ExtendedOpTxEnvelope<CustomTransactionEnvelope>, CustomHeader>;
|
||||
|
||||
/// The body type of this node
|
||||
pub type BlockBody = alloy_consensus::BlockBody<OpTransactionSigned, CustomHeader>;
|
||||
pub type BlockBody =
|
||||
alloy_consensus::BlockBody<ExtendedOpTxEnvelope<CustomTransactionEnvelope>, CustomHeader>;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use alloy_consensus::Transaction;
|
||||
use alloy_consensus::{error::ValueError, Transaction};
|
||||
use alloy_eips::{
|
||||
eip2718::{Eip2718Error, Eip2718Result, IsTyped2718},
|
||||
eip2930::AccessList,
|
||||
eip7702::SignedAuthorization,
|
||||
Decodable2718, Encodable2718, Typed2718,
|
||||
};
|
||||
use alloy_primitives::{bytes::Buf, ChainId, TxHash};
|
||||
use alloy_primitives::{bytes::Buf, ChainId, Signature, TxHash};
|
||||
use alloy_rlp::{BufMut, Decodable, Encodable, Result as RlpResult};
|
||||
use op_alloy_consensus::OpTxEnvelope;
|
||||
use op_alloy_consensus::{OpPooledTransaction, OpTxEnvelope};
|
||||
use reth_codecs::Compact;
|
||||
use reth_ethereum::primitives::{
|
||||
serde_bincode_compat::SerdeBincodeCompat, transaction::signed::RecoveryError, InMemorySize,
|
||||
@@ -15,6 +15,8 @@ use reth_ethereum::primitives::{
|
||||
};
|
||||
use revm_primitives::{Address, Bytes, TxKind, B256, U256};
|
||||
|
||||
use super::CustomTransactionEnvelope;
|
||||
|
||||
macro_rules! delegate {
|
||||
($self:expr => $tx:ident.$method:ident($($arg:expr),*)) => {
|
||||
match $self {
|
||||
@@ -39,6 +41,50 @@ pub enum ExtendedTxEnvelope<BuiltIn, Other> {
|
||||
|
||||
pub type ExtendedOpTxEnvelope<T> = ExtendedTxEnvelope<OpTxEnvelope, T>;
|
||||
|
||||
impl TryFrom<ExtendedTxEnvelope<OpTxEnvelope, CustomTransactionEnvelope>>
|
||||
for ExtendedTxEnvelope<OpPooledTransaction, CustomTransactionEnvelope>
|
||||
{
|
||||
type Error = OpTxEnvelope;
|
||||
|
||||
fn try_from(
|
||||
value: ExtendedTxEnvelope<OpTxEnvelope, CustomTransactionEnvelope>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
ExtendedTxEnvelope::BuiltIn(tx) => {
|
||||
let converted_tx: OpPooledTransaction = tx.clone().try_into().map_err(|_| tx)?;
|
||||
Ok(ExtendedTxEnvelope::BuiltIn(converted_tx))
|
||||
}
|
||||
ExtendedTxEnvelope::Other(tx) => Ok(ExtendedTxEnvelope::Other(tx)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<OpPooledTransaction> for ExtendedTxEnvelope<OpTxEnvelope, CustomTransactionEnvelope> {
|
||||
fn from(tx: OpPooledTransaction) -> Self {
|
||||
ExtendedTxEnvelope::BuiltIn(tx.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<ExtendedTxEnvelope<OpTxEnvelope, CustomTransactionEnvelope>> for OpPooledTransaction {
|
||||
type Error = ValueError<OpTxEnvelope>;
|
||||
|
||||
fn try_from(
|
||||
_tx: ExtendedTxEnvelope<OpTxEnvelope, CustomTransactionEnvelope>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
match _tx {
|
||||
ExtendedTxEnvelope::BuiltIn(inner) => inner.try_into(),
|
||||
ExtendedTxEnvelope::Other(_tx) => Err(ValueError::new(
|
||||
OpTxEnvelope::Legacy(alloy_consensus::Signed::new_unchecked(
|
||||
alloy_consensus::TxLegacy::default(),
|
||||
Signature::decode_rlp_vrs(&mut &[0u8; 65][..], |_| Ok(false)).unwrap(),
|
||||
B256::default(),
|
||||
)),
|
||||
"Cannot convert custom transaction to OpPooledTransaction",
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, T> Transaction for ExtendedTxEnvelope<B, T>
|
||||
where
|
||||
B: Transaction,
|
||||
|
||||
@@ -15,7 +15,7 @@ pub mod tx_custom;
|
||||
pub use tx_custom::*;
|
||||
|
||||
use reth_ethereum::primitives::NodePrimitives;
|
||||
use reth_op::{OpReceipt, OpTransactionSigned};
|
||||
use reth_op::OpReceipt;
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
pub struct CustomNodePrimitives;
|
||||
@@ -24,6 +24,6 @@ impl NodePrimitives for CustomNodePrimitives {
|
||||
type Block = Block;
|
||||
type BlockHeader = CustomHeader;
|
||||
type BlockBody = BlockBody;
|
||||
type SignedTx = OpTransactionSigned;
|
||||
type SignedTx = ExtendedOpTxEnvelope<CustomTransactionEnvelope>;
|
||||
type Receipt = OpReceipt;
|
||||
}
|
||||
|
||||
@@ -204,18 +204,18 @@ impl reth_codecs::alloy::transaction::Envelope for CustomTransactionEnvelope {
|
||||
}
|
||||
}
|
||||
|
||||
// impl Compact for CustomTransactionEnvelope {
|
||||
// fn to_compact<B>(&self, buf: &mut B) -> usize
|
||||
// where
|
||||
// B: alloy_rlp::bytes::BufMut + AsMut<[u8]>,
|
||||
// {
|
||||
// self.inner.tx().to_compact(buf)
|
||||
// }
|
||||
//
|
||||
// fn from_compact(buf: &[u8], len: usize) -> (Self, &[u8]) {
|
||||
// let (signature, rest) = Signature::from_compact(buf, len);
|
||||
// let (inner, buf) = <TxCustom as Compact>::from_compact(rest, len);
|
||||
// let signed = Signed::new_unhashed(inner, signature);
|
||||
// (CustomTransactionEnvelope { inner: signed }, buf)
|
||||
// }
|
||||
// }
|
||||
impl Compact for CustomTransactionEnvelope {
|
||||
fn to_compact<B>(&self, buf: &mut B) -> usize
|
||||
where
|
||||
B: alloy_rlp::bytes::BufMut + AsMut<[u8]>,
|
||||
{
|
||||
self.inner.tx().to_compact(buf)
|
||||
}
|
||||
|
||||
fn from_compact(buf: &[u8], len: usize) -> (Self, &[u8]) {
|
||||
let (signature, rest) = Signature::from_compact(buf, len);
|
||||
let (inner, buf) = <TxCustom as Compact>::from_compact(rest, len);
|
||||
let signed = Signed::new_unhashed(inner, signature);
|
||||
(CustomTransactionEnvelope { inner: signed }, buf)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user