-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Setup permissionless lanes for AssetHubs - heads/state-roots store #8324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bkontur
wants to merge
17
commits into
bko-permlanes-on-ahs
Choose a base branch
from
bko-permlanes-on-ahs-1-heads-store
base: bko-permlanes-on-ahs
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
280d358
Added `relayed_incoming_message_proofs_works` test-cases
bkontur f7388f2
Add simple proof root store (`pallet-bridge-proof-root-store`)
bkontur 99f848f
Setup message proof validation with `pallet-bridge-proof-root-store` …
bkontur 5b70690
Merge branch 'bko-permlanes-on-ahs' into bko-permlanes-on-ahs-1-heads…
bkontur 296b387
Update from github-actions[bot] running command 'fmt'
github-actions[bot] 0a05cca
Merge branch 'bko-permlanes-on-ahs' into bko-permlanes-on-ahs-1-heads…
bkontur 3a55ba8
Merge branch 'bko-permlanes-on-ahs' into bko-permlanes-on-ahs-1-heads…
bkontur 26c3f27
Merge branch 'bko-permlanes-on-ahs' into bko-permlanes-on-ahs-1-heads…
bkontur f619494
Merge branch 'bko-permlanes-on-ahs' into bko-permlanes-on-ahs-1-heads…
bkontur 25b7df9
Merge branch 'bko-permlanes-on-ahs' into bko-permlanes-on-ahs-1-heads…
bkontur e61c62c
Merge branch 'bko-permlanes-on-ahs' into bko-permlanes-on-ahs-1-heads…
bkontur 3aa761d
Update bridges/modules/proof-root-store/src/lib.rs
bkontur 9cd9507
Merge branch 'bko-permlanes-on-ahs' into bko-permlanes-on-ahs-1-heads…
bkontur b76a9b8
Merge remote-tracking branch 'origin/bko-permlanes-on-ahs' into bko-p…
bkontur 340bfe7
Merge remote-tracking branch 'origin/bko-permlanes-on-ahs' into bko-p…
bkontur 578de6f
Refactor ring buffer - align with pallet-bridge-grandpa
bkontur 426b0c1
Merge branch 'bko-permlanes-on-ahs' into bko-permlanes-on-ahs-1-heads…
bkontur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| [package] | ||
| name = "pallet-bridge-proof-root-store" | ||
| version = "0.1.0" | ||
| description = "Module that allows bridged relay chains to exchange information on their parachains' heads." | ||
| authors.workspace = true | ||
| edition.workspace = true | ||
| homepage.workspace = true | ||
| license.workspace = true | ||
| repository.workspace = true | ||
|
|
||
| [lints] | ||
| workspace = true | ||
|
|
||
| [dependencies] | ||
| codec = { features = ["derive"], workspace = true } | ||
| frame-benchmarking = { optional = true, workspace = true } | ||
| frame-support = { workspace = true } | ||
| frame-system = { workspace = true } | ||
| scale-info = { features = ["derive"], workspace = true } | ||
|
|
||
| [dev-dependencies] | ||
| bp-proof-root-store = { workspace = true } | ||
| sp-io = { workspace = true } | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| runtime-benchmarks = [ | ||
| "frame-benchmarking", | ||
| "frame-benchmarking/runtime-benchmarks", | ||
| "frame-support/runtime-benchmarks", | ||
| "frame-system/runtime-benchmarks", | ||
| ] | ||
| std = [ | ||
| "codec/std", | ||
| "frame-benchmarking?/std", | ||
| "frame-support/std", | ||
| "frame-system/std", | ||
| "scale-info/std", | ||
| ] | ||
| try-runtime = [ | ||
| "frame-support/try-runtime", | ||
| "frame-system/try-runtime", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| // Copyright (C) Parity Technologies (UK) 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. | ||
|
|
||
| //! This pallet provides mechanisms for tracking and updating data related to the state root of an | ||
| //! external chain. | ||
| //! | ||
| //! The `T::Value` type represents state root-related data—for example, a `state_root` or | ||
| //! an entire `HeadData` structure. | ||
| //! The `T::Key` type serves as the identifier in the map where we store `T::Value`. | ||
| //! For example, it could be a `block_hash` or `block_number`. | ||
| //! | ||
| //! Example use cases: | ||
| //! 1. Store a `block_hash` → `state_root` mapping. | ||
| //! 2. Store a `block_number` → `HeadData` mapping. | ||
| //! | ||
| //! Root data is stored in a ring buffer, respecting the `T::RootsToKeep` limit. | ||
| //! When the limit is reached, the oldest entries are removed. | ||
| //! | ||
| //! There are two approaches for storing data: | ||
| //! 1. Send root data between chains using the dedicated extrinsic `fn note_new_roots(...)`. | ||
| //! 2. Implement an adapter (e.g., using the `OnSystemEvent` callback) that triggers | ||
| //! `pallet_bridge_proof_root_store::Pallet::<T, I>::do_note_new_roots(...)`. | ||
|
|
||
| #![cfg_attr(not(feature = "std"), no_std)] | ||
|
|
||
| extern crate alloc; | ||
|
|
||
| use alloc::collections::VecDeque; | ||
|
|
||
| pub use pallet::*; | ||
| pub mod weights; | ||
| pub use weights::WeightInfo; | ||
|
|
||
| #[cfg(feature = "runtime-benchmarks")] | ||
| pub mod benchmarking { | ||
| // TODO: FAIL-CI | ||
| } | ||
| #[cfg(test)] | ||
| mod mock; | ||
| #[cfg(test)] | ||
| mod tests; | ||
|
|
||
| #[frame_support::pallet] | ||
| pub mod pallet { | ||
| use super::*; | ||
| use frame_support::pallet_prelude::*; | ||
| use frame_system::pallet_prelude::*; | ||
|
|
||
| /// Configuration trait for the pallet. | ||
| #[pallet::config] | ||
| pub trait Config<I: 'static = ()>: frame_system::Config { | ||
| /// Weight information for extrinsics in this pallet. | ||
| type WeightInfo: WeightInfo; | ||
|
|
||
| /// The origin allowed to submit head updates. | ||
| type SubmitOrigin: EnsureOrigin<Self::RuntimeOrigin>; | ||
|
|
||
| /// The key type used to identify stored values of type `T::Value`. | ||
| type Key: Parameter + MaxEncodedLen; | ||
|
|
||
| /// The type of the root value. | ||
| type Value: Parameter + MaxEncodedLen; | ||
|
|
||
| /// Maximum number of roots to retain in storage. | ||
| /// This setting prevents unbounded growth of the on-chain state. | ||
| #[pallet::constant] | ||
| type RootsToKeep: Get<u32>; | ||
| } | ||
|
|
||
| #[pallet::pallet] | ||
| pub struct Pallet<T, I = ()>(PhantomData<(T, I)>); | ||
|
|
||
| /// Storage for root-related data, bounded by `RootIndex` and `T::RootsToKeep`. | ||
| #[pallet::storage] | ||
| pub type Roots<T: Config<I>, I: 'static = ()> = | ||
| StorageMap<_, Blake2_128Concat, T::Key, T::Value, OptionQuery>; | ||
|
|
||
| /// Storage tracking the insertion order of roots for `T::RootsToKeep` (implemented as a simple | ||
| /// ring buffer). | ||
| #[pallet::storage] | ||
| #[pallet::unbounded] | ||
| pub type RootIndex<T: Config<I>, I: 'static = ()> = | ||
| StorageValue<_, VecDeque<T::Key>, ValueQuery>; | ||
bkontur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #[pallet::call(weight(<T as Config<I>>::WeightInfo))] | ||
| impl<T: Config<I>, I: 'static> Pallet<T, I> { | ||
| /// Records a new root data. | ||
| #[pallet::call_index(0)] | ||
| pub fn note_new_roots( | ||
| origin: OriginFor<T>, | ||
| roots: BoundedVec<(T::Key, T::Value), T::RootsToKeep>, | ||
| ) -> DispatchResult { | ||
| let _ = T::SubmitOrigin::ensure_origin(origin); | ||
| Self::do_note_new_roots(roots); | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| #[pallet::hooks] | ||
| impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> { | ||
| #[cfg(feature = "try-runtime")] | ||
| fn try_state( | ||
| _n: BlockNumberFor<T>, | ||
| ) -> Result<(), frame_support::sp_runtime::TryRuntimeError> { | ||
| Self::do_try_state() | ||
| } | ||
| } | ||
|
|
||
| #[cfg(any(feature = "try-runtime", test))] | ||
| impl<T: Config<I>, I: 'static> Pallet<T, I> { | ||
| /// Ensure the correctness of the state of this pallet. | ||
| pub fn do_try_state() -> Result<(), frame_support::sp_runtime::TryRuntimeError> { | ||
| // Check that `RootIndex` is aligned with `Roots`. | ||
| let index = RootIndex::<T, I>::get(); | ||
| ensure!( | ||
| index.len() == Roots::<T, I>::iter_keys().count(), | ||
| "`RootIndex` contains different keys than `Roots`" | ||
| ); | ||
| for key in index { | ||
| ensure!( | ||
| Roots::<T, I>::get(key).is_some(), | ||
| "`Roots` does not contain key from `RootIndex`!" | ||
| ); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| impl<T: Config<I>, I: 'static> Pallet<T, I> { | ||
| /// Stores root values. | ||
| pub fn do_note_new_roots(roots: BoundedVec<(T::Key, T::Value), T::RootsToKeep>) { | ||
| // Update `RootIndex` ring buffer. | ||
| RootIndex::<T, I>::mutate(|index| { | ||
| // Add all at the end. | ||
| for (key, value) in roots { | ||
| if !index.contains(&key) { | ||
| Roots::<T, I>::insert(key.clone(), value); | ||
| index.push_back(key); | ||
| } | ||
| } | ||
|
|
||
| // Remove from the front up to the `T::RootsToKeep` limit. | ||
| while index.len() > T::RootsToKeep::get() as usize { | ||
| if let Some(key) = index.pop_front() { | ||
| Roots::<T, I>::remove(key); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| /// Returns the stored value for the given key. | ||
| pub fn get_root(key: &T::Key) -> Option<T::Value> { | ||
| Roots::<T, I>::get(key) | ||
| } | ||
|
|
||
| /// Returns the stored `RootIndex` data. | ||
| pub fn get_root_index() -> VecDeque<T::Key> { | ||
| RootIndex::<T, I>::get() | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Copyright (C) Parity Technologies (UK) 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(test)] | ||
|
|
||
| use crate as pallet_bridge_proof_root_store; | ||
| use frame_support::{ | ||
| derive_impl, | ||
| sp_runtime::{traits::ConstU32, BuildStorage}, | ||
| }; | ||
| use frame_system::EnsureRoot; | ||
|
|
||
| type Block = frame_system::mocking::MockBlock<TestRuntime>; | ||
|
|
||
| frame_support::construct_runtime! { | ||
| pub enum TestRuntime { | ||
| System: frame_system, | ||
| ProofRootStore: pallet_bridge_proof_root_store, | ||
| } | ||
| } | ||
|
|
||
| #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] | ||
| impl frame_system::Config for TestRuntime { | ||
| type Block = Block; | ||
| } | ||
|
|
||
| impl pallet_bridge_proof_root_store::Config for TestRuntime { | ||
| type WeightInfo = (); | ||
| type SubmitOrigin = EnsureRoot<u64>; | ||
| type Key = u8; | ||
| type Value = u8; | ||
| type RootsToKeep = ConstU32<4>; | ||
| } | ||
|
|
||
| /// Return test externalities to use in tests. | ||
| pub fn new_test_ext() -> sp_io::TestExternalities { | ||
| let t = frame_system::GenesisConfig::<TestRuntime>::default().build_storage().unwrap(); | ||
| sp_io::TestExternalities::new(t) | ||
| } | ||
|
|
||
| /// Run pallet test. | ||
| pub fn run_test<T>(test: impl FnOnce() -> T) -> T { | ||
| new_test_ext().execute_with(test) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.