Corda:Party拒绝会话请求,因为Requestor尚未注册

问题描述:

我有一个Corda应用程序,它使用M14构建并运行corda以运行TwoPartyProtocol,其中任一方都可以交换数据以达到数据有效性共识。我按照Corda flow cookbook建立了一个流程。Corda:Party拒绝会话请求,因为Requestor尚未注册

此外,在阅读了几个不同的corda里程碑文档后,我了解到M14不再需要release notes中提到的flowSessions,这也消除了注册服务的需要。

我与内FlowLogics TwoPartyFlow:

class TwoPartyFlow{ 
    @InitiatingFlow 
    @StartableByRPC 
    open class Requestor(val price: Long, 
         val otherParty: Party) : FlowLogic<SignedTransaction>(){ 
     @Suspendable 
     override fun call(): SignedTransaction { 
      val notary = serviceHub.networkMapCache.notaryNodes.single().notaryIdentity 
      send(otherParty, price) 
      /*Some code to generate SignedTransaction*/ 
     } 
    } 

    @InitiatedBy(Requestor::class) 
    open class Responder(val requestingParty : Party) : FlowLogic<SignedTransaction>(){ 
      @Suspendable 
      override fun call(): SignedTransaction { 
       val request = receive<Long>(requestor).unwrap { price -> price } 
       println(request) 
       /*Some code to generate SignedTransaction*/ 
      }  
    } 

} 

但是,使用startTrackedFlow从AP运行以上导致上述错误:

Party CN=Other,O=Other,L=NY,C=US rejected session request: com.testapp.flow.TwoPartyFlow$Requestor has not been registered 

我已经很难找到从琴弦文档或日志的原因因为在Corda的几个里程碑中双方流程的实施已经发生了变化。有人可以帮我理解这里的问题。

我的API调用:

@GET 
@Path("start-flow") 
fun requestOffering(@QueryParam(value = "price") price: String) : Response{ 
     val price : Long = 10L 
     /*Code to get otherParty details*/ 
     val otherPartyHostAndPort = HostAndPort.fromString("localhost:10031") 
     val client = CordaRPCClient(otherPartyHostAndPort) 
     val services : CordaRPCOps = client.start("user1","test").proxy 
     val otherParty: Party = services.nodeIdentity().legalIdentity 
     val (status, message) = try { 
      val flowHandle = services.startTrackedFlow(::Requestor, price, otherParty) 
      val result = flowHandle.use { it.returnValue.getOrThrow() } 
      // Return the response. 
      Response.Status.CREATED to "Transaction id ${result.id} committed to ledger.\n" 
     } catch (e: Exception) { 
      Response.Status.BAD_REQUEST to e.message 
     } 
     return Response.status(status).entity(message).build() 
} 

我的摇篮deployNodes任务:

task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { 
directory "./build/nodes" 
networkMap "CN=Controller,O=R3,OU=corda,L=London,C=UK" 
node { 
    name "CN=Controller,O=R3,OU=corda,L=London,C=UK" 
    advertisedServices = ["corda.notary.validating"] 
    p2pPort 10021 
    rpcPort 10022 
    cordapps = [] 
} 
node { 
    name "CN=Subject,O=Subject,L=NY,C=US" 
    advertisedServices = [] 
    p2pPort 10027 
    rpcPort 10028 
    webPort 10029 
    cordapps = [] 
    rpcUsers = [[ user: "user1", "password": "test", "permissions": []]] 
} 
node { 
    name "CN=Other,O=Other,L=NY,C=US" 
    advertisedServices = [] 
    p2pPort 10030 
    rpcPort 10031 
    webPort 10032 
    cordapps = [] 
    rpcUsers = [[ user: "user1", "password": "test", "permissions": []]] 
} 
+0

你可以发布API调用吗?你似乎正在启动一个'InitiatorFlow',我没有看到上面定义。 – joel

+0

对不起。我用API调用和正确的流量错误更新了我的问题。 – codeviper

+0

您如何运行节点来测试API? – joel

似乎有一对夫妇与您发布的代码问题:

  • 注释应是@StartableByRPC,而不是@StartableNByRPC
  • 价格传递到startTrackedFlow应该是一个很长的,而不是一个整数

但是,即使解决这些问题后,我无法复制您的错误。您可以应用这些修补程序,做一个干净的重新部署您的节点(gradlew clean deployNodes),并查看错误是否更改?

+0

感谢您的期待进入问题。我做了修复,并做了gradlew clean deployNodes。但是,我看到同样的错误。我是否需要将这些节点添加为deployNodes任务中权限的一部分?还是我想念任何其他步骤? – codeviper

+0

您是否可以更新问题中的代码示例以更正错误并显示如何在API中获得对方? – joel

+0

更正了代码示例并添加了代码以获得另一方。 – codeviper

您不应该通过RPC连接到其他节点。 RPC是节点的所有者如何与节点通话。在现实世界中,您不会拥有其他节点的RPC凭据,并且无法以此方式登录到节点。

相反,你应该用你自己的节点的RPC客户端来获取对方的身份:

val otherParty = services.partyFromX500Name("CN=Other,O=Other,L=NY,C=US")!!

看到M14这里举例:https://github.com/corda/cordapp-example/blob/release-M14/kotlin-source/src/main/kotlin/com/example/api/ExampleApi.kt

+0

有道理。谢谢。 – codeviper