chore(sdk): limit FillTxEnv to super trait of FullSignedTx (#12614)

This commit is contained in:
Emilia Hane
2024-11-18 22:43:26 +01:00
committed by GitHub
parent 7fb862cbde
commit 641d1288e9
7 changed files with 60 additions and 42 deletions

70
Cargo.lock generated
View File

@ -4964,9 +4964,9 @@ dependencies = [
[[package]]
name = "mockall"
version = "0.13.0"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4c28b3fb6d753d28c20e826cd46ee611fda1cf3cde03a443a974043247c065a"
checksum = "39a6bfcc6c8c7eed5ee98b9c3e33adc726054389233e201c95dab2d41a3839d2"
dependencies = [
"cfg-if",
"downcast",
@ -4978,9 +4978,9 @@ dependencies = [
[[package]]
name = "mockall_derive"
version = "0.13.0"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "341014e7f530314e9a1fdbc7400b244efea7122662c96bfa248c31da5bfb2020"
checksum = "25ca3004c2efe9011bd4e461bd8256445052b9615405b4f7ea43fc8ca5c20898"
dependencies = [
"cfg-if",
"proc-macro2",
@ -5286,9 +5286,9 @@ checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9"
[[package]]
name = "op-alloy-consensus"
version = "0.6.6"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "862db7293434837c1ca32ef509806a7b330bd24605da95438cd6e928a58b4b2c"
checksum = "72da577a88d35b893fae6467112651f26ef023434c196b2a0b3dc75bc853e0e4"
dependencies = [
"alloy-consensus",
"alloy-eips",
@ -5299,14 +5299,14 @@ dependencies = [
"derive_more 1.0.0",
"serde",
"serde_with",
"spin",
"thiserror 2.0.3",
]
[[package]]
name = "op-alloy-genesis"
version = "0.6.6"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ebd0391a3123b47e44ccca8a6f63a39ead2d7ea52e4fc132ff1297f6184314e"
checksum = "818180672dd14ca6642fb57942e1cbd602669f42b6e0222b7ea9bbcae065d67e"
dependencies = [
"alloy-consensus",
"alloy-eips",
@ -5314,13 +5314,14 @@ dependencies = [
"alloy-sol-types",
"serde",
"serde_repr",
"thiserror 2.0.3",
]
[[package]]
name = "op-alloy-network"
version = "0.6.6"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fd5d57f04f7ce1ba8be7704ba87fe7bea151a94ffc971f5a8a68b3bdf962471"
checksum = "12f82e805bad171ceae2af45efaecf8d0b50622cff3473e3c998ff1dd340de35"
dependencies = [
"alloy-consensus",
"alloy-network",
@ -5333,10 +5334,11 @@ dependencies = [
[[package]]
name = "op-alloy-protocol"
version = "0.6.6"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0220768efb59871af53e1685b90983c9f3090cdf45df3d0107348362ba7055ee"
checksum = "1803a1ac96203b8f713b1fa9b7509c46c645ca7bc22b582761a7495e999d4301"
dependencies = [
"alloc-no-stdlib",
"alloy-consensus",
"alloy-eips",
"alloy-primitives",
@ -5344,19 +5346,20 @@ dependencies = [
"alloy-serde",
"async-trait",
"brotli",
"derive_more 1.0.0",
"miniz_oxide",
"op-alloy-consensus",
"op-alloy-genesis",
"serde",
"thiserror 2.0.3",
"tracing",
"unsigned-varint",
]
[[package]]
name = "op-alloy-rpc-types"
version = "0.6.6"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03db591ad512fdc70170fcb2bff3517b64811443f9fb65d3a1a6344c60acdbf0"
checksum = "a838c125256e02e2f9da88c51e263b02a06cda7e60382fe2551a3385b516f5bb"
dependencies = [
"alloy-consensus",
"alloy-eips",
@ -5373,9 +5376,9 @@ dependencies = [
[[package]]
name = "op-alloy-rpc-types-engine"
version = "0.6.6"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd1a11a9cf2f2e8ed9ae11c93dce5990ff81ff98f17995772f567b586a864812"
checksum = "c227fcc7d81d4023363ba12406e57ebcc1c7cbb1075c38ea471ae32138d4706d"
dependencies = [
"alloy-eips",
"alloy-primitives",
@ -5387,6 +5390,7 @@ dependencies = [
"op-alloy-protocol",
"serde",
"snap",
"thiserror 2.0.3",
]
[[package]]
@ -5466,9 +5470,9 @@ dependencies = [
[[package]]
name = "parity-scale-codec"
version = "3.6.12"
version = "3.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "306800abfa29c7f16596b5970a588435e3d5b3149683d00c12b699cc19f895ee"
checksum = "8be4817d39f3272f69c59fe05d0535ae6456c2dc2fa1ba02910296c7e0a5c590"
dependencies = [
"arbitrary",
"arrayvec",
@ -5477,19 +5481,20 @@ dependencies = [
"bytes",
"impl-trait-for-tuples",
"parity-scale-codec-derive",
"rustversion",
"serde",
]
[[package]]
name = "parity-scale-codec-derive"
version = "3.6.12"
version = "3.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c"
checksum = "8781a75c6205af67215f382092b6e0a4ff3734798523e69073d4bcd294ec767b"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn 1.0.109",
"syn 2.0.87",
]
[[package]]
@ -9744,9 +9749,9 @@ dependencies = [
[[package]]
name = "rustix"
version = "0.38.40"
version = "0.38.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0"
checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6"
dependencies = [
"bitflags 2.6.0",
"errno",
@ -10057,9 +10062,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.132"
version = "1.0.133"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03"
checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377"
dependencies = [
"indexmap 2.6.0",
"itoa",
@ -10384,9 +10389,6 @@ name = "spin"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
dependencies = [
"lock_api",
]
[[package]]
name = "spki"
@ -10990,9 +10992,9 @@ dependencies = [
[[package]]
name = "tower-http"
version = "0.6.1"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8437150ab6bbc8c5f0f519e3d5ed4aa883a83dd4cdd3d1b21f9482936046cb97"
checksum = "403fa3b783d4b626a8ad51d766ab03cb6d2dbfc46b1c5d4448395e6628dc9697"
dependencies = [
"async-compression",
"base64 0.22.1",
@ -11592,9 +11594,9 @@ dependencies = [
[[package]]
name = "wasmtimer"
version = "0.4.0"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb4f099acbc1043cc752b91615b24b02d7f6fcd975bd781fed9f50b3c3e15bf7"
checksum = "0048ad49a55b9deb3953841fa1fc5858f0efbcb7a18868c899a360269fac1b23"
dependencies = [
"futures",
"js-sys",

View File

@ -7,7 +7,7 @@ use alloy_eips::{
use alloy_primitives::{keccak256, Address, Bytes, B256, B64, U256};
use alloy_rlp::Encodable;
use alloy_rpc_types_engine::{ExecutionPayloadEnvelopeV2, ExecutionPayloadV1, PayloadId};
use op_alloy_consensus::eip1559::{decode_holocene_extra_data, EIP1559ParamError};
use op_alloy_consensus::{decode_holocene_extra_data, EIP1559ParamError};
/// Re-export for use in downstream arguments.
pub use op_alloy_rpc_types_engine::OpPayloadAttributes;
use op_alloy_rpc_types_engine::{OpExecutionPayloadEnvelopeV3, OpExecutionPayloadEnvelopeV4};

View File

@ -26,6 +26,7 @@ pub use receipt::{FullReceipt, Receipt};
pub mod transaction;
pub use transaction::{
execute::FillTxEnv,
signed::{FullSignedTx, SignedTransaction},
FullTransaction, Transaction, TransactionExt,
};

View File

@ -0,0 +1,10 @@
//! Abstraction of an executable transaction.
use alloy_primitives::Address;
use revm_primitives::TxEnv;
/// Loads transaction into execution environment.
pub trait FillTxEnv {
/// Fills [`TxEnv`] with an [`Address`] and transaction.
fn fill_tx_env(&self, tx_env: &mut TxEnv, sender: Address);
}

View File

@ -1,5 +1,6 @@
//! Transaction abstraction
pub mod execute;
pub mod signed;
use core::{fmt, hash::Hash};

View File

@ -6,14 +6,19 @@ use core::hash::Hash;
use alloy_eips::eip2718::{Decodable2718, Encodable2718};
use alloy_primitives::{keccak256, Address, PrimitiveSignature, TxHash, B256};
use reth_codecs::Compact;
use revm_primitives::TxEnv;
use crate::{FullTransaction, InMemorySize, MaybeArbitrary, MaybeSerde, Transaction};
use crate::{FillTxEnv, FullTransaction, InMemorySize, MaybeArbitrary, MaybeSerde, Transaction};
/// Helper trait that unifies all behaviour required by block to support full node operations.
pub trait FullSignedTx: SignedTransaction<Transaction: FullTransaction> + Compact {}
pub trait FullSignedTx:
SignedTransaction<Transaction: FullTransaction> + FillTxEnv + Compact
{
}
impl<T> FullSignedTx for T where T: SignedTransaction<Transaction: FullTransaction> + Compact {}
impl<T> FullSignedTx for T where
T: SignedTransaction<Transaction: FullTransaction> + FillTxEnv + Compact
{
}
/// A signed transaction.
#[auto_impl::auto_impl(&, Arc)]
@ -71,9 +76,6 @@ pub trait SignedTransaction:
fn recalculate_hash(&self) -> B256 {
keccak256(self.encoded_2718())
}
/// Fills [`TxEnv`] with an [`Address`] and transaction.
fn fill_tx_env(&self, tx_env: &mut TxEnv, sender: Address);
}
/// Helper trait used in testing.

View File

@ -1360,7 +1360,9 @@ impl SignedTransaction for TransactionSigned {
let signature_hash = self.signature_hash();
recover_signer_unchecked(&self.signature, signature_hash)
}
}
impl reth_primitives_traits::FillTxEnv for TransactionSigned {
fn fill_tx_env(&self, tx_env: &mut TxEnv, sender: Address) {
tx_env.caller = sender;
match self.as_ref() {