From 9153ba36259cc9d7b256d992b209a91ced7b8f00 Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 27 Dec 2025 10:09:20 -0800 Subject: [PATCH] =?UTF-8?q?fix(identity-service):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=92=B1=E5=8C=85=E9=87=8D=E8=AF=95=E5=8F=91=E5=B8=83=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BA=8B=E4=BB=B6=E7=B1=BB=E5=9E=8B=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - 重试代码使用 createWalletGenerationEvent() 发布 UserAccountCreatedEvent - 该事件发布到 identity.UserAccountCreated topic - 但 MPC 服务监听的是 mpc.KeygenRequested topic - 导致重试触发成功但钱包不会被生成 修复: - triggerWalletRetryAsync: 改为发布 MpcKeygenRequestedEvent - WalletRetryTask.retryWalletGeneration: 改为发布 MpcKeygenRequestedEvent - 与注册流程使用相同的事件类型和参数格式 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../services/user-application.service.ts | 20 +++++++++++++----- .../application/tasks/wallet-retry.task.ts | 21 ++++++++++++++----- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/backend/services/identity-service/src/application/services/user-application.service.ts b/backend/services/identity-service/src/application/services/user-application.service.ts index 0991b241..88829233 100644 --- a/backend/services/identity-service/src/application/services/user-application.service.ts +++ b/backend/services/identity-service/src/application/services/user-application.service.ts @@ -1752,16 +1752,26 @@ export class UserApplicationService { * 异步触发钱包生成重试 * * 内部方法,由 getWalletStatus 调用 - * 重新发布 UserAccountCreatedEvent 触发 MPC 生成流程 + * 发布 MpcKeygenRequestedEvent 触发 MPC 生成流程 */ private async triggerWalletRetryAsync( userId: string, account: UserAccount, ): Promise { try { - // 发布事件触发钱包生成 - const event = account.createWalletGenerationEvent(); - await this.eventPublisher.publish(event); + // 发布 MpcKeygenRequestedEvent 触发钱包生成(与注册流程使用相同的事件类型) + const sessionId = crypto.randomUUID(); + await this.eventPublisher.publish( + new MpcKeygenRequestedEvent({ + sessionId, + userId: account.userId.toString(), + accountSequence: account.accountSequence.value, + username: `user_${account.accountSequence.value}`, + threshold: 2, + totalParties: 3, + requireDelegate: true, + }), + ); // 更新 Redis 状态为 pending const statusData = { @@ -1777,7 +1787,7 @@ export class UserApplicationService { ); this.logger.log( - `[WALLET-STATUS] Wallet generation retry triggered for user ${userId}`, + `[WALLET-STATUS] Wallet generation retry triggered for user ${userId}, sessionId=${sessionId}`, ); } catch (error) { this.logger.error( diff --git a/backend/services/identity-service/src/application/tasks/wallet-retry.task.ts b/backend/services/identity-service/src/application/tasks/wallet-retry.task.ts index 559614f3..d17f0ff4 100644 --- a/backend/services/identity-service/src/application/tasks/wallet-retry.task.ts +++ b/backend/services/identity-service/src/application/tasks/wallet-retry.task.ts @@ -28,6 +28,7 @@ import { } from '@/domain/repositories/user-account.repository.interface'; import { Inject } from '@nestjs/common'; import { UserId } from '@/domain/value-objects'; +import { MpcKeygenRequestedEvent } from '@/domain/events'; // Redis key prefix const KEYGEN_STATUS_PREFIX = 'keygen:status:'; @@ -284,7 +285,7 @@ export class WalletRetryTask { /** * 执行钱包生成重试 * - * 幂等:重新发布 UserAccountCreatedEvent,由 MPC 服务处理 + * 发布 MpcKeygenRequestedEvent 触发 MPC 服务生成钱包 */ private async retryWalletGeneration(userId: string): Promise { this.logger.log(`[TASK] Retrying wallet generation for user: ${userId}`); @@ -302,12 +303,22 @@ export class WalletRetryTask { // 2. 更新重试记录(包含指数退避时间) const retryCount = await this.updateRetryRecord(userId); - // 3. 重新触发钱包生成流程 - const event = account.createWalletGenerationEvent(); - await this.eventPublisher.publish(event); + // 3. 发布 MpcKeygenRequestedEvent 触发钱包生成(与注册流程使用相同的事件类型) + const sessionId = crypto.randomUUID(); + await this.eventPublisher.publish( + new MpcKeygenRequestedEvent({ + sessionId, + userId: account.userId.toString(), + accountSequence: account.accountSequence.value, + username: `user_${account.accountSequence.value}`, + threshold: 2, + totalParties: 3, + requireDelegate: true, + }), + ); this.logger.log( - `[TASK] Wallet generation retry #${retryCount} triggered for user: ${userId}`, + `[TASK] Wallet generation retry #${retryCount} triggered for user: ${userId}, sessionId=${sessionId}`, ); // 4. 更新 Redis 状态为 pending