mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-24 18:15:48 +00:00
Allow Substrate Pallet to be Initialized via Dipatchable (#481)
* Add dispatchable for intializing pallet * Add Polkadot JS types for Substrate bridge pallet * Ensure Root is the only one that can initialize the pallet * Add some tests * Pack initialization data into struct * Only allow pallet to be initialized once * Use new initialization config in nodes * Rename ScheduledChange in Ethereum pallet We're renaming it to prevent clashes with Substrate bridge pallet type of the same name. This is relevant when importing types to Polkadot JS Apps. * Move all Polkadot JS types into one file * Appease Clippy
This commit is contained in:
committed by
Bastian Köcher
parent
d4fc7bebdc
commit
cac8319480
@@ -120,7 +120,7 @@ pub struct ValidatorsSet {
|
||||
/// Validators set change as it is stored in the runtime storage.
|
||||
#[derive(Encode, Decode, PartialEq, RuntimeDebug)]
|
||||
#[cfg_attr(test, derive(Clone))]
|
||||
pub struct ScheduledChange {
|
||||
pub struct AuraScheduledChange {
|
||||
/// Validators of this set.
|
||||
pub validators: Vec<Address>,
|
||||
/// Hash of the block which has emitted previous validators change signal.
|
||||
@@ -187,7 +187,7 @@ pub struct ImportContext<Submitter> {
|
||||
parent_hash: H256,
|
||||
parent_header: AuraHeader,
|
||||
parent_total_difficulty: U256,
|
||||
parent_scheduled_change: Option<ScheduledChange>,
|
||||
parent_scheduled_change: Option<AuraScheduledChange>,
|
||||
validators_set_id: u64,
|
||||
validators_set: ValidatorsSet,
|
||||
last_signal_block: Option<HeaderId>,
|
||||
@@ -210,7 +210,7 @@ impl<Submitter> ImportContext<Submitter> {
|
||||
}
|
||||
|
||||
/// Returns the validator set change if the parent header has signaled a change.
|
||||
pub fn parent_scheduled_change(&self) -> Option<&ScheduledChange> {
|
||||
pub fn parent_scheduled_change(&self) -> Option<&AuraScheduledChange> {
|
||||
self.parent_scheduled_change.as_ref()
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ pub trait Storage {
|
||||
) -> Option<ImportContext<Self::Submitter>>;
|
||||
/// Get new validators that are scheduled by given header and hash of the previous
|
||||
/// block that has scheduled change.
|
||||
fn scheduled_change(&self, hash: &H256) -> Option<ScheduledChange>;
|
||||
fn scheduled_change(&self, hash: &H256) -> Option<AuraScheduledChange>;
|
||||
/// Insert imported header.
|
||||
fn insert_header(&mut self, header: HeaderToImport<Self::Submitter>);
|
||||
/// Finalize given block and schedules pruning of all headers
|
||||
@@ -479,7 +479,7 @@ decl_storage! {
|
||||
/// When it reaches zero, we are free to prune validator set as well.
|
||||
ValidatorsSetsRc: map hasher(twox_64_concat) u64 => Option<u64>;
|
||||
/// Map of validators set changes scheduled by given header.
|
||||
ScheduledChanges: map hasher(identity) H256 => Option<ScheduledChange>;
|
||||
ScheduledChanges: map hasher(identity) H256 => Option<AuraScheduledChange>;
|
||||
}
|
||||
add_extra_genesis {
|
||||
config(initial_header): AuraHeader;
|
||||
@@ -766,7 +766,7 @@ impl<T: Trait<I>, I: Instance> Storage for BridgeStorage<T, I> {
|
||||
})
|
||||
}
|
||||
|
||||
fn scheduled_change(&self, hash: &H256) -> Option<ScheduledChange> {
|
||||
fn scheduled_change(&self, hash: &H256) -> Option<AuraScheduledChange> {
|
||||
ScheduledChanges::<I>::get(hash)
|
||||
}
|
||||
|
||||
@@ -777,7 +777,7 @@ impl<T: Trait<I>, I: Instance> Storage for BridgeStorage<T, I> {
|
||||
if let Some(scheduled_change) = header.scheduled_change {
|
||||
ScheduledChanges::<I>::insert(
|
||||
&header.id.hash,
|
||||
ScheduledChange {
|
||||
AuraScheduledChange {
|
||||
validators: scheduled_change,
|
||||
prev_signal_block: header.context.last_signal_block,
|
||||
},
|
||||
@@ -1119,7 +1119,7 @@ pub(crate) mod tests {
|
||||
if i == 7 && j == 1 {
|
||||
ScheduledChanges::<DefaultInstance>::insert(
|
||||
hash,
|
||||
ScheduledChange {
|
||||
AuraScheduledChange {
|
||||
validators: validators_addresses(5),
|
||||
prev_signal_block: None,
|
||||
},
|
||||
|
||||
@@ -277,7 +277,7 @@ pub(crate) mod tests {
|
||||
use super::*;
|
||||
use crate::mock::{run_test, validators_addresses, validators_change_receipt, TestRuntime};
|
||||
use crate::DefaultInstance;
|
||||
use crate::{BridgeStorage, Headers, ScheduledChange, ScheduledChanges, StoredHeader};
|
||||
use crate::{AuraScheduledChange, BridgeStorage, Headers, ScheduledChanges, StoredHeader};
|
||||
use bp_eth_poa::compute_merkle_root;
|
||||
use frame_support::StorageMap;
|
||||
|
||||
@@ -428,7 +428,7 @@ pub(crate) mod tests {
|
||||
next_validators_set_id: 0,
|
||||
last_signal_block: scheduled_at,
|
||||
};
|
||||
let scheduled_change = ScheduledChange {
|
||||
let scheduled_change = AuraScheduledChange {
|
||||
validators: validators_addresses(1),
|
||||
prev_signal_block: None,
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::validators::{Validators, ValidatorsConfiguration};
|
||||
use crate::{AuraConfiguration, ChainTime, ImportContext, PoolConfiguration, ScheduledChange, Storage};
|
||||
use crate::{AuraConfiguration, AuraScheduledChange, ChainTime, ImportContext, PoolConfiguration, Storage};
|
||||
use bp_eth_poa::{
|
||||
public_to_address, step_validator, Address, AuraHeader, HeaderId, Receipt, SealedEmptyStep, H256, H520, U128, U256,
|
||||
};
|
||||
@@ -341,7 +341,7 @@ fn find_next_validators_signal<S: Storage>(storage: &S, context: &ImportContext<
|
||||
// if parent schedules validators set change, then it may be our set
|
||||
// else we'll start with last known change
|
||||
let mut current_set_signal_block = context.last_signal_block();
|
||||
let mut next_scheduled_set: Option<ScheduledChange> = None;
|
||||
let mut next_scheduled_set: Option<AuraScheduledChange> = None;
|
||||
|
||||
loop {
|
||||
// if we have reached block that signals finalized change, then
|
||||
@@ -456,7 +456,7 @@ mod tests {
|
||||
});
|
||||
ScheduledChanges::<DefaultInstance>::insert(
|
||||
header.header.parent_hash,
|
||||
ScheduledChange {
|
||||
AuraScheduledChange {
|
||||
validators: signalled_set,
|
||||
prev_signal_block: None,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user