Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ members = [
"modules/ismp/state-machines/hyperbridge",
"modules/pallets/consensus-incentives",
"modules/pallets/messaging-fees",
"modules/pallets/outbound-proofs",

# evm stuff
# "evm/integration-tests",
Expand Down Expand Up @@ -119,7 +120,6 @@ members = [
"tesseract/consensus/polygon",
"tesseract/consensus/tendermint",


# Airdrop
"modules/pallets/bridge-drop",
]
Expand Down Expand Up @@ -303,6 +303,7 @@ pallet-ismp-host-executive = { path = "modules/pallets/host-executive", default-
pallet-call-decompressor = { path = "modules/pallets/call-decompressor", default-features = false }
pallet-consensus-incentives = { path = "modules/pallets/consensus-incentives", default-features = false }
pallet-messaging-fees= { path = "modules/pallets/messaging-fees", default-features = false }
pallet-outbound-proofs = { path = "modules/pallets/outbound-proofs", default-features = false }
pallet-collator-manager = { path = "modules/pallets/collator-manager", default-features = false }
pallet-xcm-gateway = { path = "modules/pallets/xcm-gateway", default-features = false }
pallet-token-governor = { path = "modules/pallets/token-governor", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions modules/pallets/intents-coprocessor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl pallet_ismp::Config for Test {
type ConsensusClients = ();
type OffchainDB = ();
type FeeHandler = ();
type OnDispatch = ();
}

parameter_types! {
Expand Down
7 changes: 6 additions & 1 deletion modules/pallets/ismp/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
dispatcher::{FeeMetadata, RequestMetadata},
fee_handler::FeeHandler,
offchain::{self, ForkIdentifier, Leaf, LeafIndexAndPos, OffchainDBProvider},
Config, Error, Event, Pallet, Responded,
Config, Error, Event, OnDispatch, Pallet, Responded,
};
use alloc::{string::ToString, vec, vec::Vec};
use codec::Decode;
Expand Down Expand Up @@ -117,6 +117,8 @@ impl<T: Config> Pallet<T> {
},
);

T::OnDispatch::on_dispatch();

Ok(commitment)
}

Expand Down Expand Up @@ -157,6 +159,9 @@ impl<T: Config> Pallet<T> {
},
);
Responded::<T>::insert(req_commitment, true);

T::OnDispatch::on_dispatch();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not call it for every message make be call it if the child_trie root changes in onfinalized_hook


Ok(commitment)
}

Expand Down
13 changes: 13 additions & 0 deletions modules/pallets/ismp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ pub mod pallet {
use sp_std::prelude::*;
pub use utils::*;

/// Hook called when an outgoing message is dispatched
pub trait OnDispatch {
fn on_dispatch();
}

impl OnDispatch for () {
fn on_dispatch() {}
}

/// [`PalletId`] where relayer fees will be collected
pub const RELAYER_FEE_ACCOUNT: PalletId = PalletId(*b"ISMPFEES");

Expand Down Expand Up @@ -160,6 +169,10 @@ pub mod pallet {
/// This offchain DB is also allowed to "merkelize" and "generate proofs" for messages.
/// Most state machines will likey not need this and can just provide `()`
type OffchainDB: OffchainDBProvider<Leaf = Leaf>;

/// Hook called when an outgoing request is dispatched.
/// Use `()` for a no-op implementation.
type OnDispatch: OnDispatch;
}

// Simple declaration of the `Pallet` type. It is placeholder we use to implement traits and
Expand Down
33 changes: 33 additions & 0 deletions modules/pallets/outbound-proofs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "pallet-outbound-proofs"
version = "0.1.0"
edition = "2021"
authors = ["Polytope Labs <[email protected]>"]
license = "Apache-2.0"
description = "Pallet for storing and rewarding outbound consensus proofs on Hyperbridge"
publish = false

[dependencies]
codec = { workspace = true }
pallet-ismp = { workspace = true }
scale-info = { workspace = true }
sp1-verifier = { version = "6.0.2", default-features = false, optional = true }

[dependencies.polkadot-sdk]
workspace = true
features = ["frame-support", "frame-system", "sp-io", "sp-runtime"]

[features]
default = ["std"]
std = [
"polkadot-sdk/std",
"codec/std",
"pallet-ismp/std",
"scale-info/std",
]
sp1 = ["sp1-verifier"]
runtime-benchmarks = [
"polkadot-sdk/frame-benchmarking",
"polkadot-sdk/runtime-benchmarks",
]
try-runtime = ["polkadot-sdk/try-runtime"]
160 changes: 160 additions & 0 deletions modules/pallets/outbound-proofs/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// Copyright (C) Polytope Labs Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![cfg(feature = "runtime-benchmarks")]

use super::*;
use alloc::vec;
use frame_benchmarking::v2::*;
use frame_support::BoundedVec;
use frame_system::RawOrigin;
use pallet::{
ConsensusState, CurrentEpoch, LatestMessageBlock, LatestProvenParachainHeight, ProvenHeights,
Sp1VkeyHash,
};
use types::BeefyConsensusState;

#[benchmarks(
where
T::AccountId: From<[u8; 32]>,
<T::Currency as frame_support::traits::fungible::Inspect<T::AccountId>>::Balance: From<u128>,
)]
mod benchmarks {
use super::*;

#[benchmark]
fn submit_proof() {
let caller: T::AccountId = whitelisted_caller();

CurrentEpoch::<T>::put(0u64);
ConsensusState::<T>::put(BeefyConsensusState::default());

let proof: BoundedVec<u8, T::MaxProofSize> =
vec![0u8; 100].try_into().expect("fits in bounds");

#[extrinsic_call]
_(RawOrigin::Signed(caller), proof, 1000u64, 500u64, 1u64);

assert!(ProvenHeights::<T>::contains_key(1000u64));
assert_eq!(CurrentEpoch::<T>::get(), 1u64);
}

#[benchmark]
fn set_proof_reward() {
let reward: <T::Currency as frame_support::traits::fungible::Inspect<T::AccountId>>::Balance = 1000u128.into();
#[extrinsic_call]
_(RawOrigin::Root, reward);

assert_eq!(pallet::ProofReward::<T>::get(), reward);
}

#[benchmark]
fn set_sp1_vkey_hash() {
let vkey = vec![0xabu8; 32];
#[extrinsic_call]
_(RawOrigin::Root, vkey.clone());

assert_eq!(Sp1VkeyHash::<T>::get(), vkey);
}

}

