mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 12:11:09 +00:00
Finality Verifier Pallet (#629)
* Add skeleton for `pallet-finality-verifier` * Sketch out implementation for importing finality proofs * Get pallet compiling * Introduce skeleton for mock runtime * Start using real Grandpa types in finality pallet * Redefine types in header chain primitives crate * Implement HeaderChain for Substrate bridge pallet * Plug Substrate Bridge Pallet into verifier mock * Fix compilation of `header-chain` primitives * Start writing to base pallet storage * Add first "cross-pallet" test * Move keyring primitives used in tests to shared crate * Stop pulling `std` deps into `no_std` builds * Revert "Stop pulling `std` deps into `no_std` builds" This reverts commit f74dd660652f98b7336936d1534a4e63cc9169a5. * Revert "Move keyring primitives used in tests to shared crate" This reverts commit b774fa730b2cdc40545afff308a66b0840266001. * Use new SS58Prefix type in mock * Start using `bp-test-utils` in finality pallet * Start using real justification code * Get a test working with real justification verification * Add basic tests for invalid proofs * Get rid of AncestryProof config type * Add error types to transaction outcome * Bound number of headers allowed in a single ancestry proof * Disallow invalid authority sets * Remove unused items * Add some documentation * Get rid of Clippy warnings * Rename BaseHeaderChain to TransactionVerifier * Remove unused code * Make dummy trait implementations more generic * Fix more Clippy complaints * Update tests to use fix for duplicate headers * Fix benchmarking compilation * Rename TransactionVerifier to InclusionProofVerifier
This commit is contained in:
committed by
Bastian Köcher
parent
5e38b126f2
commit
ea5d8662be
@@ -32,6 +32,7 @@
|
||||
#![allow(clippy::large_enum_variant)]
|
||||
|
||||
use crate::storage::ImportedHeader;
|
||||
use bp_header_chain::AuthoritySet;
|
||||
use bp_runtime::{BlockNumberOf, Chain, HashOf, HasherOf, HeaderOf};
|
||||
use frame_support::{
|
||||
decl_error, decl_module, decl_storage, dispatch::DispatchResult, ensure, traits::Get, weights::DispatchClass,
|
||||
@@ -43,7 +44,7 @@ use sp_std::{marker::PhantomData, prelude::*};
|
||||
use sp_trie::StorageProof;
|
||||
|
||||
// Re-export since the node uses these when configuring genesis
|
||||
pub use storage::{AuthoritySet, InitializationData, ScheduledChange};
|
||||
pub use storage::{InitializationData, ScheduledChange};
|
||||
|
||||
pub use storage_proof::StorageProofChecker;
|
||||
|
||||
@@ -361,6 +362,38 @@ impl<T: Config> Module<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> bp_header_chain::HeaderChain<BridgedHeader<T>> for Module<T> {
|
||||
fn best_finalized() -> BridgedHeader<T> {
|
||||
PalletStorage::<T>::new().best_finalized_header().header
|
||||
}
|
||||
|
||||
fn authority_set() -> AuthoritySet {
|
||||
PalletStorage::<T>::new().current_authority_set()
|
||||
}
|
||||
|
||||
fn import_header(header: BridgedHeader<T>) -> Result<(), ()> {
|
||||
let mut verifier = verifier::Verifier {
|
||||
storage: PalletStorage::<T>::new(),
|
||||
};
|
||||
|
||||
let _ = verifier.import_header(header.hash(), header).map_err(|_| ())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn import_finality_proof(header: BridgedHeader<T>, finality_proof: Vec<u8>) -> Result<(), ()> {
|
||||
let mut verifier = verifier::Verifier {
|
||||
storage: PalletStorage::<T>::new(),
|
||||
};
|
||||
|
||||
let _ = verifier
|
||||
.import_finality_proof(header.hash(), finality_proof.into())
|
||||
.map_err(|_| ())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure that the origin is either root, or `ModuleOwner`.
|
||||
fn ensure_owner_or_root<T: Config>(origin: T::Origin) -> Result<(), BadOrigin> {
|
||||
match origin.into() {
|
||||
|
||||
Reference in New Issue
Block a user