Skip to content

Commit

Permalink
Code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed Aug 12, 2024
1 parent 40af527 commit 33b7cd6
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 82 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ sp-session = { git = "https://github.com/paritytech/polkadot-sdk", branch = "sta
sp-state-machine = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
sp-storage = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
sp-trie = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
sp-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
sp-transaction-pool = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
sp-trie = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
sp-version = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
sp-weights = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
# Substrate FRAME
Expand Down
6 changes: 3 additions & 3 deletions frame/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ frame-support = { workspace = true }
frame-system = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
# Cumulus
cumulus-primitives-storage-weight-reclaim = { workspace = true }
# Frontier
fp-consensus = { workspace = true }
fp-ethereum = { workspace = true }
fp-evm = { workspace = true }
fp-rpc = { workspace = true }
fp-storage = { workspace = true }
pallet-evm = { workspace = true }
cumulus-primitives-storage-weight-reclaim = { workspace = true }
log = { workspace = true }

[dev-dependencies]
hex = { workspace = true }
Expand All @@ -51,9 +51,9 @@ std = [
"evm/std",
"ethereum-types/std",
"rlp/std",
"log/std",
"scale-codec/std",
"scale-info/std",
# Cumulus
"cumulus-primitives-storage-weight-reclaim/std",
# Substrate
"frame-support/std",
Expand Down
11 changes: 5 additions & 6 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,11 @@ impl<T: Config> Pallet<T> {
transaction_data.gas_limit.unique_saturated_into(),
true,
);
let proof_size_pre_execution = cumulus_primitives_storage_weight_reclaim::get_proof_size();
Some(TransactionPov::new(
weight_limit,
extrinsics_len,
proof_size_pre_execution,
))
cumulus_primitives_storage_weight_reclaim::get_proof_size().map(
|proof_size_pre_execution| {
TransactionPov::new(weight_limit, extrinsics_len, proof_size_pre_execution)
},
)
}

fn recover_signer(transaction: &Transaction) -> Option<H160> {
Expand Down
1 change: 0 additions & 1 deletion frame/ethereum/src/tests/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ fn validated_transaction_apply_zero_gas_price_works() {
});
}


