fix(co-sign): fix session start logic to check all registered participants
- CanStart(): Check if all registered participants have joined, not based on T/N - AddParticipant(): Keep N as max limit (API handles T vs T+1 validation) - AllPartiesReady(): Check all registered participants, not based on T/N - This approach works for both co-managed (T parties) and persistent (T+1 parties) signing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
a09e163704
commit
99fa003b12
|
|
@ -98,6 +98,9 @@ func NewMPCSession(
|
||||||
|
|
||||||
// AddParticipant adds a participant to the session
|
// AddParticipant adds a participant to the session
|
||||||
func (s *MPCSession) AddParticipant(p *Participant) error {
|
func (s *MPCSession) AddParticipant(p *Participant) error {
|
||||||
|
// For sign sessions, the max participant check is handled at the API level
|
||||||
|
// (co-managed uses T, persistent uses T+1)
|
||||||
|
// Here we just prevent exceeding N which is the absolute maximum
|
||||||
if len(s.Participants) >= s.Threshold.N() {
|
if len(s.Participants) >= s.Threshold.N() {
|
||||||
return ErrSessionFull
|
return ErrSessionFull
|
||||||
}
|
}
|
||||||
|
|
@ -140,26 +143,22 @@ func (s *MPCSession) UpdateParticipantStatus(partyID value_objects.PartyID, stat
|
||||||
|
|
||||||
// CanStart checks if all participants have joined and the session can start
|
// CanStart checks if all participants have joined and the session can start
|
||||||
func (s *MPCSession) CanStart() bool {
|
func (s *MPCSession) CanStart() bool {
|
||||||
// Determine required participant count based on session type
|
// Session can start when all registered participants have joined
|
||||||
// For keygen: all N parties must participate
|
// The number of participants was determined at session creation time:
|
||||||
// For sign: only T parties participate
|
// - For keygen: N parties are registered
|
||||||
requiredCount := s.Threshold.N()
|
// - For sign: T or T+1 parties are registered (depending on the signing flow)
|
||||||
if s.SessionType == SessionTypeSign {
|
// We don't need to check against T or N here - just verify all registered parties have joined
|
||||||
requiredCount = s.Threshold.T()
|
if len(s.Participants) == 0 {
|
||||||
}
|
|
||||||
|
|
||||||
if len(s.Participants) != requiredCount {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
readyCount := 0
|
|
||||||
for _, p := range s.Participants {
|
for _, p := range s.Participants {
|
||||||
// Accept participants in either joined or ready status
|
// All participants must be in joined or ready status
|
||||||
if p.IsJoined() || p.IsReady() {
|
if !p.IsJoined() && !p.IsReady() {
|
||||||
readyCount++
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return readyCount == requiredCount
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start transitions the session to in_progress
|
// Start transitions the session to in_progress
|
||||||
|
|
@ -265,7 +264,9 @@ func (s *MPCSession) MarkPartyReady(partyID string) error {
|
||||||
|
|
||||||
// AllPartiesReady checks if all participants are ready
|
// AllPartiesReady checks if all participants are ready
|
||||||
func (s *MPCSession) AllPartiesReady() bool {
|
func (s *MPCSession) AllPartiesReady() bool {
|
||||||
if len(s.Participants) != s.Threshold.N() {
|
// Check that all registered participants are ready or completed
|
||||||
|
// The participant count was determined at session creation time
|
||||||
|
if len(s.Participants) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, p := range s.Participants {
|
for _, p := range s.Participants {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue