-
Notifications
You must be signed in to change notification settings - Fork 228
improve delay messages on multikeys #7791
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
AdoAdoAdo
merged 2 commits into
feat/supernova-async-exec
from
better-delay-management-multikey
Mar 17, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -108,6 +108,14 @@ func (sr *subroundSignature) doSignatureJob(ctx context.Context) bool { | |
| return false | ||
| } | ||
|
|
||
| // Wait once for the entire node if competing block detected | ||
| nonce := sr.GetHeader().GetNonce() | ||
| currentHash := sr.GetData() | ||
| shouldAbort := sr.waitIfCompetingBlockForNode(ctx, nonce, currentHash) | ||
| if shouldAbort { | ||
| return false | ||
| } | ||
|
|
||
| isSelfSingleKeyInConsensusGroup := sr.IsNodeInConsensusGroup(sr.SelfPubKey()) && commonConsensus.ShouldConsiderSelfKeyInConsensus(sr.NodeRedundancyHandler()) | ||
| if isSelfSingleKeyInConsensusGroup { | ||
| if !sr.doSignatureJobForSingleKey(ctx) { | ||
|
|
@@ -251,16 +259,11 @@ func (sr *subroundSignature) doSignatureJobForManagedKeys(ctx context.Context) b | |
| return sentSigForAllKeys.IsSet() | ||
| } | ||
|
|
||
| func (sr *subroundSignature) sendSignatureForManagedKey(ctx context.Context, idx int, pk string) bool { | ||
| func (sr *subroundSignature) sendSignatureForManagedKey(_ context.Context, idx int, pk string) bool { | ||
| pkBytes := []byte(pk) | ||
| nonce := sr.GetHeader().GetNonce() | ||
| currentHash := sr.GetData() | ||
|
|
||
| shouldAbort := sr.waitIfCompetingBlock(ctx, pkBytes, nonce, currentHash) | ||
| if shouldAbort { | ||
| return false | ||
| } | ||
|
|
||
| signatureShare, err := sr.SigningHandler().CreateSignatureShareForPublicKey( | ||
| currentHash, | ||
| uint16(idx), | ||
|
|
@@ -301,16 +304,11 @@ func (sr *subroundSignature) checkGoRoutinesThrottler(ctx context.Context) error | |
| return nil | ||
| } | ||
|
|
||
| func (sr *subroundSignature) doSignatureJobForSingleKey(ctx context.Context) bool { | ||
| func (sr *subroundSignature) doSignatureJobForSingleKey(_ context.Context) bool { | ||
| pkBytes := []byte(sr.SelfPubKey()) | ||
| nonce := sr.GetHeader().GetNonce() | ||
| currentHash := sr.GetData() | ||
|
|
||
| shouldAbort := sr.waitIfCompetingBlock(ctx, pkBytes, nonce, currentHash) | ||
| if shouldAbort { | ||
| return false | ||
| } | ||
|
|
||
| selfIndex, err := sr.SelfConsensusGroupIndex() | ||
| if err != nil { | ||
| log.Debug("doSignatureJobForSingleKey.SelfConsensusGroupIndex: not in consensus group") | ||
|
|
@@ -341,9 +339,33 @@ func (sr *subroundSignature) doSignatureJobForSingleKey(ctx context.Context) boo | |
| return sr.completeSignatureSubRound(sr.SelfPubKey()) | ||
| } | ||
|
|
||
| // waitIfCompetingBlock checks if this node already signed a different block for the same nonce. | ||
| // If so, it waits for a fraction of the round time to give the previous block's proof a chance to arrive. | ||
| // Returns true if the signing should be aborted (proof for previous block arrived or context cancelled). | ||
| // waitIfCompetingBlockForNode checks if any key managed by this node previously signed a different | ||
| // hash for the given nonce. If found, waits once for the entire node instead of per-key. | ||
| func (sr *subroundSignature) waitIfCompetingBlockForNode(ctx context.Context, nonce uint64, currentHash []byte) bool { | ||
| // Check self key first | ||
| selfPk := []byte(sr.SelfPubKey()) | ||
| previousHash, exists := sr.sentSignatureTracker.GetSignedHash(selfPk, nonce) | ||
| if exists && !bytes.Equal(previousHash, currentHash) { | ||
| return sr.waitIfCompetingBlock(ctx, selfPk, nonce, currentHash) | ||
| } | ||
|
|
||
| // Check managed keys | ||
| for _, pk := range sr.ConsensusGroup() { | ||
| pkBytes := []byte(pk) | ||
| if !sr.IsKeyManagedBySelf(pkBytes) { | ||
| continue | ||
| } | ||
| previousHash, exists = sr.sentSignatureTracker.GetSignedHash(pkBytes, nonce) | ||
| if exists && !bytes.Equal(previousHash, currentHash) { | ||
| return sr.waitIfCompetingBlock(ctx, pkBytes, nonce, currentHash) | ||
| } | ||
|
Comment on lines
+347
to
+361
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can come as an improvement afterwards, keeping the changes minimal for now. |
||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| // waitIfCompetingBlock waits if this node already signed a different block for the same nonce. | ||
| // The delay is measured from round start. Returns true if signing should be aborted. | ||
| func (sr *subroundSignature) waitIfCompetingBlock(ctx context.Context, pkBytes []byte, nonce uint64, currentHash []byte) bool { | ||
| previousHash, exists := sr.sentSignatureTracker.GetSignedHash(pkBytes, nonce) | ||
| if !exists { | ||
|
|
@@ -354,10 +376,16 @@ func (sr *subroundSignature) waitIfCompetingBlock(ctx context.Context, pkBytes [ | |
| return false | ||
| } | ||
|
|
||
| delay := time.Duration(float64(sr.RoundHandler().TimeDuration()) * competingBlockSignDelay) | ||
| // Delay is measured from round start, not from when this function is called | ||
| roundStart := sr.GetRoundTimeStamp() | ||
| targetTime := time.Duration(float64(sr.RoundHandler().TimeDuration()) * competingBlockSignDelay) | ||
| delay := sr.RoundHandler().RemainingTime(roundStart, targetTime) | ||
| if delay <= 0 { | ||
| log.Debug("waitIfCompetingBlock: already past competing block delay deadline, proceeding to sign") | ||
| return false | ||
| } | ||
|
|
||
| // Cap the delay so signing still happens within the signature subround window. | ||
| roundStart := sr.GetRoundTimeStamp() | ||
| sigEndDuration := time.Duration(sr.EndTime()) | ||
| remaining := sr.RoundHandler().RemainingTime(roundStart, sigEndDuration) | ||
| safetyMargin := 10 * time.Millisecond | ||
|
|
||
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.