From 99f8c4026b4430078d9d60c232cff391b3b2cbb5 Mon Sep 17 00:00:00 2001 From: bear Date: Tue, 12 Dec 2023 15:38:36 +0800 Subject: [PATCH] Ensure the actual executed proof base size is the same as the estimate approach --- frame/ethereum/src/lib.rs | 2 +- primitives/ethereum/src/lib.rs | 30 ++++++++---------------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/frame/ethereum/src/lib.rs b/frame/ethereum/src/lib.rs index e9aa870f11..4ce3303887 100644 --- a/frame/ethereum/src/lib.rs +++ b/frame/ethereum/src/lib.rs @@ -365,7 +365,7 @@ impl Pallet { ) { weight_limit if weight_limit.proof_size() > 0 => ( Some(weight_limit), - Some(transaction_data.proof_size_base_cost.unwrap_or_default()), + Some(transaction_data.proof_size_base_cost()), ), _ => (None, None), } diff --git a/primitives/ethereum/src/lib.rs b/primitives/ethereum/src/lib.rs index 2aeee6cbff..765ace3000 100644 --- a/primitives/ethereum/src/lib.rs +++ b/primitives/ethereum/src/lib.rs @@ -47,7 +47,6 @@ pub struct TransactionData { pub value: U256, pub chain_id: Option, pub access_list: Vec<(H160, Vec)>, - pub proof_size_base_cost: Option, } impl TransactionData { @@ -64,7 +63,7 @@ impl TransactionData { chain_id: Option, access_list: Vec<(H160, Vec)>, ) -> Self { - let mut transaction_data = Self { + Self { action, input, nonce, @@ -75,20 +74,19 @@ impl TransactionData { value, chain_id, access_list, - proof_size_base_cost: None, - }; - let proof_size_base_cost = transaction_data - .encode() + } + } + + // The transact call wrapped in the extrinsic is part of the PoV, record this as a base cost for the size of the proof. + pub fn proof_size_base_cost(&self) -> u64 { + self.encode() .len() // signature .saturating_add(65) // pallet index .saturating_add(1) // call index - .saturating_add(1) as u64; - transaction_data.proof_size_base_cost = Some(proof_size_base_cost); - - transaction_data + .saturating_add(1) as u64 } } @@ -115,15 +113,6 @@ impl From for CheckEvmTransactionInput { impl From<&Transaction> for TransactionData { fn from(t: &Transaction) -> Self { - // The call wrapped in the extrinsic is part of the PoV, record this as a base cost for the size of the proof. - let proof_size_base_cost = t - .encode() - .len() - // pallet index - .saturating_add(1) - // call index - .saturating_add(1) as u64; - match t { Transaction::Legacy(t) => TransactionData { action: t.action, @@ -136,7 +125,6 @@ impl From<&Transaction> for TransactionData { value: t.value, chain_id: t.signature.chain_id(), access_list: Vec::new(), - proof_size_base_cost: Some(proof_size_base_cost), }, Transaction::EIP2930(t) => TransactionData { action: t.action, @@ -153,7 +141,6 @@ impl From<&Transaction> for TransactionData { .iter() .map(|d| (d.address, d.storage_keys.clone())) .collect(), - proof_size_base_cost: Some(proof_size_base_cost), }, Transaction::EIP1559(t) => TransactionData { action: t.action, @@ -170,7 +157,6 @@ impl From<&Transaction> for TransactionData { .iter() .map(|d| (d.address, d.storage_keys.clone())) .collect(), - proof_size_base_cost: Some(proof_size_base_cost), }, } }