!5291itz/keysign-rotation-gate-3.21.2 → develope72ca325eb

GG20 keysign rotation: gate at 3.21.2, signature wait covers rotated joins

AI-generatedEverything on this page was written by an AI agent from the diff: the summaries, the narration, the diagrams, the flags and the glossary. It can be wrong or incomplete, so check it against the code before you rely on it.

4commits
3files
160lines changed
41lines to read
45s→185ssig wait (rotated)
3.21.1→3.21.2rotation gate

Where the diff is

Look here first

Gate must equal first shipping releaseNetwork version = min active version; if 3.21.2 ships without this code, rotation flips per node and parties split. Release-process check.keysign_leader_rotation.go:28 ↗verify
23− // an atomic, consensus-synchronized switch is mandatory. Mirrors frostJoinRotationVersion.
24− keysignLeaderRotationVersion = "3.21.1"
21+ // consensus version (GetThorchainVersion), which is the lowest version among active
22+ // validators, so the whole fleet flips to the new party-formation protocol atomically
23+ // once the last active node runs this release — a rotating node derives a distinct
24+ // per-attempt join id and cannot form a party with a pre-rotation peer, so an atomic,
25+ // consensus-synchronized switch is mandatory. The gate must therefore be the first
26+ // release that ships this code: a lower gate would switch nodes on one by one as they
27+ // upgrade from a release that already meets it. Mirrors frostJoinRotationVersion.
28+ keysignLeaderRotationVersion = "3.21.2"
2529 // keysignJoinAttemptDomain separates GG20 join-attempt digests from the FROST ones so
2630 // the two protocols can never collide on a shared msgID.
2731 keysignJoinAttemptDomain = "thorchain-keysign-join-attempt-v1"
32+ // keysignSignatureWaitSlack pads the rotated signature wait for start skew between
33+ // nodes, matching the slack FROST adds to its result wait (KeySignTimeout+5s).
34+ keysignSignatureWaitSlack = 5 * time.Second
2835 )
2936
3037 // keysignLeaderRotationEnabled reports whether the gated GG20 keysign leader-rotation /
3138 // no-blame protocol is active for this request version.
3239 func keysignLeaderRotationEnabled(version string) (bool, error) {
3340 old, err := conversion.VersionLTCheck(strings.TrimSpace(version), keysignLeaderRotationVersion)
3441 if err != nil {
Wait = KeySign + 5s + 3 × Party185s at defaults, under RemoteSignTimeout 5m; operator-raised timeouts (e.g. 75s/75s) would exceed 5m silently.keysign_leader_rotation.go:57 ↗careful
48+// With leader rotation a party can form on any of frostMaxJoinLeaderAttempts join attempts,
49+// each bounded by the party timeout, before the signing ceremony itself starts. The wait
50+// adds those attempts and keysignSignatureWaitSlack to the keysign timeout, so a signature
51+// from a party formed on a later attempt, or by a peer that started a little later, still
52+// arrives while this node listens and can abort its own remaining attempts. It is a
53+// best-effort budget, not a hard bound: the keysign timeout is an idle timeout, so a
54+// ceremony that keeps exchanging messages can run past it.
55+func (t *TssServer) keysignSignatureWaitTimeout(version string) time.Duration {
56+ if enabled, err := keysignLeaderRotationEnabled(version); err == nil && enabled {
57+ return t.conf.KeySignTimeout + keysignSignatureWaitSlack + frostMaxJoinLeaderAttempts*t.conf.PartyTimeout
58+ }
59+ return t.conf.KeySignTimeout
60+}
61+
4062 // keysignJoinAttemptID derives a unique, ephemeral join-party session id for one GG20
4163 // keysign leader-rotation attempt. It reuses p2p.FrostJoinAttemptIDPrefix — the generic
4264 // ephemeral-retryable-join marker the coordinator special-cases (an early/stood-down request
4365 // is reset, not parked) — and a distinct domain so GG20 digests are disjoint from FROST's.
4466 func keysignJoinAttemptID(msgID, leader string, eligiblePeers []string, attempt int) (string, error) {
4567 msgID = strings.TrimSpace(msgID)
4668 leader = strings.TrimSpace(leader)
4769 if msgID == "" || leader == "" || len(eligiblePeers) == 0 || attempt < 0 {
4870 return "", errors.New("invalid keysign join attempt context")
Failed ceremonies now hold KeySign 185sKeySign waits on both goroutines; non-selected nodes block the full 185s rotated budget since failure notices don't end the wait.keysign.go:321 ↗careful
314313 msgsCopy := make([][]byte, len(msgsToSign))
315314 for i, msg := range msgsToSign {
316315 msgsCopy[i] = make([]byte, len(msg))
317316 copy(msgsCopy[i], msg)
318317 }
319318 // we wait for signatures
320319 go func() {
321320 defer wg.Done()
322− receivedSig, errWait = t.waitForSignatures(msgID, req.PoolPubKey, msgsCopy, algo, sigChan)
321+ receivedSig, errWait = t.waitForSignatures(msgID, req.PoolPubKey, msgsCopy, algo, t.keysignSignatureWaitTimeout(req.Version), sigChan)
323322 // we received an valid signature indeed
324323 if errWait == nil {
325324 sigChan <- "signature received"
326325 t.logger.Debug().Msgf("received signature for messageID (%s) from peer", msgID)
327326 return
328327 }
329328 if errWait != p2p.ErrSigGenerated {
330329 t.logger.Error().Err(errWait).Msg("waitForSignatures returned error")
331330 }
332331 }()
333332
334333 // we generate the signature ourselves
335334 go func() {
Unparsable version falls back to legacy waitParse error is swallowed here; KeySign rejects bad versions earlier via NEWJOINPARTYVERSION check, so fallback is unreachable in practice.keysign_leader_rotation.go:56 ↗look
47+// keysignSignatureWaitTimeout bounds how long a node waits for a peer's keysign signature.
48+// With leader rotation a party can form on any of frostMaxJoinLeaderAttempts join attempts,
49+// each bounded by the party timeout, before the signing ceremony itself starts. The wait
50+// adds those attempts and keysignSignatureWaitSlack to the keysign timeout, so a signature
51+// from a party formed on a later attempt, or by a peer that started a little later, still
52+// arrives while this node listens and can abort its own remaining attempts. It is a
53+// best-effort budget, not a hard bound: the keysign timeout is an idle timeout, so a
54+// ceremony that keeps exchanging messages can run past it.
55+func (t *TssServer) keysignSignatureWaitTimeout(version string) time.Duration {
56+ if enabled, err := keysignLeaderRotationEnabled(version); err == nil && enabled {
57+ return t.conf.KeySignTimeout + keysignSignatureWaitSlack + frostMaxJoinLeaderAttempts*t.conf.PartyTimeout
58+ }
59+ return t.conf.KeySignTimeout
60+}
61+
4062 // keysignJoinAttemptID derives a unique, ephemeral join-party session id for one GG20
4163 // keysign leader-rotation attempt. It reuses p2p.FrostJoinAttemptIDPrefix — the generic
4264 // ephemeral-retryable-join marker the coordinator special-cases (an early/stood-down request
4365 // is reset, not parked) — and a distinct domain so GG20 digests are disjoint from FROST's.
4466 func keysignJoinAttemptID(msgID, leader string, eligiblePeers []string, attempt int) (string, error) {
4567 msgID = strings.TrimSpace(msgID)
4668 leader = strings.TrimSpace(leader)
4769 if msgID == "" || leader == "" || len(eligiblePeers) == 0 || attempt < 0 {
Timeout now a parameterwaitForSignatures takes timeout; stale 'wait twice' comment removed. Only caller updated.keysign.go:28 ↗look
2222 "gitlab.com/thorchain/thornode/v3/bifrost/tss/go-tss/keysign"
2323 "gitlab.com/thorchain/thornode/v3/bifrost/tss/go-tss/keysign/ecdsa"
2424 "gitlab.com/thorchain/thornode/v3/bifrost/tss/go-tss/keysign/eddsa"
2525 tcommon "gitlab.com/thorchain/thornode/v3/common"
2626 )
2727
28−func (t *TssServer) waitForSignatures(msgID, poolPubKey string, msgsToSign [][]byte, algo tcommon.SigningAlgo, sigChan chan string) (keysign.Response, error) {
29− // TSS keysign include both form party and keysign itself, thus we wait twice of the timeout
30− data, err := t.signatureNotifier.WaitForSignature(msgID, msgsToSign, poolPubKey, t.conf.KeySignTimeout, sigChan)
28+func (t *TssServer) waitForSignatures(msgID, poolPubKey string, msgsToSign [][]byte, algo tcommon.SigningAlgo, timeout time.Duration, sigChan chan string) (keysign.Response, error) {
29+ data, err := t.signatureNotifier.WaitForSignature(msgID, msgsToSign, poolPubKey, timeout, sigChan)
3130 if err != nil {
3231 return keysign.Response{}, err
3332 }
3433 // for gg20, it wrap the signature R,S into ECSignature structure
3534 if len(data) == 0 {
3635 return keysign.Response{}, errors.New("keysign failed")
3736 }
3837
3938 return t.batchSignatures(algo, data, msgsToSign), nil
4039 }
4140
4241 func (t *TssServer) generateSignature(

Ask an AI about this change

Chat assistantClaude, ChatGPT, … (reads a link)

Coding agentClaude Code, Cursor, … (reads the repo)

The context file is context.md. Use Copy with context for an AI that can't open links; it pastes the whole file in.

Glossary

GG20
The ECDSA threshold-signature protocol (Gennaro-Goldfeder 2020) bifrost's go-tss uses for secp256k1 vault keysign. keysign.go ↗
Leader rotation
Retrying party formation with a different join leader on each of up to 3 attempts, each with a distinct join id. keysign_leader_rotation.go ↗
Network version
The lowest version among active validators, from /thorchain/version current; passed to go-tss as req.Version.
PartyTimeout / KeySignTimeout
go-tss timeouts for forming a party and for the signing ceremony; both 45s by default. config/default.yaml ↗
RemoteSignTimeout
Bifrost signer's 5-minute ceiling on one TSS keysign call. tss_signer.go ↗