Skip to content

Commit

Permalink
Re-add accounts diff pruning
Browse files Browse the repository at this point in the history
- Improve clearing revert infos.
- Prune accounts diffs.

This reverts the revert of the original commit on 5de29b8.
  • Loading branch information
jsdanielh committed Nov 5, 2024
1 parent 8ec565c commit 0290ba1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
4 changes: 0 additions & 4 deletions blockchain/src/blockchain/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ impl Blockchain {
return Err(PushError::MissingAccountsTrieDiff);
}

// Macro blocks are final and receipts for the previous batch are no longer necessary
// as rebranching across this block is not possible.
self.chain_store.clear_revert_infos(txn.raw());

let total_tx_size = self
.history_store
.add_block(txn.raw(), block, inherents)
Expand Down
6 changes: 2 additions & 4 deletions blockchain/src/blockchain/history_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,6 @@ impl Blockchain {
// Unwrap the block.
let macro_block = block.unwrap_macro_ref();

// Macro blocks are final and receipts for the previous batch are no longer necessary
// as rebranching across this block is not possible.
this.chain_store.clear_revert_infos(&mut txn);

// Store the new historic transactions into the History tree.
this.history_store.add_to_history(
&mut txn,
Expand Down Expand Up @@ -412,6 +408,8 @@ impl Blockchain {
return Err(PushError::InvalidBlock(BlockError::AccountsHashMismatch));
}

this.chain_store.finalize_batch(&mut txn);

// Give up database transactions and push lock before creating notifications.
txn.commit();

Expand Down
16 changes: 5 additions & 11 deletions blockchain/src/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use nimiq_blockchain_interface::{BlockchainError, ChainInfo, Direction};
use nimiq_database::{
declare_table,
mdbx::{MdbxDatabase, MdbxReadTransaction, MdbxWriteTransaction, OptionalTransaction},
traits::{Database, DupReadCursor, ReadCursor, ReadTransaction, WriteCursor, WriteTransaction},
traits::{Database, DupReadCursor, ReadCursor, ReadTransaction, WriteTransaction},
};
use nimiq_database_value_derive::DbSerializable;
use nimiq_hash::Blake2bHash;
Expand Down Expand Up @@ -620,6 +620,7 @@ impl ChainStore {
if chain_info.prunable {
txn.remove(&self.chain_table, &hash);
txn.remove(&self.pushed_block_table, &hash);
txn.remove(&self.accounts_diff_table, &hash);
txn.remove_item(&self.height_idx, &height, &hash);
}
}
Expand All @@ -641,6 +642,9 @@ impl ChainStore {
}
// Then clear the stored block table
txn.clear_table(&self.stored_block_table);
// Macro blocks are final and receipts for the previous batch are no longer necessary
// as rebranching across this block is not possible.
txn.clear_table(&self.revert_table);
}

/// Puts a revert info for a block height
Expand All @@ -664,16 +668,6 @@ impl ChainStore {
txn.get(&self.revert_table, &block_height)
}

pub fn clear_revert_infos(&self, txn: &mut MdbxWriteTransaction) {
let mut cursor = WriteTransaction::cursor(txn, &self.revert_table);
let mut pos: Option<(u32, RevertInfo)> = cursor.first();

while pos.is_some() {
cursor.remove();
pos = cursor.next();
}
}

pub fn put_accounts_diff(
&self,
txn: &mut MdbxWriteTransaction,
Expand Down

0 comments on commit 0290ba1

Please sign in to comment.