fn note_finalized(
		&self,
		transaction: &mut DBTransaction,
		header: &Block::Header,
		hash: Block::Hash,
		displaced: &mut Option<FinalizationDisplaced<Block::Hash, NumberFor<Block>>>,
	) -> ClientResult<()> {
		let meta = self.meta.read();
		if &meta.finalized_hash != header.parent_hash() {
			return Err(::client::error::ErrorKind::NonSequentialFinalization(
				format!("Last finalized {:?} not parent of {:?}",
					meta.finalized_hash, hash),
			).into())
		}

		let lookup_key = utils::number_and_hash_to_lookup_key(header.number().clone(), hash);
		transaction.put(columns::META, meta_keys::FINALIZED_BLOCK, &lookup_key);

		// build new CHT(s) if required
		if let Some(new_cht_number) = cht::is_build_required(cht::SIZE, *header.number()) {
			let new_cht_start: NumberFor<Block> = cht::start_number(cht::SIZE, new_cht_number);

			let new_header_cht_root = cht::compute_root::<Block::Header, Blake2Hasher, _>(
				cht::SIZE, new_cht_number, (new_cht_start.as_()..)
				.map(|num| self.hash(As::sa(num)))
			)?;
			transaction.put(
				columns::CHT,
				&cht_key(HEADER_CHT_PREFIX, new_cht_start),
				new_header_cht_root.as_ref()
			);

			// if the header includes changes trie root, let's build a changes tries roots CHT
			if header.digest().log(DigestItem::as_changes_trie_root).is_some() {
				let new_changes_trie_cht_root = cht::compute_root::<Block::Header, Blake2Hasher, _>(
					cht::SIZE, new_cht_number, (new_cht_start.as_()..)
					.map(|num| self.changes_trie_root(BlockId::Number(As::sa(num))))
				)?;
				transaction.put(
					columns::CHT,
					&cht_key(CHANGES_TRIE_CHT_PREFIX, new_cht_start),
					new_changes_trie_cht_root.as_ref()
				);
			}

			// prune headers that are replaced with CHT
			let mut prune_block = new_cht_start;
			let new_cht_end = cht::end_number(cht::SIZE, new_cht_number);
			trace!(target: "db", "Replacing blocks [{}..{}] with CHT#{}",
				new_cht_start, new_cht_end, new_cht_number);

			while prune_block <= new_cht_end {
				if let Some(hash) = self.hash(prune_block)? {
					let lookup_key = block_id_to_lookup_key::<Block>(&*self.db, columns::KEY_LOOKUP, BlockId::Number(prune_block))?
						.expect("retrieved hash for `prune_block` right above. therefore retrieving lookup key must succeed. q.e.d.");
					utils::remove_key_mappings(
						transaction,
						columns::KEY_LOOKUP,
						prune_block,
						hash
					);
					transaction.delete(columns::HEADER, &lookup_key);
				}
				prune_block += One::one();
			}
		}

		let new_displaced = self.leaves.write().finalize_height(header.number().clone());
		match displaced {
			x @ &mut None => *x = Some(new_displaced),
			&mut Some(ref mut displaced) => displaced.merge(new_displaced),
		}

		Ok(())
	}
// Note that a block is finalized. Only call with child of last finalized block.
Note that a block is finalized. Only call with child of last finalized block.
Note that a block is finalized . Only call with child of last finalized block .
fn note_finalized(
		&self,
		transaction: &mut DBTransaction,
		header: &Block::Header,
		hash: Block::Hash,
		displaced: &mut Option<FinalizationDisplaced<Block::Hash, NumberFor<Block>>>,
	) -> ClientResult<()> {
		let meta = self.meta.read();
		if &meta.finalized_hash != header.parent_hash() {
			return Err(::client::error::ErrorKind::NonSequentialFinalization(
				format!("Last finalized {:?} not parent of {:?}",
					meta.finalized_hash, hash),
			).into())
		}
		let lookup_key = utils::number_and_hash_to_lookup_key(header.number().clone(), hash);
		transaction.put(columns::META, meta_keys::FINALIZED_BLOCK, &lookup_key);
		// build new CHT(s) if required
		if let Some(new_cht_number) = cht::is_build_required(cht::SIZE, *header.number()) {
			let new_cht_start: NumberFor<Block> = cht::start_number(cht::SIZE, new_cht_number);
			let new_header_cht_root = cht::compute_root::<Block::Header, Blake2Hasher, _>(
				cht::SIZE, new_cht_number, (new_cht_start.as_()..)
				.map(|num| self.hash(As::sa(num)))
			)?;
			transaction.put(
				columns::CHT,
				&cht_key(HEADER_CHT_PREFIX, new_cht_start),
				new_header_cht_root.as_ref()
			);
			// if the header includes changes trie root, let's build a changes tries roots CHT
			if header.digest().log(DigestItem::as_changes_trie_root).is_some() {
				let new_changes_trie_cht_root = cht::compute_root::<Block::Header, Blake2Hasher, _>(
					cht::SIZE, new_cht_number, (new_cht_start.as_()..)
					.map(|num| self.changes_trie_root(BlockId::Number(As::sa(num))))
				)?;
				transaction.put(
					columns::CHT,
					&cht_key(CHANGES_TRIE_CHT_PREFIX, new_cht_start),
					new_changes_trie_cht_root.as_ref()
				);
			}
			// prune headers that are replaced with CHT
			let mut prune_block = new_cht_start;
			let new_cht_end = cht::end_number(cht::SIZE, new_cht_number);
			trace!(target: "db", "Replacing blocks [{}..{}] with CHT#{}",
				new_cht_start, new_cht_end, new_cht_number);
			while prune_block <= new_cht_end {
				if let Some(hash) = self.hash(prune_block)? {
					let lookup_key = block_id_to_lookup_key::<Block>(&*self.db, columns::KEY_LOOKUP, BlockId::Number(prune_block))?
						.expect("retrieved hash for `prune_block` right above. therefore retrieving lookup key must succeed. q.e.d.");
					utils::remove_key_mappings(
						transaction,
						columns::KEY_LOOKUP,
						prune_block,
						hash
					);
					transaction.delete(columns::HEADER, &lookup_key);
				}
				prune_block += One::one();
			}
		}
		let new_displaced = self.leaves.write().finalize_height(header.number().clone());
		match displaced {
			x @ &mut None => *x = Some(new_displaced),
			&mut Some(ref mut displaced) => displaced.merge(new_displaced),
		}
		Ok(())
	}
