Skip to content

Create index on transactions.blockNumber for lite nodes#135

Merged
eonwarped merged 1 commit into
hive-engine:qafrom
TheCrazyGM:fix-lite-node-transactions-index
May 31, 2026
Merged

Create index on transactions.blockNumber for lite nodes#135
eonwarped merged 1 commit into
hive-engine:qafrom
TheCrazyGM:fix-lite-node-transactions-index

Conversation

@TheCrazyGM
Copy link
Copy Markdown
Contributor

Problem

During lite node operations, the LightNode plugin periodically purges historical data. The transaction cleanup logic in libs/Database.js executes the following query every 10 minutes:

await this.database.collection('transactions').deleteMany({ blockNumber: { $lte: cleanupUntilBlock } });

Because the transactions collection lacked an index on blockNumber, MongoDB was forced to perform a full collection scan (COLLSCAN) through approximately 40 million records (~3.19 GB) per cycle. This created severe, compounding overhead on system memory, CPU utilization, and disk I/O.

Solution

  • Manual Mitigation: Successfully verified the fix by manually building the index on the target database:
  db.transactions.createIndex({ blockNumber: 1 })
  • Programmatic Fix: Updated libs/Database.js to ensure this index is automatically created on startup, preventing regressions on fresh node deployments.

Impact

  • Eliminates the 10-minute COLLSCAN spikes.
  • Drastically reduces ambient CPU usage and disk I/O bottlenecks for all node operators running a lite strategy.

@eonwarped eonwarped merged commit 3c1de23 into hive-engine:qa May 31, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants