mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Light friendly storage tracking: changes trie + extending over ranges (#628)
* changes_trie * changs_trie: continue * changes_trie: adding tests * fixed TODO * removed obsolete ExtrinsicChanges * encodable ChangesTrieConfiguration * removed polkadot fle * fixed grumbles * ext_storage_changes_root returns u32 * moved changes trie root to digest * removed commented code * read storage values from native code * fixed grumbles * fixed grumbles * missing comma
This commit is contained in:
committed by
Gav Wood
parent
24479cd7f5
commit
7fa337afbc
@@ -46,15 +46,10 @@ use runtime_support::{storage, Parameter};
|
||||
use runtime_support::dispatch::Result;
|
||||
use runtime_support::storage::StorageValue;
|
||||
use runtime_support::storage::unhashed::StorageVec;
|
||||
use primitives::traits::{MaybeSerializeDebug, OnFinalise, Member, DigestItem};
|
||||
use primitives::traits::{MaybeSerializeDebug, OnFinalise, Member};
|
||||
use primitives::bft::MisbehaviorReport;
|
||||
use system::{ensure_signed, ensure_inherent};
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
use substrate_primitives::Blake2Hasher;
|
||||
#[cfg(any(feature = "std", test))]
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub const AUTHORITY_AT: &'static [u8] = b":auth:";
|
||||
pub const AUTHORITY_COUNT: &'static [u8] = b":auth:len";
|
||||
|
||||
@@ -88,22 +83,24 @@ pub enum RawLog<SessionKey> {
|
||||
AuthoritiesChange(Vec<SessionKey>),
|
||||
}
|
||||
|
||||
impl<SessionKey: Member> DigestItem for RawLog<SessionKey> {
|
||||
type AuthorityId = SessionKey;
|
||||
|
||||
impl<SessionKey: Member> RawLog<SessionKey> {
|
||||
/// Try to cast the log entry as AuthoritiesChange log entry.
|
||||
fn as_authorities_change(&self) -> Option<&[SessionKey]> {
|
||||
pub fn as_authorities_change(&self) -> Option<&[SessionKey]> {
|
||||
match *self {
|
||||
RawLog::AuthoritiesChange(ref item) => Some(&item),
|
||||
RawLog::AuthoritiesChange(ref item) => Some(item),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Implementation for tests outside of this crate.
|
||||
impl<N> From<RawLog<N>> for u64 {
|
||||
fn from(log: RawLog<N>) -> u64 {
|
||||
#[cfg(any(feature = "std", test))]
|
||||
impl<N> From<RawLog<N>> for primitives::testing::DigestItem {
|
||||
fn from(log: RawLog<N>) -> primitives::testing::DigestItem {
|
||||
match log {
|
||||
RawLog::AuthoritiesChange(_) => 1,
|
||||
RawLog::AuthoritiesChange(authorities) =>
|
||||
primitives::generic::DigestItem::AuthoritiesChange
|
||||
::<substrate_primitives::H256, u64>(authorities.into_iter()
|
||||
.enumerate().map(|(i, _)| i as u64).collect()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -252,10 +249,10 @@ impl<T: Trait> Default for GenesisConfig<T> {
|
||||
#[cfg(any(feature = "std", test))]
|
||||
impl<T: Trait> primitives::BuildStorage for GenesisConfig<T>
|
||||
{
|
||||
fn build_storage(self) -> ::std::result::Result<HashMap<Vec<u8>, Vec<u8>>, String> {
|
||||
fn build_storage(self) -> ::std::result::Result<primitives::StorageMap, String> {
|
||||
use codec::{Encode, KeyedVec};
|
||||
let auth_count = self.authorities.len() as u32;
|
||||
let mut r: runtime_io::TestExternalities<Blake2Hasher> = self.authorities.into_iter().enumerate().map(|(i, v)|
|
||||
let mut r: primitives::StorageMap = self.authorities.into_iter().enumerate().map(|(i, v)|
|
||||
((i as u32).to_keyed_vec(AUTHORITY_AT), v.encode())
|
||||
).collect();
|
||||
r.insert(AUTHORITY_COUNT.to_vec(), auth_count.encode());
|
||||
|
||||
Reference in New Issue
Block a user