diff --git a/node/src/main/kotlin/net/corda/node/utilities/AppendOnlyPersistentMap.kt b/node/src/main/kotlin/net/corda/node/utilities/AppendOnlyPersistentMap.kt index 4912871b46..c6b875dbd9 100644 --- a/node/src/main/kotlin/net/corda/node/utilities/AppendOnlyPersistentMap.kt +++ b/node/src/main/kotlin/net/corda/node/utilities/AppendOnlyPersistentMap.kt @@ -57,6 +57,7 @@ abstract class AppendOnlyPersistentMapBase( // Depending on 'store' method, this may insert without checking key duplication or it may avoid inserting a duplicated key. val existingInDb = store(key, value) if (existingInDb != null) { // Always reuse an existing value from the storage of a duplicated key. + isUnique = false Optional.of(existingInDb) } else { Optional.of(value) diff --git a/node/src/test/kotlin/net/corda/node/services/persistence/DBTransactionStorageTests.kt b/node/src/test/kotlin/net/corda/node/services/persistence/DBTransactionStorageTests.kt index 5247788410..4c2ffc2843 100644 --- a/node/src/test/kotlin/net/corda/node/services/persistence/DBTransactionStorageTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/persistence/DBTransactionStorageTests.kt @@ -172,9 +172,22 @@ class DBTransactionStorageTests { assertEquals(expected, actual) } - private fun newTransactionStorage() { + @Test + fun `duplicates are detected when transaction is evicted from cache`() { + newTransactionStorage(cacheSizeBytesOverride = 0) + val transaction = newTransaction() database.transaction { - transactionStorage = DBTransactionStorage(NodeConfiguration.defaultTransactionCacheSize) + val firstInserted = transactionStorage.addTransaction(transaction) + val secondInserted = transactionStorage.addTransaction(transaction) + require(firstInserted) { "We inserted a fresh transaction" } + require(!secondInserted) { "Second time should be redundant" } + println("$firstInserted $secondInserted") + } + } + + private fun newTransactionStorage(cacheSizeBytesOverride: Long? = null) { + database.transaction { + transactionStorage = DBTransactionStorage(cacheSizeBytesOverride ?: NodeConfiguration.defaultTransactionCacheSize) } }