// Minimal test runtime for benchmark tests
#[cfg(test)]
use polkadot_sdk::*;

#[cfg(test)]
type Block = frame_system::mocking::MockBlock<Test>;

#[cfg(test)]
frame_support::construct_runtime!(
pub enum Test {
System: frame_system,
Balances: pallet_balances,
OutboundProofs: crate::pallet,
}
);

#[cfg(test)]
#[frame_support::derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type Block = Block;
type AccountData = pallet_balances::AccountData<u128>;
}

#[cfg(test)]
#[frame_support::derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
impl pallet_balances::Config for Test {
type AccountStore = System;
}

#[cfg(test)]
pub struct DummyVerifier;
#[cfg(test)]
impl ProofVerifier for DummyVerifier {
fn verify(
trusted_state: &BeefyConsensusState,
_proof: &[u8],
) -> Result<BeefyConsensusState, frame_support::pallet_prelude::DispatchError> {
Ok(trusted_state.clone())
}
}

#[cfg(test)]
pub struct DummyOnDispatch;
#[cfg(test)]
impl pallet_ismp::OnDispatch for DummyOnDispatch {
fn on_dispatch() {}
}

#[cfg(test)]
frame_support::parameter_types! {
pub const TreasuryId: frame_support::PalletId = frame_support::PalletId(*b"hb/trsry");
}

#[cfg(test)]
pub struct TestWeights;
#[cfg(test)]
impl pallet::WeightInfo for TestWeights {
fn submit_proof() -> frame_support::weights::Weight {
frame_support::weights::Weight::zero()
}
fn set_proof_reward() -> frame_support::weights::Weight {
frame_support::weights::Weight::zero()
}
fn set_sp1_vkey_hash() -> frame_support::weights::Weight {
frame_support::weights::Weight::zero()
}
}

#[cfg(test)]
impl crate::pallet::Config for Test {
type AdminOrigin = frame_system::EnsureRoot<u64>;
type ProofVerifier = DummyVerifier;
type Currency = Balances;
type TreasuryPalletId = TreasuryId;
type MaxProofSize = frame_support::traits::ConstU32<100_000>;
type MaxStoredProofs = frame_support::traits::ConstU32<100>;
type WeightInfo = TestWeights;
}

#[cfg(test)]
pub fn new_test_ext() -> sp_io::TestExternalities {
use sp_runtime::BuildStorage;
let t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| frame_system::Pallet::<Test>::set_block_number(1));
ext
}
Loading
Loading