pub fn canonicalize<E: fmt::Debug>(&mut self, hash: &BlockHash) -> Result<CommitSet<Key>, Error<E>> {
		trace!(target: "state-db", "Canonicalizing {:?}", hash);
		let level = self.levels.get(self.pending_canonicalizations.len()).ok_or_else(|| Error::InvalidBlock)?;
		let index = level
			.iter()
			.position(|overlay| overlay.hash == *hash)
			.ok_or_else(|| Error::InvalidBlock)?;

		let mut commit = CommitSet::default();
		let mut discarded_journals = Vec::new();
		for (i, overlay) in level.into_iter().enumerate() {
			if i == index {
				// that's the one we need to canonicalize
				commit.data.inserted = overlay.inserted.iter()
					.map(|k| (k.clone(), self.values.get(k).expect("For each key in verlays there's a value in values").1.clone()))
					.collect();
				commit.data.deleted = overlay.deleted.clone();
			} else {
				self.discard_journals(self.pending_canonicalizations.len() + 1, &mut discarded_journals, &overlay.hash);
			}
			discarded_journals.push(overlay.journal_key.clone());
		}
		commit.meta.deleted.append(&mut discarded_journals);
		let canonicalized = (hash.clone(), self.front_block_number() + self.pending_canonicalizations.len() as u64);
		commit.meta.inserted.push((to_meta_key(LAST_CANONICAL, &()), canonicalized.encode()));
		trace!(target: "state-db", "Discarding {} records", commit.meta.deleted.len());
		self.pending_canonicalizations.push(hash.clone());
		Ok(commit)
	}
/// Select a top-level root and canonicalized it. Discards all sibling subtrees and the root.
/// Returns a set of changes that need to be added to the DB.
Select a top-level root and canonicalized it. Discards all sibling subtrees and the root.
Returns a set of changes that need to be added to the DB.
Select a top - level root and canonicalized it . Discards all sibling subtrees and the root . Returns a set of changes that need to be added to the DB .
pub fn canonicalize<E: fmt::Debug>(&mut self, hash: &BlockHash) -> Result<CommitSet<Key>, Error<E>> {
		trace!(target: "state-db", "Canonicalizing {:?}", hash);
		let level = self.levels.get(self.pending_canonicalizations.len()).ok_or_else(|| Error::InvalidBlock)?;
		let index = level
			.iter()
			.position(|overlay| overlay.hash == *hash)
			.ok_or_else(|| Error::InvalidBlock)?;
		let mut commit = CommitSet::default();
		let mut discarded_journals = Vec::new();
		for (i, overlay) in level.into_iter().enumerate() {
			if i == index {
				// that's the one we need to canonicalize
				commit.data.inserted = overlay.inserted.iter()
					.map(|k| (k.clone(), self.values.get(k).expect("For each key in verlays there's a value in values").1.clone()))
					.collect();
				commit.data.deleted = overlay.deleted.clone();
			} else {
				self.discard_journals(self.pending_canonicalizations.len() + 1, &mut discarded_journals, &overlay.hash);
			}
			discarded_journals.push(overlay.journal_key.clone());
		}
		commit.meta.deleted.append(&mut discarded_journals);
		let canonicalized = (hash.clone(), self.front_block_number() + self.pending_canonicalizations.len() as u64);
		commit.meta.inserted.push((to_meta_key(LAST_CANONICAL, &()), canonicalized.encode()));
		trace!(target: "state-db", "Discarding {} records", commit.meta.deleted.len());
		self.pending_canonicalizations.push(hash.clone());
		Ok(commit)
	}
pub fn canonicalize < E : fmt :: Debug > ( & mut self , hash : & BlockHash ) -> Result < CommitSet < Key > , Error < E > > { trace ! ( target " " " " hash ) ; let level = self . levels . get ( self . pending_canonicalizations . len ( ) ) . ok_or_else ( | | Error :: InvalidBlock ) ? ; let index = level . iter ( ) . position ( | overlay | overlay . hash == * hash ) . ok_or_else ( | | Error :: InvalidBlock ) ? ; let mut commit = CommitSet :: default ( ) ; let mut discarded_journals = Vec :: new ( ) ; for ( i , overlay ) in level . into_iter ( ) . enumerate ( ) { if i == index { // that's the one we need to canonicalize commit . data . inserted = overlay . inserted . iter ( ) . map ( | k | ( k . clone ( ) , self . values . get ( k ) . expect ( " " ) . 1 . clone ( ) ) ) . collect ( ) ; commit . data . deleted = overlay . deleted . clone ( ) ; } else { self . discard_journals ( self . pending_canonicalizations . len ( ) + 1 , & mut discarded_journals , & overlay . hash ) ; } discarded_journals . push ( overlay . journal_key . clone ( ) ) ; } commit . meta . deleted . append ( & mut discarded_journals ) ; let canonicalized = ( hash . clone ( ) , self . front_block_number ( ) + self . pending_canonicalizations . len ( ) as u64 ) ; commit . meta . inserted . push ( ( to_meta_key ( LAST_CANONICAL , & ( ) ) , canonicalized . encode ( ) ) ) ; trace ! ( target " " " " commit meta deleted len ( ) ) ; self . pending_canonicalizations . push ( hash . clone ( ) ) ; Ok ( commit ) }
Select a top-level root and canonicalized it.
Select a top - level root and canonicalized it .
&mut self
hash
&BlockHash
&mut self
hash
&BlockHash