【问题标题】:Corda Race Condition, Invoking some other flow from current flow, but input state is from current flowCorda Race Condition,从当前流中调用一些其他流,但输入状态来自当前流
【发布时间】:2019-01-08 16:57:57
【问题描述】:

这个问题是在讨论Making asynchronous HTTP calls from flows时提出的

假设,我们正在实施贷款申请。在收到LoanRequest 后,Corda flow 会进行 HTTP 调用来验证请求,我们希望根据 HTTP 调用的结果自动调用其他事务,即记录ApprovedLoanRejectedLoan 的状态。

现在这种情况下的问题是,ApprovedLoanRejectedLoan 事务将需要输入状态为LoanRequest。所以我们不能从LoanRequest流的Acceptor调用另一个流,因为输入状态还没有提交,从而导致竞争条件。

任何关于如何实施的建议或示例将不胜感激。

谢谢。

【问题讨论】:

    标签: corda


    【解决方案1】:

    您需要先将LoanRequest 事务提交到每个节点的存储,然后在接受器中进行调用以决定是批准还是拒绝请求。您还需要使用FlowLogic.waitForLedgerCommit 以确保在存储LoanRequest 之前不会启动批准或拒绝。这是一个例子:

    @InitiatingFlow
    @StartableByRPC
    class Initiator(val otherParty: Party) : FlowLogic<SignedTransaction>() {
    
        /**
         * The flow logic is encapsulated within the call() method.
         */
        @Suspendable
        override fun call(): SignedTransaction {
            val session = initiateFlow(otherParty)
    
            val fullySignedTx: SignedTransaction = TODO("Build fully signed transaction.")
    
            subFlow(FinalityFlow(fullySignedTx))
    
            session.send(fullySignedTx.id)
        }
    }
    
    @InitiatedBy(Initiator::class)
    class Acceptor(val session: FlowSession) : FlowLogic<SignedTransaction>() {
        @Suspendable
        override fun call(): SignedTransaction {
            TODO("Response logic for building fully signed transaction.")
    
            val txId = session.receive<SecureHash>().unwrap { secureHash -> secureHash }
    
            waitForLedgerCommit(txId)
    
            val approve: Boolean = TODO("Make HTTP call to decide whether to approve or reject.")
    
            if (approve) {
                TODO("Response logic for building approval transaction.")
            } else {
                TODO("Response logic for building rejection transaction.")
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2022-01-09
      • 1970-01-01
      • 2021-12-11
      • 2021-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多