From a17ab0d54760bf006366931dc9b7a3bb7d1dc1d4 Mon Sep 17 00:00:00 2001 From: josecoll Date: Thu, 14 Feb 2019 16:30:28 +0000 Subject: [PATCH] Revert unnecessary refactoring. --- .../core/contracts/AttachmentConstraint.kt | 20 ++++++------------- .../TransactionVerifierServiceInternal.kt | 5 +++-- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/contracts/AttachmentConstraint.kt b/core/src/main/kotlin/net/corda/core/contracts/AttachmentConstraint.kt index f5e4debc9e..b2d86bc012 100644 --- a/core/src/main/kotlin/net/corda/core/contracts/AttachmentConstraint.kt +++ b/core/src/main/kotlin/net/corda/core/contracts/AttachmentConstraint.kt @@ -7,7 +7,6 @@ import net.corda.core.crypto.SecureHash import net.corda.core.crypto.isFulfilledBy import net.corda.core.internal.AttachmentWithContext import net.corda.core.internal.isUploaderTrusted -import net.corda.core.internal.warnOnce import net.corda.core.serialization.CordaSerializable import net.corda.core.transactions.TransactionBuilder import net.corda.core.utilities.loggerFor @@ -52,19 +51,12 @@ data class HashAttachmentConstraint(val attachmentId: SecureHash) : AttachmentCo val disableHashConstraints = System.getProperty("net.corda.node.disableHashConstraints")?.toBoolean() ?: false } override fun isSatisfiedBy(attachment: Attachment): Boolean { - return when { - disableHashConstraints -> { - log.warnOnce("Skipping hash constraints verification.") - true - } - attachment is AttachmentWithContext -> { - log.debug("Checking attachment uploader ${attachment.contractAttachment.uploader} is trusted") - attachment.id == attachmentId && isUploaderTrusted(attachment.contractAttachment.uploader) - } - else -> { - log.warn("Hash constraint check failed: $attachmentId does not match contract attachment JAR ${attachment.id} or contract attachment JAR is untrusted") - false - } + return if (attachment is AttachmentWithContext) { + log.debug("Checking attachment uploader ${attachment.contractAttachment.uploader} is trusted") + attachment.id == attachmentId && isUploaderTrusted(attachment.contractAttachment.uploader) + } else { + log.warn("Hash constraint check failed: $attachmentId does not match contract attachment JAR ${attachment.id} or contract attachment JAR is untrusted") + false } } } diff --git a/core/src/main/kotlin/net/corda/core/internal/TransactionVerifierServiceInternal.kt b/core/src/main/kotlin/net/corda/core/internal/TransactionVerifierServiceInternal.kt index 129bac65e4..b16ad3bb24 100644 --- a/core/src/main/kotlin/net/corda/core/internal/TransactionVerifierServiceInternal.kt +++ b/core/src/main/kotlin/net/corda/core/internal/TransactionVerifierServiceInternal.kt @@ -338,9 +338,10 @@ class Verifier(val ltx: LedgerTransaction, val constraintAttachment = AttachmentWithContext(contractAttachment, contract, ltx.networkParameters!!.whitelistedContractImplementations) - if (!constraint.isSatisfiedBy(constraintAttachment)) { + if (HashAttachmentConstraint.disableHashConstraints && constraint is HashAttachmentConstraint) + logger.warnOnce("Skipping hash constraints verification.") + else if (!constraint.isSatisfiedBy(constraintAttachment)) throw TransactionVerificationException.ContractConstraintRejection(ltx.id, contract) - } } }