You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Corda中BroadcastTransaction未注册报错问题求助

解决Corda中BroadcastTransaction未注册的报错问题

这个报错的核心原因是自定义流未被节点正确识别,且缺少对应的接收流处理逻辑,下面是一步步的解决方法:

1. 修复BroadcastTransaction的包声明问题

首先看你的BroadcastTransaction代码,没有指定包名!Corda要求所有自定义流必须放在命名包下(不能用默认包),否则Cordapp无法正确加载和识别这些类,其他节点也找不到对应的流类型。

给BroadcastTransaction添加和CreateParkingSpace相同的包声明:

package ee.ut.cs.examples.parking.flows // 必须加上这行

import co.paralleluniverse.fibers.Suspendable
import net.corda.core.flows.FlowLogic
import net.corda.core.flows.InitiatingFlow
import net.corda.core.flows.SendTransactionFlow
import net.corda.core.transactions.SignedTransaction

/**
 * Filters out any notary identities and removes our identity, then broadcasts the [SignedTransaction] to all the
 * remaining identities.
 */
@InitiatingFlow
class BroadcastTransaction(val stx: SignedTransaction) : FlowLogic<Unit>() {
    @Suspendable
    override fun call() {
        val everyone = serviceHub.networkMapCache.allNodes.flatMap { it.legalIdentities }
        val everyoneButMeAndNotary = everyone.filter { !serviceHub.networkMapCache.isNotary(it) } - ourIdentity
        val sessions = everyoneButMeAndNotary.map { initiateFlow(it) }
        sessions.forEach { subFlow(SendTransactionFlow(it, stx)) }
    }
}

2. 添加对应的接收流(Responder Flow)

因为BroadcastTransaction是用@InitiatingFlow注解的发起流,接收方节点(比如报错里的Controller节点)需要一个用@InitiatedBy注解的响应流来处理这个会话请求。添加以下代码到同一个包下:

package ee.ut.cs.examples.parking.flows

import co.paralleluniverse.fibers.Suspendable
import net.corda.core.flows.FlowLogic
import net.corda.core.flows.InitiatedBy
import net.corda.core.flows.FlowSession
import net.corda.core.flows.ReceiveTransactionFlow

@InitiatedBy(BroadcastTransaction::class)
class BroadcastTransactionResponder(private val otherPartySession: FlowSession) : FlowLogic<Unit>() {
    @Suspendable
    override fun call() {
        // 接收并验证存储交易
        subFlow(ReceiveTransactionFlow(otherPartySession))
    }
}

这个响应流会处理来自发起方的会话,完成交易的接收和存储逻辑。

3. 在所有节点的Cordapp配置中注册流

每个节点的cordapps/config/cordapp.conf文件需要明确声明所有自定义流的全限定类名,这样节点才能加载这些流。更新配置如下:

cordapp {
    flows = [
        "ee.ut.cs.examples.parking.flows.CreateParkingSpace",
        "ee.ut.cs.examples.parking.flows.BroadcastTransaction",
        "ee.ut.cs.examples.parking.flows.BroadcastTransactionResponder"
    ]
}

4. 重新部署Cordapp并重启节点

  • 重新编译你的Cordapp生成新的JAR文件
  • 替换所有节点cordapps目录下的旧JAR
  • 重启所有参与的Corda节点

完成以上步骤后,你的BroadcastTransaction流就能被所有节点识别,不会再出现“not registered”的报错了。

内容的提问来源于stack exchange,提问作者OlevAbel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 10:03:01