Skip to content

Commit

Permalink
store contract keys with blake2_256 (paritytech#2414)
Browse files Browse the repository at this point in the history
* store contract keys with blake2_256

* bump version
  • Loading branch information
gui1117 authored and gavofyork committed Apr 29, 2019
1 parent 00278bf commit 581956f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("node"),
impl_name: create_runtime_str!("substrate-node"),
authoring_version: 10,
spec_version: 66,
spec_version: 67,
impl_version: 67,
apis: RUNTIME_API_VERSIONS,
};
Expand Down
9 changes: 5 additions & 4 deletions srml/contract/src/account_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use system;
use rstd::cell::RefCell;
use rstd::collections::btree_map::{BTreeMap, Entry};
use rstd::prelude::*;
use runtime_io::blake2_256;
use runtime_primitives::traits::Zero;
use srml_support::{StorageMap, traits::{UpdateBalanceOutcome,
SignedImbalance, Currency, Imbalance}, storage::child};
Expand Down Expand Up @@ -62,7 +63,7 @@ pub trait AccountDb<T: Trait> {
pub struct DirectAccountDb;
impl<T: Trait> AccountDb<T> for DirectAccountDb {
fn get_storage(&self, _account: &T::AccountId, trie_id: Option<&TrieId>, location: &StorageKey) -> Option<Vec<u8>> {
trie_id.and_then(|id| child::get_raw(id, location))
trie_id.and_then(|id| child::get_raw(id, &blake2_256(location)))
}
fn get_code(&self, account: &T::AccountId) -> Option<CodeHash<T>> {
<CodeHashOf<T>>::get(account)
Expand Down Expand Up @@ -105,14 +106,14 @@ impl<T: Trait> AccountDb<T> for DirectAccountDb {

let mut new_storage_size = info.storage_size;
for (k, v) in changed.storage.into_iter() {
if let Some(value) = child::get_raw(&info.trie_id[..], &k) {
if let Some(value) = child::get_raw(&info.trie_id[..], &blake2_256(&k)) {
new_storage_size -= value.len() as u64;
}
if let Some(value) = v {
new_storage_size += value.len() as u64;
child::put_raw(&info.trie_id[..], &k, &value[..]);
child::put_raw(&info.trie_id[..], &blake2_256(&k), &value[..]);
} else {
child::kill(&info.trie_id[..], &k);
child::kill(&info.trie_id[..], &blake2_256(&k));
}
}

Expand Down

0 comments on commit 581956f

Please sign in to comment.