From 554bc4499fd2ee22b0a1b6c64b0065015d204101 Mon Sep 17 00:00:00 2001 From: Uncle Stinky Date: Sat, 5 Sep 2026 23:36:27 +0300 Subject: [PATCH] fix governance benchmarking; make id dependant on the proof length Signed-off-by: Uncle Stinky --- pallets/governance/Cargo.toml | 2 +- pallets/governance/src/benchmarking.rs | 25 ++++++++++--------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/pallets/governance/Cargo.toml b/pallets/governance/Cargo.toml index ad1d17d..a580a54 100644 --- a/pallets/governance/Cargo.toml +++ b/pallets/governance/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ghost-governance" -version = "0.3.2" +version = "0.3.3" description = "Full-chain and cross-chain governance pallet with early adopter share claims" license.workspace = true authors.workspace = true diff --git a/pallets/governance/src/benchmarking.rs b/pallets/governance/src/benchmarking.rs index 571a5e2..f44621b 100644 --- a/pallets/governance/src/benchmarking.rs +++ b/pallets/governance/src/benchmarking.rs @@ -31,7 +31,7 @@ mod benchmarks { evm_addr_bytes.copy_from_slice(&pubkey_hash.as_ref()[12..32]); let dummy_evm_address = EvmAddress::from(evm_addr_bytes); - let target_index = 0u32; + let target_index = max_proof_depth - 1; let claim_package_init = ClaimPackage { shares: dummy_shares, merkle_proof: Default::default(), @@ -40,7 +40,8 @@ mod benchmarks { }; let preimage_init = claim_package_init.get_preimage(&dummy_evm_address, network_id); - let mut current_hash = SubstrateKeccakHasher::hash(&preimage_init); + let some_hash = SubstrateKeccakHasher::hash(&preimage_init); + let mut current_hash = some_hash; let mut proof_hashes = Vec::with_capacity(max_proof_depth as usize); let mut current_index = target_index as usize; @@ -48,21 +49,15 @@ mod benchmarks { let hash_len = SubstrateKeccakHasher::hash_len(); let mut combined = sp_std::vec![0u8; hash_len * 2]; - for i in 0..max_proof_depth { - let mut sibling_bytes = [0u8; 32]; - sibling_bytes[24..32].copy_from_slice(&(i as u64).to_be_bytes()); - let sibling_hash = EvmHash::from_slice(&sibling_bytes); - proof_hashes.push(sibling_hash); - - let sibling_bytes_ref = sibling_hash.as_ref(); - let hash_bytes = current_hash.as_ref(); + for _ in 0..max_proof_depth { + proof_hashes.push(some_hash); if current_index % 2 == 0 { - combined[..hash_len].copy_from_slice(hash_bytes); - combined[hash_len..].copy_from_slice(sibling_bytes_ref); + combined[..hash_len].copy_from_slice(¤t_hash.to_fixed_bytes()); + combined[hash_len..].copy_from_slice(&some_hash.to_fixed_bytes()); } else { - combined[..hash_len].copy_from_slice(sibling_bytes_ref); - combined[hash_len..].copy_from_slice(hash_bytes); + combined[..hash_len].copy_from_slice(&some_hash.to_fixed_bytes()); + combined[hash_len..].copy_from_slice(¤t_hash.to_fixed_bytes()); } current_hash = SubstrateKeccakHasher::hash(&combined); @@ -89,7 +84,7 @@ mod benchmarks { GlobalShares::::put(global_state); let claim_package = ClaimPackage { - index: 0, + index: target_index, merkle_proof: BoundedVec::try_from(proof_hashes).unwrap(), shares: dummy_shares, token_id: 0