pub fn prune<S: Storage<H>, H: Hasher, F: FnMut(H::Out)>(
	config: &Configuration,
	storage: &S,
	min_blocks_to_keep: u64,
	current_block: &AnchorBlockId<H::Out>,
	mut remove_trie_node: F,
)
	where
		H::Out: HeapSizeOf,
{
	// select range for pruning
	let (first, last) = match pruning_range(config, min_blocks_to_keep, current_block.number) {
		Some((first, last)) => (first, last),
		None => return,
	};

	// delete changes trie for every block in range
	// FIXME: limit `max_digest_interval` so that this cycle won't involve huge ranges
	for block in first..last+1 {
		let root = match storage.root(current_block, block) {
			Ok(Some(root)) => root,
			Ok(None) => continue,
			Err(error) => {
				// try to delete other tries
				warn!(target: "trie", "Failed to read changes trie root from DB: {}", error);
				continue;
			},
		};

		// enumerate all changes trie' keys, recording all nodes that have been 'touched'
		// (effectively - all changes trie nodes)
		let mut proof_recorder: Recorder<H::Out> = Default::default();
		{
			let mut trie = ProvingBackendEssence::<_, H> {
				backend: &TrieBackendEssence::new(TrieBackendAdapter::new(storage), root),
				proof_recorder: &mut proof_recorder,
			};
			trie.record_all_keys();
		}

		// all nodes of this changes trie should be pruned
		remove_trie_node(root);
		for node in proof_recorder.drain().into_iter().map(|n| n.hash) {
			remove_trie_node(node);
		}
	}
}
/// Prune obslete changes tries. Puning happens at the same block, where highest
/// level digest is created. Pruning guarantees to save changes tries for last
/// `min_blocks_to_keep` blocks. We only prune changes tries at `max_digest_iterval`
/// ranges.
/// Returns MemoryDB that contains all deleted changes tries nodes.
Prune obslete changes tries. Puning happens at the same block, where highest
level digest is created. Pruning guarantees to save changes tries for last
`min_blocks_to_keep` blocks. We only prune changes tries at `max_digest_iterval`
ranges.
Returns MemoryDB that contains all deleted changes tries nodes.
Prune obslete changes tries . Puning happens at the same block where highest level digest is created . Pruning guarantees to save changes tries for last ` min_blocks_to_keep ` blocks . We only prune changes tries at ` max_digest_iterval ` ranges . Returns MemoryDB that contains all deleted changes tries nodes .
pub fn prune<S: Storage<H>, H: Hasher, F: FnMut(H::Out)>(
	config: &Configuration,
	storage: &S,
	min_blocks_to_keep: u64,
	current_block: &AnchorBlockId<H::Out>,
	mut remove_trie_node: F,
)
	where
		H::Out: HeapSizeOf,
{
	// select range for pruning
	let (first, last) = match pruning_range(config, min_blocks_to_keep, current_block.number) {
		Some((first, last)) => (first, last),
		None => return,
	};
	// delete changes trie for every block in range
	// FIXME: limit `max_digest_interval` so that this cycle won't involve huge ranges
	for block in first..last+1 {
		let root = match storage.root(current_block, block) {
			Ok(Some(root)) => root,
			Ok(None) => continue,
			Err(error) => {
				// try to delete other tries
				warn!(target: "trie", "Failed to read changes trie root from DB: {}", error);
				continue;
			},
		};
		// enumerate all changes trie' keys, recording all nodes that have been 'touched'
		// (effectively - all changes trie nodes)
		let mut proof_recorder: Recorder<H::Out> = Default::default();
		{
			let mut trie = ProvingBackendEssence::<_, H> {
				backend: &TrieBackendEssence::new(TrieBackendAdapter::new(storage), root),
				proof_recorder: &mut proof_recorder,
			};
			trie.record_all_keys();
		}
		// all nodes of this changes trie should be pruned
		remove_trie_node(root);
		for node in proof_recorder.drain().into_iter().map(|n| n.hash) {
			remove_trie_node(node);
		}
	}
}
pub fn prune < S : Storage < H > , H : Hasher , F : FnMut ( H :: Out ) > ( config : & Configuration , storage : & S , min_blocks_to_keep : u64 , current_block : & AnchorBlockId < H :: Out > , mut remove_trie_node : F , ) where H :: Out : HeapSizeOf , { // select range for pruning let ( first , last ) = match pruning_range ( config , min_blocks_to_keep , current_block . number ) { Some ( ( first , last ) ) => ( first , last ) , None => return , } ; // delete changes trie for every block in range // FIXME: limit `max_digest_interval` so that this cycle won't involve huge ranges for block in first .. last + 1 { let root = match storage . root ( current_block , block ) { Ok ( Some ( root ) ) => root , Ok ( None ) => continue , Err ( error ) => { // try to delete other tries warn ! ( target " " " " error ) ; continue ; } , } ; // enumerate all changes trie' keys, recording all nodes that have been 'touched' // (effectively - all changes trie nodes) let mut proof_recorder : Recorder < H :: Out > = Default :: default ( ) ; { let mut trie = ProvingBackendEssence :: < _ , H > { backend : & TrieBackendEssence :: new ( TrieBackendAdapter :: new ( storage ) , root ) , proof_recorder : & mut proof_recorder , } ; trie . record_all_keys ( ) ; } // all nodes of this changes trie should be pruned remove_trie_node ( root ) ; for node in proof_recorder . drain ( ) . into_iter ( ) . map ( | n | n . hash ) { remove_trie_node ( node ) ; } } }
Prune obslete changes tries.
Prune obslete changes tries .
config
&Configuration
storage
&S
min_blocks_to_keep
u64
current_block
&AnchorBlockId<H::Out>
remove_trie_node
F
config
&Configuration
storage
&S
min_blocks_to_keep
u64
current_block
&AnchorBlockId<H::Out>
remove_trie_node
F