@@ -59,13 +59,13 @@ case class UtxPoolImpl(
5959 private [this ] val inUTXPoolOrdering = TransactionsOrdering .InUTXPool (utxSettings.fastLaneAddresses)
6060
6161 // State
62- val priorityPool = new UtxPriorityPool (blockchain)
62+ val priorityPool = new UtxPriorityPool
6363 private [this ] val transactions = new ConcurrentHashMap [ByteStr , Transaction ]()
6464
6565 override def getPriorityPool : Option [UtxPriorityPool ] = Some (priorityPool)
6666
6767 override def putIfNew (tx : Transaction , forceValidate : Boolean ): TracedResult [ValidationError , Boolean ] = {
68- if (transactions.containsKey(tx.id()) || priorityPool.contains(tx.id()) ) TracedResult .wrapValue(false )
68+ if (transactions.containsKey(tx.id())) TracedResult .wrapValue(false )
6969 else putNewTx(tx, forceValidate)
7070 }
7171
@@ -171,10 +171,8 @@ case class UtxPoolImpl(
171171 removeIds(ids)
172172 }
173173
174- def setPrioritySnapshots (discSnapshots : Seq [StateSnapshot ]): Unit = {
175- val txs = priorityPool.setPriorityDiffs(discSnapshots)
176- txs.foreach(addTransaction(_, verify = false , canLock = false ))
177- }
174+ def setPrioritySnapshots (discSnapshots : Seq [StateSnapshot ]): Unit =
175+ priorityPool.setPriorityDiffs(discSnapshots).foreach(addTransaction(_, verify = false ))
178176
179177 def resetPriorityPool (): Unit =
180178 priorityPool.setPriorityDiffs(Seq .empty)
@@ -186,23 +184,19 @@ case class UtxPoolImpl(
186184 }
187185 }
188186
189- private [this ] def removeIds (removed : Set [ByteStr ]): Unit = {
190- val priorityRemoved = priorityPool.removeIds(removed)
191- val factRemoved = priorityRemoved ++ removed.flatMap(id => removeFromOrdPool(id))
192- factRemoved.foreach(TxStateActions .removeMined(_))
193- }
187+ private [this ] def removeIds (removed : Set [ByteStr ]): Unit =
188+ removed.flatMap(id => removeFromOrdPool(id)).foreach(TxStateActions .removeMined(_))
194189
195190 private [utx] def addTransaction (
196191 tx : Transaction ,
197192 verify : Boolean ,
198- forceValidate : Boolean = false ,
199- canLock : Boolean = true
193+ forceValidate : Boolean = false
200194 ): TracedResult [ValidationError , Boolean ] = {
201195 val diffEi = {
202196 def calculateSnapshot (): TracedResult [ValidationError , StateSnapshot ] = {
203197 if (forceValidate)
204198 TransactionDiffer .forceValidate(blockchain.lastBlockTimestamp, time.correctedTime(), enableExecutionLog = true )(
205- priorityPool.compositeBlockchain ,
199+ blockchain ,
206200 tx
207201 )
208202 else
@@ -213,13 +207,12 @@ case class UtxPoolImpl(
213207 verify,
214208 enableExecutionLog = true
215209 )(
216- priorityPool.compositeBlockchain ,
210+ blockchain ,
217211 tx
218212 )
219213 }
220214
221- if (canLock) priorityPool.optimisticRead(calculateSnapshot())(_.resultE.isLeft)
222- else calculateSnapshot()
215+ calculateSnapshot()
223216 }
224217
225218 if (! verify || diffEi.resultE.isRight) {
@@ -235,13 +228,12 @@ case class UtxPoolImpl(
235228 }
236229
237230 override def all : Seq [Transaction ] =
238- (priorityPool.priorityTransactions ++ nonPriorityTransactions).distinct
231+ (priorityPool.priorityTransactionIds.flatMap(id => Option (transactions.get(id))) ++ nonPriorityTransactions).distinct
239232
240233 override def size : Int = transactions.size
241234
242235 override def transactionById (transactionId : ByteStr ): Option [Transaction ] =
243236 Option (transactions.get(transactionId))
244- .orElse(priorityPool.transactionById(transactionId))
245237
246238 private def scriptedAddresses (tx : Transaction ): Set [Address ] = tx match {
247239 case t if inUTXPoolOrdering.isWhitelisted(t) => Set .empty
@@ -256,23 +248,21 @@ case class UtxPoolImpl(
256248 private [this ] case class TxEntry (tx : Transaction , priority : Boolean )
257249
258250 private [this ] def createTxEntrySeq (): Seq [TxEntry ] =
259- priorityPool.priorityTransactions.map(TxEntry (_, priority = true )) ++ nonPriorityTransactions.map(
260- TxEntry (_, priority = false )
261- )
251+ priorityPool.priorityTransactionIds.flatMap(id => Option (transactions.get(id)).map(TxEntry (_, priority = true ))) ++
252+ nonPriorityTransactions.map(TxEntry (_, priority = false ))
262253
263254 override def packUnconfirmed (
264255 initialConstraint : MultiDimensionalMiningConstraint ,
265256 prevStateHash : Option [ByteStr ],
266257 strategy : PackStrategy ,
267258 cancelled : () => Boolean
268- ): (Option [Seq [Transaction ]], MultiDimensionalMiningConstraint , Option [ByteStr ]) = {
259+ ): (Option [Seq [Transaction ]], MultiDimensionalMiningConstraint , Option [ByteStr ]) =
269260 pack(TransactionDiffer (blockchain.lastBlockTimestamp, time.correctedTime(), enableExecutionLog = true ))(
270261 initialConstraint,
271262 strategy,
272263 prevStateHash,
273264 cancelled
274265 )
275- }
276266
277267 def cleanUnconfirmed (): Unit = {
278268 log.trace(s " Starting UTX cleanup at height ${blockchain.height}" )
@@ -286,7 +276,7 @@ case class UtxPoolImpl(
286276 } else {
287277 val differ = if (! isMiningEnabled && utxSettings.forceValidateInCleanup) {
288278 TransactionDiffer .forceValidate(blockchain.lastBlockTimestamp, time.correctedTime(), enableExecutionLog = true )(
289- priorityPool.compositeBlockchain ,
279+ blockchain ,
290280 _
291281 )
292282 } else {
@@ -296,7 +286,7 @@ case class UtxPoolImpl(
296286 utxSettings.alwaysUnlimitedExecution,
297287 enableExecutionLog = true
298288 )(
299- priorityPool.compositeBlockchain ,
289+ blockchain ,
300290 _
301291 )
302292 }
@@ -480,11 +470,10 @@ case class UtxPoolImpl(
480470
481471 log.trace(
482472 s " Validated ${packResult.validatedTransactions.size} transactions, " +
483- s " of which ${packResult.transactions.fold(0 )(_.size)} were packed, ${transactions.size() + priorityPool.priorityTransactions.size } transactions remaining "
473+ s " of which ${packResult.transactions.fold(0 )(_.size)} were packed, ${transactions.size()} transactions remaining "
484474 )
485475
486476 if (packResult.removedTransactions.nonEmpty) log.trace(s " Removing invalid transactions: ${packResult.removedTransactions.mkString(" , " )}" )
487- priorityPool.invalidateTxs(packResult.removedTransactions)
488477 (packResult.transactions.map(_.reverse), packResult.constraint, packResult.stateHash)
489478 }
490479
@@ -563,7 +552,7 @@ case class UtxPoolImpl(
563552
564553 private def cleanupLoop (): Unit = cleanupScheduler.execute { () =>
565554 while (scheduled.compareAndSet(true , false )) {
566- if (! transactions.isEmpty || priorityPool.priorityTransactions.nonEmpty ) {
555+ if (! transactions.isEmpty) {
567556 cleanUnconfirmed()
568557 }
569558 }
0 commit comments