Changes tries: support forks (#950)

* forks support in changes trie storage

* moved convert_hash to primitives

* optimize ChangesTrieRootsStorage::root when anchor is canonicalized
This commit is contained in:
Svyatoslav Nikolsky
2018-11-13 14:17:14 +03:00
committed by Gav Wood
parent 037f9dde10
commit 6e3c56c135
25 changed files with 276 additions and 138 deletions
+10
View File
@@ -76,6 +76,16 @@ impl_rest!(H160, 20);
impl_rest!(H256, 32);
impl_rest!(H512, 64);
/// Hash conversion. Used to convert between unbound associated hash types in traits,
/// implemented by the same hash type.
/// Panics if used to convert between different hash types.
pub fn convert_hash<H1: Default + AsMut<[u8]>, H2: AsRef<[u8]>>(src: &H2) -> H1 {
let mut dest = H1::default();
assert_eq!(dest.as_mut().len(), src.as_ref().len());
dest.as_mut().copy_from_slice(src.as_ref());
dest
}
#[cfg(test)]
mod tests {
use super::*;
+1 -1
View File
@@ -107,7 +107,7 @@ mod changes_trie;
#[cfg(test)]
mod tests;
pub use self::hash::{H160, H256, H512};
pub use self::hash::{H160, H256, H512, convert_hash};
pub use self::uint::U256;
pub use authority_id::AuthorityId;
pub use changes_trie::ChangesTrieConfiguration;