Skip to content

Conversation

@ohcee
Copy link
Collaborator

@ohcee ohcee commented Dec 17, 2025

Summary

This PR improves block validation and sync performance by reducing unnecessary Zerocoin database work during chain synchronization, while remaining fully consensus-safe and compatible with existing wallets.

The changes focus on:

  • Writing all Zerocoin data for a block in a single batch
  • Skipping empty Zerocoin database writes
  • Avoiding repeated accumulator rebuilds after Light Zerocoin activation, except where required for correctness

No protocol rules, data formats, or wallet behavior are changed.


Technical Details

1. Zerocoin DB batching

  • Introduces WriteBlockZerocoinData() to write spends, mints, and pubcoin spends in a single LevelDB batch.
  • Adds a fast-path that returns immediately when there is no Zerocoin data to write for a block.

2. Accumulator validation optimization

  • Pre-Light Zerocoin: retains existing behavior (validate every block).
  • Post-Light Zerocoin:
    • Accumulators are only rebuilt on checksum boundary blocks.
    • Accumulator values are written only when needed for future spend verification.
  • This preserves correctness while eliminating redundant work during sync.

3. Safety and compatibility

  • No consensus logic is altered.
  • Zerocoin staking remains fully supported.
  • RingCT behavior is unchanged.

Performance Results

Observed improvements during sync testing:

  • macOS (Apple Silicon): consistent reduction in block connect time and higher blocks/hour over long runs
  • Older Ubuntu systems: major reduction in Zerocoin database write time
    • Zerocoin DB writes reduced from ~347 ms/blk to ~88 ms/blk
  • Community side-by-side testing shows significantly faster historical catch-up compared to the current wallet

Exact gains vary by hardware, but improvements are consistent across systems.


Testing

  • Tested on macOS and Linux
  • Tested from snapshots and during long continuous syncs

Testers may optionally compare against the previous Zerocoin batching PR to observe the incremental improvement from the fast-path and accumulator changes.


Notes

This PR is designed to benefit all users automatically.
No configuration flags or user action is required.

ohcee added 10 commits November 27, 2025 08:27
Refactor zerocoin data writing logic to improve clarity and error handling.
Updated comment for clarity and removed unused code.
Refactor zerocoin data writing logic for clarity and efficiency.
Add early return for empty spend and mint info
validation: build zerocoin accumulators when spends are present (post-LZC)

Post-Light Zerocoin blocks were skipping accumulator construction unless the
block was on the checksum boundary, which can break zerocoin spend validation
("pubcoinhash ... not found").

Fix by forcing ValidateAccumulatorCheckpoint() when zerocoin spends exist,
while still only writing DatabaseChecksums() on checksum-boundary blocks.
@ohcee
Copy link
Collaborator Author

ohcee commented Dec 19, 2025

Closing for now. Optimization skips required Zerocoin accumulator state updates, causing valid Zerocoin spends to be rejected (InvalidChainFound at ~3,606,027).

@ohcee ohcee closed this Dec 19, 2025
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