ffldb: Support storing spend journals and switch to mutable treap #20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1: Switch the dbcache to use mutable treaps.
ffldb was using a immutable treap for the database cache. While this is
good in that it supports snapshotting of the database transactions,
there is no need for this as a generic Bitcoin block storage.
Even worse, the immutable treap would allocate O(n) nodes per insert and
deletion, leading to a huge amount of memory being allcated.
This PR switches away from immutable treaps as there isn't really a need
for snapshotting and it costs too much in terms of memory allocation.
2: Save spend journals as flat files.
Spend journals are needed during reorgs, which rarely happens. These
spend journals were being stored in leveldb, which isn't necessary.
This PR makes the spend journals to be saved in flat files, just like
blocks.
There now isn't any support for deleting spend journals but this isn't
really a concern. The current btcd model of storing blocks is if the
received block passes initial pow and sanity checks. Since spend
journals are only created when the block passes all verification, it's
even less likely that the spend journals are effected by disk fill
attacks.
There isn't any need for deleting blocks and so there is even less of a
need for deleting spend journals.