ENT-10110 timeDiscriminator must also be shared for DR synchronisation. ()

This commit is contained in:
Jose Coll 2023-10-02 17:28:44 +01:00 committed by GitHub
parent a6254d54e3
commit 4e355b953b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions
node/src
main/kotlin/net/corda/node/services/persistence
test/kotlin/net/corda/node/services/persistence

@ -155,7 +155,7 @@ class DBTransactionStorageLedgerRecovery(private val database: CordaPersistence,
val hashedDistributionList = HashedDistributionList(
distributionList.senderStatesToRecord,
hashedPeersToStatesToRecord,
HashedDistributionList.PublicHeader(senderRecordingTimestamp)
HashedDistributionList.PublicHeader(senderRecordingTimestamp, timeDiscriminator)
)
hashedDistributionList.encrypt(encryptionService)
}
@ -170,7 +170,7 @@ class DBTransactionStorageLedgerRecovery(private val database: CordaPersistence,
val publicHeader = HashedDistributionList.PublicHeader.unauthenticatedDeserialise(distributionList.opaqueData, encryptionService)
database.transaction {
val receiverDistributionRecord = DBReceiverDistributionRecord(
Key(partyInfoCache.getPartyIdByCordaX500Name(sender), publicHeader.senderRecordedTimestamp),
Key(partyInfoCache.getPartyIdByCordaX500Name(sender), publicHeader.senderRecordedTimestamp, publicHeader.timeDiscriminator),
txId,
distributionList.opaqueData,
distributionList.receiverStatesToRecord

@ -38,12 +38,14 @@ data class HashedDistributionList(
@CordaSerializable
data class PublicHeader(
val senderRecordedTimestamp: Instant
val senderRecordedTimestamp: Instant,
val timeDiscriminator: Int
) {
fun serialise(): ByteArray {
val buffer = ByteBuffer.allocate(1 + java.lang.Long.BYTES)
val buffer = ByteBuffer.allocate(1 + java.lang.Long.BYTES + Integer.BYTES)
buffer.put(VERSION_TAG.toByte())
buffer.putLong(senderRecordedTimestamp.toEpochMilli())
buffer.putInt(timeDiscriminator)
return buffer.array()
}
@ -67,7 +69,8 @@ data class HashedDistributionList(
val version = buffer.get().toInt()
require(version == VERSION_TAG) { "Unknown distribution list format $version" }
val senderRecordedTimestamp = Instant.ofEpochMilli(buffer.getLong())
return PublicHeader(senderRecordedTimestamp)
val timeDiscriminator = buffer.getInt()
return PublicHeader(senderRecordedTimestamp, timeDiscriminator)
} catch (e: Exception) {
throw IllegalArgumentException("Corrupt or not a distribution list header", e)
}

@ -320,7 +320,7 @@ class DBTransactionStorageLedgerRecoveryTests {
val hashedDistList = HashedDistributionList(
ALL_VISIBLE,
mapOf(SecureHash.sha256(BOB.name.toString()) to NONE, SecureHash.sha256(CHARLIE_NAME.toString()) to ONLY_RELEVANT),
HashedDistributionList.PublicHeader(now())
HashedDistributionList.PublicHeader(now(), 1)
)
val roundtrip = HashedDistributionList.decrypt(hashedDistList.encrypt(encryptionService), encryptionService)
assertThat(roundtrip).isEqualTo(hashedDistList)