问题
In Corda, FinalityFlow:
- Verifies transaction on initiator node
- Notarizes transaction
- Persists signedTransaction to vault of initiator
- 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.
回答1:
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.
来源:https://stackoverflow.com/questions/53314281/corda-walking-the-chain-in-finalityflow