diff --git a/core/src/main/kotlin/net/corda/core/contracts/TransactionTypes.kt b/core/src/main/kotlin/net/corda/core/contracts/TransactionTypes.kt index 5a2fbdb917..db388b5c8c 100644 --- a/core/src/main/kotlin/net/corda/core/contracts/TransactionTypes.kt +++ b/core/src/main/kotlin/net/corda/core/contracts/TransactionTypes.kt @@ -2,7 +2,6 @@ package net.corda.core.contracts import net.corda.core.identity.Party import net.corda.core.serialization.CordaSerializable -import net.corda.core.serialization.DeserializeAsKotlinObjectDef import net.corda.core.transactions.LedgerTransaction import net.corda.core.transactions.TransactionBuilder import java.security.PublicKey @@ -61,7 +60,7 @@ sealed class TransactionType { abstract fun verifyTransaction(tx: LedgerTransaction) /** A general transaction type where transaction validity is determined by custom contract code */ - object General : TransactionType(), DeserializeAsKotlinObjectDef { + object General : TransactionType() { /** Just uses the default [TransactionBuilder] with no special logic */ class Builder(notary: Party?) : TransactionBuilder(General, notary) @@ -141,7 +140,7 @@ sealed class TransactionType { * A special transaction type for reassigning a notary for a state. Validation does not involve running * any contract code, it just checks that the states are unmodified apart from the notary field. */ - object NotaryChange : TransactionType(), DeserializeAsKotlinObjectDef { + object NotaryChange : TransactionType() { /** * A transaction builder that automatically sets the transaction type to [NotaryChange] * and adds the list of participants to the signers set for every input state. diff --git a/core/src/main/kotlin/net/corda/core/serialization/DefaultKryoCustomizer.kt b/core/src/main/kotlin/net/corda/core/serialization/DefaultKryoCustomizer.kt index edf3792bea..f32d1e9d2b 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/DefaultKryoCustomizer.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/DefaultKryoCustomizer.kt @@ -86,9 +86,6 @@ object DefaultKryoCustomizer { // This ensures a NonEmptySetSerializer is constructed with an initial value. register(NonEmptySet::class.java, NonEmptySetSerializer) - /** This ensures any kotlin objects that implement [DeserializeAsKotlinObjectDef] are read back in as singletons. */ - addDefaultSerializer(DeserializeAsKotlinObjectDef::class.java, KotlinObjectSerializer) - addDefaultSerializer(SerializeAsToken::class.java, SerializeAsTokenSerializer()) register(MetaData::class.java, MetaDataSerializer) diff --git a/core/src/main/kotlin/net/corda/core/serialization/Kryo.kt b/core/src/main/kotlin/net/corda/core/serialization/Kryo.kt index de0dea59cb..b6757d5cf4 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/Kryo.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/Kryo.kt @@ -462,20 +462,6 @@ inline fun readListOfLength(kryo: Kryo, input: Input, minLen: Int = return list } -/** Marker interface for kotlin object definitions so that they are deserialized as the singleton instance. */ -// TODO This is not needed anymore -interface DeserializeAsKotlinObjectDef - -/** Serializer to deserialize kotlin object definitions marked with [DeserializeAsKotlinObjectDef]. */ -object KotlinObjectSerializer : Serializer() { - override fun read(kryo: Kryo, input: Input, type: Class): DeserializeAsKotlinObjectDef { - // read the public static INSTANCE field that kotlin compiler generates. - return type.getField("INSTANCE").get(null) as DeserializeAsKotlinObjectDef - } - - override fun write(kryo: Kryo, output: Output, obj: DeserializeAsKotlinObjectDef) {} -} - // No ClassResolver only constructor. MapReferenceResolver is the default as used by Kryo in other constructors. private val internalKryoPool = KryoPool.Builder { DefaultKryoCustomizer.customize(CordaKryo(makeAllButBlacklistedClassResolver())) }.build() private val kryoPool = KryoPool.Builder { DefaultKryoCustomizer.customize(CordaKryo(makeStandardClassResolver())) }.build() @@ -533,7 +519,7 @@ inline fun Kryo.register( return register( type.java, object : Serializer() { - override fun read(kryo: Kryo, input: Input, type: Class): T = read(kryo, input) + override fun read(kryo: Kryo, input: Input, clazz: Class): T = read(kryo, input) override fun write(kryo: Kryo, output: Output, obj: T) = write(kryo, output, obj) } ) diff --git a/core/src/test/kotlin/net/corda/core/serialization/KryoTests.kt b/core/src/test/kotlin/net/corda/core/serialization/KryoTests.kt index daa27fe0cb..1b70f24b68 100644 --- a/core/src/test/kotlin/net/corda/core/serialization/KryoTests.kt +++ b/core/src/test/kotlin/net/corda/core/serialization/KryoTests.kt @@ -3,10 +3,9 @@ package net.corda.core.serialization import com.esotericsoftware.kryo.Kryo import com.google.common.primitives.Ints import net.corda.core.crypto.* +import net.corda.node.services.persistence.NodeAttachmentService import net.corda.testing.ALICE import net.corda.testing.BOB -import net.corda.node.services.messaging.Ack -import net.corda.node.services.persistence.NodeAttachmentService import net.corda.testing.BOB_PUBKEY import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy @@ -16,7 +15,8 @@ import org.junit.Test import org.slf4j.LoggerFactory import java.io.ByteArrayInputStream import java.io.InputStream -import java.security.cert.* +import java.security.cert.CertPath +import java.security.cert.CertificateFactory import java.time.Instant import java.util.* import kotlin.test.assertEquals @@ -92,11 +92,10 @@ class KryoTests { } @Test - fun `write and read Ack`() { - val tokenizableBefore = Ack - val serializedBytes = tokenizableBefore.serialize(kryo) - val tokenizableAfter = serializedBytes.deserialize(kryo) - assertThat(tokenizableAfter).isSameAs(tokenizableBefore) + fun `write and read Kotlin object singleton`() { + val serialised = TestSingleton.serialize(kryo) + val deserialised = serialised.deserialize(kryo) + assertThat(deserialised).isSameAs(TestSingleton) } @Test @@ -173,4 +172,7 @@ class KryoTests { override fun toString(): String = "Cyclic($value)" } + @CordaSerializable + private object TestSingleton + } diff --git a/node/src/main/kotlin/net/corda/node/services/messaging/Messaging.kt b/node/src/main/kotlin/net/corda/node/services/messaging/Messaging.kt index d9003681d9..c5396a0067 100644 --- a/node/src/main/kotlin/net/corda/node/services/messaging/Messaging.kt +++ b/node/src/main/kotlin/net/corda/node/services/messaging/Messaging.kt @@ -8,7 +8,6 @@ import net.corda.core.messaging.SingleMessageRecipient import net.corda.core.node.services.DEFAULT_SESSION_ID import net.corda.core.node.services.PartyInfo import net.corda.core.serialization.CordaSerializable -import net.corda.core.serialization.DeserializeAsKotlinObjectDef import net.corda.core.serialization.deserialize import net.corda.core.serialization.serialize import org.bouncycastle.asn1.x500.X500Name @@ -229,10 +228,3 @@ object TopicStringValidator { /** @throws IllegalArgumentException if the given topic contains invalid characters */ fun check(tag: String) = require(regex.matcher(tag).matches()) } - -/** - * A general Ack message that conveys no content other than it's presence for use when you want an acknowledgement - * from a recipient. Using [Unit] can be ambiguous as it is similar to [Void] and so could mean no response. - */ -@CordaSerializable -object Ack : DeserializeAsKotlinObjectDef diff --git a/node/src/main/kotlin/net/corda/node/services/statemachine/StateMachineManager.kt b/node/src/main/kotlin/net/corda/node/services/statemachine/StateMachineManager.kt index 8066a7293f..3e1a8bdf35 100644 --- a/node/src/main/kotlin/net/corda/node/services/statemachine/StateMachineManager.kt +++ b/node/src/main/kotlin/net/corda/node/services/statemachine/StateMachineManager.kt @@ -89,6 +89,7 @@ class StateMachineManager(val serviceHub: ServiceHubInternal, } }.build() + // TODO Move this into the blacklist and upgrade the blacklist to allow custom messages private object AutoCloseableSerialisationDetector : Serializer() { override fun write(kryo: Kryo, output: Output, closeable: AutoCloseable) { val message = if (closeable is CloseableIterator<*>) {