mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 08:51:09 +00:00
Extract well known keys into a single place (#764)
* Extract well known keys into a single place * Fixes.
This commit is contained in:
committed by
Gav Wood
parent
7fa337afbc
commit
e7d1933d25
@@ -148,6 +148,7 @@ fn prepare_digest_input<'a, S, H, C>(
|
||||
mod test {
|
||||
use codec::Encode;
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
use primitives::storage::well_known_keys::EXTRINSIC_INDEX;
|
||||
use backend::InMemory;
|
||||
use changes_trie::storage::InMemoryStorage;
|
||||
use overlayed_changes::OverlayedValue;
|
||||
@@ -208,7 +209,7 @@ mod test {
|
||||
}),
|
||||
].into_iter().collect(),
|
||||
committed: vec![
|
||||
(b":extrinsic_index".to_vec(), OverlayedValue {
|
||||
(EXTRINSIC_INDEX.to_vec(), OverlayedValue {
|
||||
value: Some(3u32.encode()),
|
||||
extrinsics: None,
|
||||
}),
|
||||
|
||||
@@ -229,6 +229,7 @@ where
|
||||
mod tests {
|
||||
use codec::Encode;
|
||||
use primitives::{Blake2Hasher, RlpCodec};
|
||||
use primitives::storage::well_known_keys::EXTRINSIC_INDEX;
|
||||
use backend::InMemory;
|
||||
use changes_trie::{Configuration as ChangesTrieConfiguration,
|
||||
InMemoryStorage as InMemoryChangesTrieStorage};
|
||||
@@ -242,7 +243,7 @@ mod tests {
|
||||
fn prepare_overlay_with_changes() -> OverlayedChanges {
|
||||
OverlayedChanges {
|
||||
prospective: vec![
|
||||
(b":extrinsic_index".to_vec(), OverlayedValue {
|
||||
(EXTRINSIC_INDEX.to_vec(), OverlayedValue {
|
||||
value: Some(3u32.encode()),
|
||||
extrinsics: Some(vec![1].into_iter().collect())
|
||||
}),
|
||||
|
||||
@@ -44,6 +44,7 @@ use patricia_trie::NodeCodec;
|
||||
use rlp::Encodable;
|
||||
use heapsize::HeapSizeOf;
|
||||
use codec::Decode;
|
||||
use primitives::storage::well_known_keys;
|
||||
|
||||
pub mod backend;
|
||||
mod changes_trie;
|
||||
@@ -260,11 +261,11 @@ where
|
||||
let strategy: ExecutionStrategy = (&manager).into();
|
||||
|
||||
// make a copy.
|
||||
let code = try_read_overlay_value(overlay, backend, b":code")?
|
||||
let code = try_read_overlay_value(overlay, backend, well_known_keys::CODE)?
|
||||
.ok_or_else(|| Box::new(ExecutionError::CodeEntryDoesNotExist) as Box<Error>)?
|
||||
.to_vec();
|
||||
|
||||
let heap_pages = try_read_overlay_value(overlay, backend, b":heappages")?
|
||||
let heap_pages = try_read_overlay_value(overlay, backend, well_known_keys::HEAP_PAGES)?
|
||||
.and_then(|v| u64::decode(&mut &v[..])).unwrap_or(8) as usize;
|
||||
|
||||
// read changes trie configuration. The reason why we're doing it here instead of the
|
||||
@@ -272,7 +273,11 @@ where
|
||||
// proof-of-execution on light clients. And the proof is recorded by the backend which
|
||||
// is created after OverlayedChanges
|
||||
|
||||
let changes_trie_config = try_read_overlay_value(overlay, backend, b":changes_trie")?;
|
||||
let changes_trie_config = try_read_overlay_value(
|
||||
overlay,
|
||||
backend,
|
||||
well_known_keys::CHANGES_TRIE_CONFIG
|
||||
)?;
|
||||
set_changes_trie_config(overlay, changes_trie_config)?;
|
||||
|
||||
let result = {
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use codec::Decode;
|
||||
use changes_trie::{NO_EXTRINSIC_INDEX, Configuration as ChangesTrieConfig};
|
||||
use primitives::storage::well_known_keys::EXTRINSIC_INDEX;
|
||||
|
||||
/// The overlayed changes to state to be queried on top of the backend.
|
||||
///
|
||||
@@ -168,7 +169,7 @@ impl OverlayedChanges {
|
||||
#[cfg(test)]
|
||||
pub(crate) fn set_extrinsic_index(&mut self, extrinsic_index: u32) {
|
||||
use codec::Encode;
|
||||
self.prospective.insert(b":extrinsic_index".to_vec(), OverlayedValue {
|
||||
self.prospective.insert(EXTRINSIC_INDEX.to_vec(), OverlayedValue {
|
||||
value: Some(extrinsic_index.encode()),
|
||||
extrinsics: None,
|
||||
});
|
||||
@@ -183,7 +184,7 @@ impl OverlayedChanges {
|
||||
fn extrinsic_index(&self) -> Option<u32> {
|
||||
match self.changes_trie_config.is_some() {
|
||||
true => Some(
|
||||
self.storage(b":extrinsic_index")
|
||||
self.storage(EXTRINSIC_INDEX)
|
||||
.and_then(|idx| idx.and_then(|idx| Decode::decode(&mut &*idx)))
|
||||
.unwrap_or(NO_EXTRINSIC_INDEX)),
|
||||
false => None,
|
||||
@@ -201,6 +202,7 @@ impl From<Option<Vec<u8>>> for OverlayedValue {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use primitives::{Blake2Hasher, RlpCodec, H256};
|
||||
use primitives::storage::well_known_keys::EXTRINSIC_INDEX;
|
||||
use backend::InMemory;
|
||||
use changes_trie::InMemoryStorage as InMemoryChangesTrieStorage;
|
||||
use ext::Ext;
|
||||
@@ -209,7 +211,7 @@ mod tests {
|
||||
|
||||
fn strip_extrinsic_index(map: &HashMap<Vec<u8>, OverlayedValue>) -> HashMap<Vec<u8>, OverlayedValue> {
|
||||
let mut clone = map.clone();
|
||||
clone.remove(&b":extrinsic_index".to_vec());
|
||||
clone.remove(&EXTRINSIC_INDEX.to_vec());
|
||||
clone
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ use rlp::Encodable;
|
||||
use triehash::trie_root;
|
||||
use backend::InMemory;
|
||||
use changes_trie::{compute_changes_trie_root, InMemoryStorage as ChangesTrieInMemoryStorage};
|
||||
use primitives::storage::well_known_keys::CHANGES_TRIE_CONFIG;
|
||||
use super::{Externalities, OverlayedChanges};
|
||||
|
||||
/// Simple HashMap-based Externalities impl.
|
||||
@@ -41,7 +42,7 @@ impl<H: Hasher, C: NodeCodec<H>> TestExternalities<H, C> where H::Out: HeapSizeO
|
||||
let mut overlay = OverlayedChanges::default();
|
||||
super::set_changes_trie_config(
|
||||
&mut overlay,
|
||||
inner.get(&b":changes_trie".to_vec()).cloned())
|
||||
inner.get(&CHANGES_TRIE_CONFIG.to_vec()).cloned())
|
||||
.expect("changes trie configuration is correct in test env; qed");
|
||||
|
||||
TestExternalities {
|
||||
|
||||
Reference in New Issue
Block a user