diff --git a/hash-db/src/lib.rs b/hash-db/src/lib.rs index cfd2a067..249ae4eb 100644 --- a/hash-db/src/lib.rs +++ b/hash-db/src/lib.rs @@ -72,7 +72,7 @@ pub trait PlainDB: Send + Sync + AsPlainDB { /// hash is not known. fn get(&self, key: &K) -> Option; - /// Check for the existance of a hash-key. + /// Check for the existence of a hash-key. fn contains(&self, key: &K) -> bool; /// Insert a datum item into the DB. Insertions are counted and the equivalent @@ -113,7 +113,7 @@ pub trait HashDB: Send + Sync + AsHashDB { /// hash is not known. fn get(&self, key: &H::Out, prefix: Prefix) -> Option; - /// Check for the existance of a hash-key. + /// Check for the existence of a hash-key. fn contains(&self, key: &H::Out, prefix: Prefix) -> bool; /// Insert a datum item into the DB and return the datum's hash for a later lookup. Insertions diff --git a/trie-db/Cargo.toml b/trie-db/Cargo.toml index f0a3ae46..e640220b 100644 --- a/trie-db/Cargo.toml +++ b/trie-db/Cargo.toml @@ -9,7 +9,7 @@ license = "Apache-2.0" [dependencies] log = "0.4" rand = { version = "0.6", default-features = false } -elastic-array = { version = "0.10", default-features = false } +smallvec = "1.0.0" hash-db = { path = "../hash-db", default-features = false, version = "0.15.2"} hashbrown = { version = "0.6.3", default-features = false } @@ -29,7 +29,6 @@ parity-codec-derive = "3.0" [features] default = ["std"] std = [ - "elastic-array/std", "hash-db/std", "rand/std", ] diff --git a/trie-db/src/fatdb.rs b/trie-db/src/fatdb.rs index 1ffd0d95..5040722d 100644 --- a/trie-db/src/fatdb.rs +++ b/trie-db/src/fatdb.rs @@ -119,8 +119,7 @@ where let aux_hash = L::Hash::hash(&hash); ( self.trie.db().get(&aux_hash, Default::default()) - .expect("Missing fatdb hash") - .into_vec(), + .expect("Missing fatdb hash"), value, ) }) @@ -144,9 +143,10 @@ mod test { t.insert(&[0x01u8, 0x23], &[0x01u8, 0x23]).unwrap(); } let t = RefFatDB::new(&memdb, &root).unwrap(); - assert_eq!(t.get(&[0x01u8, 0x23]).unwrap().unwrap(), DBValue::from_slice(&[0x01u8, 0x23])); + assert_eq!(t.get(&[0x01u8, 0x23]).unwrap().unwrap(), vec![0x01u8, 0x23]); assert_eq!( t.iter().unwrap().map(Result::unwrap).collect::>(), - vec![(vec![0x01u8, 0x23], DBValue::from_slice(&[0x01u8, 0x23] as &[u8]))]); + vec![(vec![0x01u8, 0x23], vec![0x01u8, 0x23])] + ); } } diff --git a/trie-db/src/fatdbmut.rs b/trie-db/src/fatdbmut.rs index 943c4f1c..8b9edb18 100644 --- a/trie-db/src/fatdbmut.rs +++ b/trie-db/src/fatdbmut.rs @@ -88,7 +88,7 @@ where // insert if it doesn't exist. if out.is_none() { let aux_hash = L::Hash::hash(hash.as_ref()); - db.emplace(aux_hash, EMPTY_PREFIX, DBValue::from_slice(key)); + db.emplace(aux_hash, EMPTY_PREFIX, key.to_vec()); } Ok(out) } @@ -126,7 +126,7 @@ mod test { let t = RefTrieDB::new(&memdb, &root).unwrap(); assert_eq!( t.get(&KeccakHasher::hash(&[0x01u8, 0x23])), - Ok(Some(DBValue::from_slice(&[0x01u8, 0x23]))), + Ok(Some(vec![0x01u8, 0x23])), ); } @@ -140,8 +140,8 @@ mod test { let aux_hash = KeccakHasher::hash(&key_hash); let mut t = RefFatDBMut::new(&mut memdb, &mut root); t.insert(&key, &val).unwrap(); - assert_eq!(t.get(&key), Ok(Some(DBValue::from_slice(&val)))); - assert_eq!(t.db().get(&aux_hash, EMPTY_PREFIX), Some(DBValue::from_slice(&key))); + assert_eq!(t.get(&key), Ok(Some(val.to_vec()))); + assert_eq!(t.db().get(&aux_hash, EMPTY_PREFIX), Some(key.to_vec())); t.remove(&key).unwrap(); assert_eq!(t.db().get(&aux_hash, EMPTY_PREFIX), None); } diff --git a/trie-db/src/lib.rs b/trie-db/src/lib.rs index 67bbce49..ddc93182 100644 --- a/trie-db/src/lib.rs +++ b/trie-db/src/lib.rs @@ -18,7 +18,7 @@ #[cfg(not(feature = "std"))] extern crate alloc; -extern crate elastic_array; +extern crate smallvec; extern crate hash_db; extern crate rand; #[macro_use] @@ -106,7 +106,8 @@ pub use trie_codec::{decode_compact, encode_compact}; #[cfg(feature = "std")] pub use iter_build::TrieRootPrint; -pub type DBValue = elastic_array::ElasticArray128; +/// Database value +pub type DBValue = Vec; /// Trie Errors. /// @@ -190,7 +191,7 @@ pub trait Query { impl<'a, H: Hasher> Query for &'a mut Recorder { type Item = DBValue; - fn decode(self, value: &[u8]) -> DBValue { DBValue::from_slice(value) } + fn decode(self, value: &[u8]) -> DBValue { value.to_vec() } fn record(&mut self, hash: &H::Out, data: &[u8], depth: u32) { (&mut **self).record(hash, data, depth); } @@ -227,7 +228,7 @@ pub trait Trie { &'a self, key: &'key [u8], ) -> Result, TrieHash, CError> where 'a: 'key { - self.get_with(key, DBValue::from_slice) + self.get_with(key, |v: &[u8]| v.to_vec() ) } /// Search for the key with the given query parameter. See the docs of the `Query` @@ -428,9 +429,9 @@ pub trait TrieLayout { type Codec: NodeCodec::Out>; } -/// This traits associates a trie definition with prefered methods. +/// This trait associates a trie definition with preferred methods. /// It also contains own default implementations and can be -/// use to allow switching implementation. +/// used to allow switching implementation. pub trait TrieConfiguration: Sized + TrieLayout { /// Operation to build a trie db from its ordered iterator over its key/values. fn trie_build(db: &mut DB, input: I) -> ::Out where diff --git a/trie-db/src/nibble/mod.rs b/trie-db/src/nibble/mod.rs index cf0e95ae..1059e207 100644 --- a/trie-db/src/nibble/mod.rs +++ b/trie-db/src/nibble/mod.rs @@ -16,7 +16,6 @@ mod nibblevec; mod nibbleslice; -use elastic_array::ElasticArray36; use crate::node::NodeKey; use core_::cmp; @@ -146,13 +145,16 @@ pub mod nibble_ops { } +/// Backing storage for `NibbleVec`s. +pub(crate) type BackingByteVec = smallvec::SmallVec<[u8; 36]>; + /// Owning, nibble-oriented byte vector. Counterpart to `NibbleSlice`. /// Nibbles are always left aligned, so making a `NibbleVec` from /// a `NibbleSlice` can get costy. #[cfg_attr(feature = "std", derive(Debug))] #[derive(Clone, PartialEq, Eq)] pub struct NibbleVec { - inner: ElasticArray36, + inner: BackingByteVec, len: usize, } diff --git a/trie-db/src/nibble/nibbleslice.rs b/trie-db/src/nibble/nibbleslice.rs index e544cdf5..f702f7c4 100644 --- a/trie-db/src/nibble/nibbleslice.rs +++ b/trie-db/src/nibble/nibbleslice.rs @@ -16,8 +16,7 @@ use ::core_::cmp::*; use ::core_::fmt; -use super::{nibble_ops, NibbleSlice, NibbleSliceIterator}; -use elastic_array::ElasticArray36; +use super::{nibble_ops, NibbleSlice, NibbleSliceIterator, BackingByteVec}; use node::NodeKey; use node_codec::Partial; use hash_db::Prefix; @@ -78,13 +77,13 @@ impl<'a> NibbleSlice<'a> { let end = (self.offset + nb) / nibble_ops::NIBBLE_PER_BYTE; ( self.offset % nibble_ops::NIBBLE_PER_BYTE, - ElasticArray36::from_slice(&self.data[start..end]), + BackingByteVec::from_slice(&self.data[start..end]), ) } else { // unaligned let start = self.offset / nibble_ops::NIBBLE_PER_BYTE; let end = (self.offset + nb) / nibble_ops::NIBBLE_PER_BYTE; - let ea = ElasticArray36::from_slice(&self.data[start..=end]); + let ea = BackingByteVec::from_slice(&self.data[start..=end]); let ea_offset = self.offset % nibble_ops::NIBBLE_PER_BYTE; let n_offset = nibble_ops::number_padding(nb); let mut result = (ea_offset, ea); @@ -229,7 +228,7 @@ impl<'a> NibbleSlice<'a> { } /// Owned version of a `Prefix` from a `left` method call. - pub fn left_owned(&'a self) -> (ElasticArray36, Option) { + pub fn left_owned(&'a self) -> (BackingByteVec, Option) { let (a, b) = self.left(); (a.into(), b) } @@ -285,8 +284,7 @@ impl<'a> fmt::Debug for NibbleSlice<'a> { #[cfg(test)] mod tests { - use crate::nibble::NibbleSlice; - use elastic_array::ElasticArray36; + use crate::nibble::{NibbleSlice, BackingByteVec}; static D: &'static [u8;3] = &[0x01u8, 0x23, 0x45]; #[test] @@ -329,16 +327,16 @@ mod tests { #[test] fn encoded_pre() { let n = NibbleSlice::new(D); - assert_eq!(n.to_stored(), (0, ElasticArray36::from_slice(&[0x01, 0x23, 0x45]))); - assert_eq!(n.mid(1).to_stored(), (1, ElasticArray36::from_slice(&[0x01, 0x23, 0x45]))); - assert_eq!(n.mid(2).to_stored(), (0, ElasticArray36::from_slice(&[0x23, 0x45]))); - assert_eq!(n.mid(3).to_stored(), (1, ElasticArray36::from_slice(&[0x23, 0x45]))); + assert_eq!(n.to_stored(), (0, BackingByteVec::from_slice(&[0x01, 0x23, 0x45]))); + assert_eq!(n.mid(1).to_stored(), (1, BackingByteVec::from_slice(&[0x01, 0x23, 0x45]))); + assert_eq!(n.mid(2).to_stored(), (0, BackingByteVec::from_slice(&[0x23, 0x45]))); + assert_eq!(n.mid(3).to_stored(), (1, BackingByteVec::from_slice(&[0x23, 0x45]))); } #[test] fn from_encoded_pre() { let n = NibbleSlice::new(D); - let stored: ElasticArray36 = [0x01, 0x23, 0x45][..].into(); + let stored: BackingByteVec = [0x01, 0x23, 0x45][..].into(); assert_eq!(n, NibbleSlice::from_stored(&(0, stored.clone()))); assert_eq!(n.mid(1), NibbleSlice::from_stored(&(1, stored))); } diff --git a/trie-db/src/nibble/nibblevec.rs b/trie-db/src/nibble/nibblevec.rs index 30d2a3a2..cee11c23 100644 --- a/trie-db/src/nibble/nibblevec.rs +++ b/trie-db/src/nibble/nibblevec.rs @@ -13,8 +13,8 @@ // limitations under the License. //! An owning, nibble-oriented byte vector. -use elastic_array::ElasticArray36; -use nibble::NibbleSlice; + +use nibble::{NibbleSlice, BackingByteVec}; use nibble::nibble_ops; use hash_db::Prefix; use node_codec::Partial; @@ -30,7 +30,7 @@ impl NibbleVec { /// Make a new `NibbleVec`. pub fn new() -> Self { NibbleVec { - inner: ElasticArray36::new(), + inner: BackingByteVec::new(), len: 0, } } @@ -138,7 +138,7 @@ impl NibbleVec { } let pad = self.inner.len() * nibble_ops::NIBBLE_PER_BYTE - self.len; if pad == 0 { - self.inner.append_slice(&sl[..]); + self.inner.extend_from_slice(&sl[..]); } else { let kend = self.inner.len() - 1; if sl.len() > 0 { diff --git a/trie-db/src/node.rs b/trie-db/src/node.rs index 0a318e84..a286daed 100644 --- a/trie-db/src/node.rs +++ b/trie-db/src/node.rs @@ -12,9 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -use elastic_array::ElasticArray36; use hash_db::Hasher; -use nibble::NibbleSlice; +use nibble::{self, NibbleSlice}; use nibble::nibble_ops; use node_codec::NodeCodec; @@ -25,7 +24,7 @@ use alloc::vec::Vec; /// Partial node key type: offset and owned value of a nibbleslice. /// Offset is applied on first byte of array (bytes are right aligned). -pub type NodeKey = (usize, ElasticArray36); +pub type NodeKey = (usize, nibble::BackingByteVec); /// A reference to a trie node which may be stored within another trie node. #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/trie-db/src/sectriedb.rs b/trie-db/src/sectriedb.rs index e98880bd..82028bf3 100644 --- a/trie-db/src/sectriedb.rs +++ b/trie-db/src/sectriedb.rs @@ -102,6 +102,6 @@ mod test { t.insert(&KeccakHasher::hash(&[0x01u8, 0x23]), &[0x01u8, 0x23]).unwrap(); } let t = RefSecTrieDB::new(&db, &root).unwrap(); - assert_eq!(t.get(&[0x01u8, 0x23]).unwrap().unwrap(), DBValue::from_slice(&[0x01u8, 0x23])); + assert_eq!(t.get(&[0x01u8, 0x23]).unwrap().unwrap(), vec![0x01u8, 0x23]); } } diff --git a/trie-db/src/sectriedbmut.rs b/trie-db/src/sectriedbmut.rs index 324002fb..848fff7e 100644 --- a/trie-db/src/sectriedbmut.rs +++ b/trie-db/src/sectriedbmut.rs @@ -107,7 +107,7 @@ mod test { let t = RefTrieDB::new(&memdb, &root).unwrap(); assert_eq!( t.get(&KeccakHasher::hash(&[0x01u8, 0x23])).unwrap().unwrap(), - DBValue::from_slice(&[0x01u8, 0x23]), + vec![0x01u8, 0x23], ); } } diff --git a/trie-db/src/triedb.rs b/trie-db/src/triedb.rs index 679aad72..23d76cdf 100644 --- a/trie-db/src/triedb.rs +++ b/trie-db/src/triedb.rs @@ -56,7 +56,7 @@ use alloc::vec::Vec; /// RefTrieDBMut::new(&mut memdb, &mut root).insert(b"foo", b"bar").unwrap(); /// let t = RefTrieDB::new(&memdb, &root).unwrap(); /// assert!(t.contains(b"foo").unwrap()); -/// assert_eq!(t.get(b"foo").unwrap().unwrap(), DBValue::from_slice(b"bar")); +/// assert_eq!(t.get(b"foo").unwrap().unwrap(), b"bar".to_vec()); /// } /// ``` pub struct TrieDB<'db, L> @@ -119,7 +119,7 @@ where (Some(node_hash), node_data) } - NodeHandle::Inline(data) => (None, DBValue::from_slice(data)), + NodeHandle::Inline(data) => (None, data.to_vec()), }; let owned_node = OwnedNode::new::(node_data) .map_err(|e| Box::new(TrieError::DecoderError(node_hash.unwrap_or(parent_hash), e)))?; @@ -320,7 +320,7 @@ impl<'a, L: TrieLayout> Iterator for TrieDBIterator<'a, L> { TrieError::ValueAtIncompleteKey(key, extra_nibble) ))); } - return Some(Ok((key, DBValue::from_slice(value)))); + return Some(Ok((key, value.to_vec()))); } }, Err(err) => return Some(Err(err)), @@ -417,7 +417,7 @@ mod tests { iter.next().unwrap().unwrap(), ( hex!("0103000000000000000464").to_vec(), - DBValue::from_slice(&hex!("fffffffffe")[..]), + hex!("fffffffffe").to_vec(), ) ); iter.seek(&hex!("00")[..]).unwrap(); @@ -458,7 +458,7 @@ mod tests { let mut iter = t.iter().unwrap(); assert_eq!( iter.next().unwrap().unwrap(), - (hex!("0103000000000000000464").to_vec(), DBValue::from_slice(&hex!("fffffffffe")[..])) + (hex!("0103000000000000000464").to_vec(), hex!("fffffffffe").to_vec()) ); iter.seek(&hex!("00")[..]).unwrap(); assert_eq!( @@ -476,10 +476,10 @@ mod tests { #[test] fn iterator() { let d = vec![ - DBValue::from_slice(b"A"), - DBValue::from_slice(b"AA"), - DBValue::from_slice(b"AB"), - DBValue::from_slice(b"B"), + b"A".to_vec(), + b"AA".to_vec(), + b"AB".to_vec(), + b"B".to_vec(), ]; let mut memdb = MemoryDB::, DBValue>::default(); @@ -494,7 +494,7 @@ mod tests { let t = RefTrieDB::new(&memdb, &root).unwrap(); assert_eq!( d.iter() - .map(|i| i.clone().into_vec()) + .map(|i| i.clone()) .collect::>(), t.iter() .unwrap() @@ -507,10 +507,10 @@ mod tests { #[test] fn iterator_without_extension() { let d = vec![ - DBValue::from_slice(b"A"), - DBValue::from_slice(b"AA"), - DBValue::from_slice(b"AB"), - DBValue::from_slice(b"B"), + b"A".to_vec(), + b"AA".to_vec(), + b"AB".to_vec(), + b"B".to_vec(), ]; let mut memdb = MemoryDB::, DBValue>::default(); @@ -524,7 +524,7 @@ mod tests { let t = RefTrieDBNoExt::new(&memdb, &root).unwrap(); assert_eq!( - d.iter().map(|i| i.clone().into_vec()).collect::>(), + d.iter().map(|i| i.clone()).collect::>(), t.iter().unwrap().map(|x| x.unwrap().0).collect::>(), ); assert_eq!(d, t.iter().unwrap().map(|x| x.unwrap().1).collect::>()); @@ -533,10 +533,10 @@ mod tests { #[test] fn iterator_seek() { let d = vec![ - DBValue::from_slice(b"A"), - DBValue::from_slice(b"AA"), - DBValue::from_slice(b"AB"), - DBValue::from_slice(b"B"), + b"A".to_vec(), + b"AA".to_vec(), + b"AB".to_vec(), + b"B".to_vec(), ]; let mut memdb = MemoryDB::, DBValue>::default(); @@ -550,7 +550,7 @@ mod tests { let t = RefTrieDBNoExt::new(&memdb, &root).unwrap(); let mut iter = t.iter().unwrap(); - assert_eq!(iter.next().unwrap().unwrap(), (b"A".to_vec(), DBValue::from_slice(b"A"))); + assert_eq!(iter.next().unwrap().unwrap(), (b"A".to_vec(), b"A".to_vec())); iter.seek(b"!").unwrap(); assert_eq!(d, iter.map(|x| x.unwrap().1).collect::>()); let mut iter = t.iter().unwrap(); @@ -611,10 +611,10 @@ mod tests { #[test] fn debug_output_supports_pretty_print() { let d = vec![ - DBValue::from_slice(b"A"), - DBValue::from_slice(b"AA"), - DBValue::from_slice(b"AB"), - DBValue::from_slice(b"B"), + b"A".to_vec(), + b"AA".to_vec(), + b"AB".to_vec(), + b"B".to_vec(), ]; let mut memdb = MemoryDB::, DBValue>::default(); diff --git a/trie-db/src/triedbmut.rs b/trie-db/src/triedbmut.rs index 55bbd03d..33d7cc30 100644 --- a/trie-db/src/triedbmut.rs +++ b/trie-db/src/triedbmut.rs @@ -21,8 +21,7 @@ use node_codec::NodeCodec; use super::{DBValue, node::NodeKey}; use hash_db::{HashDB, Hasher, Prefix, EMPTY_PREFIX}; -use nibble::{NibbleVec, NibbleSlice, nibble_ops}; -use elastic_array::ElasticArray36; +use nibble::{NibbleVec, NibbleSlice, nibble_ops, BackingByteVec}; use ::core_::convert::TryFrom; use ::core_::mem; use ::core_::ops::Index; @@ -139,7 +138,7 @@ where .map_err(|e| Box::new(TrieError::DecoderError(node_hash, e)))?; let node = match encoded_node { EncodedNode::Empty => Node::Empty, - EncodedNode::Leaf(k, v) => Node::Leaf(k.into(), DBValue::from_slice(&v)), + EncodedNode::Leaf(k, v) => Node::Leaf(k.into(), v.to_vec()), EncodedNode::Extension(key, cb) => { Node::Extension( key.into(), @@ -160,7 +159,7 @@ where child(12)?, child(13)?, child(14)?, child(15)?, ]); - Node::Branch(children, val.map(DBValue::from_slice)) + Node::Branch(children, val.map(|v| v.to_vec())) }, EncodedNode::NibbledBranch(k, encoded_children, val) => { let mut child = |i:usize| match encoded_children[i] { @@ -176,7 +175,7 @@ where child(12)?, child(13)?, child(14)?, child(15)?, ]); - Node::NibbledBranch(k.into(), children, val.map(DBValue::from_slice)) + Node::NibbledBranch(k.into(), children, val.map(|v| v.to_vec())) }, }; Ok(node) @@ -393,7 +392,7 @@ impl<'a, H> Index<&'a StorageHandle> for NodeStorage { /// assert_eq!(*t.root(), KeccakHasher::hash(&[0u8][..])); /// t.insert(b"foo", b"bar").unwrap(); /// assert!(t.contains(b"foo").unwrap()); -/// assert_eq!(t.get(b"foo").unwrap().unwrap(), DBValue::from_slice(b"bar")); +/// assert_eq!(t.get(b"foo").unwrap().unwrap(), b"bar".to_vec()); /// t.remove(b"foo").unwrap(); /// assert!(!t.contains(b"foo").unwrap()); /// } @@ -406,7 +405,7 @@ where db: &'a mut dyn HashDB, root: &'a mut TrieHash, root_handle: NodeHandle>, - death_row: HashSet<(TrieHash, (ElasticArray36, Option))>, + death_row: HashSet<(TrieHash, (BackingByteVec, Option))>, /// The number of hash operations this trie has performed. /// Note that none are performed until changes are committed. hash_count: usize, @@ -526,14 +525,14 @@ where let (mid, child) = match *handle { NodeHandle::Hash(ref hash) => return Lookup:: { db: &self.db, - query: DBValue::from_slice, + query: |v: &[u8]| v.to_vec(), hash: hash.clone(), }.look_up(partial), NodeHandle::InMemory(ref handle) => match self.storage[handle] { Node::Empty => return Ok(None), Node::Leaf(ref key, ref value) => { if NibbleSlice::from_stored(key) == partial { - return Ok(Some(DBValue::from_slice(value))); + return Ok(Some(value.to_vec())); } else { return Ok(None); } @@ -548,7 +547,7 @@ where }, Node::Branch(ref children, ref value) => { if partial.is_empty() { - return Ok(value.as_ref().map(|v| DBValue::from_slice(v))); + return Ok(value.as_ref().map(|v| v.to_vec())); } else { let idx = partial.at(0); match children[idx as usize].as_ref() { @@ -560,7 +559,7 @@ where Node::NibbledBranch(ref slice, ref children, ref value) => { let slice = NibbleSlice::from_stored(slice); if partial.is_empty() { - return Ok(value.as_ref().map(|v| DBValue::from_slice(v))); + return Ok(value.as_ref().map(|v| v.to_vec())); } else if partial.starts_with(&slice) { let idx = partial.at(0); match children[idx as usize].as_ref() { @@ -1236,7 +1235,7 @@ where let (start, alloc_start, prefix_end) = match key2.left() { (start, None) => (start, None, Some(nibble_ops::push_at_left(0, a, 0))), (start, Some(v)) => { - let mut so: ElasticArray36 = start.into(); + let mut so: BackingByteVec = start.into(); so.push(nibble_ops::pad_left(v) | a); (start, Some(so), None) }, @@ -1310,7 +1309,7 @@ where let (start, alloc_start, prefix_end) = match key2.left() { (start, None) => (start, None, Some(nibble_ops::push_at_left(0, last, 0))), (start, Some(v)) => { - let mut so: ElasticArray36 = start.into(); + let mut so: BackingByteVec = start.into(); // Complete last byte with `last`. so.push(nibble_ops::pad_left(v) | last); (start, Some(so), None) @@ -1531,7 +1530,7 @@ where let (new_handle, changed) = self.insert_at( root_handle, &mut NibbleSlice::new(key), - DBValue::from_slice(value), + value.to_vec(), &mut old_val, )?; @@ -1601,9 +1600,9 @@ mod tests { use memory_db::{MemoryDB, PrefixedKey}; use hash_db::{Hasher, HashDB}; use keccak_hasher::KeccakHasher; - use elastic_array::ElasticArray36; use reference_trie::{RefTrieDBMutNoExt, RefTrieDBMut, TrieMut, NodeCodec, ReferenceNodeCodec, reference_trie_root, reference_trie_root_no_extension}; + use nibble::BackingByteVec; fn populate_trie<'db>( db: &'db mut dyn HashDB, @@ -1925,9 +1924,9 @@ mod tests { let mut root = Default::default(); let mut t = RefTrieDBMut::new(&mut memdb, &mut root); t.insert(&[0x01u8, 0x23], &[0x01u8, 0x23]).unwrap(); - assert_eq!(t.get(&[0x1, 0x23]).unwrap().unwrap(), DBValue::from_slice(&[0x1u8, 0x23])); + assert_eq!(t.get(&[0x1, 0x23]).unwrap().unwrap(), vec![0x1u8, 0x23]); t.commit(); - assert_eq!(t.get(&[0x1, 0x23]).unwrap().unwrap(), DBValue::from_slice(&[0x1u8, 0x23])); + assert_eq!(t.get(&[0x1, 0x23]).unwrap().unwrap(), vec![0x1u8, 0x23]); } #[test] @@ -1938,14 +1937,14 @@ mod tests { t.insert(&[0x01u8, 0x23], &[0x01u8, 0x23]).unwrap(); t.insert(&[0xf1u8, 0x23], &[0xf1u8, 0x23]).unwrap(); t.insert(&[0x81u8, 0x23], &[0x81u8, 0x23]).unwrap(); - assert_eq!(t.get(&[0x01, 0x23]).unwrap().unwrap(), DBValue::from_slice(&[0x01u8, 0x23])); - assert_eq!(t.get(&[0xf1, 0x23]).unwrap().unwrap(), DBValue::from_slice(&[0xf1u8, 0x23])); - assert_eq!(t.get(&[0x81, 0x23]).unwrap().unwrap(), DBValue::from_slice(&[0x81u8, 0x23])); + assert_eq!(t.get(&[0x01, 0x23]).unwrap().unwrap(), vec![0x01u8, 0x23]); + assert_eq!(t.get(&[0xf1, 0x23]).unwrap().unwrap(), vec![0xf1u8, 0x23]); + assert_eq!(t.get(&[0x81, 0x23]).unwrap().unwrap(), vec![0x81u8, 0x23]); assert_eq!(t.get(&[0x82, 0x23]).unwrap(), None); t.commit(); - assert_eq!(t.get(&[0x01, 0x23]).unwrap().unwrap(), DBValue::from_slice(&[0x01u8, 0x23])); - assert_eq!(t.get(&[0xf1, 0x23]).unwrap().unwrap(), DBValue::from_slice(&[0xf1u8, 0x23])); - assert_eq!(t.get(&[0x81, 0x23]).unwrap().unwrap(), DBValue::from_slice(&[0x81u8, 0x23])); + assert_eq!(t.get(&[0x01, 0x23]).unwrap().unwrap(), vec![0x01u8, 0x23]); + assert_eq!(t.get(&[0xf1, 0x23]).unwrap().unwrap(), vec![0xf1u8, 0x23]); + assert_eq!(t.get(&[0x81, 0x23]).unwrap().unwrap(), vec![0x81u8, 0x23]); assert_eq!(t.get(&[0x82, 0x23]).unwrap(), None); } @@ -2046,19 +2045,19 @@ mod tests { let mut t = RefTrieDBMut::new(&mut db, &mut root); for &(ref key, ref value) in &x { assert!(t.insert(key, value).unwrap().is_none()); - assert_eq!(t.insert(key, value).unwrap(), Some(DBValue::from_slice(value))); + assert_eq!(t.insert(key, value).unwrap(), Some(value.clone())); } for (key, value) in x { - assert_eq!(t.remove(&key).unwrap(), Some(DBValue::from_slice(&value))); + assert_eq!(t.remove(&key).unwrap(), Some(value)); assert!(t.remove(&key).unwrap().is_none()); } } #[test] fn combine_test() { - let a: ElasticArray36 = [0x12, 0x34][..].into(); + let a: BackingByteVec = [0x12, 0x34][..].into(); let b: &[u8] = [0x56, 0x78][..].into(); - let test_comb = |a: (_, &ElasticArray36<_>), b, c| { + let test_comb = |a: (_, &BackingByteVec), b, c| { let mut a = (a.0, a.1.clone()); super::combine_key(&mut a, b); assert_eq!((a.0, &a.1[..]), c);