#[test]
fn proof_size_base_cost_should_keep_the_same_in_execution_and_estimate() {
let (pairs, mut ext) = new_test_ext(1);
Expand Down
3 changes: 2 additions & 1 deletion frame/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ hex = { workspace = true }
pallet-balances = { workspace = true, features = ["default", "insecure_zero_ed"] }
pallet-evm-precompile-simple = { workspace = true, features = ["default"] }
pallet-timestamp = { workspace = true, features = ["default"] }
sp-state-machine = { workspace = true }
sp-trie = { workspace = true, features = ["default"] }
# Cumulus
cumulus-primitives-storage-weight-reclaim = { workspace = true }
sp-state-machine = { workspace = true }

[features]
default = ["std"]
Expand Down
6 changes: 3 additions & 3 deletions frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,6 @@ pub mod pallet {

#[pallet::error]
pub enum Error<T> {
/// Proof size limit is too low
ProofLimitTooLow,
/// Not enough balance to perform action
BalanceLow,
/// Calculating total fee overflowed
Expand All @@ -503,14 +501,15 @@ pub mod pallet {
Reentrancy,
/// EIP-3607,
TransactionMustComeFromEOA,
/// Proof size limit is too low
ProofLimitTooLow,
/// Undefined error.
Undefined,
}

impl<T> From<TransactionValidationError> for Error<T> {
fn from(validation_error: TransactionValidationError) -> Self {
match validation_error {
TransactionValidationError::ProofLimitTooLow => Error::<T>::ProofLimitTooLow,
TransactionValidationError::GasLimitTooLow => Error::<T>::GasLimitTooLow,
TransactionValidationError::GasLimitTooHigh => Error::<T>::GasLimitTooHigh,
TransactionValidationError::BalanceTooLow => Error::<T>::BalanceLow,
Expand All @@ -521,6 +520,7 @@ pub mod pallet {
TransactionValidationError::InvalidFeeInput => Error::<T>::GasPriceTooLow,
TransactionValidationError::InvalidChainId => Error::<T>::InvalidChainId,
TransactionValidationError::InvalidSignature => Error::<T>::InvalidSignature,
TransactionValidationError::ProofLimitTooLow => Error::<T>::ProofLimitTooLow,
TransactionValidationError::UnknownError => Error::<T>::Undefined,
}
}
Expand Down
2 changes: 1 addition & 1 deletion frame/evm/src/runner/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ where
standard: opcode_used_gas.into(),
effective: used_gas,
},
weight_info: transaction_pov.map(|pov| WeightInfo::from_transaction_pov(pov)),
weight_info: transaction_pov.map(WeightInfo::from_transaction_pov),
logs: state.substate.logs,
})
}
Expand Down
9 changes: 6 additions & 3 deletions frame/evm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ fn proof_size_reach_limit() {
None,
None,
Vec::new(),
true, // transactional
true, // transactional
false, // must be validated
Some(transaction_pov),
&<Test as Config>::config().clone(),
Expand All @@ -853,7 +853,7 @@ fn proof_size_reach_limit() {
None,
None,
Vec::new(),
true, // transactional
true, // transactional
false, // must be validated
Some(transaction_pov),
&<Test as Config>::config().clone(),
Expand Down Expand Up @@ -889,6 +889,9 @@ fn proof_size_reach_limit_nonce_increase() {
)
.expect("create contract failed");
assert_eq!(res.exit_reason, ExitReason::Error(ExitError::OutOfGas));
assert_eq!(EVM::account_basic(&H160::default()).0.nonce, original_nonce + 1);
assert_eq!(
EVM::account_basic(&H160::default()).0.nonce,
original_nonce + 1
);
});
}
6 changes: 4 additions & 2 deletions primitives/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ num_enum = { workspace = true, default-features = false }
scale-codec = { package = "parity-scale-codec", workspace = true }
scale-info = { workspace = true }
serde = { workspace = true, optional = true }
cumulus-primitives-storage-weight-reclaim = { workspace = true }
# Substrate
frame-support = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
# Cumulus
cumulus-primitives-storage-weight-reclaim = { workspace = true }

[features]
default = ["std"]
Expand All @@ -33,8 +34,9 @@ std = [
# Substrate
"frame-support/std",
"sp-core/std",
"cumulus-primitives-storage-weight-reclaim/std",
"sp-runtime/std",
# Cumulus
"cumulus-primitives-storage-weight-reclaim/std",
]
serde = [
"dep:serde",
Expand Down
23 changes: 4 additions & 19 deletions primitives/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,20 @@ pub struct Vicinity {

/// `System::Account` 16(hash) + 20 (key) + 60 (AccountInfo::max_encoded_len)
pub const ACCOUNT_BASIC_PROOF_SIZE: u64 = 96;
/// `AccountCodesMetadata` read, temptatively 16 (hash) + 20 (key) + 40 (CodeMetadata).
pub const ACCOUNT_CODES_METADATA_PROOF_SIZE: u64 = 76;
/// 16 (hash1) + 20 (key1) + 16 (hash2) + 32 (key2) + 32 (value)
pub const ACCOUNT_STORAGE_PROOF_SIZE: u64 = 116;
/// Fixed trie 32 byte hash.
pub const WRITE_PROOF_SIZE: u64 = 32;
/// Account basic proof size + 5 bytes max of `decode_len` call.
pub const IS_EMPTY_CHECK_PROOF_SIZE: u64 = 93;


#[derive(Clone, Copy, Eq, PartialEq, Debug, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TransactionPov {
pub weight_limit: Weight,
pub extrinsics_len: u64,
pub proof_size_pre_execution: Option<u64>,
pub proof_size_pre_execution: u64,
}

impl TransactionPov {
pub fn new(
weight_limit: Weight,
extrinsics_len: u64,
proof_size_pre_execution: Option<u64>,
) -> Self {
pub fn new(weight_limit: Weight, extrinsics_len: u64, proof_size_pre_execution: u64) -> Self {
Self {
weight_limit,
extrinsics_len,
Expand All @@ -92,20 +83,14 @@ impl TransactionPov {
}

pub fn proof_size_used(&self) -> u64 {
// if we don't have proof_size_pre_execution, that means that we don't care about the tx proof size
let Some(proof_size_pre_execution) = self.proof_size_pre_execution else {
return 0;
};

// If proof_size_pre_execution is enabled, then proof_size_post_execution should also be enabled; otherwise, something is break.
let Some(proof_size_post_execution) =
cumulus_primitives_storage_weight_reclaim::get_proof_size()
else {
return 0;
};

proof_size_post_execution
.saturating_sub(proof_size_pre_execution)
.saturating_sub(self.proof_size_pre_execution)
.saturating_add(self.extrinsics_len)
}
}
Expand Down
4 changes: 2 additions & 2 deletions primitives/evm/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ mod tests {

#[derive(Debug, PartialEq)]
pub enum TestError {
ProofLimitTooLow,
GasLimitTooLow,
GasLimitTooHigh,
GasPriceTooLow,
Expand All @@ -259,6 +258,7 @@ mod tests {
InvalidFeeInput,
InvalidChainId,
InvalidSignature,
ProofLimitTooLow,
UnknownError,
}

Expand All @@ -267,7 +267,6 @@ mod tests {
impl From<TransactionValidationError> for TestError {
fn from(e: TransactionValidationError) -> Self {
match e {
TransactionValidationError::ProofLimitTooLow => TestError::ProofLimitTooLow,
TransactionValidationError::GasLimitTooLow => TestError::GasLimitTooLow,
TransactionValidationError::GasLimitTooHigh => TestError::GasLimitTooHigh,
TransactionValidationError::GasPriceTooLow => TestError::GasPriceTooLow,
Expand All @@ -278,6 +277,7 @@ mod tests {
TransactionValidationError::InvalidFeeInput => TestError::InvalidFeeInput,
TransactionValidationError::InvalidChainId => TestError::InvalidChainId,
TransactionValidationError::InvalidSignature => TestError::InvalidSignature,
TransactionValidationError::ProofLimitTooLow => TestError::ProofLimitTooLow,
TransactionValidationError::UnknownError => TestError::UnknownError,
}
}
Expand Down
5 changes: 2 additions & 3 deletions template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ jsonrpsee = { workspace = true, features = ["server", "macros"] }
log = { workspace = true }
scale-codec = { package = "parity-scale-codec", workspace = true }
serde_json = { workspace = true, features = ["arbitrary_precision"] }

cumulus-client-service = { workspace = true }

# Substrate
prometheus-endpoint = { package = "substrate-prometheus-endpoint", workspace = true }
sc-basic-authorship = { workspace = true }
Expand Down Expand Up @@ -57,6 +54,8 @@ sp-runtime = { workspace = true, features = ["default"] }
sp-session = { workspace = true, features = ["default"] }
sp-timestamp = { workspace = true, features = ["default"] }
sp-transaction-pool = { workspace = true, features = ["default"] }
# Cumulus
cumulus-client-service = { workspace = true }
# These dependencies are used for RPC
frame-system-rpc-runtime-api = { workspace = true }
pallet-transaction-payment-rpc = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ pub fn development_config(enable_manual_seal: bool) -> ChainSpec {
AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")), // Dorothy
AccountId::from(hex!("Ff64d3F6efE2317EE2807d223a0Bdc4c0c49dfDB")), // Ethan
AccountId::from(hex!("C0F0f4ab324C46e55D02D0033343B4Be8A55532d")), // Faith
AccountId::from(hex!("6Bc9543094D17f52CF6b419FB692797E48d275d0")), // BEAR
],
// Initial PoA authorities
vec![authority_keys_from_seed("Alice")],
Expand Down
3 changes: 1 addition & 2 deletions template/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ pallet-sudo = { workspace = true }
pallet-timestamp = { workspace = true }
pallet-transaction-payment = { workspace = true }
pallet-transaction-payment-rpc-runtime-api = { workspace = true }

# Cumulus
cumulus-primitives-storage-weight-reclaim = { workspace = true }

# Frontier
fp-account = { workspace = true, features = ["serde"] }
fp-evm = { workspace = true, features = ["serde"] }
Expand Down
Loading

0 comments on commit 33b7cd6

Please sign in to comment.