close
Skip to content

fix: dao reog and init path - #7774

Draft
wodoro wants to merge 1 commit into
bisq-network:masterfrom
wodoro:fix_reorg
Draft

fix: dao reog and init path#7774
wodoro wants to merge 1 commit into
bisq-network:masterfrom
wodoro:fix_reorg

Conversation

@wodoro

@wodoro wodoro commented May 13, 2026

Copy link
Copy Markdown
Contributor

fixes some edge cases and re-org issues

Summary by CodeRabbit

  • Bug Fixes
    • Snapshot recovery now completes only when snapshot application succeeds, improving reliability.
    • Synthetic/empty snapshots with chain height zero are treated as benign no-ops to avoid unnecessary failures.
    • Chain-height validation tightened: persisted state reporting a non-zero height with no blocks now triggers resynchronization instead of being treated as matching.

@coderabbitai

coderabbitai Bot commented May 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5a1eabbe-2c24-403e-a435-2e72698f4bdf

📥 Commits

Reviewing files that changed from the base of the PR and between bbfa9e9 and 2027867.

📒 Files selected for processing (2)
  • core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java
  • core/src/main/java/bisq/core/dao/state/storage/DaoStateStorageService.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java
  • core/src/main/java/bisq/core/dao/state/storage/DaoStateStorageService.java

📝 Walkthrough

Walkthrough

This PR refines snapshot recovery and chain-height validation in the DAO state layer. DaoStateStorageService now explicitly signals mismatches when chain height is non-zero but no blocks are persisted. DaoStateSnapshotService treats missing snapshots, empty blocks during initialization, and sub-genesis heights as benign no-ops. The revert handler only executes on snapshot application success.

Changes

DAO Snapshot Recovery and Validation Refinement

Layer / File(s) Summary
Chain height matching refinement
core/src/main/java/bisq/core/dao/state/storage/DaoStateStorageService.java
isChainHeightMatchingLastBlockHeight now returns true only when chainHeight == 0 with empty blocks (benign), otherwise logs a warning and returns false to signal an explicit mismatch.
applySnapshot benign-case and flow updates
core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java
applySnapshot removes the persisted-null failure path, treats a storage-synthesized empty snapshot (empty blocks with chainHeight==0) as a benign no-op returning true, and returns true for persisted chain heights below genesis.
Snapshot revert completion handler
core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java
revertToLastSnapshot now conditionally executes completeHandler only on successful applySnapshot; on failure it logs that resync-from-resources will handle recovery.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 Three snapshots walked up the chain,
Two said "benign" with a knowing refrain,
Recovery grins when no blocks remain,
Revert waits till apply succeeds again,
Resync hops in, cleaning the lane.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'fix: dao reog and init path' is vague and contains unclear terminology that doesn't clearly describe what was fixed. Use a more specific title like 'fix: improve DAO reorg handling and snapshot initialization' to clearly communicate the actual changes being made.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java`:
- Around line 325-327: The unreachable persistedDaoState == null branch is due
to storage synthesizing new DaoState() when none exists; update
DaoStateSnapshotService to detect that synthetic "no snapshot" state before the
empty-block resync path by treating a DaoState with no blocks
(persistedDaoState.getBlocks().isEmpty()) and other default/absent identifying
fields (e.g., no last block/header or timestamp) as equivalent to null and
return true (benign retry) instead of falling through to revertToLastSnapshot();
make the same change in the other occurrence covering lines ~342-352; reference
persistedDaoState, DaoStateSnapshotService,
DaoStateStorageService#getPersistedBsqStateAtStartup(),
loadPersistedDaoData(...), and revertToLastSnapshot() when implementing the
check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b9ebecd4-049e-4f6e-ac68-b975ee74f478

📥 Commits

Reviewing files that changed from the base of the PR and between 39e6caa and cd8ad33.

📒 Files selected for processing (2)
  • core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java
  • core/src/main/java/bisq/core/dao/state/storage/DaoStateStorageService.java

