fix(android): 修复连续创建MPC账户失败的bug

问题描述:
- 用户第一次创建MPC账户成功后返回钱包界面
- 再次创建新的MPC账户时,keygen无法自动开始
- 原因是第一次keygen完成后错误地取消了全局会话事件订阅

根本原因分析:
1. startKeygenAsInitiator() 完成时调用了 sessionEventJob?.cancel()
2. sessionEventJob 是在 registerParty() 时启动的全局事件订阅
3. 取消后,新创建的keygen会话无法接收 session_started 事件
4. 导致keygen无法自动触发

对比发现:
- Sign流程在开始前会调用 ensureSessionEventSubscriptionActive() 检查订阅状态
- Keygen流程没有这个检查,存在不一致性

修复方案:
1. 删除 startKeygenAsInitiator() 中的 sessionEventJob?.cancel()
   - 全局订阅不应该在单次操作完成后取消
   - 只在 cancelSession() 和断开连接时才取消

2. 在 createKeygenSession() 开头添加 ensureSessionEventSubscriptionActive()
   - 与sign流程保持一致
   - 即使有其他代码意外取消订阅,也能自我恢复

影响范围:
- TssRepository.kt: startKeygenAsInitiator(), createKeygenSession()

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-27 08:03:28 -08:00
parent d04f0a08e0
commit 71eea98ea5
1 changed files with 6 additions and 1 deletions

View File

@ -642,6 +642,10 @@ class TssRepository @Inject constructor(
thresholdN: Int,
participantName: String
): Result<CreateKeygenSessionResult> {
// Ensure session event subscription is active before creating keygen session
// This handles the case where a previous keygen might have left the subscription inactive
ensureSessionEventSubscriptionActive()
return withContext(Dispatchers.IO) {
try {
val jsonMediaType = "application/json; charset=utf-8".toMediaType()
@ -1975,7 +1979,8 @@ class TssRepository @Inject constructor(
stopProgressCollection()
_sessionStatus.value = SessionStatus.COMPLETED
pendingSessionId = null // Clear pending session ID on completion
sessionEventJob?.cancel()
// NOTE: Do NOT cancel sessionEventJob here - it's a global subscription
// that should remain active for subsequent keygen/sign sessions
Result.success(shareEntity.copy(id = id).toShareRecord())