/// <summary> /// Compacts the block and transaction database by recreating the tables without the deleted references. /// </summary> private void CompactDataBase() { Task task = Task.Run(() => { using (DBreeze.Transactions.Transaction dbreezeTransaction = this.blockRepository.DBreeze.GetTransaction()) { dbreezeTransaction.SynchronizeTables(BlockRepository.BlockTableName, BlockRepository.TransactionTableName); var tempBlocks = dbreezeTransaction.SelectDictionary <byte[], byte[]>(BlockRepository.BlockTableName); if (tempBlocks.Count != 0) { this.logger.LogInformation($"{tempBlocks.Count} blocks will be copied to the pruned table."); dbreezeTransaction.RemoveAllKeys(BlockRepository.BlockTableName, true); dbreezeTransaction.InsertDictionary(BlockRepository.BlockTableName, tempBlocks, false); var tempTransactions = dbreezeTransaction.SelectDictionary <byte[], byte[]>(BlockRepository.TransactionTableName); if (tempTransactions.Count != 0) { this.logger.LogInformation($"{tempTransactions.Count} transactions will be copied to the pruned table."); dbreezeTransaction.RemoveAllKeys(BlockRepository.TransactionTableName, true); dbreezeTransaction.InsertDictionary(BlockRepository.TransactionTableName, tempTransactions, false); } // Save the hash and height of where the node was pruned up to. dbreezeTransaction.Insert(BlockRepository.CommonTableName, prunedTipKey, this.dBreezeSerializer.Serialize(this.PrunedTip)); } dbreezeTransaction.Commit(); } return(Task.CompletedTask); }); }