@@ -12,6 +12,10 @@ use reth_codecs::{
1212 txtype:: COMPACT_EXTENDED_IDENTIFIER_FLAG ,
1313 Compact ,
1414} ;
15+ use reth_db_api:: {
16+ table:: { Compress , Decompress } ,
17+ DatabaseError ,
18+ } ;
1519use reth_primitives_traits:: { InMemorySize , SignedTransaction } ;
1620use std:: vec:: Vec ;
1721
@@ -21,7 +25,17 @@ pub const EVNODE_TX_TYPE_ID: u8 = 0x76;
2125pub const EVNODE_SPONSOR_DOMAIN : u8 = 0x78 ;
2226
2327/// Single call entry in an EvNode transaction.
24- #[ derive( Clone , Debug , PartialEq , Eq , Hash , RlpEncodable , RlpDecodable , serde:: Serialize , serde:: Deserialize ) ]
28+ #[ derive(
29+ Clone ,
30+ Debug ,
31+ PartialEq ,
32+ Eq ,
33+ Hash ,
34+ RlpEncodable ,
35+ RlpDecodable ,
36+ serde:: Serialize ,
37+ serde:: Deserialize ,
38+ ) ]
2539pub struct Call {
2640 /// Destination (CALL or CREATE).
2741 pub to : TxKind ,
@@ -82,7 +96,10 @@ impl EvNodeTransaction {
8296 }
8397
8498 /// Recovers the executor address from the provided signature.
85- pub fn recover_executor ( & self , signature : & Signature ) -> Result < Address , alloy_primitives:: SignatureError > {
99+ pub fn recover_executor (
100+ & self ,
101+ signature : & Signature ,
102+ ) -> Result < Address , alloy_primitives:: SignatureError > {
86103 signature. recover_address_from_prehash ( & self . executor_signing_hash ( ) )
87104 }
88105
@@ -101,14 +118,25 @@ impl EvNodeTransaction {
101118
102119 fn encoded_payload ( & self , fee_payer_signature : Option < & Signature > ) -> Vec < u8 > {
103120 let payload_len = self . payload_fields_length ( fee_payer_signature) ;
104- let mut out = Vec :: with_capacity ( Header { list : true , payload_length : payload_len } . length_with_payload ( ) ) ;
105- Header { list : true , payload_length : payload_len } . encode ( & mut out) ;
121+ let mut out = Vec :: with_capacity (
122+ Header {
123+ list : true ,
124+ payload_length : payload_len,
125+ }
126+ . length_with_payload ( ) ,
127+ ) ;
128+ Header {
129+ list : true ,
130+ payload_length : payload_len,
131+ }
132+ . encode ( & mut out) ;
106133 self . encode_payload_fields ( & mut out, fee_payer_signature) ;
107134 out
108135 }
109136
110137 fn encoded_payload_with_executor ( & self , executor : Address ) -> Vec < u8 > {
111- let mut out = Vec :: with_capacity ( self . payload_fields_length ( self . fee_payer_signature . as_ref ( ) ) + 32 ) ;
138+ let mut out =
139+ Vec :: with_capacity ( self . payload_fields_length ( self . fee_payer_signature . as_ref ( ) ) + 32 ) ;
112140 out. extend_from_slice ( executor. as_slice ( ) ) ;
113141 self . encode_payload_fields ( & mut out, self . fee_payer_signature . as_ref ( ) ) ;
114142 out
@@ -139,7 +167,7 @@ impl EvNodeTransaction {
139167
140168impl Transaction for EvNodeTransaction {
141169 fn chain_id ( & self ) -> Option < alloy_primitives:: ChainId > {
142- Some ( self . chain_id . into ( ) )
170+ Some ( self . chain_id )
143171 }
144172
145173 fn nonce ( & self ) -> u64 {
@@ -189,7 +217,9 @@ impl Transaction for EvNodeTransaction {
189217 }
190218
191219 fn kind ( & self ) -> TxKind {
192- self . first_call ( ) . map ( |call| call. to ) . unwrap_or ( TxKind :: Create )
220+ self . first_call ( )
221+ . map ( |call| call. to )
222+ . unwrap_or ( TxKind :: Create )
193223 }
194224
195225 fn is_create ( & self ) -> bool {
@@ -228,18 +258,26 @@ impl alloy_eips::Typed2718 for EvNodeTransaction {
228258
229259impl SignableTransaction < Signature > for EvNodeTransaction {
230260 fn set_chain_id ( & mut self , chain_id : alloy_primitives:: ChainId ) {
231- self . chain_id = chain_id. into ( ) ;
261+ self . chain_id = chain_id;
232262 }
233263
234264 fn encode_for_signing ( & self , out : & mut dyn BufMut ) {
235265 out. put_u8 ( EVNODE_TX_TYPE_ID ) ;
236266 let payload_len = self . payload_fields_length ( None ) ;
237- Header { list : true , payload_length : payload_len } . encode ( out) ;
267+ Header {
268+ list : true ,
269+ payload_length : payload_len,
270+ }
271+ . encode ( out) ;
238272 self . encode_payload_fields ( out, None ) ;
239273 }
240274
241275 fn payload_len_for_signature ( & self ) -> usize {
242- 1 + Header { list : true , payload_length : self . payload_fields_length ( None ) } . length_with_payload ( )
276+ 1 + Header {
277+ list : true ,
278+ payload_length : self . payload_fields_length ( None ) ,
279+ }
280+ . length_with_payload ( )
243281 }
244282}
245283
@@ -272,7 +310,11 @@ impl RlpEcdsaDecodableTx for EvNodeTransaction {
272310
273311impl Encodable for EvNodeTransaction {
274312 fn length ( & self ) -> usize {
275- Header { list : true , payload_length : self . rlp_encoded_fields_length ( ) } . length_with_payload ( )
313+ Header {
314+ list : true ,
315+ payload_length : self . rlp_encoded_fields_length ( ) ,
316+ }
317+ . length_with_payload ( )
276318 }
277319
278320 fn encode ( & self , out : & mut dyn BufMut ) {
@@ -418,8 +460,9 @@ impl FromTxCompact for EvTxEnvelope {
418460 {
419461 match tx_type {
420462 EvTxType :: Ethereum ( inner) => {
421- let ( tx, buf) =
422- reth_ethereum_primitives:: TransactionSigned :: from_tx_compact ( buf, inner, signature) ;
463+ let ( tx, buf) = reth_ethereum_primitives:: TransactionSigned :: from_tx_compact (
464+ buf, inner, signature,
465+ ) ;
423466 ( Self :: Ethereum ( tx) , buf)
424467 }
425468 EvTxType :: EvNode => {
@@ -459,6 +502,21 @@ impl SignedTransaction for EvTxEnvelope {}
459502
460503impl reth_primitives_traits:: serde_bincode_compat:: RlpBincode for EvTxEnvelope { }
461504
505+ impl Compress for EvTxEnvelope {
506+ type Compressed = Vec < u8 > ;
507+
508+ fn compress_to_buf < B : bytes:: BufMut + AsMut < [ u8 ] > > ( & self , buf : & mut B ) {
509+ let _ = Compact :: to_compact ( self , buf) ;
510+ }
511+ }
512+
513+ impl Decompress for EvTxEnvelope {
514+ fn decompress ( value : & [ u8 ] ) -> Result < Self , DatabaseError > {
515+ let ( obj, _) = Compact :: from_compact ( value, value. len ( ) ) ;
516+ Ok ( obj)
517+ }
518+ }
519+
462520fn optional_signature_length ( value : Option < & Signature > ) -> usize {
463521 match value {
464522 Some ( sig) => sig. as_bytes ( ) . as_slice ( ) . length ( ) ,
@@ -478,7 +536,9 @@ fn decode_optional_signature(buf: &mut &[u8]) -> alloy_rlp::Result<Option<Signat
478536 if bytes. is_empty ( ) {
479537 return Ok ( None ) ;
480538 }
481- let raw: [ u8 ; 65 ] = bytes. try_into ( ) . map_err ( |_| alloy_rlp:: Error :: UnexpectedLength ) ?;
539+ let raw: [ u8 ; 65 ] = bytes
540+ . try_into ( )
541+ . map_err ( |_| alloy_rlp:: Error :: UnexpectedLength ) ?;
482542 Signature :: from_raw_array ( & raw )
483543 . map ( Some )
484544 . map_err ( |_| alloy_rlp:: Error :: Custom ( "invalid signature bytes" ) )
@@ -502,7 +562,11 @@ mod tests {
502562 max_priority_fee_per_gas : 1 ,
503563 max_fee_per_gas : 2 ,
504564 gas_limit : 30_000 ,
505- calls : vec ! [ Call { to: TxKind :: Create , value: U256 :: from( 1 ) , input: Bytes :: new( ) } ] ,
565+ calls : vec ! [ Call {
566+ to: TxKind :: Create ,
567+ value: U256 :: from( 1 ) ,
568+ input: Bytes :: new( ) ,
569+ } ] ,
506570 access_list : AccessList :: default ( ) ,
507571 fee_payer_signature : None ,
508572 }
0 commit comments