CORDA-4130: Move checkNotaryWhitelisted call to run under attachmentsClassLoader (#6890)

* CORDA-4130: Move checkNotaryWhitelisted call to run under attachmentsClassLoader for normal transactions.

* CORDA-4130: Reverted API change.

* CORDA-4130: Further simplication. Removed protected method.

* CORDA-4130: Remove unused import.

* Revert "CORDA-4130: Remove unused import."

This reverts commit d0836bda8122496c178c0bdcca33f645cc322aba.

* Revert "CORDA-4130: Further simplication. Removed protected method."

This reverts commit 3023a2e1ac244b847a62eec31fdef09afd931c56.
This commit is contained in:
Adel El-Beik 2021-03-18 14:24:30 +00:00 committed by GitHub
parent d41f608e4e
commit 1470d14795
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 20 deletions

View File

@ -242,3 +242,25 @@ internal fun BaseTransaction.checkSupportedHashType() {
throw TransactionVerificationException.UnsupportedHashTypeException(id)
}
}
/** Make sure the assigned notary is part of the network parameter whitelist. */
internal fun checkNotaryWhitelisted(ftx: FullTransaction) {
ftx.notary?.let { notaryParty ->
// Network parameters will never be null if the transaction is resolved from a CoreTransaction rather than constructed directly.
ftx.networkParameters?.let { parameters ->
val notaryWhitelist = parameters.notaries.map { it.identity }
// Transaction can combine different identities of the same notary after key rotation.
// Each of these identities should be whitelisted.
val notaries = setOf(notaryParty) + (ftx.inputs + ftx.references).map { it.state.notary }
notaries.forEach {
check(it in notaryWhitelist) {
"Notary [${it.description()}] specified by the transaction is not on the network parameter whitelist: " +
" [${notaryWhitelist.joinToString { party -> party.description() }}]"
}
}
}
}
}

View File

@ -47,6 +47,8 @@ abstract class Verifier(val ltx: LedgerTransaction, protected val transactionCla
checkNoNotaryChange()
checkEncumbrancesValid()
ltx.checkSupportedHashType()
checkTransactionWithTimeWindowIsNotarised()
checkNotaryWhitelisted(ltx)
// The following checks ensure the integrity of the current transaction and also of the future chain.
// See: https://docs.corda.net/head/api-contract-constraints.html
@ -70,6 +72,10 @@ abstract class Verifier(val ltx: LedgerTransaction, protected val transactionCla
verifyContracts()
}
private fun checkTransactionWithTimeWindowIsNotarised() {
if (ltx.timeWindow != null) check(ltx.notary != null) { "Transactions with time-windows must be notarised" }
}
/**
* This method returns the attachment with the code for each contract.
* It makes sure there is one and only one.

View File

@ -4,6 +4,7 @@ import net.corda.core.contracts.ContractState
import net.corda.core.contracts.StateAndRef
import net.corda.core.contracts.StateRef
import net.corda.core.crypto.SecureHash
import net.corda.core.internal.checkNotaryWhitelisted
import net.corda.core.node.NetworkParameters
import net.corda.core.serialization.CordaSerializable
@ -52,20 +53,6 @@ abstract class FullTransaction : BaseTransaction() {
/** Make sure the assigned notary is part of the network parameter whitelist. */
protected fun checkNotaryWhitelisted() {
notary?.let { notaryParty ->
// Network parameters will never be null if the transaction is resolved from a CoreTransaction rather than constructed directly.
networkParameters?.let { parameters ->
val notaryWhitelist = parameters.notaries.map { it.identity }
// Transaction can combine different identities of the same notary after key rotation.
// Each of these identities should be whitelisted.
val notaries = setOf(notaryParty) + (inputs + references).map { it.state.notary }
notaries.forEach {
check(it in notaryWhitelist) {
"Notary [${it.description()}] specified by the transaction is not on the network parameter whitelist: " +
" [${notaryWhitelist.joinToString { party -> party.description() }}]"
}
}
}
}
checkNotaryWhitelisted(this)
}
}

View File

@ -120,11 +120,6 @@ private constructor(
networkParameters, references, componentGroups, serializedInputs, serializedReferences,
isAttachmentTrusted, verifierFactory, attachmentsClassLoaderCache, DigestService.sha2_256)
init {
if (timeWindow != null) check(notary != null) { "Transactions with time-windows must be notarised" }
checkNotaryWhitelisted()
}
@KeepForDJVM
companion object {
private val logger = contextLogger()