mirror of
https://github.com/corda/corda.git
synced 2025-06-18 15:18:16 +00:00
Check for duplicate transaction records
This commit is contained in:
@ -52,15 +52,15 @@ abstract class ServiceHubInternal : PluginServiceHub {
|
||||
*/
|
||||
internal fun recordTransactionsInternal(writableStorageService: TxWritableStorageService, txs: Iterable<SignedTransaction>) {
|
||||
val stateMachineRunId = FlowStateMachineImpl.currentStateMachine()?.id
|
||||
val recordedTransactions = txs.filter { writableStorageService.validatedTransactions.addTransaction(it) }
|
||||
if (stateMachineRunId != null) {
|
||||
txs.forEach {
|
||||
recordedTransactions.forEach {
|
||||
storageService.stateMachineRecordedTransactionMapping.addMapping(stateMachineRunId, it.id)
|
||||
}
|
||||
} else {
|
||||
log.warn("Transaction recorded from outside of a state machine")
|
||||
log.warn("Transactions recorded from outside of a state machine")
|
||||
}
|
||||
txs.forEach { writableStorageService.validatedTransactions.addTransaction(it) }
|
||||
vaultService.notifyAll(txs.map { it.tx })
|
||||
vaultService.notifyAll(recordedTransactions.map { it.tx })
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,6 +7,7 @@ import net.corda.core.node.services.TransactionStorage
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
import net.corda.node.utilities.*
|
||||
import org.jetbrains.exposed.sql.ResultRow
|
||||
import org.jetbrains.exposed.sql.exposedLogger
|
||||
import org.jetbrains.exposed.sql.statements.InsertStatement
|
||||
import rx.Observable
|
||||
import rx.subjects.PublishSubject
|
||||
@ -34,11 +35,21 @@ class DBTransactionStorage : TransactionStorage {
|
||||
|
||||
private val txStorage = synchronizedMap(TransactionsMap())
|
||||
|
||||
override fun addTransaction(transaction: SignedTransaction) {
|
||||
synchronized(txStorage) {
|
||||
txStorage.put(transaction.id, transaction)
|
||||
updatesPublisher.onNext(transaction)
|
||||
override fun addTransaction(transaction: SignedTransaction): Boolean {
|
||||
val recorded = synchronized(txStorage) {
|
||||
val old = txStorage.get(transaction.id)
|
||||
if (old == null) {
|
||||
txStorage.put(transaction.id, transaction)
|
||||
updatesPublisher.onNext(transaction)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
if (!recorded) {
|
||||
exposedLogger.warn("Duplicate recording of transaction ${transaction.id}")
|
||||
}
|
||||
return recorded
|
||||
}
|
||||
|
||||
override fun getTransaction(id: SecureHash): SignedTransaction? {
|
||||
|
@ -561,11 +561,12 @@ class TwoPartyTradeFlowTests {
|
||||
override val updates: Observable<SignedTransaction>
|
||||
get() = delegate.updates
|
||||
|
||||
override fun addTransaction(transaction: SignedTransaction) {
|
||||
override fun addTransaction(transaction: SignedTransaction): Boolean {
|
||||
databaseTransaction(database) {
|
||||
records.add(TxRecord.Add(transaction))
|
||||
delegate.addTransaction(transaction)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun getTransaction(id: SecureHash): SignedTransaction? {
|
||||
|
Reference in New Issue
Block a user