From 75a247023347a0b59b22a4e76cba83c5646f39bc Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 29 Dec 2025 13:15:47 -0800 Subject: [PATCH] =?UTF-8?q?debug(service-party-app):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20keygen=20=E8=A7=A6=E5=8F=91=E6=B5=81=E7=A8=8B=E8=AF=A6?= =?UTF-8?q?=E7=BB=86=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 [KEYGEN] 前缀的 console.log 来追踪: - checkAndTriggerKeygen 是否被调用 - activeKeygenSession 的状态 - 轮询条件是否满足 - handleSessionStart 的执行 - participateKeygen 的参数 帮助诊断 external party 为何不启动 TSS 进程 Generated with Claude Code Co-Authored-By: Claude Opus 4.5 --- .../service-party-app/electron/main.ts | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/backend/mpc-system/services/service-party-app/electron/main.ts b/backend/mpc-system/services/service-party-app/electron/main.ts index e56e27f5..fdf425f7 100644 --- a/backend/mpc-system/services/service-party-app/electron/main.ts +++ b/backend/mpc-system/services/service-party-app/electron/main.ts @@ -128,14 +128,23 @@ function cleanExpiredEventCache() { // 检查并触发 keygen(100% 可靠方案:轮询等待所有参与者加入) // 与 server-party 的 waitForAllParticipants 逻辑保持一致 async function checkAndTriggerKeygen(sessionId: string) { + console.log('[KEYGEN] checkAndTriggerKeygen called with sessionId:', sessionId); + if (!activeKeygenSession || activeKeygenSession.sessionId !== sessionId) { - console.log('No matching active keygen session for', sessionId); + console.log('[KEYGEN] No matching active keygen session for', sessionId); return; } + console.log('[KEYGEN] Active session found:', { + sessionId: activeKeygenSession.sessionId, + partyIndex: activeKeygenSession.partyIndex, + threshold: activeKeygenSession.threshold, + participantCount: activeKeygenSession.participants.length, + }); + // 如果 TSS 已经在运行,不重复触发 if (tssHandler?.getIsRunning()) { - console.log('TSS already running, skip check'); + console.log('[KEYGEN] TSS already running, skip check'); return; } @@ -143,6 +152,7 @@ async function checkAndTriggerKeygen(sessionId: string) { const maxWaitMs = 5 * 60 * 1000; // 5分钟超时 const startTime = Date.now(); + console.log('[KEYGEN] Starting to poll session status...'); debugLog.info('main', `Starting to poll session status for ${sessionId}`); while (Date.now() - startTime < maxWaitMs) { @@ -180,7 +190,16 @@ async function checkAndTriggerKeygen(sessionId: string) { status.status === 'all_joined' || status.status === 'waiting_for_keygen'; + console.log('[KEYGEN] Check conditions:', { + hasAllParticipants, + statusReady, + currentParticipants, + expectedN, + status: status.status, + }); + if (hasAllParticipants && statusReady) { + console.log('[KEYGEN] Conditions met! Triggering keygen...'); debugLog.info('main', `All ${expectedN} participants joined (status: ${status.status}), triggering keygen...`); // 使用后端返回的 participants 信息(包含正确的 party_index) @@ -393,7 +412,16 @@ async function handleSessionStart(event: { thresholdT: number; selectedParties: string[]; }) { + console.log('[KEYGEN] handleSessionStart called:', { + eventType: event.eventType, + sessionId: event.sessionId, + thresholdN: event.thresholdN, + thresholdT: event.thresholdT, + selectedParties: event.selectedParties?.length, + }); + if (!activeKeygenSession) { + console.log('[KEYGEN] No active keygen session, ignoring'); debugLog.debug('main', 'No active keygen session, ignoring session start event'); return; } @@ -472,6 +500,13 @@ async function handleSessionStart(event: { })))}`); } + console.log('[KEYGEN] Calling tssHandler.participateKeygen with:', { + sessionId: activeKeygenSession.sessionId, + partyId: grpcClient?.getPartyId(), + partyIndex: activeKeygenSession.partyIndex, + participants: activeKeygenSession.participants.map(p => ({ partyId: p.partyId.substring(0, 8), partyIndex: p.partyIndex })), + threshold: activeKeygenSession.threshold, + }); debugLog.info('tss', `Starting keygen for session ${event.sessionId}...`); try {