Skip to content

feat(plugins): backfill section bloom - #81

Closed
317787106 wants to merge 2 commits into
release_v4.8.3from
feature/backfill_sectionbloom
Closed

317787106 wants to merge 2 commits into
release_v4.8.3from
feature/backfill_sectionbloom

Conversation

@317787106

@317787106 317787106 commented Jul 24, 2026 •

Copy link
Copy Markdown
Owner

What does this PR do?

Adds an offline Toolkit command to rebuild missing historical SectionBloom indexes from retained transaction results:

java -jar Toolkit.jar db backfill-bloom

The command reads transactionRetStore and creates or updates section-bloom. It supports:

  • Inclusive start/end block numbers. Omitted or zero bounds select the earliest available non-zero transaction-result block and the latest persisted block header (latest_block_header_number in properties). Earlier starts are raised to the first available block; later ends are capped at the persisted header. Negative bounds and inverted ranges are rejected.
  • Engine detection from an existing section-bloom, or from transactionRetStore when creating it. Missing engine metadata retains the legacy LevelDB default. ARM64 rejects LevelDB before opening or creating databases.
  • Concurrent processing by 2,048-block sections, with each section handled by one worker. Index bits are accumulated in memory; each touched index record is read once and written at most once per section.
  • Idempotent backfilling that preserves existing index bits and can be rerun after interruption. Unchanged records are not rewritten, and successful-block counts are added after the section's required writes finish.
  • Parameter/database validation, a terminal progress bar, progress logs every 10,000 scanned blocks, and a final execution summary. Block and task failures produce a nonzero exit status; the summary reflects the overall result, and database write failures retain their original causes.

Usage and operational requirements are documented in plugins/README.md.

Bloom encoding is shared through BloomUtils in the existing crypto module. The node's Bloom class delegates to this utility while retaining its public API. Toolkit decodes TransactionRet directly from Protobuf, so the command needs no chainbase runtime dependency. Keccak hashing, bloom bit ordering, section keys, and the compressed database format remain compatible with the node.

Why are these changes required?

Historical blocks processed before v4.8.1 with isJsonRpcFilterEnabled disabled may lack SectionBloom indexes. Since v4.8.1, index generation is independent of this setting. This command rebuilds missing indexes from retained transaction results for address/topic filtering by eth_getLogs, without replaying the blockchain.

This PR has been tested by:

  • All 19 tests in the consolidated DbBackfillBloomTest passed, with no failures or skips. Coverage includes engine selection, ARM rejection, persisted-head bounds, explicit zero bounds, validation, progress reporting, and failure summaries, including worker Error propagation and original exception causes. Additional tests verify one read/write per changed index per section, zero writes on complete reruns, and recovery after partial section read/write failures.
  • Real RocksDB tests compare exact keys and compressed values with the node's SectionBloomStore, covering the 2047/2048 boundary, concurrent sections, missing target creation, existing bits, repeated runs, empty/missing transaction results, empty bloom values, and malformed Protobuf.
  • Related encoder/node suites passed: BloomUtilsTest, BloomTest, SectionBloomStoreTest, LogBlockQueryTest, and LogsFilterCapsuleTest. Shared encoder tests use an independent Keccak digest and integer-based bit representation.
  • Standalone RocksDB smoke tests produced identical 174-entry indexes before and after encoder extraction, including repeated runs. Runtime dependency and JAR-content checks verified that chainbase and its excluded transitive dependencies are absent.
  • Root checkstyleMain checkstyleTest and git diff --check passed after the final changes. Encoder validation also included javac --release 8 for BloomUtils and the delegating Bloom class.

Automated local validation used macOS ARM64/JDK 17. The standalone command was also validated on Ubuntu x86 with real node data and -c 16, including an initially empty section-bloom database. The full repository test suite was not run locally.

Measured performance on Ubuntu x86 with 16 workers:

Scenario Inclusive block range Blocks Duration Blocks/second Bloom writes
Before section accumulation 79,775,907–80,000,000 224,094 1,245 s 180.00 93,765,660
After optimization, existing indexes 79,775,907–80,000,000 224,094 12 s 18,674.50 0
After optimization, empty index database 79,775,907–86,290,757 6,514,851 257 s 25,349.61 6,516,736

All three runs completed with zero reported errors. The empty-database run processed 3,182 sections and wrote exactly 3,182 × 2,048 = 6,516,736 index records. These are observed results; block ranges and initial index states differ across runs, and throughput depends on the workload and hardware.

Follow up

None.

Extra details

Stop the node and any other process accessing the database before running the command. The directory must contain properties and transactionRetStore, with at least one non-zero transaction-result block. storage.transHistory.switch must have been enabled when the target blocks were processed, and those results must still be present; the tool cannot recover missing transaction results.

The command can be rerun after interruption. Multiple backfill processes must not operate on the same database concurrently.

Known limitation: node checkpoint replay may overwrite backfilled bits in sections covered by retained checkpoints. Historical sections outside those checkpoints are unaffected. This edge case is not addressed in this PR.

@317787106 317787106 changed the title Feature/backfill sectionbloom feat(tookit): backfill sectionbloom Jul 24, 2026
Repository owner deleted a comment from coderabbitai Bot Jul 24, 2026
Repository owner deleted a comment from github-actions Bot Jul 24, 2026
@317787106 317787106 changed the title feat(tookit): backfill sectionbloom feat(plugins): backfill section bloom Jul 24, 2026
@317787106
317787106 changed the base branch from develop to release_v4.8.3 September 14, 2026 09:21
Rebuild historical SectionBloom indexes from retained transaction results
with engine detection, persisted-head bounds, and failure reporting.
Share bloom encoding with the node while preserving the database format.

Validate engine handling, index compatibility, reruns, and error paths in
the consolidated backfill suite; document operation and known limitations.
@317787106
317787106 force-pushed the feature/backfill_sectionbloom branch from cf64bb1 to e1622e1 Compare September 16, 2026 07:24
Repository owner deleted a comment from github-actions Bot Sep 16, 2026
@317787106 317787106 closed this Sep 16, 2026
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.

1 participant