From affd6a6310cab9ec2c55dda3b556fbd7b38969bb Mon Sep 17 00:00:00 2001 From: zees-dev Date: Wed, 9 Oct 2024 11:25:41 +1300 Subject: [PATCH] reduce weight checks for subsequent evm migrations by validating against a single address --- runtime/src/migrations/evm.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/runtime/src/migrations/evm.rs b/runtime/src/migrations/evm.rs index eb59a2030..6d65f578c 100644 --- a/runtime/src/migrations/evm.rs +++ b/runtime/src/migrations/evm.rs @@ -69,7 +69,16 @@ impl OnRuntimeUpgrade for Upgrade { fn on_runtime_upgrade() -> Weight { log::info!(target: "Migration", "🛠️ EVM: creating EIP-2470 factory deployer and factory contract 🛠️"); - let weight = v1::migrate::(); + // reading factory deployer + let mut weight = ::DbWeight::get().reads(3); + + let factory_deployer = H160::from_str(EIP2470_EOA_ADDRESS).unwrap(); + if !EVM::is_account_empty(&factory_deployer) { + log::info!(target: "Migration", "Factory deployer already exists, skipping migration"); + return weight; + } + + weight += v1::migrate::(); log::info!(target: "Migration", "✅ EVM: EIP-2470 factory deployer and factory contract successfully created ✅"); @@ -221,10 +230,12 @@ pub mod v1 { // Post-upgrade checks Upgrade::post_upgrade(pre_upgrade_state).expect("Post-upgrade should succeed"); - // Validate future runtime upgrade fails (6 reads each - i.e. factory and universal deployer) + // Validate future runtime upgrade fails + // 3 reads for factory deployer check only let new_weight = Upgrade::on_runtime_upgrade(); - assert!( - new_weight.eq(&::DbWeight::get().reads(12)), + assert_eq!( + new_weight, + ::DbWeight::get().reads(3), "Migration weight mismatch" ); });