Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocks && fully spent transactions pruning #510

Closed
wants to merge 5 commits into from
Closed

Conversation

svyatonik
Copy link
Collaborator

closes #472

So the idea is:

  1. to remove BlockHeader and BlockTransactions of ancient blocks (blocks from canon chain with age > 2048);
  2. to remove Transaction and TransactionMeta of transaction, when block, spending the last utxo of this transaction became ancient.

prune-mode cli option can take 3 values now:
"none" - no pruning;
"header" - 1 from ^^^;
"full" - 1+2 from ^^^.

I'll leave one of chains (--btc or --bch) syncing to see the final db size && post it here.

@svyatonik svyatonik added A3-inprogress Pull request is in progress. No review needed at this stage. M4-core Core client code / Rust. labels May 14, 2018
@@ -397,7 +501,7 @@ impl<T> BlockHeaderProvider for BlockChainDatabase<T> where T: KeyValueDatabase
}

impl<T> BlockProvider for BlockChainDatabase<T> where T: KeyValueDatabase {
fn block_number(&self, hash: &H256) -> Option<u32> {
fn block_number(&self, hash: &H256) -> Option<u32> {
Copy link
Member

Choose a reason for hiding this comment

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

Extra tab typo.

@@ -13,6 +13,7 @@ pub const COL_TRANSACTIONS: u32 = 4;
pub const COL_TRANSACTIONS_META: u32 = 5;
pub const COL_BLOCK_NUMBERS: u32 = 6;
pub const COL_CONFIGURATION: u32 = 7;
pub const COL_SPENT_TRANSACTIONS: u32 = 8;
Copy link
Member

Choose a reason for hiding this comment

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

Note to myself (and possibly others reviewing this code): we have COL_COUNT preset to 10 so no db migration needed for this change. 🎉

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. I even had an idea to keep this in-memory only - so if node doesn't restarts while syncing, all fully spent transactions will be pruned. But in the case of restart, we could miss some fully spent transactions => 'garbage' in db. Not sure - what's better in general, but for my use-cases (I'm often restarting the node), the permanent storage is better.

@svyatonik svyatonik added A4-gotissues Pull request is reviewed and has significant issues which must be addressed. and removed A3-inprogress Pull request is in progress. No review needed at this stage. labels May 15, 2018
@svyatonik
Copy link
Collaborator Author

Two issues:

  1. Key::SpentTransactions is never deleted from database
  2. when block is decanonized, value of Key::SpentTransactions(this_block_number + pruning_depth) must be deleted

@svyatonik svyatonik added A0-pleasereview Pull request needs code review. and removed A4-gotissues Pull request is reviewed and has significant issues which must be addressed. labels May 15, 2018
@5chdn 5chdn added this to the 0.9 milestone May 17, 2018
@svyatonik svyatonik added A3-inprogress Pull request is in progress. No review needed at this stage. and removed A0-pleasereview Pull request needs code review. labels May 18, 2018
@svyatonik
Copy link
Collaborator Author

Seems like this patch is not as effective as it intended to be - probably because number of fully spent transactions is not that big. After synchronizing ~310000 blocks, db size is almost the same. And most of space is still occupied by tx && tx meta columns.

I'll try to change db structure by extracting tx outputs to separate columns && reopen PR when results will be ready.

@svyatonik svyatonik closed this May 18, 2018
@svyatonik
Copy link
Collaborator Author

To me in the future: last commit of this branch changes size of db to ~12GB at block 416614 - it is > x10 times smaller than before. Still have to check another option (single tx out column with spent/unspent sign) + adjust config options + check that performance (tools/bencher) is not significantly affected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A3-inprogress Pull request is in progress. No review needed at this stage. M4-core Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support pruning of transactions
3 participants