optimize get_preimage_slice function and add new benchmarked weights
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
parent
414604f296
commit
20e03d21ec
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ghost-weaver"
|
||||
version = "0.0.9"
|
||||
version = "0.0.10"
|
||||
description = "Weaving a secure cryptographic tapestry across different external chains."
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
|
||||
@ -367,29 +367,17 @@ where
|
||||
NetworkId: Copy + Clone + Eq + PartialEq + UniqueSaturatedInto<u64>,
|
||||
{
|
||||
let slot_index_usize: usize = self.slot_index.unique_saturated_into();
|
||||
let slot_index_out_of_range = slot_index_usize >= self.slots.len();
|
||||
let too_many_slots_given = (EVM_VALUES_DEPTH as usize) < self.slots.len();
|
||||
let mut slot_values: Vec<H256> = self.slots.to_vec();
|
||||
|
||||
if slot_index_out_of_range || too_many_slots_given {
|
||||
return SubstrateKeccakHasher::empty();
|
||||
match slot_values.get_mut(slot_index_usize) {
|
||||
Some(slot) => {
|
||||
*slot = self.compute_arguments_hash(network_id);
|
||||
cumulative_hash::<SubstrateKeccakHasher, _>(slot_values)
|
||||
}
|
||||
None => {
|
||||
SubstrateKeccakHasher::empty()
|
||||
}
|
||||
|
||||
(slot_index_usize < self.slots.len())
|
||||
.then(|| {
|
||||
self.slots
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, &preimage)| {
|
||||
if index == slot_index_usize {
|
||||
self.compute_arguments_hash(network_id)
|
||||
} else {
|
||||
preimage
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.map(|slots| cumulative_hash::<SubstrateKeccakHasher, _>(slots))
|
||||
.unwrap_or(SubstrateKeccakHasher::empty())
|
||||
}
|
||||
|
||||
pub fn get_unique_key<NetworkId>(
|
||||
@ -400,11 +388,23 @@ where
|
||||
where
|
||||
NetworkId: Copy + Clone + Eq + PartialEq + UniqueSaturatedInto<u64>,
|
||||
{
|
||||
let session_bytes = (session as u64).to_be_bytes();
|
||||
let slot_index_bytes = (self.slot_index as u64).to_be_bytes();
|
||||
let proof_index_bytes = (self.proof_index as u64).to_be_bytes();
|
||||
|
||||
let network_id_u64: u64 = network_id.unique_saturated_into();
|
||||
let network_id_bytes = network_id_u64.to_be_bytes();
|
||||
|
||||
let mut h1 = [0u8; 32]; h1[24..32].copy_from_slice(&session_bytes);
|
||||
let mut h2 = [0u8; 32]; h2[24..32].copy_from_slice(&slot_index_bytes);
|
||||
let mut h3 = [0u8; 32]; h3[24..32].copy_from_slice(&proof_index_bytes);
|
||||
let mut h4 = [0u8; 32]; h4[24..32].copy_from_slice(&network_id_bytes);
|
||||
|
||||
let metadata: [H256; 4] = [
|
||||
H256::from_low_u64_be(session as u64),
|
||||
H256::from_low_u64_be(self.slot_index.unique_saturated_into()),
|
||||
H256::from_low_u64_be(self.proof_index.unique_saturated_into()),
|
||||
H256::from_low_u64_be(network_id.unique_saturated_into()),
|
||||
H256::from(h1),
|
||||
H256::from(h2),
|
||||
H256::from(h3),
|
||||
H256::from(h4),
|
||||
];
|
||||
|
||||
sequential_hash::<SubstrateBlake2Hasher, _>(metadata)
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
//! Autogenerated weights for `ghost_weaver`
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
|
||||
//! DATE: 2026-09-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
|
||||
//! DATE: 2026-09-16, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
|
||||
//! WORST CASE MAP SIZE: `1000000`
|
||||
//! HOSTNAME: `ghostown`, CPU: `Intel(R) Core(TM) i3-2310M CPU @ 2.10GHz`
|
||||
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("casper-dev")`, DB CACHE: 1024
|
||||
@ -69,11 +69,11 @@ impl WeightInfo for () {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `223 + a * (32 ±0)`
|
||||
// Estimated: `3687 + a * (32 ±0)`
|
||||
// Minimum execution time: 210_105_000 picoseconds.
|
||||
Weight::from_parts(214_589_101, 0)
|
||||
// Minimum execution time: 211_189_000 picoseconds.
|
||||
Weight::from_parts(215_074_977, 0)
|
||||
.saturating_add(Weight::from_parts(0, 3687))
|
||||
// Standard Error: 1_420
|
||||
.saturating_add(Weight::from_parts(50_124, 0).saturating_mul(a.into()))
|
||||
// Standard Error: 1_505
|
||||
.saturating_add(Weight::from_parts(46_499, 0).saturating_mul(a.into()))
|
||||
.saturating_add(RocksDbWeight::get().reads(5))
|
||||
.saturating_add(RocksDbWeight::get().writes(1))
|
||||
.saturating_add(Weight::from_parts(0, 32).saturating_mul(a.into()))
|
||||
@ -95,11 +95,11 @@ impl WeightInfo for () {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `518 + a * (32 ±0)`
|
||||
// Estimated: `3982 + a * (32 ±0)`
|
||||
// Minimum execution time: 241_676_000 picoseconds.
|
||||
Weight::from_parts(246_243_389, 0)
|
||||
// Minimum execution time: 241_010_000 picoseconds.
|
||||
Weight::from_parts(245_378_305, 0)
|
||||
.saturating_add(Weight::from_parts(0, 3982))
|
||||
// Standard Error: 1_686
|
||||
.saturating_add(Weight::from_parts(32_125, 0).saturating_mul(a.into()))
|
||||
// Standard Error: 1_583
|
||||
.saturating_add(Weight::from_parts(32_330, 0).saturating_mul(a.into()))
|
||||
.saturating_add(RocksDbWeight::get().reads(6))
|
||||
.saturating_add(RocksDbWeight::get().writes(2))
|
||||
.saturating_add(Weight::from_parts(0, 32).saturating_mul(a.into()))
|
||||
@ -121,10 +121,10 @@ impl WeightInfo for () {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `346`
|
||||
// Estimated: `3811`
|
||||
// Minimum execution time: 170_554_000 picoseconds.
|
||||
Weight::from_parts(170_660_694, 0)
|
||||
// Standard Error: 4_207
|
||||
.saturating_add(Weight::from_parts(3_450_120, 0).saturating_mul(a.into()))
|
||||
// Minimum execution time: 170_701_000 picoseconds.
|
||||
Weight::from_parts(170_150_850, 0)
|
||||
// Standard Error: 4_368
|
||||
.saturating_add(Weight::from_parts(3_363_930, 0).saturating_mul(a.into()))
|
||||
.saturating_add(RocksDbWeight::get().reads(6))
|
||||
.saturating_add(RocksDbWeight::get().writes(3))
|
||||
}
|
||||
@ -144,8 +144,8 @@ impl WeightInfo for () {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `3446`
|
||||
// Estimated: `3811`
|
||||
// Minimum execution time: 136_258_000 picoseconds.
|
||||
Weight::from_parts(137_856_000, 0)
|
||||
// Minimum execution time: 138_215_000 picoseconds.
|
||||
Weight::from_parts(140_004_000, 0)
|
||||
.saturating_add(Weight::from_parts(0, 3811))
|
||||
.saturating_add(RocksDbWeight::get().reads(6))
|
||||
.saturating_add(RocksDbWeight::get().writes(3))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user