make benchmarking dependant on the actual data
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
parent
06af604cc8
commit
8ee32ff609
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ghost-weaver"
|
||||
version = "0.0.2"
|
||||
version = "0.0.3"
|
||||
description = "Weaving a secure cryptographic tapestry across different external chains."
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
use super::*;
|
||||
use frame_benchmarking::v2::*;
|
||||
use frame_system::RawOrigin;
|
||||
use sp_runtime::AccountId32;
|
||||
use sp_std::vec;
|
||||
|
||||
use ghost_helpers::networks::NetworkDataBuilder;
|
||||
@ -135,40 +136,17 @@ mod benchmarks {
|
||||
|
||||
#[benchmark]
|
||||
fn pull_utxo_thread(
|
||||
a: Linear<1, { T::MaxAuthorities::get() as u32 }>,
|
||||
a: Linear<1, { crate::types::UTXO_MAX_HISTORY_DEPTH }>,
|
||||
) -> Result<(), BenchmarkError> {
|
||||
let session = 69;
|
||||
let max_history_depth = a as usize;
|
||||
let (network_id, _, _) = prepare_pallet::<T>(1);
|
||||
|
||||
// https://blockstream.info/tx/6fdcb55eaeddae87fdbbd3e6fd8c2b80c1e7e7c1214e1a6e35c06a70e5f21fba?expand
|
||||
// NOTE: this is the best transaction that matches the max sizes I found,
|
||||
// would be nice to find exact edge case
|
||||
|
||||
let root_string =
|
||||
hex::decode("00000000000000000000662f626dbc3c06161a324d879fadcd0293d8e0884a1d")
|
||||
.expect("Bitcoin Root hex should be valid");
|
||||
let expected_root = H256::from_slice(&root_string);
|
||||
|
||||
LoomStates::<T>::insert(&network_id, &session, expected_root);
|
||||
|
||||
let receiver_32: [u8; 32] =
|
||||
hex::decode("6969696969696969696969696969696969696969696969696969696969696969")
|
||||
.expect("Bytes32 from UTXO should be valid")
|
||||
.try_into()
|
||||
.expect("Receiver address must be exactly 32 bytes");
|
||||
let receiver_account = sp_runtime::AccountId32::from(receiver_32);
|
||||
|
||||
let transfer_amount: BalanceOf<T> = 140_693u64.unique_saturated_into();
|
||||
|
||||
let payload = ThreadPayload::new(12, transfer_amount, receiver_account);
|
||||
let utxo_thread_proof = UtxoThreadProof::new(
|
||||
1,
|
||||
0,
|
||||
transfer_amount,
|
||||
payload,
|
||||
hex::decode("008008201643a05d24fe1f015bf472fdedd8ef39dd8247568d3901000000000000000000569ac8f0aed0c5b632dd1dcc031f3d826a170e13cd8176430a2873a33d4694c2501f6a6ad43a02178dbac0d66b1600000e88be94dbcedc3f32bce789eb4512c68b39b91b54c4f2913e84baf7bae21bdc466d954b10876c1e8ad6591461027236c9a471883f96c028a7d1f08deb833f56fa18f457a6faa9c41340be484af67e444f8565b03085e1392fa2d56962f89919c4fcfff99fc6e92be067d01028fb54e8dc1e8425f0ef6bf1cc64220a2ba22163666eb01f99648e8c2af1bb1a0e1ba297f0244a09aa6a6ff87092312b02e8d75aef61e5c08f5b59184a45855e987c5ea114e5da61e55337bfae99f3a2e9601e72ae6036633dc97631609813a30d1185f98e7d6effc4a0330db0394da388c0058e9a730a62d8c679c35bf8d270ca8b95cec7d848729cdfd94a284f060f353b379bfc36310ac78306183a056a04156efd7e77661ce7ba50a4ef9f9e6b3681dfb39d8d0161ad0d2ec46834b5f270b67aa63a8a5b69287e8606b8a438785f8a5af66f84a2641438ba4a5fa22029227e9c2ddb6f23867b112c027d2fc2cf031a46c874701768b5c4983959b98d98736a2ed5ab0dd064ee24e49a3a7dac63e8b857ad4c8b5aa0cf22a7eac3180f3a54630b486de928ecf590e807d2e821818e2fe7e86610187d6673a6f95c639af80a7a7710b0088d44057ca61bdf5f4d5ba68d46b88e4304ffb70000").expect("Bytes32 from UTXO should be valid"),
|
||||
hex::decode("020000000001029ee4235efd4a3cb183d4c311ce858eeee7748263a28afd3d861bac1cb4a8d368010000000001000000d7c5869bfffaa1877d0ecd37e46dc70c232a16f7955e635d57f926d1b3e640bf0100000000ffffffff02ff490b0000000000160014f635b17877709ba3c5acbe153f38a47a733f5b169525020000000000160014c6e4e0f822c31540b4b05903ce3c67b6cff8e6d40247304402200f2f3763fad59d38b4e101b9675450c0a54d45fe17e2b1babde0d0ce6051ea5b0220643e71d66752c0f1bd30dc0897305da77f223d14c781e86063ac181ad7fb90b6012102aad4cca3dab6427bc754a5a123de32cd037e7177fade9f72d83088b00066cffc0247304402200c8f1ff8230813e5e4ab8ec802c614bc8705c407c5958d64dd79cc8422d85a6202203ea832d581c404200b5974fd1a11abfe1ebac213842083cb02eba3f253c8c2aa012102d70df1d4d58701adab82b4816e0640c27403d1fab859ca9f47cb6eccca3dd96200000000").expect("Bytes32 from UTXO should be valid"),
|
||||
vec![
|
||||
let historical_hashes = vec![
|
||||
hex::decode("00a01520c1d508977a3787523a0f959e14a8df763dc87927c7910000000000000000000036303f2bcf94f752a1d4b0641d1adbc2d80aa89628feefd7f837a74792e26ab8bb276a6ad43a0217bece2e64").expect("Bytes32 from UTXO should be valid"),
|
||||
hex::decode("0400e020702ff95ecc1b8575cff205bfc24592c87ba09280bd84000000000000000000008ca9c40d5ab762f160661635cade50fd14571dcf5fdf8c463b617caf9b07dc5a3b296a6ad43a02171340d661").expect("Bytes32 from UTXO should be valid"),
|
||||
hex::decode("000000345457ca4006ddc376db24b7a37db04dfa0b46c1d99267010000000000000000009409d64eb06a6dd83ae2937f70d07222d75505a07f12e756b61a27189851e3bbfe2c6a6ad43a0217a06575b5").expect("Bytes32 from UTXO should be valid"),
|
||||
@ -313,7 +291,49 @@ mod benchmarks {
|
||||
hex::decode("00e02c3ade01a429e0f5c328824f4ee063b98f24ff3b0dc0db08000000000000000000009d0b402f41ab9c16e08f95de962044b206413f878608abca2015ee2074713078606d6b6ad43a0217c0650150").expect("Bytes32 from UTXO should be valid"),
|
||||
hex::decode("00008f2604b952dcd44dfcb61080ad77c5b626efd760e5f8ac8401000000000000000000ee81697e6cf7f41db37b63a9680906d3023be7a905785ef1b5ebd03fd22dd8bb2d6f6b6ad43a0217287aa17f").expect("Bytes32 from UTXO should be valid"),
|
||||
hex::decode("008017262c315a069a8896ec04d88ef423ff5cb3845320a6f123010000000000000000002d42d9519e62f5a48d4880b0ff0cd8021a38eadd469a2f7aabd0886061026a5026706b6ad43a02172ea14dd2").expect("Bytes32 from UTXO should be valid"),
|
||||
]
|
||||
];
|
||||
|
||||
let receiver_32: [u8; 32] =
|
||||
hex::decode("6969696969696969696969696969696969696969696969696969696969696969")
|
||||
.expect("Bytes32 from UTXO should be valid")
|
||||
.try_into()
|
||||
.expect("Receiver address must be exactly 32 bytes");
|
||||
|
||||
let receiver_account = AccountId32::from(receiver_32);
|
||||
let transfer_amount: BalanceOf<T> = 140_693u64.unique_saturated_into();
|
||||
|
||||
let ancestry_headers_vec: Vec<Vec<u8>> = historical_hashes
|
||||
.iter()
|
||||
.take(max_history_depth)
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
let gettxproof_bytes = hex::decode("008008201643a05d24fe1f015bf472fdedd8ef39dd8247568d3901000000000000000000569ac8f0aed0c5b632dd1dcc031f3d826a170e13cd8176430a2873a33d4694c2501f6a6ad43a02178dbac0d66b1600000e88be94dbcedc3f32bce789eb4512c68b39b91b54c4f2913e84baf7bae21bdc466d954b10876c1e8ad6591461027236c9a471883f96c028a7d1f08deb833f56fa18f457a6faa9c41340be484af67e444f8565b03085e1392fa2d56962f89919c4fcfff99fc6e92be067d01028fb54e8dc1e8425f0ef6bf1cc64220a2ba22163666eb01f99648e8c2af1bb1a0e1ba297f0244a09aa6a6ff87092312b02e8d75aef61e5c08f5b59184a45855e987c5ea114e5da61e55337bfae99f3a2e9601e72ae6036633dc97631609813a30d1185f98e7d6effc4a0330db0394da388c0058e9a730a62d8c679c35bf8d270ca8b95cec7d848729cdfd94a284f060f353b379bfc36310ac78306183a056a04156efd7e77661ce7ba50a4ef9f9e6b3681dfb39d8d0161ad0d2ec46834b5f270b67aa63a8a5b69287e8606b8a438785f8a5af66f84a2641438ba4a5fa22029227e9c2ddb6f23867b112c027d2fc2cf031a46c874701768b5c4983959b98d98736a2ed5ab0dd064ee24e49a3a7dac63e8b857ad4c8b5aa0cf22a7eac3180f3a54630b486de928ecf590e807d2e821818e2fe7e86610187d6673a6f95c639af80a7a7710b0088d44057ca61bdf5f4d5ba68d46b88e4304ffb70000").expect("Bytes32 from UTXO should be valid");
|
||||
|
||||
let dynamic_trusted_root = if ancestry_headers_vec.is_empty() {
|
||||
let first_sha = sp_io::hashing::sha2_256(&gettxproof_bytes[..80]);
|
||||
let mut native_le = sp_io::hashing::sha2_256(&first_sha);
|
||||
native_le.reverse();
|
||||
H256::from(native_le)
|
||||
} else {
|
||||
let last_header = ancestry_headers_vec.last().unwrap();
|
||||
let first_sha = sp_io::hashing::sha2_256(&last_header[..80]);
|
||||
let mut native_le = sp_io::hashing::sha2_256(&first_sha);
|
||||
native_le.reverse();
|
||||
H256::from(native_le)
|
||||
};
|
||||
|
||||
LoomStates::<T>::insert(&network_id, &session, dynamic_trusted_root);
|
||||
|
||||
let payload = ThreadPayload::new(12, transfer_amount, receiver_account);
|
||||
let utxo_thread_proof = UtxoThreadProof::new(
|
||||
1,
|
||||
0,
|
||||
transfer_amount,
|
||||
payload,
|
||||
gettxproof_bytes,
|
||||
hex::decode("020000000001029ee4235efd4a3cb183d4c311ce858eeee7748263a28afd3d861bac1cb4a8d368010000000001000000d7c5869bfffaa1877d0ecd37e46dc70c232a16f7955e635d57f926d1b3e640bf0100000000ffffffff02ff490b0000000000160014f635b17877709ba3c5acbe153f38a47a733f5b169525020000000000160014c6e4e0f822c31540b4b05903ce3c67b6cff8e6d40247304402200f2f3763fad59d38b4e101b9675450c0a54d45fe17e2b1babde0d0ce6051ea5b0220643e71d66752c0f1bd30dc0897305da77f223d14c781e86063ac181ad7fb90b6012102aad4cca3dab6427bc754a5a123de32cd037e7177fade9f72d83088b00066cffc0247304402200c8f1ff8230813e5e4ab8ec802c614bc8705c407c5958d64dd79cc8422d85a6202203ea832d581c404200b5974fd1a11abfe1ebac213842083cb02eba3f253c8c2aa012102d70df1d4d58701adab82b4816e0640c27403d1fab859ca9f47cb6eccca3dd96200000000").expect("Bytes32 from UTXO should be valid"),
|
||||
ancestry_headers_vec,
|
||||
);
|
||||
|
||||
let thread_proof = ThreadProof::UtxoThreadProof(utxo_thread_proof);
|
||||
|
||||
@ -306,7 +306,9 @@ pub mod pallet {
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::call_index(0)]
|
||||
#[pallet::weight((
|
||||
T::WeightInfo::extend_warp(),
|
||||
T::WeightInfo::extend_warp(
|
||||
Authorities::<T>::decode_len().unwrap_or(1) as u32,
|
||||
),
|
||||
DispatchClass::Normal,
|
||||
Pays::No,
|
||||
))]
|
||||
@ -359,7 +361,9 @@ pub mod pallet {
|
||||
|
||||
#[pallet::call_index(1)]
|
||||
#[pallet::weight((
|
||||
T::WeightInfo::weave_weft(),
|
||||
T::WeightInfo::weave_weft(
|
||||
Authorities::<T>::decode_len().unwrap_or(1) as u32,
|
||||
),
|
||||
DispatchClass::Normal,
|
||||
Pays::No,
|
||||
))]
|
||||
@ -415,7 +419,9 @@ pub mod pallet {
|
||||
#[pallet::call_index(2)]
|
||||
#[pallet::weight((
|
||||
match &thread_proof {
|
||||
ThreadProof::UtxoThreadProof(_) => T::WeightInfo::pull_utxo_thread(),
|
||||
ThreadProof::UtxoThreadProof(thread) => T::WeightInfo::pull_utxo_thread(
|
||||
thread.ancestry_headers_len(),
|
||||
),
|
||||
ThreadProof::EvmThreadProof(_) => T::WeightInfo::pull_evm_thread(),
|
||||
},
|
||||
DispatchClass::Normal,
|
||||
|
||||
@ -21,11 +21,16 @@ use crate::{ExternalBlockNumber, ThreadId, WeavingSession};
|
||||
const EVM_MERKLE_DEPTH: u32 = 8;
|
||||
const EVM_VALUES_DEPTH: u32 = 8;
|
||||
|
||||
const UTXO_MAX_HISTORY_DEPTH_VALUE: u32 = 144;
|
||||
const UTXO_MAX_PROOF_BYTES: u32 = 1024;
|
||||
const UTXO_MAX_HEADER_BYTES: u32 = 80;
|
||||
const UTXO_MAX_HISTORY_DEPTH: u32 = 144;
|
||||
const UTXO_MAX_TX_BYTES: u32 = ghost_helpers::utxo::MAX_TX_LEN as u32;
|
||||
|
||||
#[cfg(not(feature = "runtime-benchmarks"))]
|
||||
const UTXO_MAX_HISTORY_DEPTH: u32 = UTXO_MAX_HISTORY_DEPTH_VALUE;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
pub const UTXO_MAX_HISTORY_DEPTH: u32 = UTXO_MAX_HISTORY_DEPTH_VALUE;
|
||||
|
||||
pub enum WeavingOk<NetworkId> {
|
||||
Block(ExternalBlockNumber, NetworkId),
|
||||
Hash(ExternalBlockNumber, H256, WeavingSession, NetworkId),
|
||||
@ -474,6 +479,9 @@ impl<Balance> UtxoThreadProof<Balance>
|
||||
where
|
||||
Balance: Copy + Clone + Eq + PartialEq + UniqueSaturatedInto<u128>,
|
||||
{
|
||||
pub fn ancestry_headers_len(&self) -> u32 {
|
||||
self.ancestry_headers.len() as u32
|
||||
}
|
||||
pub fn amount(&self) -> Balance {
|
||||
self.expected_amount
|
||||
}
|
||||
@ -487,9 +495,7 @@ where
|
||||
pub fn verify_proof(&self, root_hash: H256, gatekeeper_ref: &[u8]) -> Option<AccountId32> {
|
||||
use ghost_helpers::utxo::{Header, Transaction};
|
||||
|
||||
if self.gettxproof_bytes.len() < 85 {
|
||||
return None;
|
||||
}
|
||||
if self.gettxproof_bytes.len() < 85 { return None; }
|
||||
let header_bytes = &self.gettxproof_bytes[..80];
|
||||
|
||||
let is_chain_valid = verify_hash_ancestry::<UtxoSha2Hasher, _>(
|
||||
@ -497,9 +503,8 @@ where
|
||||
self.ancestry_headers.iter(),
|
||||
root_hash,
|
||||
);
|
||||
if !is_chain_valid {
|
||||
return None;
|
||||
}
|
||||
|
||||
if !is_chain_valid { return None; }
|
||||
|
||||
let transaction =
|
||||
Transaction::<UtxoSha2Hasher>::try_from(self.getrawtransaction_bytes.as_ref()).ok()?;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user