From 36e1359f439c837427fbdf15a357bd3439028792 Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 6 Dec 2025 05:38:38 -0800 Subject: [PATCH] fix(session-coordinator): pass PartyComposition from gRPC request to use case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed critical bug where PartyComposition (persistent/delegate party counts) was being sent by account-service in gRPC request but was not being extracted and passed to the CreateSession use case, causing delegate party selection to fail. Changes: - Extract PartyComposition from protobuf request and pass to CreateSessionInput - Add logging for party composition values in gRPC handler - Return delegate_party_id and selected_parties in CreateSessionResponse - Load session after creation to get delegate party ID This fixes the issue where require_delegate=true had no effect and all parties selected were persistent parties instead of 2 persistent + 1 delegate. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../input/grpc/session_grpc_handler.go | 36 +++++++++++++++++-- backend/mpc-system/test_create_session.go | 7 ++-- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/backend/mpc-system/services/session-coordinator/adapters/input/grpc/session_grpc_handler.go b/backend/mpc-system/services/session-coordinator/adapters/input/grpc/session_grpc_handler.go index 8fa0762e..125543a5 100644 --- a/backend/mpc-system/services/session-coordinator/adapters/input/grpc/session_grpc_handler.go +++ b/backend/mpc-system/services/session-coordinator/adapters/input/grpc/session_grpc_handler.go @@ -160,6 +160,19 @@ func (s *SessionCoordinatorServer) CreateSession( ExpiresIn: time.Duration(req.ExpiresInSeconds) * time.Second, } + // Add party composition if provided (for automatic party selection) + if req.PartyComposition != nil { + inputData.PartyComposition = &input.PartyComposition{ + PersistentCount: int(req.PartyComposition.PersistentCount), + DelegateCount: int(req.PartyComposition.DelegateCount), + TemporaryCount: int(req.PartyComposition.TemporaryCount), + } + logger.Info("Party composition specified in gRPC request", + zap.Int("persistent_count", inputData.PartyComposition.PersistentCount), + zap.Int("delegate_count", inputData.PartyComposition.DelegateCount), + zap.Int("temporary_count", inputData.PartyComposition.TemporaryCount)) + } + // Add delegate user share if provided (for sign sessions with delegate party) if req.DelegateUserShare != nil { inputData.DelegateUserShare = &input.DelegateUserShare{ @@ -180,11 +193,28 @@ func (s *SessionCoordinatorServer) CreateSession( zap.String("session_id", output.SessionID.String()), zap.Int("num_join_tokens", len(output.JoinTokens))) + // Load session to get delegate party ID + session, err := s.sessionRepo.FindByUUID(ctx, output.SessionID) + if err != nil { + logger.Error("Failed to load session after creation", zap.Error(err)) + return nil, toGRPCError(err) + } + + // Extract selected party IDs from join tokens + selectedParties := make([]string, 0, len(output.JoinTokens)) + for partyID := range output.JoinTokens { + if partyID != "*" { // Exclude universal token + selectedParties = append(selectedParties, partyID) + } + } + // Convert output to response return &pb.CreateSessionResponse{ - SessionId: output.SessionID.String(), - JoinTokens: output.JoinTokens, - ExpiresAt: output.ExpiresAt.UnixMilli(), + SessionId: output.SessionID.String(), + JoinTokens: output.JoinTokens, + ExpiresAt: output.ExpiresAt.UnixMilli(), + SelectedParties: selectedParties, + DelegatePartyId: session.DelegatePartyID, }, nil } diff --git a/backend/mpc-system/test_create_session.go b/backend/mpc-system/test_create_session.go index e9b345c2..8e46eb30 100644 --- a/backend/mpc-system/test_create_session.go +++ b/backend/mpc-system/test_create_session.go @@ -57,9 +57,10 @@ func main() { // Create keygen session via account-service sessionData := map[string]interface{}{ - "threshold_n": 3, - "threshold_t": 2, - "username": "admin", + "threshold_n": 3, + "threshold_t": 2, + "username": "admin", + "require_delegate": true, } jsonData, err := json.Marshal(sessionData)