Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OrderedTxPool rework #1958

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Prev Previous commit
fixed imports in tests
  • Loading branch information
jellymlg committed Jul 1, 2023
commit 25cccf70920367ca955f7634e4c19c6d4eb610ce
3 changes: 2 additions & 1 deletion src/test/scala/org/ergoplatform/mining/ErgoMinerSpec.scala
Original file line number Diff line number Diff line change
@@ -9,11 +9,12 @@ import org.ergoplatform.mining.CandidateGenerator.{Candidate, GenerateCandidate}
import org.ergoplatform.mining.ErgoMiner.StartMining
import org.ergoplatform.modifiers.ErgoFullBlock
import org.ergoplatform.modifiers.history.header.Header
import org.ergoplatform.modifiers.mempool.{ErgoTransaction, UnconfirmedTransaction, UnsignedErgoTransaction}
import org.ergoplatform.modifiers.mempool.{ErgoTransaction, UnsignedErgoTransaction}
import org.ergoplatform.network.ErgoNodeViewSynchronizer.ReceivableMessages.FullBlockApplied
import org.ergoplatform.nodeView.ErgoNodeViewHolder.ReceivableMessages.LocallyGeneratedTransaction
import org.ergoplatform.nodeView.ErgoReadersHolder.{GetReaders, Readers}
import org.ergoplatform.nodeView.history.ErgoHistoryReader
import org.ergoplatform.nodeView.mempool.UnconfirmedTransaction
import org.ergoplatform.nodeView.state._
import org.ergoplatform.nodeView.wallet._
import org.ergoplatform.nodeView.{ErgoNodeViewRef, ErgoReadersHolderRef}
Original file line number Diff line number Diff line change
@@ -4,11 +4,11 @@ import akka.actor.{ActorRef, ActorSystem}
import akka.testkit.TestProbe
import org.ergoplatform.modifiers.BlockSection
import org.ergoplatform.modifiers.history.header.Header
import org.ergoplatform.modifiers.mempool.{ErgoTransaction, UnconfirmedTransaction}
import org.ergoplatform.modifiers.mempool.ErgoTransaction
import org.ergoplatform.network.ErgoNodeViewSynchronizer.ReceivableMessages._
import org.ergoplatform.nodeView.ErgoNodeViewHolder.ReceivableMessages.{GetNodeViewChanges, ModifiersFromRemote}
import org.ergoplatform.nodeView.history.{ErgoHistory, ErgoSyncInfo, ErgoSyncInfoMessageSpec}
import org.ergoplatform.nodeView.mempool.ErgoMemPool
import org.ergoplatform.nodeView.mempool.{ErgoMemPool, UnconfirmedTransaction}
import org.ergoplatform.nodeView.state.UtxoState.ManifestId
import org.ergoplatform.nodeView.state._
import org.ergoplatform.settings.Algos
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ package org.ergoplatform.nodeView.mempool

import org.ergoplatform.{ErgoBoxCandidate, Input}
import org.ergoplatform.nodeView.mempool.ErgoMemPool.SortingOption
import org.ergoplatform.modifiers.mempool.{ErgoTransaction, UnconfirmedTransaction}
import org.ergoplatform.modifiers.mempool.ErgoTransaction
import org.ergoplatform.nodeView.mempool.ErgoMemPool.ProcessingOutcome
import org.ergoplatform.nodeView.state.wrapped.WrappedUtxoState
import org.ergoplatform.settings.{ErgoSettings, MonetarySettings}
@@ -64,7 +64,7 @@ class ErgoMemPoolSpec extends AnyFlatSpec
))

var poolSize = ErgoMemPool.empty(sortBySizeSettings)
val uTx1 = mempool.UnconfirmedTransaction(tx, None)
val uTx1 = UnconfirmedTransaction(tx, None)
poolSize = poolSize.process(uTx1, wus)._1
poolSize.pool.orderedTransactions.firstKey._2 shouldBe uTx1.weight(ms,fPb)

@@ -74,7 +74,7 @@ class ErgoMemPoolSpec extends AnyFlatSpec
))

var poolCost = ErgoMemPool.empty(sortByCostSettings)
val uTx2 = mempool.UnconfirmedTransaction(tx, None)
val uTx2 = UnconfirmedTransaction(tx, None)
poolCost = poolCost.process(uTx2, wus)._1
poolCost.pool.orderedTransactions.firstKey._2 shouldBe uTx2.withCost(wus.validateWithCost(tx, Int.MaxValue).get).weight(ms,fPc)
}
@@ -332,6 +332,13 @@ class ErgoMemPoolSpec extends AnyFlatSpec
})
}

val weights = pool.pool.orderedTransactions.keysIterator.take(11).toSeq
val ids = weights.map(_._1)

pool.take(11).toSeq.map(_.transaction.id) shouldBe ids
pool.getAll.map(_.transaction.id) shouldBe ids
pool.getAllPrioritized.map(_.transaction.id) shouldBe ids

val conformingTxs = pool.take(3).toSeq
val stateWithTxs = wus.withUnconfirmedTransactions(conformingTxs)

@@ -389,9 +396,9 @@ class ErgoMemPoolSpec extends AnyFlatSpec
}

it should "accept double-spending transaction if it is paying more than one already sitting in the pool" in {
val (us, bh) = createUtxoState(extendedParameters)
val (us, bh) = createUtxoState(settings)
val genesis = validFullBlock(None, us, bh)
val wus = WrappedUtxoState(us, bh, stateConstants, extendedParameters).applyModifier(genesis)(_ => ()).get
val wus = WrappedUtxoState(us, bh, settings, extendedParameters).applyModifier(genesis)(_ => ()).get

val input = wus.takeBoxes(100).collectFirst {
case box if box.ergoTree == TrueLeaf.toSigmaProp.treeWithSegregation => box
@@ -407,7 +414,7 @@ class ErgoMemPoolSpec extends AnyFlatSpec
ContextExtension(Map((1: Byte) -> ByteArrayConstant(Array.fill(1 + txCount - i)(0: Byte))))))
), IndexedSeq(out)
)
txs(i) = mempool.UnconfirmedTransaction(ErgoTransaction(txLike.inputs, txLike.outputCandidates), None)
txs(i) = UnconfirmedTransaction(ErgoTransaction(txLike.inputs, txLike.outputCandidates), None)
}

val pool = ErgoMemPool.empty(settings)