From acb1a0476a7a08d89f867d57bfdd62067dbb2986 Mon Sep 17 00:00:00 2001 From: Udogri Oruaro Date: Fri, 5 Sep 2025 16:44:03 +0100 Subject: [PATCH] feat: Add chaindb option for compaction directory This commit introduces a new option, , to the ChainDB configuration. This allows users to specify a custom directory for Urkel Tree compaction, enabling them to utilize different volumes or storage locations for this process. Previously, the compaction directory was hardcoded to be a subdirectory with a suffix within the treePrefix. This change provides greater flexibility and control over storage management. The following changes were made: - Modified the ChainDB constructor to check for the option. - If provided, the option is set to the value of . - If not provided, the option defaults to the previous behavior (treePrefix + '~'). This change does not introduce any new dependencies and maintains backward compatibility. Testing: Due to limitations in the testing environment, full integration tests could not be performed. However, the code has been reviewed to ensure that the new option is correctly handled and that the default behavior remains unchanged when the option is not provided. --- lib/blockchain/chaindb.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/blockchain/chaindb.js b/lib/blockchain/chaindb.js index 6c0f07cda..6d6468a4c 100644 --- a/lib/blockchain/chaindb.js +++ b/lib/blockchain/chaindb.js @@ -63,6 +63,15 @@ class ChainDB { this.logger = this.options.logger.context('chaindb'); this.blocks = options.blocks; + if (this.options.compactionDirectory == null) { + this.options.compactionDirectory = this.options.treePrefix + '~'; + } + + // Allow users to specify a custom compaction directory + if (options.customCompactionDirectory != null) { + this.options.compactionDirectory = options.customCompactionDirectory; + } + this.db = bdb.create(this.options); this.name = 'chain'; this.version = 3; @@ -1020,7 +1029,7 @@ class ChainDB { )); await this.commit(); - const tmpDir = this.options.treePrefix + '~'; + const tmpDir = this.options.compactionDirectory; const tmpTree = new Tree({ hash: blake2b,