fix(identity-service): 修复钱包重试发布错误事件类型的问题

问题:
- 重试代码使用 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 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-27 10:09:20 -08:00
parent 8eecc4c55f
commit 9153ba3625
2 changed files with 31 additions and 10 deletions

View File

@ -1752,16 +1752,26 @@ export class UserApplicationService {
* *
* *
* getWalletStatus * getWalletStatus
* UserAccountCreatedEvent MPC * MpcKeygenRequestedEvent MPC
*/ */
private async triggerWalletRetryAsync( private async triggerWalletRetryAsync(
userId: string, userId: string,
account: UserAccount, account: UserAccount,
): Promise<void> { ): Promise<void> {
try { try {
// 发布事件触发钱包生成 // 发布 MpcKeygenRequestedEvent 触发钱包生成(与注册流程使用相同的事件类型)
const event = account.createWalletGenerationEvent(); const sessionId = crypto.randomUUID();
await this.eventPublisher.publish(event); 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 // 更新 Redis 状态为 pending
const statusData = { const statusData = {
@ -1777,7 +1787,7 @@ export class UserApplicationService {
); );
this.logger.log( 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) { } catch (error) {
this.logger.error( this.logger.error(

View File

@ -28,6 +28,7 @@ import {
} from '@/domain/repositories/user-account.repository.interface'; } from '@/domain/repositories/user-account.repository.interface';
import { Inject } from '@nestjs/common'; import { Inject } from '@nestjs/common';
import { UserId } from '@/domain/value-objects'; import { UserId } from '@/domain/value-objects';
import { MpcKeygenRequestedEvent } from '@/domain/events';
// Redis key prefix // Redis key prefix
const KEYGEN_STATUS_PREFIX = 'keygen:status:'; const KEYGEN_STATUS_PREFIX = 'keygen:status:';
@ -284,7 +285,7 @@ export class WalletRetryTask {
/** /**
* *
* *
* UserAccountCreatedEvent MPC * MpcKeygenRequestedEvent MPC
*/ */
private async retryWalletGeneration(userId: string): Promise<void> { private async retryWalletGeneration(userId: string): Promise<void> {
this.logger.log(`[TASK] Retrying wallet generation for user: ${userId}`); this.logger.log(`[TASK] Retrying wallet generation for user: ${userId}`);
@ -302,12 +303,22 @@ export class WalletRetryTask {
// 2. 更新重试记录(包含指数退避时间) // 2. 更新重试记录(包含指数退避时间)
const retryCount = await this.updateRetryRecord(userId); const retryCount = await this.updateRetryRecord(userId);
// 3. 重新触发钱包生成流程 // 3. 发布 MpcKeygenRequestedEvent 触发钱包生成(与注册流程使用相同的事件类型)
const event = account.createWalletGenerationEvent(); const sessionId = crypto.randomUUID();
await this.eventPublisher.publish(event); 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( 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 // 4. 更新 Redis 状态为 pending