Revert unnecessary refactoring.

This commit is contained in:
josecoll 2019-02-14 16:30:28 +00:00 committed by Mike Hearn
parent 758c855493
commit a17ab0d547
2 changed files with 9 additions and 16 deletions

View File

@ -7,7 +7,6 @@ import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.isFulfilledBy import net.corda.core.crypto.isFulfilledBy
import net.corda.core.internal.AttachmentWithContext import net.corda.core.internal.AttachmentWithContext
import net.corda.core.internal.isUploaderTrusted import net.corda.core.internal.isUploaderTrusted
import net.corda.core.internal.warnOnce
import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.CordaSerializable
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.loggerFor import net.corda.core.utilities.loggerFor
@ -52,22 +51,15 @@ data class HashAttachmentConstraint(val attachmentId: SecureHash) : AttachmentCo
val disableHashConstraints = System.getProperty("net.corda.node.disableHashConstraints")?.toBoolean() ?: false val disableHashConstraints = System.getProperty("net.corda.node.disableHashConstraints")?.toBoolean() ?: false
} }
override fun isSatisfiedBy(attachment: Attachment): Boolean { override fun isSatisfiedBy(attachment: Attachment): Boolean {
return when { return if (attachment is AttachmentWithContext) {
disableHashConstraints -> {
log.warnOnce("Skipping hash constraints verification.")
true
}
attachment is AttachmentWithContext -> {
log.debug("Checking attachment uploader ${attachment.contractAttachment.uploader} is trusted") log.debug("Checking attachment uploader ${attachment.contractAttachment.uploader} is trusted")
attachment.id == attachmentId && isUploaderTrusted(attachment.contractAttachment.uploader) attachment.id == attachmentId && isUploaderTrusted(attachment.contractAttachment.uploader)
} } else {
else -> {
log.warn("Hash constraint check failed: $attachmentId does not match contract attachment JAR ${attachment.id} or contract attachment JAR is untrusted") log.warn("Hash constraint check failed: $attachmentId does not match contract attachment JAR ${attachment.id} or contract attachment JAR is untrusted")
false false
} }
} }
} }
}
/** /**
* An [AttachmentConstraint] that verifies that the hash of the attachment is in the network parameters whitelist. * An [AttachmentConstraint] that verifies that the hash of the attachment is in the network parameters whitelist.

View File

@ -338,11 +338,12 @@ class Verifier(val ltx: LedgerTransaction,
val constraintAttachment = AttachmentWithContext(contractAttachment, contract, ltx.networkParameters!!.whitelistedContractImplementations) 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) throw TransactionVerificationException.ContractConstraintRejection(ltx.id, contract)
} }
} }
}
/** /**
* Check the transaction is contract-valid by running the verify() for each input and output state contract. * Check the transaction is contract-valid by running the verify() for each input and output state contract.