vishal gawde
vishal gawde

Reputation: 168

Corda Walking the Chain in finalityFlow

In Corda, FinalityFlow:

  1. Verifies transaction on initiator node
  2. Notarizes transaction
  3. Persists signedTransaction to vault of initiator
  4. Distributes transaction to the participants

As per consensus, verification involves walking the chain.

I looked in FinalityFlow code. Where exactly does the walking-the-chain thing happen?

Do the notary and the participants also walk the chain? If yes, they check the signatures on each transaction in the chain, but where exactly in the code does it happen?

As per my understanding, SendTransactionFlow sends the transaction to the other parties on the participants lists. The other party also requests for attachments and transaction dependencies. Where actually does the walking-the-chain thing happen?

I need to understand walking the chain from a coding perspective.

Upvotes: 0

Views: 310

Answers (1)

Joel
Joel

Reputation: 23140

In FinalityFlow, the caller uses the following line to send the notarised transaction to the participants of all the states:

subFlow(SendTransactionFlow(session, notarised))

If we look at AbstractNode.installCoreFlows, we see that the node installs a default handler for FinalityFlow called FinalityHandler. FinalityHandler responds to the call to SendTransactionFlow in FinalityFlow by calling ReceiveTransactionFlow.

Inside ReceiveTransactionFlow, we can see that the node resolves the transaction's dependencies, verifies the transaction and checks its signatures:

val stx = otherSideSession.receive<SignedTransaction>().unwrap {
    subFlow(ResolveTransactionsFlow(it, otherSideSession))
    it.verify(serviceHub, checkSufficientSignatures)
    it
}

As part of resolving the transaction's dependencies in ResolveTransactionsFlow, the node verifies each one and checks its signatures (by default, verify checks the signatures on the transaction):

result.forEach {
    it.verify(serviceHub)
    serviceHub.recordTransactions(StatesToRecord.NONE, listOf(it))
}

The notary will only walk the chain in this way if they are a validating notary.

Upvotes: 2

Related Questions