Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
hyperdrive outgoing (#76)
Browse files Browse the repository at this point in the history
* hyperdrive outgoing

* set weights

from mix of calculation and benchmarking

* address reviews

* docs
  • Loading branch information
gitsimon authored Apr 13, 2023
1 parent ff55504 commit b3d2351
Show file tree
Hide file tree
Showing 19 changed files with 2,391 additions and 14 deletions.
4 changes: 3 additions & 1 deletion pallets/acurast/common/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ pub type SerialNumber = BoundedVec<u8, ConstU32<SERIAL_NUMBER_MAX_LENGTH>>;
#[derive(RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Clone, Eq, PartialEq)]
pub enum MultiOrigin<AcurastAccountId> {
Acurast(AcurastAccountId),
Tezos(BoundedVec<u8, CU32<36>>),
Tezos(TezosAddressBytes),
}

pub type TezosAddressBytes = BoundedVec<u8, CU32<36>>;

/// The type of a job identifier sequence.
pub type JobIdSequence = u128;

Expand Down
10 changes: 5 additions & 5 deletions pallets/assets-manager/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ impl pallet_balances::Config for Test {
}

impl frame_system::Config for Test {
type BaseCallFilter = Everything;
type BlockWeights = ();
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u32;
type BlockNumber = BlockNumber;
Expand All @@ -91,18 +95,14 @@ impl frame_system::Config for Test {
type Lookup = AccountIdLookup<AccountId, ()>;
type Header = generic::Header<BlockNumber, BlakeTwo256>;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type BlockHashCount = BlockHashCount;
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
type DbWeight = ();
type BaseCallFilter = Everything;
type SystemWeightInfo = ();
type BlockWeights = ();
type BlockLength = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
Expand Down
87 changes: 87 additions & 0 deletions pallets/hyperdrive-outgoing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
[package]
name = "pallet-acurast-hyperdrive-mmr"
authors = ["Papers AG", "Parity Technologies <admin@parity.io>"]
description = "Acurast Hyperdrive is a building block allowing for general bidirectional message passing"
version = "0.0.1"
license = "MIT"
homepage = "https://docs.acurast.com/"
edition = "2021"
publish = false
repository = "https://github.com/acurast/acurast-core"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [
"derive",
] }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" }

# Acurast
pallet-acurast = { path = "../acurast", default-features = false }
pallet-acurast-marketplace = { path = "../marketplace", default-features = false}
acurast-common = { path = "../acurast/common", default-features = false }
mmr-lib = { package = "ckb-merkle-mountain-range", version = "0.5.2", default-features = false }

# SDKs
tezos-core = { git = "https://github.com/airgap-it/tezos-rust-sdk", default-features = false, branch = "feat/nostd" }
tezos-michelson = { git = "https://github.com/airgap-it/tezos-rust-sdk", default-features = false, branch = "feat/nostd" }
derive_more = { version = "0.99.17", default-features = false }
strum = { version = "0.24.1", default-features = false }
strum_macros = { version = "0.24.1", default-features = false }
once_cell = { version = "1.17.1", default-features = false }

# Benchmarks
hex-literal = { version = "0.3", optional = true }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", optional = true, default-features = false }

# Substrate
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false }
scale-info = { version = "2.2.0", default-features = false, features = [
"derive",
] }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false }
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", default-features = false }


serde = { version = "1.0.136", features = ["derive"], optional = true }
thiserror = "1.0"
log = { version = "0.4.17", default-features = false }

[dev-dependencies]
hex-literal = "0.3"

array-bytes = "4.1"
env_logger = "0.9"
itertools = "0.10.3"

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"acurast-common/std",
"pallet-acurast/std",
"pallet-acurast-marketplace/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-api/std",
"sp-runtime/std",
"sp-std/std",
"strum/std",
"tezos-core/std",
"tezos-michelson/std",
"mmr-lib/std",
"serde",
"log/std",
]
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"]
try-runtime = ["frame-support/try-runtime"]
26 changes: 26 additions & 0 deletions pallets/hyperdrive-outgoing/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! Benchmarks for the MMR pallet.
#![cfg(feature = "runtime-benchmarks")]

use frame_benchmarking::benchmarks_instance_pallet;

use crate::stub::action;
use crate::*;

benchmarks_instance_pallet! {
send_message {
let x in 1 .. 1_000;

let leaves = x as NodeIndex;
for i in 0..leaves {
_ = Pallet::<T, I>::send_message(action(i as u128));
}
}: {
// insert last leave as the benchmarked one
_ = Pallet::<T, I>::send_message(action(leaves as u128));
} verify {
assert_eq!(crate::NumberOfLeaves::<T, I>::get(), leaves+1);
}

impl_benchmark_test_suite!(Pallet, crate::tests::new_test_ext(), crate::mock::Test);
}
42 changes: 42 additions & 0 deletions pallets/hyperdrive-outgoing/src/default_weights.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//! Default weights for the MMR Pallet
//! This file was not auto-generated.
use crate::NodeIndex;
use frame_support::weights::{
constants::{RocksDbWeight as DbWeight, WEIGHT_REF_TIME_PER_NANOS},
Weight,
};

pub trait WeightInfo {
fn check_snapshot() -> Weight {
let maximum_blocks_before_snapshot_reached = DbWeight::get().reads(1);
maximum_blocks_before_snapshot_reached
}
fn create_snapshot() -> Weight {
// maximum_blocks_before_snapshot_reached
let check_weight = Self::check_snapshot();
let message_numbers = DbWeight::get().reads_writes(1, 1);
let next_snapshot_number = DbWeight::get().reads_writes(1, 1);
let snapshot_root_hash = DbWeight::get().writes(1);
let snapshot_meta = DbWeight::get().reads_writes(1, 1);
check_weight
.saturating_add(message_numbers)
.saturating_add(next_snapshot_number)
.saturating_add(snapshot_root_hash)
.saturating_add(snapshot_meta)
}
fn send_message() -> Weight;
fn send_message_actual_weight(peaks: NodeIndex) -> Weight {
// Reading the parent hash.
let leaf_weight = DbWeight::get().reads(1);
// Blake2 hash cost.
let hash_weight = Weight::from_ref_time(2u64 * WEIGHT_REF_TIME_PER_NANOS);
// No-op hook.
let hook_weight = Weight::zero();

leaf_weight
.saturating_add(hash_weight)
.saturating_add(hook_weight)
.saturating_add(DbWeight::get().reads_writes(2 + peaks, 2 + peaks))
}
}
Loading

0 comments on commit b3d2351

Please sign in to comment.