mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11:02 +00:00
Implement Substrate Pallet Runtime APIs (#389)
* Implement public helpers for querying header info * Update `best_header` when importing headers * Add BestHeader to GenesisConfig * Define extra types for Millau primitives * Start implementing runtime APIs in Millau runtime * Add helper for getting headers which require a justification * Add runtime API for getting headers requiring a justification * Reword `expect()` proof for valid authority sets * Fix typo * Clean up Hasher comment * Add the Call Dispatch Pallet back to the Millau runtime * Use types from Rialto in bridge pallet config * Use the Rialto runtime APIS in the Millau runtime * Include Millau bridge instance in Rialto runtime * Add missing doc comment * Use one storage function for setting and clearing `RequiresJustification` * Remove TODO comments
This commit is contained in:
committed by
Bastian Köcher
parent
cfe1e43473
commit
86834e2fd6
@@ -15,9 +15,11 @@ serde = { version = "1.0.115", optional = true, features = ["derive"] }
|
||||
|
||||
bp-message-lane = { path = "../../../primitives/message-lane", default-features = false }
|
||||
bp-millau = { path = "../../../primitives/millau", default-features = false }
|
||||
bp-rialto = { path = "../../../primitives/rialto", default-features = false }
|
||||
pallet-bridge-call-dispatch = { path = "../../../modules/call-dispatch", default-features = false }
|
||||
pallet-message-lane = { path = "../../../modules/message-lane", default-features = false }
|
||||
pallet-shift-session-manager = { path = "../../../modules/shift-session-manager", default-features = false }
|
||||
pallet-substrate-bridge = { path = "../../../modules/substrate", default-features = false }
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
@@ -53,6 +55,7 @@ default = ["std"]
|
||||
std = [
|
||||
"bp-message-lane/std",
|
||||
"bp-millau/std",
|
||||
"bp-rialto/std",
|
||||
"codec/std",
|
||||
"frame-executive/std",
|
||||
"frame-support/std",
|
||||
@@ -66,6 +69,7 @@ std = [
|
||||
"pallet-randomness-collective-flip/std",
|
||||
"pallet-shift-session-manager/std",
|
||||
"pallet-session/std",
|
||||
"pallet-substrate-bridge/std",
|
||||
"pallet-sudo/std",
|
||||
"pallet-timestamp/std",
|
||||
"pallet-transaction-payment/std",
|
||||
|
||||
@@ -54,6 +54,7 @@ pub use frame_support::{
|
||||
};
|
||||
|
||||
pub use pallet_balances::Call as BalancesCall;
|
||||
pub use pallet_substrate_bridge::Call as BridgeSubstrateCall;
|
||||
pub use pallet_timestamp::Call as TimestampCall;
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
@@ -216,7 +217,6 @@ impl frame_system::Trait for Runtime {
|
||||
impl pallet_aura::Trait for Runtime {
|
||||
type AuthorityId = AuraId;
|
||||
}
|
||||
|
||||
impl pallet_bridge_call_dispatch::Trait for Runtime {
|
||||
type Event = Event;
|
||||
type MessageId = (bp_message_lane::LaneId, bp_message_lane::MessageNonce);
|
||||
@@ -308,6 +308,13 @@ impl pallet_session::Trait for Runtime {
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
impl pallet_substrate_bridge::Trait for Runtime {
|
||||
type BridgedHeader = bp_rialto::Header;
|
||||
type BridgedBlockNumber = bp_rialto::BlockNumber;
|
||||
type BridgedBlockHash = bp_rialto::Hash;
|
||||
type BridgedBlockHasher = bp_rialto::Hasher;
|
||||
}
|
||||
|
||||
impl pallet_shift_session_manager::Trait for Runtime {}
|
||||
|
||||
construct_runtime!(
|
||||
@@ -316,6 +323,7 @@ construct_runtime!(
|
||||
NodeBlock = opaque::Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic
|
||||
{
|
||||
BridgeRialto: pallet_substrate_bridge::{Module, Call, Storage},
|
||||
BridgeCallDispatch: pallet_bridge_call_dispatch::{Module, Event<T>},
|
||||
System: frame_system::{Module, Call, Config, Storage, Event<T>},
|
||||
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
|
||||
@@ -479,4 +487,34 @@ impl_runtime_apis! {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl bp_rialto::RialtoHeaderApi<Block> for Runtime {
|
||||
fn best_block() -> (bp_rialto::BlockNumber, bp_rialto::Hash) {
|
||||
let header = BridgeRialto::best_header();
|
||||
(header.number, header.hash())
|
||||
}
|
||||
|
||||
fn finalized_block() -> (bp_rialto::BlockNumber, bp_rialto::Hash) {
|
||||
let header = BridgeRialto::best_finalized();
|
||||
(header.number, header.hash())
|
||||
}
|
||||
|
||||
fn incomplete_headers() -> Vec<(bp_rialto::BlockNumber, bp_rialto::Hash)> {
|
||||
// Since the pallet doesn't accept multiple scheduled changes right now
|
||||
// we can only have one header requiring a justification at any time.
|
||||
if let Some(header) = BridgeRialto::requires_justification() {
|
||||
vec![(header.number, header.hash())]
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
fn is_known_block(hash: bp_rialto::Hash) -> bool {
|
||||
BridgeRialto::is_known_header(hash)
|
||||
}
|
||||
|
||||
fn is_finalized_block(hash: bp_rialto::Hash) -> bool {
|
||||
BridgeRialto::is_finalized_header(hash)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user