Skip to content

Fix infinite loop in darkside setPrevhash (#552)#553

Open
mnm458 wants to merge 2 commits intozcash:masterfrom
mnm458:552_fix_darkside_setPrevhash_loop
Open

Fix infinite loop in darkside setPrevhash (#552)#553
mnm458 wants to merge 2 commits intozcash:masterfrom
mnm458:552_fix_darkside_setPrevhash_loop

Conversation

@mnm458
Copy link
Copy Markdown

@mnm458 mnm458 commented Mar 10, 2026

Description:

Fix infinite loop in darkside setPrevhash by computing block hash after updating prevhash bytes.

Summary

setPrevhash() was parsing each block's raw bytes before writing the corrected prevhash, then computing the block hash from the stale parsed struct. This caused subsequent blocks to have incorrect prevhash values, leading BlockIngestor into an infinite add/reorg loop when ApplyStaged was called.

The fix moves the copy() of the prevhash to occur before ParseFromSlice(), so the hash is computed from the updated bytes.

Closes #552

Documentation

No external documentation changes required. The fix corrects internal behavior to match the existing documented darkside tutorial in docs/darksidewalletd.md.

Test Plan

  • Added regression test TestSetPrevhashChainConsistency in common/darkside_test.go
  • Test verifies that each block's prevhash matches the preceding block's hash after setPrevhash runs
  • Test fails against the old (buggy) code and passes with the fix
  • All existing tests pass (go test ./...)
  • Manual verification: run the darkside tutorial from docs/darksidewalletd.md and confirm ApplyStaged no longer produces infinite log output

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.

Darkside setPrevhash causes infinite add/reorg loop in BlockIngestor

1 participant