fn note_finalized ( & self , transaction : & mut DBTransaction , header : & Block :: Header , hash : Block :: Hash , displaced : & mut Option < FinalizationDisplaced < Block :: Hash , NumberFor < Block > > > , ) -> ClientResult < ( ) > { let meta = self . meta . read ( ) ; if & meta . finalized_hash != header . parent_hash ( ) { return Err ( :: client :: error :: ErrorKind :: NonSequentialFinalization ( format ! ( " " meta finalized_hash hash ) , ) . into ( ) ) } let lookup_key = utils :: number_and_hash_to_lookup_key ( header . number ( ) . clone ( ) , hash ) ; transaction . put ( columns :: META , meta_keys :: FINALIZED_BLOCK , & lookup_key ) ; // build new CHT(s) if required if let Some ( new_cht_number ) = cht :: is_build_required ( cht :: SIZE , * header . number ( ) ) { let new_cht_start : NumberFor < Block > = cht :: start_number ( cht :: SIZE , new_cht_number ) ; let new_header_cht_root = cht :: compute_root :: < Block :: Header , Blake2Hasher , _ > ( cht :: SIZE , new_cht_number , ( new_cht_start . as_ ( ) .. ) . map ( | num | self . hash ( As :: sa ( num ) ) ) ) ? ; transaction . put ( columns :: CHT , & cht_key ( HEADER_CHT_PREFIX , new_cht_start ) , new_header_cht_root . as_ref ( ) ) ; // if the header includes changes trie root, let's build a changes tries roots CHT if header . digest ( ) . log ( DigestItem :: as_changes_trie_root ) . is_some ( ) { let new_changes_trie_cht_root = cht :: compute_root :: < Block :: Header , Blake2Hasher , _ > ( cht :: SIZE , new_cht_number , ( new_cht_start . as_ ( ) .. ) . map ( | num | self . changes_trie_root ( BlockId :: Number ( As :: sa ( num ) ) ) ) ) ? ; transaction . put ( columns :: CHT , & cht_key ( CHANGES_TRIE_CHT_PREFIX , new_cht_start ) , new_changes_trie_cht_root . as_ref ( ) ) ; } // prune headers that are replaced with CHT let mut prune_block = new_cht_start ; let new_cht_end = cht :: end_number ( cht :: SIZE , new_cht_number ) ; trace ! ( target " " " " new_cht_start new_cht_end new_cht_number ) ; while prune_block <= new_cht_end { if let Some ( hash ) = self . hash ( prune_block ) ? { let lookup_key = block_id_to_lookup_key :: < Block > ( & * self . db , columns :: KEY_LOOKUP , BlockId :: Number ( prune_block ) ) ? . expect ( " " ) ; utils :: remove_key_mappings ( transaction , columns :: KEY_LOOKUP , prune_block , hash ) ; transaction . delete ( columns :: HEADER , & lookup_key ) ; } prune_block += One :: one ( ) ; } } let new_displaced = self . leaves . write ( ) . finalize_height ( header . number ( ) . clone ( ) ) ; match displaced { x @ & mut None => * x = Some ( new_displaced ) , & mut Some ( ref mut displaced ) => displaced . merge ( new_displaced ) , } Ok ( ( ) ) }
Note that a block is finalized.
Note that a block is finalized .
&self
transaction
&mut DBTransaction
header
&Block::Header
hash
Block::Hash
displaced
&mut Option<FinalizationDisplaced<Block::Hash, NumberFor<Block>>>
&self
transaction
&mut DBTransaction
header
&Block::Header
hash
Block::Hash
displaced
&mut Option<FinalizationDisplaced<Block::Hash, NumberFor<Block>>>