From d3b847aa8ed7fff663a3bd4d323602f752d05ae8 Mon Sep 17 00:00:00 2001 From: Rick Parker Date: Mon, 4 Nov 2024 13:06:22 +0000 Subject: [PATCH] ENT-12395: Stop warning about failed verification when resolving missing dependencies in TransactionBuilder (#7867) * Stop warning about failed verification when resolving missing dependencies in TransactionBuilder * Stop warning about failed verification when resolving missing dependencies in TransactionBuilder --- .../core/transactions/TransactionBuilder.kt | 2 +- .../corda/core/transactions/WireTransaction.kt | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt b/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt index 221a31cc84..5394c328b8 100644 --- a/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt +++ b/core/src/main/kotlin/net/corda/core/transactions/TransactionBuilder.kt @@ -243,7 +243,7 @@ open class TransactionBuilder( */ private fun addMissingDependency(serviceHub: VerifyingServiceHub, wireTx: WireTransaction, tryCount: Int): Boolean { log.debug { "Checking if there are any missing attachment dependencies for transaction ${wireTx.id}..." } - val verificationResult = wireTx.tryVerify(serviceHub) + val verificationResult = wireTx.tryVerify(serviceHub, true) // Check both legacy and non-legacy components are working, and try to add any missing dependencies if either are not. (verificationResult.inProcessResult as? Failure)?.let { (inProcessException) -> return addMissingDependency(inProcessException, wireTx, false, serviceHub, tryCount) diff --git a/core/src/main/kotlin/net/corda/core/transactions/WireTransaction.kt b/core/src/main/kotlin/net/corda/core/transactions/WireTransaction.kt index 7b33618591..7b82683bc6 100644 --- a/core/src/main/kotlin/net/corda/core/transactions/WireTransaction.kt +++ b/core/src/main/kotlin/net/corda/core/transactions/WireTransaction.kt @@ -382,11 +382,11 @@ class WireTransaction(componentGroups: List, val privacySalt: Pr */ @CordaInternal @JvmSynthetic - internal fun tryVerify(verificationSupport: NodeVerificationSupport): VerificationResult { + internal fun tryVerify(verificationSupport: NodeVerificationSupport, disableWarnings: Boolean = false): VerificationResult { return when { legacyAttachments.isEmpty() -> { log.debug { "${toSimpleString()} will be verified in-process" } - InProcess(Try.on { verifyInProcess(verificationSupport) }) + InProcess(Try.on { verifyInProcess(verificationSupport, disableWarnings) }) } nonLegacyAttachments.isEmpty() -> { log.debug { "${toSimpleString()} will be verified by the external verifer" } @@ -394,7 +394,7 @@ class WireTransaction(componentGroups: List, val privacySalt: Pr } else -> { log.debug { "${toSimpleString()} will be verified both in-process and by the external verifer" } - val inProcessResult = Try.on { verifyInProcess(verificationSupport) } + val inProcessResult = Try.on { verifyInProcess(verificationSupport, disableWarnings) } val externalResult = Try.on { verificationSupport.externalVerifierHandle.verifyTransaction(this) } InProcessAndExternal(inProcessResult, externalResult) } @@ -403,31 +403,31 @@ class WireTransaction(componentGroups: List, val privacySalt: Pr @CordaInternal @JvmSynthetic - internal fun verifyInProcess(verificationSupport: VerificationSupport): LedgerTransaction { + internal fun verifyInProcess(verificationSupport: VerificationSupport, disableWarnings: Boolean = false): LedgerTransaction { val ltx = toLedgerTransactionInternal(verificationSupport) try { ltx.verify() } catch (e: NoClassDefFoundError) { - checkReverifyAllowed(e) + checkReverifyAllowed(e, disableWarnings) val missingClass = e.message ?: throw e log.warn("Transaction {} has missing class: {}", ltx.id, missingClass) reverifyWithFixups(ltx, verificationSupport, missingClass) } catch (e: NotSerializableException) { - checkReverifyAllowed(e) + checkReverifyAllowed(e, disableWarnings) retryVerification(e, e, ltx, verificationSupport) } catch (e: TransactionDeserialisationException) { - checkReverifyAllowed(e) + checkReverifyAllowed(e, disableWarnings) retryVerification(e.cause, e, ltx, verificationSupport) } return ltx } - private fun checkReverifyAllowed(ex: Throwable) { + private fun checkReverifyAllowed(ex: Throwable, disableWarnings: Boolean) { // If that transaction was created with and after Corda 4 then just fail. // The lenient dependency verification is only supported for Corda 3 transactions. // To detect if the transaction was created before Corda 4 we check if the transaction has the NetworkParameters component group. if (networkParametersHash != null) { - log.warn("TRANSACTION VERIFY FAILED - No attempt to auto-repair as TX is Corda 4+") + if (!disableWarnings) log.warn("TRANSACTION VERIFY FAILED - No attempt to auto-repair as TX is Corda 4+") throw ex } }