Repository navigation
fix(dashmate): use complete DKG membership for safe stops #5231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
PastaPastaPasta
merged 7 commits into
v5.1-dev
from
fix/dashmate-dkg-membership-safe-stop
Oct 15, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
926a74e
fix(dashmate): only block stops for DKGs this masternode is in
PastaPastaPasta b5d0721
test(dashmate): cover needsSafeStopConfirmation directly
PastaPastaPasta 052c18a
fix(dashmate): use complete DKG membership without confirmation delay
PastaPastaPasta dff9044
fix(dashmate): follow active DKG session RPC contract
PastaPastaPasta acc0f3a
docs(dashmate): clarify DKG membership safety assumptions
PastaPastaPasta 3b540cc
refactor(dashmate): key DKG membership safety on upcoming_dkgs
PastaPastaPasta 2608662
Merge branch 'v5.1-dev' into fix/dashmate-dkg-membership-safe-stop
PastaPastaPasta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/dashmate/src/core/quorum/checkMasternodeSafeToStop.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import isMasternodeSafeToStopDuringDkg, { | ||
| shouldInspectDkgStatusForSafeStop, | ||
| } from './isMasternodeSafeToStopDuringDkg.js'; | ||
|
|
||
| /** | ||
| * Query Core and decide whether stopping would disrupt a DKG session. | ||
| * Older Core responses require the existing per-session status checks. | ||
| * | ||
| * @param {RpcClient} rpcClient | ||
| * @return {Promise<boolean>} | ||
| */ | ||
| export default async function checkMasternodeSafeToStop(rpcClient) { | ||
| const { result: dkgInfo } = await rpcClient.quorum('dkginfo'); | ||
|
|
||
| let dkgStatus; | ||
| let currentHeight; | ||
| if (shouldInspectDkgStatusForSafeStop(dkgInfo)) { | ||
| [ | ||
| { result: dkgStatus }, | ||
| { result: currentHeight }, | ||
| ] = await Promise.all([ | ||
| rpcClient.quorum('dkgstatus'), | ||
| rpcClient.getBlockCount(), | ||
| ]); | ||
| } | ||
|
|
||
| return isMasternodeSafeToStopDuringDkg(dkgInfo, dkgStatus, currentHeight); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,19 @@ | ||
| import wait from '../../util/wait.js'; | ||
| import isMasternodeSafeToStopDuringDkg, { | ||
| shouldInspectDkgStatusForSafeStop, | ||
| } from './isMasternodeSafeToStopDuringDkg.js'; | ||
| import checkMasternodeSafeToStop from './checkMasternodeSafeToStop.js'; | ||
|
|
||
| const CHECK_INTERVAL_MS = 10000; | ||
|
|
||
| /** | ||
| * Poll Core until the masternode is safe to stop without disrupting a | ||
| * DKG session. See {@link isMasternodeSafeToStopDuringDkg} for the | ||
| * DKG session. See {@link checkMasternodeSafeToStop} for the | ||
| * safety rule. The only acceptable exit is reaching a safe state, so | ||
| * that `--safe` cannot silently fall back to an unsafe restart. | ||
| * | ||
| * @param {RpcClient} rpcClient | ||
| * @return {Promise<void>} | ||
| */ | ||
| export default async function waitForDKGWindowPass(rpcClient) { | ||
| for (;;) { | ||
| const { result: dkgInfo } = await rpcClient.quorum('dkginfo'); | ||
|
|
||
| let dkgStatus; | ||
| let currentHeight; | ||
| if (shouldInspectDkgStatusForSafeStop(dkgInfo)) { | ||
| [ | ||
| { result: dkgStatus }, | ||
| { result: currentHeight }, | ||
| ] = await Promise.all([ | ||
| rpcClient.quorum('dkgstatus'), | ||
| rpcClient.getBlockCount(), | ||
| ]); | ||
| } | ||
|
|
||
| if (isMasternodeSafeToStopDuringDkg(dkgInfo, dkgStatus, currentHeight)) { | ||
| return; | ||
| } | ||
|
|
||
| while (!await checkMasternodeSafeToStop(rpcClient)) { | ||
| await wait(CHECK_INTERVAL_MS); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/dashmate/test/unit/core/quorum/checkMasternodeSafeToStop.spec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import checkMasternodeSafeToStop from '../../../../src/core/quorum/checkMasternodeSafeToStop.js'; | ||
|
|
||
| describe('checkMasternodeSafeToStop', () => { | ||
| let rpcClient; | ||
|
|
||
| beforeEach(function beforeEach() { | ||
| rpcClient = { quorum: this.sinon.stub(), getBlockCount: this.sinon.stub() }; | ||
| }); | ||
|
|
||
| it('should allow a non-member immediately using one membership response', async () => { | ||
| rpcClient.quorum.withArgs('dkginfo').resolves({ | ||
| result: { | ||
| active_dkgs: 0, | ||
| next_dkg: 1, | ||
| upcoming_dkgs: [{ blocksUntilStart: 1, known: true, isMember: false }], | ||
| }, | ||
| }); | ||
| expect(await checkMasternodeSafeToStop(rpcClient)).to.equal(true); | ||
| expect(rpcClient.quorum).to.have.been.calledOnceWith('dkginfo'); | ||
| expect(rpcClient.getBlockCount).to.not.have.been.called(); | ||
| }); | ||
|
|
||
| it('should block a positive active_dkgs without inspecting dkgstatus', async () => { | ||
| rpcClient.quorum.withArgs('dkginfo').resolves({ | ||
| result: { | ||
| active_dkgs: 1, | ||
| next_dkg: 24, | ||
| upcoming_dkgs: [], | ||
| }, | ||
| }); | ||
| expect(await checkMasternodeSafeToStop(rpcClient)).to.equal(false); | ||
| expect(rpcClient.quorum).to.have.been.calledOnceWith('dkginfo'); | ||
| expect(rpcClient.getBlockCount).to.not.have.been.called(); | ||
| }); | ||
|
|
||
| it('should block a member of an imminent DKG', async () => { | ||
| rpcClient.quorum.withArgs('dkginfo').resolves({ | ||
| result: { | ||
| active_dkgs: 0, | ||
| next_dkg: 1, | ||
| upcoming_dkgs: [{ blocksUntilStart: 1, known: true, isMember: true }], | ||
| }, | ||
| }); | ||
| expect(await checkMasternodeSafeToStop(rpcClient)).to.equal(false); | ||
| expect(rpcClient.quorum).to.have.been.calledOnceWith('dkginfo'); | ||
| }); | ||
|
|
||
| it('should retain the imminent-DKG guard without upcoming_dkgs', async () => { | ||
| rpcClient.quorum.withArgs('dkginfo').resolves({ result: { active_dkgs: 0, next_dkg: 1 } }); | ||
| expect(await checkMasternodeSafeToStop(rpcClient)).to.equal(false); | ||
| expect(rpcClient.quorum).to.have.been.calledOnceWith('dkginfo'); | ||
| }); | ||
|
|
||
| it('should allow a legacy response with no active or imminent DKG', async () => { | ||
| rpcClient.quorum.withArgs('dkginfo').resolves({ result: { active_dkgs: 0, next_dkg: 24 } }); | ||
| expect(await checkMasternodeSafeToStop(rpcClient)).to.equal(true); | ||
| expect(rpcClient.quorum).to.have.been.calledOnceWith('dkginfo'); | ||
| }); | ||
|
|
||
| it('should inspect active sessions for older Core', async () => { | ||
| rpcClient.quorum.withArgs('dkginfo').resolves({ result: { active_dkgs: 1, next_dkg: 24 } }); | ||
| rpcClient.quorum.withArgs('dkgstatus').resolves({ | ||
| result: { session: [{ llmqType: 'llmq_60_75', status: { quorumHeight: 1000 } }] }, | ||
| }); | ||
| rpcClient.getBlockCount.resolves({ result: 1001 }); | ||
| expect(await checkMasternodeSafeToStop(rpcClient)).to.equal(false); | ||
| expect(rpcClient.quorum.withArgs('dkgstatus')).to.have.been.calledOnce(); | ||
| expect(rpcClient.getBlockCount).to.have.been.calledOnce(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.