From 086a406fc53caa29d61e51f13114bd41bc6ce594 Mon Sep 17 00:00:00 2001 From: Dimos Raptis Date: Tue, 15 Sep 2020 13:10:20 +0100 Subject: [PATCH] Deprecate deduplicationSeed, initiationEntropy fields from sessionState and session-init messages --- .../corda/node/services/statemachine/SessionMessage.kt | 3 --- .../node/services/statemachine/StateMachineState.kt | 9 +-------- .../transitions/DeliverSessionMessageTransition.kt | 1 - .../statemachine/transitions/StartedFlowTransition.kt | 10 ++-------- .../statemachine/transitions/TopLevelTransition.kt | 2 +- .../transitions/UnstartedFlowTransition.kt | 1 - .../node/services/statemachine/FlowFrameworkTests.kt | 8 ++++---- 7 files changed, 8 insertions(+), 26 deletions(-) diff --git a/node/src/main/kotlin/net/corda/node/services/statemachine/SessionMessage.kt b/node/src/main/kotlin/net/corda/node/services/statemachine/SessionMessage.kt index 35ecd12fc3..ec76925ffb 100644 --- a/node/src/main/kotlin/net/corda/node/services/statemachine/SessionMessage.kt +++ b/node/src/main/kotlin/net/corda/node/services/statemachine/SessionMessage.kt @@ -52,7 +52,6 @@ data class SessionId(val value: BigInteger) { * * @param initiatorSessionId the session ID of the initiator. On the sending side this is the *source* ID, on the * receiving side this is the *sink* ID. - * @param initiationEntropy additional randomness to seed the initiated flow's deduplication ID. * @param initiatorFlowClassName the class name to be used to determine the initiating-initiated mapping on the receiver * side. * @param flowVersion the version of the initiating flow. @@ -61,7 +60,6 @@ data class SessionId(val value: BigInteger) { */ data class InitialSessionMessage( val initiatorSessionId: SessionId, - val initiationEntropy: Long, val initiatorFlowClassName: String, val flowVersion: Int, val appName: String, @@ -69,7 +67,6 @@ data class InitialSessionMessage( ) : SessionMessage() { override fun toString() = "InitialSessionMessage(" + "initiatorSessionId=$initiatorSessionId, " + - "initiationEntropy=$initiationEntropy, " + "initiatorFlowClassName=$initiatorFlowClassName, " + "appName=$appName, " + "firstPayload=${firstPayload?.javaClass}" + diff --git a/node/src/main/kotlin/net/corda/node/services/statemachine/StateMachineState.kt b/node/src/main/kotlin/net/corda/node/services/statemachine/StateMachineState.kt index beb1a5d062..9a2e51c485 100644 --- a/node/src/main/kotlin/net/corda/node/services/statemachine/StateMachineState.kt +++ b/node/src/main/kotlin/net/corda/node/services/statemachine/StateMachineState.kt @@ -271,8 +271,6 @@ data class CheckpointState( */ sealed class SessionState { - abstract val deduplicationSeed: String - /** * the sender UUID last seen in this session, if there was one. */ @@ -328,15 +326,12 @@ sealed class SessionState { val destination: Destination, val initiatingSubFlow: SubFlow.Initiating, val sourceSessionId: SessionId, - val additionalEntropy: Long, val hasBeenAcknowledged: Pair?, val hasBeenRejected: RejectSessionMessage?, override val receivedMessages: Map, override val lastSenderUUID: String?, override val lastSenderSeqNo: Long? - ) : SessionState() { - override val deduplicationSeed: String get() = "R-${sourceSessionId.value}-$additionalEntropy" - } + ) : SessionState() /** * We have sent the initialisation message but have not yet received a confirmation. @@ -348,7 +343,6 @@ sealed class SessionState { data class Initiating( val bufferedMessages: List>, val rejectionError: FlowError?, - override val deduplicationSeed: String, val nextSendingSeqNumber: Int, val shardId: String, override val receivedMessages: Map, @@ -384,7 +378,6 @@ sealed class SessionState { val peerFlowInfo: FlowInfo, val otherSideErrored: Boolean, val peerSinkSessionId: SessionId, - override val deduplicationSeed: String, val nextSendingSeqNumber: Int, val lastProcessedSeqNumber: Int, val shardId: String, diff --git a/node/src/main/kotlin/net/corda/node/services/statemachine/transitions/DeliverSessionMessageTransition.kt b/node/src/main/kotlin/net/corda/node/services/statemachine/transitions/DeliverSessionMessageTransition.kt index bb960d8890..f416a54f2f 100644 --- a/node/src/main/kotlin/net/corda/node/services/statemachine/transitions/DeliverSessionMessageTransition.kt +++ b/node/src/main/kotlin/net/corda/node/services/statemachine/transitions/DeliverSessionMessageTransition.kt @@ -90,7 +90,6 @@ class DeliverSessionMessageTransition( peerFlowInfo = message.initiatedFlowInfo, receivedMessages = emptyMap(), peerSinkSessionId = message.initiatedSessionId, - deduplicationSeed = sessionState.deduplicationSeed, otherSideErrored = false, nextSendingSeqNumber = sessionState.nextSendingSeqNumber, lastProcessedSeqNumber = 0, diff --git a/node/src/main/kotlin/net/corda/node/services/statemachine/transitions/StartedFlowTransition.kt b/node/src/main/kotlin/net/corda/node/services/statemachine/transitions/StartedFlowTransition.kt index 853d981fab..c42ac0eaf9 100644 --- a/node/src/main/kotlin/net/corda/node/services/statemachine/transitions/StartedFlowTransition.kt +++ b/node/src/main/kotlin/net/corda/node/services/statemachine/transitions/StartedFlowTransition.kt @@ -292,11 +292,10 @@ class StartedFlowTransition( } val shardId = generateShardId(context.id.toString()) val counterpartySessionId = sourceSessionId.calculateInitiatedSessionId() - val initialMessage = createInitialSessionMessage(sessionState.initiatingSubFlow, sourceSessionId, sessionState.additionalEntropy, null) + val initialMessage = createInitialSessionMessage(sessionState.initiatingSubFlow, sourceSessionId, null) val newSessionState = SessionState.Initiating( bufferedMessages = emptyList(), rejectionError = null, - deduplicationSeed = sessionState.deduplicationSeed, nextSendingSeqNumber = 1, shardId = shardId, receivedMessages = emptyMap(), @@ -342,7 +341,6 @@ class StartedFlowTransition( receivedMessages = emptyMap(), otherSideErrored = false, peerSinkSessionId = sessionState.hasBeenAcknowledged.second.initiatedSessionId, - deduplicationSeed = sessionState.deduplicationSeed, nextSendingSeqNumber = 1, lastProcessedSeqNumber = 0, shardId = shardId, @@ -354,14 +352,13 @@ class StartedFlowTransition( newSessions[sourceSessionId] = SessionState.Initiating( bufferedMessages = emptyList(), rejectionError = null, - deduplicationSeed = sessionState.deduplicationSeed, nextSendingSeqNumber = 1, shardId = shardId, receivedMessages = emptyMap(), lastSenderUUID = null, lastSenderSeqNo = null ) - val initialMessage = createInitialSessionMessage(uninitiatedSessionState.initiatingSubFlow, sourceSessionId, uninitiatedSessionState.additionalEntropy, message) + val initialMessage = createInitialSessionMessage(uninitiatedSessionState.initiatingSubFlow, sourceSessionId, message) val messageType = MessageType.inferFromMessage(initialMessage) val messageIdentifier = MessageIdentifier(messageType, shardId, sourceSessionId.calculateInitiatedSessionId(), 0, checkpoint.checkpointState.suspensionTime) Action.SendInitial(uninitiatedSessionState.destination, initialMessage, SenderDeduplicationInfo(messageIdentifier, startingState.senderUUID)) @@ -527,13 +524,10 @@ class StartedFlowTransition( private fun createInitialSessionMessage( initiatingSubFlow: SubFlow.Initiating, sourceSessionId: SessionId, - additionalEntropy: Long, payload: SerializedBytes? ): InitialSessionMessage { return InitialSessionMessage( initiatorSessionId = sourceSessionId, - // We add additional entropy to add to the initiated side's deduplication seed. - initiationEntropy = additionalEntropy, initiatorFlowClassName = initiatingSubFlow.classToInitiateWith.name, flowVersion = initiatingSubFlow.flowInfo.flowVersion, appName = initiatingSubFlow.flowInfo.appName, diff --git a/node/src/main/kotlin/net/corda/node/services/statemachine/transitions/TopLevelTransition.kt b/node/src/main/kotlin/net/corda/node/services/statemachine/transitions/TopLevelTransition.kt index 78bf83906a..b1555cbbd0 100644 --- a/node/src/main/kotlin/net/corda/node/services/statemachine/transitions/TopLevelTransition.kt +++ b/node/src/main/kotlin/net/corda/node/services/statemachine/transitions/TopLevelTransition.kt @@ -318,7 +318,7 @@ class TopLevelTransition( } val sourceSessionId = SessionId.createRandom(context.secureRandom) val sessionImpl = FlowSessionImpl(event.destination, event.wellKnownParty, sourceSessionId) - val newSessions = checkpoint.checkpointState.sessions + (sourceSessionId to SessionState.Uninitiated(event.destination, initiatingSubFlow, sourceSessionId, context.secureRandom.nextLong(), null, null, emptyMap(), null, null)) + val newSessions = checkpoint.checkpointState.sessions + (sourceSessionId to SessionState.Uninitiated(event.destination, initiatingSubFlow, sourceSessionId, null, null, emptyMap(), null, null)) currentState = currentState.copy(checkpoint = checkpoint.setSessions(newSessions)) actions.add(Action.AddSessionBinding(context.id, sourceSessionId)) FlowContinuation.Resume(sessionImpl) diff --git a/node/src/main/kotlin/net/corda/node/services/statemachine/transitions/UnstartedFlowTransition.kt b/node/src/main/kotlin/net/corda/node/services/statemachine/transitions/UnstartedFlowTransition.kt index 9302d9fd43..127a2052f1 100644 --- a/node/src/main/kotlin/net/corda/node/services/statemachine/transitions/UnstartedFlowTransition.kt +++ b/node/src/main/kotlin/net/corda/node/services/statemachine/transitions/UnstartedFlowTransition.kt @@ -55,7 +55,6 @@ class UnstartedFlowTransition( } else { mapOf(0 to DataSessionMessage(initiatingMessage.firstPayload)) }, - deduplicationSeed = "D-${initiatingMessage.initiatorSessionId.value}-${initiatingMessage.initiationEntropy}", otherSideErrored = false, nextSendingSeqNumber = 1, lastProcessedSeqNumber = if (initiatingMessage.firstPayload == null) { diff --git a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt index 2a4a5517e7..ec501de964 100644 --- a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt @@ -574,7 +574,7 @@ class FlowFrameworkTests { @Test(timeout=300_000) fun `session init with unknown class is sent to the flow hospital, from where we then drop it`() { - aliceNode.sendSessionMessage(InitialSessionMessage(SessionId.createRandom(SecureRandom()), 0, "not.a.real.Class", 1, "", null), bob) + aliceNode.sendSessionMessage(InitialSessionMessage(SessionId.createRandom(SecureRandom()), "not.a.real.Class", 1, "", null), bob) mockNet.runNetwork() assertThat(receivedSessionMessages).hasSize(1) // Only the session-init is expected as the session-reject is blocked by the flow hospital val medicalRecords = bobNode.smm.flowHospital.track().apply { updates.notUsed() }.snapshot @@ -590,7 +590,7 @@ class FlowFrameworkTests { @Test(timeout=300_000) fun `non-flow class in session init`() { - aliceNode.sendSessionMessage(InitialSessionMessage(SessionId.createRandom(SecureRandom()), 0, String::class.java.name, 1, "", null), bob) + aliceNode.sendSessionMessage(InitialSessionMessage(SessionId.createRandom(SecureRandom()), String::class.java.name, 1, "", null), bob) mockNet.runNetwork() assertThat(receivedSessionMessages).hasSize(2) // Only the session-init and session-reject are expected val lastMessage = receivedSessionMessages.last().message as ExistingSessionMessage @@ -1049,7 +1049,7 @@ internal inline fun > TestStartedNode.getSingleFlow(): } private fun sanitise(message: SessionMessage) = when (message) { - is InitialSessionMessage -> message.copy(initiatorSessionId = SessionId(BigInteger.valueOf(0)), initiationEntropy = 0, appName = "") + is InitialSessionMessage -> message.copy(initiatorSessionId = SessionId(BigInteger.valueOf(0)), appName = "") is ExistingSessionMessage -> { val payload = message.payload message.copy( @@ -1107,7 +1107,7 @@ internal data class SessionTransfer(val from: Int, val message: SessionMessage, } internal fun sessionInit(clientFlowClass: KClass>, flowVersion: Int = 1, payload: Any? = null): InitialSessionMessage { - return InitialSessionMessage(SessionId(BigInteger.valueOf(0)), 0, clientFlowClass.java.name, flowVersion, "", payload?.serialize()) + return InitialSessionMessage(SessionId(BigInteger.valueOf(0)), clientFlowClass.java.name, flowVersion, "", payload?.serialize()) } internal fun sessionData(payload: Any) = ExistingSessionMessage(SessionId(BigInteger.valueOf(0)), DataSessionMessage(payload.serialize()))