mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 11:41:02 +00:00
Refactor storage hashing away from opaque types (#903)
* Refactor storage of various modules. * The real list of claims * Migration away from opaque maps * Fix * Fix for task executor API change
This commit is contained in:
@@ -106,11 +106,11 @@ decl_storage! {
|
||||
trait Store for Module<T: Trait> as Attestations {
|
||||
/// A mapping from modular block number (n % AttestationPeriod)
|
||||
/// to session index and the list of candidate hashes.
|
||||
pub RecentParaBlocks: map hasher(blake2_256) T::BlockNumber => Option<IncludedBlocks<T>>;
|
||||
pub RecentParaBlocks: map hasher(twox_64_concat) T::BlockNumber => Option<IncludedBlocks<T>>;
|
||||
|
||||
/// Attestations on a recent parachain block.
|
||||
pub ParaBlockAttestations:
|
||||
double_map hasher(blake2_256) T::BlockNumber, hasher(blake2_128) Hash
|
||||
double_map hasher(twox_64_concat) T::BlockNumber, hasher(identity) Hash
|
||||
=> Option<BlockAttestations<T>>;
|
||||
|
||||
// Did we already have more attestations included in this block?
|
||||
|
||||
@@ -25,7 +25,9 @@ use system::{ensure_root, ensure_none};
|
||||
use codec::{Encode, Decode};
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{self, Serialize, Deserialize, Serializer, Deserializer};
|
||||
use sp_runtime::traits::{Zero, CheckedSub};
|
||||
#[cfg(feature = "std")]
|
||||
use sp_runtime::traits::Zero;
|
||||
use sp_runtime::traits::CheckedSub;
|
||||
use sp_runtime::{
|
||||
RuntimeDebug, transaction_validity::{
|
||||
TransactionLongevity, TransactionValidity, ValidTransaction, InvalidTransaction
|
||||
@@ -122,7 +124,7 @@ decl_storage! {
|
||||
trait Store for Module<T: Trait> as Claims {
|
||||
Claims get(claims) build(|config: &GenesisConfig<T>| {
|
||||
config.claims.iter().map(|(a, b)| (a.clone(), b.clone())).collect::<Vec<_>>()
|
||||
}): map hasher(blake2_256) EthereumAddress => Option<BalanceOf<T>>;
|
||||
}): map hasher(identity) EthereumAddress => Option<BalanceOf<T>>;
|
||||
Total get(total) build(|config: &GenesisConfig<T>| {
|
||||
config.claims.iter().fold(Zero::zero(), |acc: BalanceOf<T>, &(_, n)| acc + n)
|
||||
}): BalanceOf<T>;
|
||||
@@ -131,7 +133,7 @@ decl_storage! {
|
||||
/// Second balance is how much should be unlocked per block.
|
||||
/// The block number is when the vesting should start.
|
||||
Vesting get(vesting) config():
|
||||
map hasher(blake2_256) EthereumAddress
|
||||
map hasher(identity) EthereumAddress
|
||||
=> Option<(BalanceOf<T>, BalanceOf<T>, T::BlockNumber)>;
|
||||
}
|
||||
add_extra_genesis {
|
||||
@@ -139,6 +141,19 @@ decl_storage! {
|
||||
}
|
||||
}
|
||||
|
||||
mod migration {
|
||||
use super::*;
|
||||
|
||||
pub fn migrate<T: Trait>() {
|
||||
if let Ok(addresses) = Vec::<EthereumAddress>::decode(&mut &include_bytes!("./claims.scale")[..]) {
|
||||
for i in &addresses {
|
||||
Vesting::<T>::migrate_key_from_blake(i);
|
||||
Claims::<T>::migrate_key_from_blake(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
type Error = Error<T>;
|
||||
@@ -149,6 +164,10 @@ decl_module! {
|
||||
/// Deposit one of this module's events by using the default implementation.
|
||||
fn deposit_event() = default;
|
||||
|
||||
fn on_runtime_upgrade() {
|
||||
migration::migrate::<T>();
|
||||
}
|
||||
|
||||
/// Make a claim to collect your DOTs.
|
||||
///
|
||||
/// The dispatch origin for this call must be _None_.
|
||||
@@ -393,7 +412,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = balances::AccountData<u64>;
|
||||
type OnNewAccount = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnKilledAccount = Balances;
|
||||
}
|
||||
|
||||
@@ -681,7 +700,7 @@ mod benchmarking {
|
||||
let vesting = Some((100_000.into(), 1_000.into(), 100.into()));
|
||||
}: _(RawOrigin::Root, account, VALUE.into(), vesting)
|
||||
|
||||
// Benchmark the time it takes to execute `validate_unsigned`
|
||||
// Benchmark the time it takes to execute `validate_unsigned`
|
||||
validate_unsigned {
|
||||
let c in ...;
|
||||
// Crate signature
|
||||
@@ -703,7 +722,7 @@ mod benchmarking {
|
||||
}
|
||||
}
|
||||
|
||||
// Benchmark the time it takes to do `repeat` number of `eth_recover`
|
||||
// Benchmark the time it takes to do `repeat` number of `eth_recover`
|
||||
eth_recover {
|
||||
let i in 0 .. 1_000;
|
||||
// Crate signature
|
||||
|
||||
Binary file not shown.
@@ -167,7 +167,7 @@ decl_storage! {
|
||||
trait Store for Module<T: Trait> as Crowdfund {
|
||||
/// Info on all of the funds.
|
||||
Funds get(funds):
|
||||
map hasher(blake2_256) FundIndex
|
||||
map hasher(twox_64_concat) FundIndex
|
||||
=> Option<FundInfo<T::AccountId, BalanceOf<T>, T::Hash, T::BlockNumber>>;
|
||||
|
||||
/// The total number of funds that have so far been allocated.
|
||||
@@ -615,7 +615,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = balances::AccountData<u64>;
|
||||
type OnNewAccount = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnKilledAccount = Balances;
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -155,16 +155,16 @@ decl_storage! {
|
||||
/// All authorities' keys at the moment.
|
||||
pub Authorities get(authorities): Vec<ValidatorId>;
|
||||
/// The parachains registered at present.
|
||||
pub Code get(parachain_code): map hasher(blake2_256) ParaId => Option<Vec<u8>>;
|
||||
pub Code get(parachain_code): map hasher(twox_64_concat) ParaId => Option<Vec<u8>>;
|
||||
/// The heads of the parachains registered at present.
|
||||
pub Heads get(parachain_head): map hasher(blake2_256) ParaId => Option<Vec<u8>>;
|
||||
pub Heads get(parachain_head): map hasher(twox_64_concat) ParaId => Option<Vec<u8>>;
|
||||
/// Messages ready to be dispatched onto the relay chain. It is subject to
|
||||
/// `MAX_MESSAGE_COUNT` and `WATERMARK_MESSAGE_SIZE`.
|
||||
pub RelayDispatchQueue: map hasher(blake2_256) ParaId => Vec<UpwardMessage>;
|
||||
pub RelayDispatchQueue: map hasher(twox_64_concat) ParaId => Vec<UpwardMessage>;
|
||||
/// Size of the dispatch queues. Separated from actual data in order to avoid costly
|
||||
/// decoding when checking receipt validity. First item in tuple is the count of messages
|
||||
/// second if the total length (in bytes) of the message payloads.
|
||||
pub RelayDispatchQueueSize: map hasher(blake2_256) ParaId => (u32, u32);
|
||||
pub RelayDispatchQueueSize: map hasher(twox_64_concat) ParaId => (u32, u32);
|
||||
/// The ordered list of ParaIds that have a `RelayDispatchQueue` entry.
|
||||
NeedsDispatch: Vec<ParaId>;
|
||||
|
||||
@@ -938,7 +938,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = balances::AccountData<u128>;
|
||||
type OnNewAccount = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -177,16 +177,16 @@ decl_storage! {
|
||||
NextFreeId: ParaId = LOWEST_USER_ID;
|
||||
|
||||
/// Pending swap operations.
|
||||
PendingSwap: map hasher(blake2_256) ParaId => Option<ParaId>;
|
||||
PendingSwap: map hasher(twox_64_concat) ParaId => Option<ParaId>;
|
||||
|
||||
/// Map of all registered parathreads/chains.
|
||||
Paras get(paras): map hasher(blake2_256) ParaId => Option<ParaInfo>;
|
||||
Paras get(paras): map hasher(twox_64_concat) ParaId => Option<ParaInfo>;
|
||||
|
||||
/// The current queue for parathreads that should be retried.
|
||||
RetryQueue get(retry_queue): Vec<Vec<(ParaId, CollatorId)>>;
|
||||
|
||||
/// Users who have paid a parathread's deposit
|
||||
Debtors: map hasher(blake2_256) ParaId => T::AccountId;
|
||||
Debtors: map hasher(twox_64_concat) ParaId => T::AccountId;
|
||||
}
|
||||
add_extra_genesis {
|
||||
config(parachains): Vec<(ParaId, Vec<u8>, Vec<u8>)>;
|
||||
@@ -704,7 +704,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = balances::AccountData<u128>;
|
||||
type OnNewAccount = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnKilledAccount = Balances;
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ decl_storage! {
|
||||
/// If a parachain doesn't exist *yet* but is scheduled to exist in the future, then it
|
||||
/// will be left-padded with one or more zeroes to denote the fact that nothing is held on
|
||||
/// deposit for the non-existent chain currently, but is held at some point in the future.
|
||||
pub Deposits get(deposits): map hasher(blake2_256) ParaId => Vec<BalanceOf<T>>;
|
||||
pub Deposits get(deposits): map hasher(twox_64_concat) ParaId => Vec<BalanceOf<T>>;
|
||||
|
||||
/// Information relating to the current auction, if there is one.
|
||||
///
|
||||
@@ -162,28 +162,28 @@ decl_storage! {
|
||||
/// The winning bids for each of the 10 ranges at each block in the final Ending Period of
|
||||
/// the current auction. The map's key is the 0-based index into the Ending Period. The
|
||||
/// first block of the ending period is 0; the last is `EndingPeriod - 1`.
|
||||
pub Winning get(winning): map hasher(blake2_256) T::BlockNumber => Option<WinningData<T>>;
|
||||
pub Winning get(winning): map hasher(twox_64_concat) T::BlockNumber => Option<WinningData<T>>;
|
||||
|
||||
/// Amounts currently reserved in the accounts of the bidders currently winning
|
||||
/// (sub-)ranges.
|
||||
pub ReservedAmounts get(reserved_amounts):
|
||||
map hasher(blake2_256) Bidder<T::AccountId> => Option<BalanceOf<T>>;
|
||||
map hasher(twox_64_concat) Bidder<T::AccountId> => Option<BalanceOf<T>>;
|
||||
|
||||
/// The set of Para IDs that have won and need to be on-boarded at an upcoming lease-period.
|
||||
/// This is cleared out on the first block of the lease period.
|
||||
pub OnboardQueue get(onboard_queue): map hasher(blake2_256) LeasePeriodOf<T> => Vec<ParaId>;
|
||||
pub OnboardQueue get(onboard_queue): map hasher(twox_64_concat) LeasePeriodOf<T> => Vec<ParaId>;
|
||||
|
||||
/// The actual on-boarding information. Only exists when one of the following is true:
|
||||
/// - It is before the lease period that the parachain should be on-boarded.
|
||||
/// - The full on-boarding information has not yet been provided and the parachain is not
|
||||
/// yet due to be off-boarded.
|
||||
pub Onboarding get(onboarding):
|
||||
map hasher(blake2_256) ParaId =>
|
||||
map hasher(twox_64_concat) ParaId =>
|
||||
Option<(LeasePeriodOf<T>, IncomingParachain<T::AccountId, T::Hash>)>;
|
||||
|
||||
/// Off-boarding account; currency held on deposit for the parachain gets placed here if the
|
||||
/// parachain gets off-boarded; i.e. its lease period is up and it isn't renewed.
|
||||
pub Offboarding get(offboarding): map hasher(blake2_256) ParaId => T::AccountId;
|
||||
pub Offboarding get(offboarding): map hasher(twox_64_concat) ParaId => T::AccountId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -916,7 +916,7 @@ mod tests {
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = balances::AccountData<u64>;
|
||||
type OnNewAccount = ();
|
||||
type MigrateAccount = (); type OnNewAccount = ();
|
||||
type OnKilledAccount = Balances;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user