Skip to content

fix(consensus): correct loop condition in checkDoubleSigningRisk for height=1 (backport #5668) - #6001

Merged
swift1337 merged 3 commits into
v0.38.xfrom
mergify/bp/v0.38.x/pr-5668
Jul 27, 2026
Merged

swift1337 merged 3 commits into
v0.38.xfrom
mergify/bp/v0.38.x/pr-5668

Conversation

@mergify

@mergify mergify Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Fixes: #5435

When double_sign_check_height is set to 1, the loop condition i := int64(1); i < 1 is never satisfied, resulting in zero iterations and no double sign checks being performed. This makes the setting functionally equivalent to 0 (disabled), silently giving validators false confidence in their double-sign protection.

Changed the loop condition from i < doubleSignCheckHeight to i <= doubleSignCheckHeight so that a value of 1 correctly checks height - 1, matching the documented intent of the configuration parameter. The existing guard if doubleSignCheckHeight > height already prevents out-of-bounds lookups on short chains, so no additional bounds protection is needed.

PR checklist

…5668)

Fixes: #5435

When `double_sign_check_height` is set to `1`, the loop condition `i :=
int64(1); i < 1` is never satisfied, resulting in zero iterations and no
double sign checks being performed. This makes the setting functionally
equivalent to `0` (disabled), silently giving validators false
confidence in their double-sign protection.

Changed the loop condition from `i < doubleSignCheckHeight` to `i <=
doubleSignCheckHeight` so that a value of `1` correctly checks `height -
1`, matching the documented intent of the configuration parameter. The
existing guard `if doubleSignCheckHeight > height` already prevents
out-of-bounds lookups on short chains, so no additional bounds
protection is needed.

#### PR checklist

- [x] Tests written/updated
- [x] Changelog entry added in `CHANGELOG.md`
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

---------

Co-authored-by: Alex Cozart <[email protected]>
(cherry picked from commit 6e8065b)

# Conflicts:
#	CHANGELOG.md
#	consensus/state_test.go
#	scripts/metricsgen/metricsgen.go
@mergify mergify Bot added the conflicts label Jul 27, 2026
@mergify

mergify Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Cherry-pick of 6e8065b has failed:

On branch mergify/bp/v0.38.x/pr-5668
Your branch is up to date with 'origin/v0.38.x'.

You are currently cherry-picking commit 6e8065b7.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   consensus/state.go
	modified:   mempool/clist_mempool.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   CHANGELOG.md
	both modified:   consensus/state_test.go
	both modified:   scripts/metricsgen/metricsgen.go

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@greptile-apps

greptile-apps Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

- CHANGELOG.md: keep only the #5668 entry (other entries were
  main-only and already present or not applicable on v0.38.x)
- consensus/state_test.go: drop main-only countingWAL/WAL fsync
  tests that were pulled in as conflict context; keep TestDoubleSigning
- mempool/clist_mempool.go, scripts/metricsgen/metricsgen.go: revert
  to v0.38.x base; those hunks were unrelated main-only cleanups
@mergify

mergify Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@swift1337
swift1337 merged commit 5adf46c into v0.38.x Jul 27, 2026
15 of 17 checks passed
@swift1337
swift1337 deleted the mergify/bp/v0.38.x/pr-5668 branch July 27, 2026 16:10
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