From 758babfdf84e0eb2ca4bca13cda250b998a24ee3 Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 2 Feb 2026 03:30:30 -0800 Subject: [PATCH] =?UTF-8?q?fix(blockchain+trading):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=81=9A=E5=B8=82=E5=95=86=E5=8C=BA=E5=9D=97=E9=93=BE=E5=85=85?= =?UTF-8?q?=E5=80=BC=E6=97=A0=E6=B3=95=E5=85=A5=E8=B4=A6=E7=9A=84=E4=B8=89?= =?UTF-8?q?=E4=B8=AA=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. OutboxPublisherService 未注册到 NestJS 模块,导致充值确认事件永远 停留在 outbox_events 表 PENDING 状态,无法发布到 Kafka 2. trading-service 消费者监听的 Kafka topic 和 event type 与发布端不匹配 (blockchain.market_maker.deposits → mining_blockchain.market_maker.deposits) 3. 消费者只更新 market_maker_config 余额,但 API 从 trading_accounts 读取 余额,导致入账后前端仍显示 0 Co-Authored-By: Claude Opus 4.5 --- .../src/application/application.module.ts | 8 +++++++- .../kafka/market-maker-deposit-consumer.service.ts | 14 +++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/backend/services/mining-blockchain-service/src/application/application.module.ts b/backend/services/mining-blockchain-service/src/application/application.module.ts index b0677eab..4ea6b85a 100644 --- a/backend/services/mining-blockchain-service/src/application/application.module.ts +++ b/backend/services/mining-blockchain-service/src/application/application.module.ts @@ -3,6 +3,8 @@ import { InfrastructureModule } from '@/infrastructure/infrastructure.module'; import { DomainModule } from '@/domain/domain.module'; import { MpcTransferInitializerService } from './services/mpc-transfer-initializer.service'; import { MarketMakerDepositDetectionService } from './services/market-maker-deposit-detection.service'; +import { OutboxPublisherService } from './services/outbox-publisher.service'; +import { DepositAckConsumerService } from '@/infrastructure/kafka/deposit-ack-consumer.service'; @Module({ imports: [InfrastructureModule, DomainModule], @@ -11,7 +13,11 @@ import { MarketMakerDepositDetectionService } from './services/market-maker-depo MpcTransferInitializerService, // 做市商充值检测服务 MarketMakerDepositDetectionService, + // Outbox 事件发布服务(将确认的充值事件发布到 Kafka) + OutboxPublisherService, + // 充值 ACK 消费者(接收 wallet-service 的确认回执) + DepositAckConsumerService, ], - exports: [], + exports: [OutboxPublisherService], }) export class ApplicationModule {} diff --git a/backend/services/trading-service/src/infrastructure/kafka/market-maker-deposit-consumer.service.ts b/backend/services/trading-service/src/infrastructure/kafka/market-maker-deposit-consumer.service.ts index 12971a31..9531571f 100644 --- a/backend/services/trading-service/src/infrastructure/kafka/market-maker-deposit-consumer.service.ts +++ b/backend/services/trading-service/src/infrastructure/kafka/market-maker-deposit-consumer.service.ts @@ -73,7 +73,7 @@ export class MarketMakerDepositConsumerService implements OnModuleInit, OnModule return; } - const topic = 'blockchain.market_maker.deposits'; + const topic = 'mining_blockchain.market_maker.deposits'; try { await this.consumer.connect(); @@ -123,7 +123,7 @@ export class MarketMakerDepositConsumerService implements OnModuleInit, OnModule const eventData = JSON.parse(message.value.toString()); // 检查事件类型 - if (eventData.eventType !== 'blockchain.market_maker.deposit.confirmed') { + if (eventData.eventType !== 'mining_blockchain.market_maker.deposit.confirmed') { return; } @@ -210,7 +210,7 @@ export class MarketMakerDepositConsumerService implements OnModuleInit, OnModule : marketMaker.cashBalance; const newBalance = currentBalance.add(new Prisma.Decimal(payload.amountFormatted)); - // 更新做市商余额 + // 更新做市商配置余额 await tx.marketMakerConfig.update({ where: { id: marketMaker.id }, data: { @@ -218,6 +218,14 @@ export class MarketMakerDepositConsumerService implements OnModuleInit, OnModule }, }); + // 同步更新交易账户余额(getConfig 从 trading_accounts 读取余额) + await tx.tradingAccount.update({ + where: { accountSequence: marketMaker.accountSequence }, + data: { + [assetField]: { increment: new Prisma.Decimal(payload.amountFormatted) }, + }, + }); + // 3. 创建流水记录 const ledger = await tx.marketMakerLedger.create({ data: {