fix(service-party-app): 添加等待所有参与者加入的逻辑

- 在 checkAndTriggerKeygen 中添加参与者数量检查
- 必须等待所有 N 个参与者加入后才能开始 keygen
- 与 server-party 的 waitForAllParticipants 逻辑保持一致
- 修复 co_managed_keygen 场景下 TSS 协议无法完成的问题

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-29 10:18:38 -08:00
parent a22fc16313
commit 820a61793c
1 changed files with 11 additions and 1 deletions

View File

@ -146,13 +146,23 @@ async function checkAndTriggerKeygen(sessionId: string) {
debugLog.info('main', `Session ${sessionId} status: ${status.status} (${status.completed_parties}/${status.total_parties} parties)`);
// 对于 co_managed_keygen必须等待所有 N 个参与者加入后才能开始
// 这与 server-party 的 waitForAllParticipants 逻辑一致
const expectedN = status.total_parties || activeKeygenSession.threshold.n;
const currentParticipants = status.participants?.length || 0;
if (currentParticipants < expectedN) {
debugLog.debug('main', `Waiting for all participants: ${currentParticipants}/${expectedN}`);
return;
}
// 如果会话已经是 in_progress 或 all_joined或者参与方已满触发 keygen
// 使用 status 字段判断是否可以开始
if (status.status === 'in_progress' ||
status.status === 'all_joined' ||
status.status === 'waiting_for_keygen') {
debugLog.info('main', 'Session ready, triggering keygen...');
debugLog.info('main', `All ${expectedN} participants joined, triggering keygen...`);
// 使用后端返回的 participants 信息(包含正确的 party_index
// 这解决了 co_managed_keygen 中 server-party 和 service-party-app 混合的问题