Comment thread core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java Outdated
@wodoro
wodoro marked this pull request as draft May 14, 2026 02:29
@wodoro
wodoro marked this pull request as ready for review June 9, 2026 17:39

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/src/main/java/bisq/core/dao/state/storage/DaoStateStorageService.java`:
- Around line 225-239: The isChainHeightMatchingLastBlockHeight(...) helper
currently treats a non-zero chainHeight with empty persistedDaoState.getBlocks()
as a mismatch, which incorrectly forces resync for valid pre-genesis snapshots;
update DaoStateStorageService.isChainHeightMatchingLastBlockHeight(...) to
exempt pre-genesis states by checking the DAO genesis height (use the existing
genesis-height accessor used elsewhere) and return true when
chainHeightOfPersistedDaoState < genesisHeight (i.e., pre-genesis), or
alternatively adjust DaoStateSnapshotService.applySnapshot(...) to call
isHeightBelowGenesisHeight(...) before invoking
isChainHeightMatchingLastBlockHeight(...); implement the exemption inside
isChainHeightMatchingLastBlockHeight(...) for minimal churn by early-returning
true for pre-genesis chainHeight values so applySnapshot keeps the benign no-op
path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 524def24-8036-4b72-98c1-67acf6c36d63

📥 Commits

Reviewing files that changed from the base of the PR and between 7bd74a1 and bbfa9e9.

📒 Files selected for processing (2)
  • core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java
  • core/src/main/java/bisq/core/dao/state/storage/DaoStateStorageService.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java

Comment on lines 225 to +239
if (persistedDaoState.getBlocks().isEmpty()) {
log.warn("Cannot check chain height: DaoState has no blocks.");
return true;
// Empty blocks list is only consistent with the freshly initialized state (chainHeight==0).
// Any other value means the proto recorded a chainHeight but the side-channel block file
// (bsqBlocksStorageService) didn't provide matching blocks — likely an incomplete or
// mis-versioned data dir. Returning true here would make applySnapshot proceed with a
// DaoState that reports a synced height but has no parsed blocks, freezing reported
// chainHeight at the stale value and stalling LiteNode sync (its startParseBlocks
// short-circuits when chainHeight == bsqWallet best height).
if (chainHeightOfPersistedDaoState == 0) {
return true;
}
log.warn("DaoState reports chainHeight={} but has no blocks — block storage is incomplete. " +
"Treating as chain-height mismatch so applySnapshot can trigger resyncDaoStateFromResources.",
chainHeightOfPersistedDaoState);
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Pre-genesis snapshots now fall into the resync path.

DaoStateSnapshotService.applySnapshot(...) calls isChainHeightMatchingLastBlockHeight(...) before isHeightBelowGenesisHeight(...) (core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java, Lines 322-378). For a valid persisted state captured before BSQ genesis, chainHeight can be non-zero while blocks is still empty. This branch now returns false for that case, so the later benign no-op path is never reached and recovery unnecessarily resyncs from resources. Please keep the sub-genesis case out of this mismatch path, either by moving the genesis-height check ahead of this call or by teaching this helper to exempt pre-genesis heights.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/src/main/java/bisq/core/dao/state/storage/DaoStateStorageService.java`
around lines 225 - 239, The isChainHeightMatchingLastBlockHeight(...) helper
currently treats a non-zero chainHeight with empty persistedDaoState.getBlocks()
as a mismatch, which incorrectly forces resync for valid pre-genesis snapshots;
update DaoStateStorageService.isChainHeightMatchingLastBlockHeight(...) to
exempt pre-genesis states by checking the DAO genesis height (use the existing
genesis-height accessor used elsewhere) and return true when
chainHeightOfPersistedDaoState < genesisHeight (i.e., pre-genesis), or
alternatively adjust DaoStateSnapshotService.applySnapshot(...) to call
isHeightBelowGenesisHeight(...) before invoking
isChainHeightMatchingLastBlockHeight(...); implement the exemption inside
isChainHeightMatchingLastBlockHeight(...) for minimal churn by early-returning
true for pre-genesis chainHeight values so applySnapshot keeps the benign no-op
path.

@HenrikJannsen
HenrikJannsen marked this pull request as draft June 10, 2026 07:23
@HenrikJannsen

Copy link
Copy Markdown
Collaborator

It will more time to address that area, thus I have converted it to draft.

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@HenrikJannsen

Copy link
Copy Markdown
Collaborator

Still relevant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants