Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Add Blocks at a Configured Depth to Pruning Queue #1689

Merged

Conversation

peterschwarz
Copy link
Contributor

This PR creates a pruning manager, which prunes state roots from a queue at predictable times. It is evaluated at chain commit time. 10 percent of the queue is pruned, which allows state roots to be returned to validity, if need be before they are finally pruned.

This PR does not solve the problem of abandoned forks, as they cannot be properly re-evaluated if a validator switches back to them. To properly cleanup state after a chain has been dropped, we will need the Block Tree Manager (See RFC 5). When uncommitted blocks expire from the Block Tree Manager, their state roots can be pruned.

Remove #[macro_use] for cpython, as it is no longer necessary.

Signed-off-by: Peter Schwarz <pschwarz@bitwise.io>
Signed-off-by: Peter Schwarz <pschwarz@bitwise.io>
@peterschwarz peterschwarz force-pushed the STL-1220.pruning_queue branch from df17664 to 9e4c206 Compare June 4, 2018 18:38
state.state_prune_manager.update_queue(
&result
.new_chain
.iter()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense to have the function take care of this .iter.map.collect stuff rather than make the caller do it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The state pruning manager operates on state root hashes, not blocks

@peterschwarz peterschwarz force-pushed the STL-1220.pruning_queue branch from 9e4c206 to c6e533c Compare June 4, 2018 19:05
@peterschwarz peterschwarz requested a review from nick-drozd June 4, 2018 19:17
@nick-drozd
Copy link
Contributor

Oh, commit Add decimate to StatePruneManager has If a root is prune, in the commit message (prune -> pruned).

@peterschwarz peterschwarz force-pushed the STL-1220.pruning_queue branch 2 times, most recently from ee433d8 to f6d005b Compare June 5, 2018 20:11
Signed-off-by: Peter Schwarz <pschwarz@bitwise.io>
- Add validation for integer CLI args (they must be positive, greater than
zero)
- Parse the args as u32 before sending them to the config object

Signed-off-by: Peter Schwarz <pschwarz@bitwise.io>
@peterschwarz peterschwarz force-pushed the STL-1220.pruning_queue branch from b3f6357 to 271c6dc Compare June 5, 2018 22:15
peterschwarz and others added 3 commits June 7, 2018 12:06
Adds the CLI argument and configuration option for
state_pruning_block_depth.

Signed-off-by: Peter Schwarz <pschwarz@bitwise.io>
Pass the state_pruning_block_depth configuration option through to the
ChainController via the FFI interface.

Signed-off-by: Peter Schwarz <peterx.schwarz@intel.com>
The StatePruningManager is responsible fore managing a queue of state
roots and their respective block heights.

It keeps track of unique hashes and supplies an execute method which will
delete any hash below a certain depth. If there are state roots that
compute the same hash value, they will be removed so as not to cause
lost state roots for newer blocks.

Any hash unsuccessfully pruned will be put back on the queue until such
time as it can be removed.

Signed-off-by: Peter Schwarz <pschwarz@bitwise.io>
@peterschwarz peterschwarz force-pushed the STL-1220.pruning_queue branch from 271c6dc to cd76cf8 Compare June 7, 2018 17:11
@peterschwarz
Copy link
Contributor Author

Added some new commits to handle the issue where an identical leaf is produced, and then is pruned from a prior state root hash. This approach is the most direct - scanning the change logs.

Future changes could make this more efficient by managing this with an in-memory reference count.

When a block is committed to the block store, the added state root
hashes and any uncommitted blocks' state root hashes are passed to the
StatePruningManager. Also, if the block is of height greater than the
state pruning depth, a block at that depth is added to the queue and the
pruning operation is executed for that height.

Signed-off-by: Peter Schwarz <pschwarz@bitwise.io>
Supply the global state database instance across the FFI boundary
in order to create the a StatePruningManager

Signed-off-by: Peter Schwarz <pschwarz@bitwise.io>
Provide the state database to the python chain controller, in order
to pass it through to the FFI rust layer.

Signed-off-by: Peter Schwarz <pschwarz@bitwise.io>
Update tests to include a state database instance

Signed-off-by: Peter Schwarz <pschwarz@bitwise.io>
Add `next` to LmdbDatabaseReaderCursor, which previously only had `first`
and `last`.

Signed-off-by: Peter Schwarz <pschwarz@bitwise.io>
Remove duplicate keys from the change log during pruning, to avoid
removing leaf or intermediate nodes that may be referenced in future
tries.

Signed-off-by: Peter Schwarz <pschwarz@bitwise.io>
@peterschwarz peterschwarz force-pushed the STL-1220.pruning_queue branch from cd76cf8 to de0babb Compare June 7, 2018 18:05
@peterschwarz peterschwarz merged commit f45be8f into hyperledger-archives:master Jun 7, 2018
@peterschwarz peterschwarz deleted the STL-1220.pruning_queue branch June 7, 2018 20:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants