R3- Corda transaction without notary signature

Viewed 510

I am new to Corda and I want to know the role of the notary in detail. As per the document it says, for example a transaction happens between Party A and Party B , notary will sign the transaction and the role of the notary is to prevent double-spending. Can we have a transaction without notary signature. In TransactionBuilder class its saying var notary: Party? Notary used for the transaction. If null, this indicates the transaction DOES NOT have a notary. As per the syntax we can set it as null and if we put it as null whether the transaction will be valid and how the corda prevent double-spending. Please correct me if I misunderstood the concept.

2 Answers

The notary signature is only required in the following cases:

  1. If your transaction has inputs: To testify that those inputs were not consumed, preventing double spends.
  2. If your transaction has reference states: To testify that those reference states were not consumed, preventing the use of "out-dated" reference data.
  3. If your transaction has a time-window: To testify that the transaction was finalized within the specified time-window.

You can see here the function needsNotarySignature() inside FinalityFlow which proves the above points.

I agree with Adel's answer on the notary signature requirement for the cases mentioned by him. To add to that, a transaction is needed to be associated with a notary, it should not be null.

One case where one might think that a notary is not required is an issuance of a state. Actually, the signature of notary is not required, however, the transaction still needs a notary since the state needs to be tagged to a notary to prevent any double-spend when the state is consumed.

In case no notary is attached to it the state can be sent to different notaries and that could lead to double spend.

You could validate this in the TransactionBuilder's addOutput method:

fun addOutputState(
    state: ContractState,
    contract: ContractClassName = requireNotNullContractClassName(state),
    constraint: AttachmentConstraint = AutomaticPlaceholderConstraint
): TransactionBuilder {
    checkNotNull(notary) { "Need to specify a notary for the state, or set a default one on TransactionBuilder initialisation" }
    addOutputState(state, contract, notary!!, constraint = constraint)
    return this
}
Related