From e4e18118a963200545bfeee99677517fb33174eb Mon Sep 17 00:00:00 2001 From: Alex Chepurnoy Date: Mon, 4 Jul 2022 12:42:24 +0300 Subject: [PATCH 1/8] 4.0.34 version set --- README.md | 2 +- src/main/resources/api/openapi.yaml | 2 +- src/main/resources/application.conf | 2 +- src/main/resources/mainnet.conf | 2 +- src/main/resources/testnet.conf | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cc58fd493d..ec24df3498 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ To run specific Ergo version `` as a service with custom config `/path/ -e MAX_HEAP=3G \ ergoplatform/ergo: -- -c /etc/myergo.conf -Available versions can be found on [Ergo Docker image page](https://hub.docker.com/r/ergoplatform/ergo/tags), for example, `v4.0.33`. +Available versions can be found on [Ergo Docker image page](https://hub.docker.com/r/ergoplatform/ergo/tags), for example, `v4.0.34`. This will connect to the Ergo mainnet or testnet following your configuration passed in `myergo.conf` and network flag `--`. Every default config value would be overwritten with corresponding value in `myergo.conf`. `MAX_HEAP` variable can be used to control how much memory can the node consume. diff --git a/src/main/resources/api/openapi.yaml b/src/main/resources/api/openapi.yaml index e88bcda500..bd8424f079 100644 --- a/src/main/resources/api/openapi.yaml +++ b/src/main/resources/api/openapi.yaml @@ -1,7 +1,7 @@ openapi: "3.0.2" info: - version: "4.0.33" + version: "4.0.34" title: Ergo Node API description: API docs for Ergo Node. Models are shared between all Ergo products contact: diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index 14a3117621..1726c383ba 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -391,7 +391,7 @@ scorex { nodeName = "ergo-node" # Network protocol version to be sent in handshakes - appVersion = 4.0.33 + appVersion = 4.0.34 # Network agent name. May contain information about client code # stack, starting from core code-base up to the end graphical interface. diff --git a/src/main/resources/mainnet.conf b/src/main/resources/mainnet.conf index 28e5c91fdb..20acdb98bb 100644 --- a/src/main/resources/mainnet.conf +++ b/src/main/resources/mainnet.conf @@ -65,7 +65,7 @@ scorex { network { magicBytes = [1, 0, 2, 4] bindAddress = "0.0.0.0:9030" - nodeName = "ergo-mainnet-4.0.33" + nodeName = "ergo-mainnet-4.0.34" nodeName = ${?NODENAME} knownPeers = [ "213.239.193.208:9030", diff --git a/src/main/resources/testnet.conf b/src/main/resources/testnet.conf index 1d6f520c0b..734a966093 100644 --- a/src/main/resources/testnet.conf +++ b/src/main/resources/testnet.conf @@ -77,7 +77,7 @@ scorex { network { magicBytes = [2, 0, 0, 2] bindAddress = "0.0.0.0:9020" - nodeName = "ergo-testnet-4.0.33" + nodeName = "ergo-testnet-4.0.34" nodeName = ${?NODENAME} knownPeers = [ "213.239.193.208:9020", From a67c2ea423b0dcf6a52be9edfc3826de550da65b Mon Sep 17 00:00:00 2001 From: Alex Chepurnoy Date: Mon, 4 Jul 2022 18:03:39 +0300 Subject: [PATCH 2/8] type signatures for history and mempool classes simplified --- .../network/ErgoNodeViewSynchronizer.scala | 6 ++--- .../nodeView/ErgoModifiersCache.scala | 2 +- .../nodeView/history/ErgoHistory.scala | 2 +- .../nodeView/history/ErgoHistoryReader.scala | 2 +- .../nodeView/mempool/ErgoMemPool.scala | 2 +- .../nodeView/mempool/ErgoMemPoolReader.scala | 2 +- .../scala/scorex/core/ModifiersCache.scala | 26 +++++++++++-------- .../core/consensus/ContainsModifiers.scala | 4 +-- .../scala/scorex/core/consensus/History.scala | 12 ++++----- .../scorex/core/consensus/HistoryReader.scala | 13 +++++----- src/main/scala/scorex/core/core.scala | 6 ----- .../scorex/core/transaction/MemoryPool.scala | 21 ++++++++------- .../core/transaction/MempoolReader.scala | 10 +++---- 13 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/main/scala/org/ergoplatform/network/ErgoNodeViewSynchronizer.scala b/src/main/scala/org/ergoplatform/network/ErgoNodeViewSynchronizer.scala index a02efcee18..399236126e 100644 --- a/src/main/scala/org/ergoplatform/network/ErgoNodeViewSynchronizer.scala +++ b/src/main/scala/org/ergoplatform/network/ErgoNodeViewSynchronizer.scala @@ -18,7 +18,7 @@ import org.ergoplatform.settings.{Constants, ErgoSettings} import org.ergoplatform.nodeView.ErgoNodeViewHolder.ReceivableMessages.{ChainIsHealthy, ChainIsStuck, GetNodeViewChanges, IsChainHealthy, ModifiersFromRemote, TransactionsFromRemote} import org.ergoplatform.nodeView.ErgoNodeViewHolder._ import scorex.core.consensus.History.{Equal, Fork, Nonsense, Older, Unknown, Younger} -import scorex.core.consensus.{HistoryReader, SyncInfo} +import scorex.core.consensus.HistoryReader import scorex.core.network.ModifiersStatus.Requested import scorex.core.{ModifierTypeId, NodeViewModifier, PersistentNodeViewModifier, idsToString} import scorex.core.network.NetworkController.ReceivableMessages.{PenalizePeer, RegisterMessageSpecs} @@ -975,9 +975,9 @@ object ErgoNodeViewSynchronizer { trait NodeViewChange extends NodeViewHolderEvent - case class ChangedHistory[HR <: HistoryReader[_ <: PersistentNodeViewModifier, _ <: SyncInfo]](reader: HR) extends NodeViewChange + case class ChangedHistory[HR <: HistoryReader](reader: HR) extends NodeViewChange - case class ChangedMempool[MR <: MempoolReader[_ <: Transaction]](mempool: MR) extends NodeViewChange + case class ChangedMempool[MR <: MempoolReader](mempool: MR) extends NodeViewChange case class ChangedVault[VR <: VaultReader](reader: VR) extends NodeViewChange diff --git a/src/main/scala/org/ergoplatform/nodeView/ErgoModifiersCache.scala b/src/main/scala/org/ergoplatform/nodeView/ErgoModifiersCache.scala index 63b72d4442..55639ecf10 100644 --- a/src/main/scala/org/ergoplatform/nodeView/ErgoModifiersCache.scala +++ b/src/main/scala/org/ergoplatform/nodeView/ErgoModifiersCache.scala @@ -9,7 +9,7 @@ import scorex.core.validation.MalformedModifierError import scala.util.Failure class ErgoModifiersCache(override val maxSize: Int) - extends DefaultModifiersCache[ErgoPersistentModifier, ErgoHistory](maxSize) { + extends DefaultModifiersCache(maxSize) { override def findCandidateKey(history: ErgoHistory): Option[K] = { def tryToApply(k: K, v: ErgoPersistentModifier): Boolean = { diff --git a/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistory.scala b/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistory.scala index 906a445daa..0de1b895b0 100644 --- a/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistory.scala +++ b/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistory.scala @@ -39,7 +39,7 @@ import scala.util.{Failure, Success, Try} * 2. Be ignored by history (verifyTransactions == false) */ trait ErgoHistory - extends History[ErgoPersistentModifier, ErgoSyncInfo, ErgoHistory] + extends History[ErgoHistory] with ErgoHistoryReader { override protected lazy val requireProofs: Boolean = nodeSettings.stateType.requireProofs diff --git a/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistoryReader.scala b/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistoryReader.scala index a47f028ddd..5672caf84f 100644 --- a/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistoryReader.scala +++ b/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistoryReader.scala @@ -25,7 +25,7 @@ import scala.util.{Failure, Try} * Read-only copy of ErgoHistory */ trait ErgoHistoryReader - extends HistoryReader[ErgoPersistentModifier, ErgoSyncInfo] + extends HistoryReader with HeadersProcessor with PoPoWProofsProcessor with UTXOSnapshotChunkProcessor diff --git a/src/main/scala/org/ergoplatform/nodeView/mempool/ErgoMemPool.scala b/src/main/scala/org/ergoplatform/nodeView/mempool/ErgoMemPool.scala index e5a4894043..abd12c6a3b 100644 --- a/src/main/scala/org/ergoplatform/nodeView/mempool/ErgoMemPool.scala +++ b/src/main/scala/org/ergoplatform/nodeView/mempool/ErgoMemPool.scala @@ -27,7 +27,7 @@ import scala.util.Try */ class ErgoMemPool private[mempool](pool: OrderedTxPool, private[mempool] val stats : MemPoolStatistics)(implicit settings: ErgoSettings) - extends MemoryPool[ErgoTransaction, ErgoMemPool] with ErgoMemPoolReader with ScorexLogging { + extends MemoryPool[ErgoMemPool] with ErgoMemPoolReader with ScorexLogging { import ErgoMemPool._ import EmissionRules.CoinsInOneErgo diff --git a/src/main/scala/org/ergoplatform/nodeView/mempool/ErgoMemPoolReader.scala b/src/main/scala/org/ergoplatform/nodeView/mempool/ErgoMemPoolReader.scala index 7fbd6fe869..ce641320da 100644 --- a/src/main/scala/org/ergoplatform/nodeView/mempool/ErgoMemPoolReader.scala +++ b/src/main/scala/org/ergoplatform/nodeView/mempool/ErgoMemPoolReader.scala @@ -6,7 +6,7 @@ import org.ergoplatform.nodeView.mempool.OrderedTxPool.WeightedTxId import scorex.core.transaction.MempoolReader import scorex.util.ModifierId -trait ErgoMemPoolReader extends MempoolReader[ErgoTransaction] { +trait ErgoMemPoolReader extends MempoolReader { override def contains(id: ModifierId): Boolean diff --git a/src/main/scala/scorex/core/ModifiersCache.scala b/src/main/scala/scorex/core/ModifiersCache.scala index fe5794669b..170953e075 100644 --- a/src/main/scala/scorex/core/ModifiersCache.scala +++ b/src/main/scala/scorex/core/ModifiersCache.scala @@ -1,6 +1,8 @@ package scorex.core -import scorex.core.consensus.{ContainsModifiers, HistoryReader} +import org.ergoplatform.modifiers.{ErgoNodeViewModifier, ErgoPersistentModifier} +import org.ergoplatform.nodeView.history.ErgoHistory +import scorex.core.consensus.ContainsModifiers import scorex.core.validation.RecoverableModifierError import scorex.util.ScorexLogging @@ -14,17 +16,18 @@ import scala.util.{Failure, Success} * This trait is not thread-save so it should be used only as a local field of an actor * and its methods should not be called from lambdas, Future, Future.map, etc. * - * @tparam PMOD - type of a persistent node view modifier (or a family of modifiers). */ -trait ModifiersCache[PMOD <: PersistentNodeViewModifier, H <: HistoryReader[PMOD, _]] extends ContainsModifiers[PMOD] { +trait ModifiersCache extends ContainsModifiers[ErgoNodeViewModifier] { require(maxSize >= 1) type K = scorex.util.ModifierId - type V = PMOD + type V = ErgoPersistentModifier protected val cache: mutable.Map[K, V] = mutable.LinkedHashMap[K, V]() - override def modifierById(modifierId: scorex.util.ModifierId): Option[PMOD] = cache.get(modifierId) + override def modifierById(modifierId: scorex.util.ModifierId): Option[ErgoNodeViewModifier] = { + cache.get(modifierId) + } def size: Int = cache.size @@ -39,7 +42,7 @@ trait ModifiersCache[PMOD <: PersistentNodeViewModifier, H <: HistoryReader[PMOD * @param history - an interface to history which could be needed to define a candidate * @return - candidate if it is found */ - def findCandidateKey(history: H): Option[K] + def findCandidateKey(history: ErgoHistory): Option[K] protected def onPut(key: K): Unit = { assert(key != null) @@ -76,12 +79,13 @@ trait ModifiersCache[PMOD <: PersistentNodeViewModifier, H <: HistoryReader[PMOD } } - def popCandidate(history: H): Option[V] = { + def popCandidate(history: ErgoHistory): Option[V] = { findCandidateKey(history).flatMap(k => remove(k)) } + } -trait LRUCache[PMOD <: PersistentNodeViewModifier, HR <: HistoryReader[PMOD, _]] extends ModifiersCache[PMOD, HR] { +trait LRUCache extends ModifiersCache { private val evictionQueue = mutable.Queue[K]() @@ -111,8 +115,8 @@ trait LRUCache[PMOD <: PersistentNodeViewModifier, HR <: HistoryReader[PMOD, _]] } } -class DefaultModifiersCache[PMOD <: PersistentNodeViewModifier, HR <: HistoryReader[PMOD, _]] -(override val maxSize: Int) extends ModifiersCache[PMOD, HR] with LRUCache[PMOD, HR] with ScorexLogging { +class DefaultModifiersCache(override val maxSize: Int) + extends ModifiersCache with LRUCache with ScorexLogging { /** * Default implementation is just about to scan. Not efficient at all and should be probably rewritten in a @@ -122,7 +126,7 @@ class DefaultModifiersCache[PMOD <: PersistentNodeViewModifier, HR <: HistoryRea * @return - candidate if it is found */ @SuppressWarnings(Array("org.wartremover.warts.IsInstanceOf")) - override def findCandidateKey(history: HR): Option[K] = { + override def findCandidateKey(history: ErgoHistory): Option[K] = { cache.find { case (k, v) => history.applicableTry(v) match { diff --git a/src/main/scala/scorex/core/consensus/ContainsModifiers.scala b/src/main/scala/scorex/core/consensus/ContainsModifiers.scala index 2ac4116a1a..55a2af0107 100644 --- a/src/main/scala/scorex/core/consensus/ContainsModifiers.scala +++ b/src/main/scala/scorex/core/consensus/ContainsModifiers.scala @@ -1,12 +1,12 @@ package scorex.core.consensus -import scorex.core.NodeViewModifier +import org.ergoplatform.modifiers.ErgoNodeViewModifier import scorex.util.ModifierId /** * Object that contains modifiers of type `MOD` */ -trait ContainsModifiers[MOD <: NodeViewModifier] { +trait ContainsModifiers[MOD <: ErgoNodeViewModifier] { /** * diff --git a/src/main/scala/scorex/core/consensus/History.scala b/src/main/scala/scorex/core/consensus/History.scala index 1e0d8bfc35..b84767fad8 100644 --- a/src/main/scala/scorex/core/consensus/History.scala +++ b/src/main/scala/scorex/core/consensus/History.scala @@ -1,5 +1,6 @@ package scorex.core.consensus +import org.ergoplatform.modifiers.ErgoPersistentModifier import scorex.core.consensus.History.ProgressInfo import scorex.core.utils.ScorexEncoder import scorex.core.{ModifierTypeId, PersistentNodeViewModifier} @@ -19,13 +20,12 @@ import scala.util.Try * function has been used instead. */ -trait History[PM <: PersistentNodeViewModifier, SI <: SyncInfo, HT <: History[PM, SI, HT]] - extends HistoryReader[PM, SI] { +trait History[HT <: History[HT]] extends HistoryReader { /** * @return append modifier to history */ - def append(modifier: PM): Try[(HT, ProgressInfo[PM])] + def append(modifier: ErgoPersistentModifier): Try[(HT, ProgressInfo[ErgoPersistentModifier])] /** * Report that modifier is valid from point of view of the state component @@ -33,7 +33,7 @@ trait History[PM <: PersistentNodeViewModifier, SI <: SyncInfo, HT <: History[PM * @param modifier - valid modifier * @return modified history */ - def reportModifierIsValid(modifier: PM): Try[HT] + def reportModifierIsValid(modifier: ErgoPersistentModifier): Try[HT] /** * Report that modifier is invalid from other nodeViewHolder components point of view @@ -42,13 +42,13 @@ trait History[PM <: PersistentNodeViewModifier, SI <: SyncInfo, HT <: History[PM * @param progressInfo - what suffix failed to be applied because of an invalid modifier * @return modified history and new progress info */ - def reportModifierIsInvalid(modifier: PM, progressInfo: ProgressInfo[PM]): Try[(HT, ProgressInfo[PM])] + def reportModifierIsInvalid(modifier: ErgoPersistentModifier, progressInfo: ProgressInfo[ErgoPersistentModifier]): Try[(HT, ProgressInfo[ErgoPersistentModifier])] /** * @return read-only copy of this history */ - def getReader: HistoryReader[PM, SI] = this + def getReader: HistoryReader = this } diff --git a/src/main/scala/scorex/core/consensus/HistoryReader.scala b/src/main/scala/scorex/core/consensus/HistoryReader.scala index 3b3f3bcca1..016a83353f 100644 --- a/src/main/scala/scorex/core/consensus/HistoryReader.scala +++ b/src/main/scala/scorex/core/consensus/HistoryReader.scala @@ -1,13 +1,14 @@ package scorex.core.consensus -import scorex.core.{NodeViewComponent, PersistentNodeViewModifier} +import org.ergoplatform.modifiers.ErgoPersistentModifier +import org.ergoplatform.nodeView.history.ErgoSyncInfo +import scorex.core.NodeViewComponent import scorex.util.ModifierId import scala.util.Try -trait HistoryReader[PM <: PersistentNodeViewModifier, SI <: SyncInfo] extends NodeViewComponent - with ContainsModifiers[PM] { +trait HistoryReader extends NodeViewComponent with ContainsModifiers[ErgoPersistentModifier] { import History._ @@ -22,7 +23,7 @@ trait HistoryReader[PM <: PersistentNodeViewModifier, SI <: SyncInfo] extends No * @param modifier - modifier to apply * @return `Success` if modifier can be applied, `Failure(ModifierError)` if can not */ - def applicableTry(modifier: PM): Try[Unit] + def applicableTry(modifier: ErgoPersistentModifier): Try[Unit] /** * Return semantic validity status of modifier with id == modifierId @@ -35,7 +36,7 @@ trait HistoryReader[PM <: PersistentNodeViewModifier, SI <: SyncInfo] extends No /** * Ids of modifiers, that node with info should download and apply to synchronize */ - def continuationIds(info: SI, size: Int): ModifierIds + def continuationIds(info: ErgoSyncInfo, size: Int): ModifierIds /** * Whether another's node syncinfo shows that another node is ahead or behind ours @@ -43,5 +44,5 @@ trait HistoryReader[PM <: PersistentNodeViewModifier, SI <: SyncInfo] extends No * @param other other's node sync info * @return Equal if nodes have the same history, Younger if another node is behind, Older if a new node is ahead */ - def compare(other: SI): HistoryComparisonResult + def compare(other: ErgoSyncInfo): HistoryComparisonResult } diff --git a/src/main/scala/scorex/core/core.scala b/src/main/scala/scorex/core/core.scala index 020c1ee0dc..bb02ad8669 100644 --- a/src/main/scala/scorex/core/core.scala +++ b/src/main/scala/scorex/core/core.scala @@ -10,12 +10,6 @@ package object core { //TODO implement ModifierTypeId as a trait object ModifierTypeId extends TaggedType[Byte] - @deprecated("use `scorex.util.ModifierId`", "") - type ModifierId = scorex.util.ModifierId.Type - - @deprecated("use `scorex.util.ModifierId`", "") - val ModifierId: scorex.util.ModifierId.type = scorex.util.ModifierId - object VersionTag extends TaggedType[String] type ModifierTypeId = ModifierTypeId.Type diff --git a/src/main/scala/scorex/core/transaction/MemoryPool.scala b/src/main/scala/scorex/core/transaction/MemoryPool.scala index e5aae4388f..261a80397f 100644 --- a/src/main/scala/scorex/core/transaction/MemoryPool.scala +++ b/src/main/scala/scorex/core/transaction/MemoryPool.scala @@ -1,13 +1,14 @@ package scorex.core.transaction +import org.ergoplatform.modifiers.mempool.ErgoTransaction + import scala.util.Try /** * Unconfirmed transactions pool * - * @tparam TX -type of transaction the pool contains */ -trait MemoryPool[TX <: Transaction, M <: MemoryPool[TX, M]] extends MempoolReader[TX] { +trait MemoryPool[M <: MemoryPool[M]] extends MempoolReader { /** * Method to put a transaction into the memory pool. Validation of tha transactions against @@ -15,20 +16,20 @@ trait MemoryPool[TX <: Transaction, M <: MemoryPool[TX, M]] extends MempoolReade * @param tx * @return Success(updatedPool), if transaction successfully added to the pool, Failure(_) otherwise */ - def put(tx: TX): Try[M] + def put(tx: ErgoTransaction): Try[M] - def put(txs: Iterable[TX]): Try[M] + def put(txs: Iterable[ErgoTransaction]): Try[M] - def putWithoutCheck(txs: Iterable[TX]): M + def putWithoutCheck(txs: Iterable[ErgoTransaction]): M - def remove(tx: TX): M + def remove(tx: ErgoTransaction): M - def filter(txs: Seq[TX]): M = filter(t => !txs.exists(_.id == t.id)) + def filter(txs: Seq[ErgoTransaction]): M = filter(t => !txs.exists(_.id == t.id)) - def filter(condition: TX => Boolean): M + def filter(condition: ErgoTransaction => Boolean): M /** * @return read-only copy of this history */ - def getReader: MempoolReader[TX] = this -} \ No newline at end of file + def getReader: MempoolReader = this +} diff --git a/src/main/scala/scorex/core/transaction/MempoolReader.scala b/src/main/scala/scorex/core/transaction/MempoolReader.scala index 6393571158..ad64b1094e 100644 --- a/src/main/scala/scorex/core/transaction/MempoolReader.scala +++ b/src/main/scala/scorex/core/transaction/MempoolReader.scala @@ -1,5 +1,6 @@ package scorex.core.transaction +import org.ergoplatform.modifiers.mempool.ErgoTransaction import scorex.core.consensus.ContainsModifiers import scorex.core.NodeViewComponent import scorex.util.ModifierId @@ -7,19 +8,18 @@ import scorex.util.ModifierId /** * Unconfirmed transactions pool * - * @tparam TX -type of transaction the pool contains */ -trait MempoolReader[TX <: Transaction] extends NodeViewComponent with ContainsModifiers[TX] { +trait MempoolReader extends NodeViewComponent with ContainsModifiers[ErgoTransaction] { //getters - override def modifierById(modifierId: ModifierId): Option[TX] + override def modifierById(modifierId: ModifierId): Option[ErgoTransaction] def contains(id: ModifierId): Boolean - def getAll(ids: Seq[ModifierId]): Seq[TX] + def getAll(ids: Seq[ModifierId]): Seq[ErgoTransaction] def size: Int - def take(limit: Int): Iterable[TX] + def take(limit: Int): Iterable[ErgoTransaction] } From 9a479939680dd0d31346c8aa71fd482ad88bed41 Mon Sep 17 00:00:00 2001 From: Alex Chepurnoy Date: Mon, 4 Jul 2022 18:40:21 +0300 Subject: [PATCH 3/8] removing History/HistoryReader, Vault/VaultReader, Mempool/MempoolReader traits --- .../local/ErgoStatsCollector.scala | 4 +- .../network/ErgoNodeViewSynchronizer.scala | 18 +++---- .../nodeView/history/ErgoHistory.scala | 27 ++++++++--- .../nodeView/history/ErgoHistoryReader.scala | 25 ++++++++-- .../nodeView/mempool/ErgoMemPool.scala | 26 +++++++--- .../nodeView/mempool/ErgoMemPoolReader.scala | 11 +++-- .../nodeView/wallet/ErgoWallet.scala | 24 ++++++---- .../nodeView/wallet/ErgoWalletActor.scala | 2 +- .../nodeView/wallet/ErgoWalletReader.scala | 4 +- .../scala/scorex/core/consensus/History.scala | 46 ------------------ .../scorex/core/consensus/HistoryReader.scala | 48 ------------------- .../scorex/core/transaction/MemoryPool.scala | 35 -------------- .../core/transaction/MempoolReader.scala | 25 ---------- .../core/transaction/wallet/Vault.scala | 32 ------------- .../core/transaction/wallet/VaultReader.scala | 9 ---- 15 files changed, 96 insertions(+), 240 deletions(-) delete mode 100644 src/main/scala/scorex/core/consensus/HistoryReader.scala delete mode 100644 src/main/scala/scorex/core/transaction/MemoryPool.scala delete mode 100644 src/main/scala/scorex/core/transaction/MempoolReader.scala delete mode 100644 src/main/scala/scorex/core/transaction/wallet/Vault.scala delete mode 100644 src/main/scala/scorex/core/transaction/wallet/VaultReader.scala diff --git a/src/main/scala/org/ergoplatform/local/ErgoStatsCollector.scala b/src/main/scala/org/ergoplatform/local/ErgoStatsCollector.scala index 6b4d7c615d..d3c5fb7fdf 100644 --- a/src/main/scala/org/ergoplatform/local/ErgoStatsCollector.scala +++ b/src/main/scala/org/ergoplatform/local/ErgoStatsCollector.scala @@ -39,9 +39,9 @@ class ErgoStatsCollector(readersHolder: ActorRef, val ec: ExecutionContextExecutor = context.dispatcher readersHolder ! GetReaders - context.system.eventStream.subscribe(self, classOf[ChangedHistory[_]]) + context.system.eventStream.subscribe(self, classOf[ChangedHistory]) context.system.eventStream.subscribe(self, classOf[ChangedState]) - context.system.eventStream.subscribe(self, classOf[ChangedMempool[_]]) + context.system.eventStream.subscribe(self, classOf[ChangedMempool]) context.system.eventStream.subscribe(self, classOf[SemanticallySuccessfulModifier]) context.system.scheduler.scheduleAtFixedRate(10.seconds, 20.seconds, networkController, GetConnectedPeers)(ec, self) context.system.scheduler.scheduleAtFixedRate(45.seconds, 30.seconds, networkController, GetPeersStatus)(ec, self) diff --git a/src/main/scala/org/ergoplatform/network/ErgoNodeViewSynchronizer.scala b/src/main/scala/org/ergoplatform/network/ErgoNodeViewSynchronizer.scala index 399236126e..8684e99a85 100644 --- a/src/main/scala/org/ergoplatform/network/ErgoNodeViewSynchronizer.scala +++ b/src/main/scala/org/ergoplatform/network/ErgoNodeViewSynchronizer.scala @@ -1,8 +1,8 @@ package org.ergoplatform.network import akka.actor.SupervisorStrategy.{Restart, Stop} - import java.net.InetSocketAddress + import akka.actor.{Actor, ActorInitializationException, ActorKilledException, ActorRef, ActorRefFactory, DeathPactException, OneForOneStrategy, Props} import org.ergoplatform.modifiers.history.ADProofs import org.ergoplatform.modifiers.history.header.Header @@ -18,12 +18,12 @@ import org.ergoplatform.settings.{Constants, ErgoSettings} import org.ergoplatform.nodeView.ErgoNodeViewHolder.ReceivableMessages.{ChainIsHealthy, ChainIsStuck, GetNodeViewChanges, IsChainHealthy, ModifiersFromRemote, TransactionsFromRemote} import org.ergoplatform.nodeView.ErgoNodeViewHolder._ import scorex.core.consensus.History.{Equal, Fork, Nonsense, Older, Unknown, Younger} -import scorex.core.consensus.HistoryReader import scorex.core.network.ModifiersStatus.Requested import scorex.core.{ModifierTypeId, NodeViewModifier, PersistentNodeViewModifier, idsToString} import scorex.core.network.NetworkController.ReceivableMessages.{PenalizePeer, RegisterMessageSpecs} import org.ergoplatform.network.ErgoNodeViewSynchronizer.ReceivableMessages._ import org.ergoplatform.nodeView.state.{ErgoStateReader, StateType} +import org.ergoplatform.nodeView.wallet.ErgoWalletReader import scorex.core.network.message.{InvSpec, MessageSpec, ModifiersSpec, RequestModifierSpec} import scorex.core.network._ import scorex.core.network.NetworkController.ReceivableMessages.SendToNetwork @@ -31,14 +31,14 @@ import scorex.core.network.message.{InvData, Message, ModifiersData} import scorex.core.network.{ConnectedPeer, ModifiersStatus, SendToPeer, SendToPeers} import scorex.core.serialization.ScorexSerializer import scorex.core.settings.NetworkSettings -import scorex.core.transaction.{MempoolReader, Transaction} +import scorex.core.transaction.Transaction import scorex.core.utils.{NetworkTimeProvider, ScorexEncoding} import scorex.core.validation.MalformedModifierError import scorex.util.{ModifierId, ScorexLogging} import scorex.core.network.DeliveryTracker import scorex.core.network.peer.PenaltyType import scorex.core.transaction.state.TransactionValidation.TooHighCostError -import scorex.core.transaction.wallet.VaultReader + import scala.annotation.tailrec import scala.collection.mutable @@ -114,8 +114,8 @@ class ErgoNodeViewSynchronizer(networkControllerRef: ActorRef, context.system.eventStream.subscribe(self, classOf[DisconnectedPeer]) // subscribe for all the node view holder events involving modifiers and transactions - context.system.eventStream.subscribe(self, classOf[ChangedHistory[ErgoHistoryReader]]) - context.system.eventStream.subscribe(self, classOf[ChangedMempool[ErgoMemPoolReader]]) + context.system.eventStream.subscribe(self, classOf[ChangedHistory]) + context.system.eventStream.subscribe(self, classOf[ChangedMempool]) context.system.eventStream.subscribe(self, classOf[ModificationOutcome]) context.system.eventStream.subscribe(self, classOf[DownloadRequest]) context.system.eventStream.subscribe(self, classOf[BlockAppliedTransactions]) @@ -975,11 +975,11 @@ object ErgoNodeViewSynchronizer { trait NodeViewChange extends NodeViewHolderEvent - case class ChangedHistory[HR <: HistoryReader](reader: HR) extends NodeViewChange + case class ChangedHistory(reader: ErgoHistoryReader) extends NodeViewChange - case class ChangedMempool[MR <: MempoolReader](mempool: MR) extends NodeViewChange + case class ChangedMempool(mempool: ErgoMemPoolReader) extends NodeViewChange - case class ChangedVault[VR <: VaultReader](reader: VR) extends NodeViewChange + case class ChangedVault(reader: ErgoWalletReader) extends NodeViewChange case class ChangedState(reader: ErgoStateReader) extends NodeViewChange diff --git a/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistory.scala b/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistory.scala index 0de1b895b0..6be580882f 100644 --- a/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistory.scala +++ b/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistory.scala @@ -13,7 +13,6 @@ import org.ergoplatform.nodeView.history.storage.modifierprocessors._ import org.ergoplatform.nodeView.history.storage.modifierprocessors.popow.{EmptyPoPoWProofsProcessor, FullPoPoWProofsProcessor} import org.ergoplatform.settings._ import org.ergoplatform.utils.LoggingUtil -import scorex.core.consensus.History import scorex.core.consensus.History.ProgressInfo import scorex.core.utils.NetworkTimeProvider import scorex.core.validation.RecoverableModifierError @@ -22,6 +21,17 @@ import scorex.util.{ModifierId, ScorexLogging, idToBytes} import scala.util.{Failure, Success, Try} /** + * + * History of a blockchain system is some blocktree in fact + * (like this: http://image.slidesharecdn.com/sfbitcoindev-chepurnoy-2015-150322043044-conversion-gate01/95/proofofstake-its-improvements-san-francisco-bitcoin-devs-hackathon-12-638.jpg), + * where longest chain is being considered as canonical one, containing right kind of history. + * + * In cryptocurrencies of today blocktree view is usually implicit, means code supports only linear history, + * but other options are possible. + * + * To say "longest chain" is the canonical one is simplification, usually some kind of "cumulative difficulty" + * function has been used instead. + * * History implementation. It is processing persistent modifiers generated locally or coming from the network. * Depending on chosen node settings, it will process modifiers in a different way, different processors define how to * process different type of modifiers. @@ -39,8 +49,7 @@ import scala.util.{Failure, Success, Try} * 2. Be ignored by history (verifyTransactions == false) */ trait ErgoHistory - extends History[ErgoHistory] - with ErgoHistoryReader { + extends ErgoHistoryReader { override protected lazy val requireProofs: Boolean = nodeSettings.stateType.requireProofs @@ -62,7 +71,7 @@ trait ErgoHistory /** * Append ErgoPersistentModifier to History if valid */ - override def append(modifier: ErgoPersistentModifier): Try[(ErgoHistory, ProgressInfo[ErgoPersistentModifier])] = synchronized { + def append(modifier: ErgoPersistentModifier): Try[(ErgoHistory, ProgressInfo[ErgoPersistentModifier])] = synchronized { log.debug(s"Trying to append modifier ${modifier.encodedId} of type ${modifier.modifierTypeId} to history") applicableTry(modifier).flatMap { _ => modifier match { @@ -87,7 +96,7 @@ trait ErgoHistory /** * Mark modifier as valid */ - override def reportModifierIsValid(modifier: ErgoPersistentModifier): Try[ErgoHistory] = synchronized { + def reportModifierIsValid(modifier: ErgoPersistentModifier): Try[ErgoHistory] = synchronized { log.debug(s"Modifier ${modifier.encodedId} of type ${modifier.modifierTypeId} is marked as valid ") modifier match { case fb: ErgoFullBlock => @@ -115,7 +124,7 @@ trait ErgoHistory * @return ProgressInfo with next modifier to try to apply */ @SuppressWarnings(Array("OptionGet", "TraversableHead")) - override def reportModifierIsInvalid(modifier: ErgoPersistentModifier, + def reportModifierIsInvalid(modifier: ErgoPersistentModifier, progressInfo: ProgressInfo[ErgoPersistentModifier] ): Try[(ErgoHistory, ProgressInfo[ErgoPersistentModifier])] = synchronized { log.warn(s"Modifier ${modifier.encodedId} of type ${modifier.modifierTypeId} is marked as invalid") @@ -219,6 +228,12 @@ trait ErgoHistory } } } + + /** + * @return read-only copy of this history + */ + def getReader: ErgoHistoryReader = this + } object ErgoHistory extends ScorexLogging { diff --git a/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistoryReader.scala b/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistoryReader.scala index 5672caf84f..3c72c24898 100644 --- a/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistoryReader.scala +++ b/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistoryReader.scala @@ -11,8 +11,9 @@ import org.ergoplatform.nodeView.history.storage._ import org.ergoplatform.nodeView.history.storage.modifierprocessors._ import org.ergoplatform.nodeView.history.storage.modifierprocessors.popow.PoPoWProofsProcessor import org.ergoplatform.settings.ErgoSettings +import scorex.core.NodeViewComponent +import scorex.core.consensus.{ContainsModifiers, ModifierSemanticValidity} import scorex.core.consensus.History._ -import scorex.core.consensus.{HistoryReader, ModifierSemanticValidity} import scorex.core.utils.ScorexEncoding import scorex.core.validation.MalformedModifierError import scorex.util.{ModifierId, ScorexLogging} @@ -20,12 +21,14 @@ import scorex.util.{ModifierId, ScorexLogging} import scala.annotation.tailrec import scala.reflect.ClassTag import scala.util.{Failure, Try} +import scorex.core.consensus.History._ /** * Read-only copy of ErgoHistory */ trait ErgoHistoryReader - extends HistoryReader + extends NodeViewComponent + with ContainsModifiers[ErgoPersistentModifier] with HeadersProcessor with PoPoWProofsProcessor with UTXOSnapshotChunkProcessor @@ -116,7 +119,7 @@ trait ErgoHistoryReader * @return Equal if nodes have the same history, Younger if another node is behind, Older if a new node is ahead, * Fork if other peer is on another chain, Unknown if we can't deduct neighbour's status */ - override def compare(info: ErgoSyncInfo): HistoryComparisonResult = { + def compare(info: ErgoSyncInfo): HistoryComparisonResult = { info match { case syncV1: ErgoSyncInfoV1 => compareV1(syncV1) @@ -293,7 +296,7 @@ trait ErgoHistoryReader * @param size max return size * @return Ids of headers, that node with info should download and apply to synchronize */ - override def continuationIds(syncInfo: ErgoSyncInfo, size: Int): ModifierIds = { + def continuationIds(syncInfo: ErgoSyncInfo, size: Int): ModifierIds = { syncInfo match { case syncV1: ErgoSyncInfoV1 => continuationIdsV1(syncV1, size) case syncV2: ErgoSyncInfoV2 => continuationIdsV2(syncV2, size) @@ -396,7 +399,13 @@ trait ErgoHistoryReader (offset until (limit + offset)).flatMap(height => bestHeaderIdAtHeight(height)) } - override def applicableTry(modifier: ErgoPersistentModifier): Try[Unit] = { + /** + * Whether a modifier could be applied to the history + * + * @param modifier - modifier to apply + * @return `Success` if modifier can be applied, `Failure(ModifierError)` if can not + */ + def applicableTry(modifier: ErgoPersistentModifier): Try[Unit] = { modifier match { case header: Header => validate(header) @@ -501,6 +510,12 @@ trait ErgoHistoryReader (ourChain, commonBlockThenSuffixes) } + /** + * Return semantic validity status of modifier with id == modifierId + * + * @param modifierId - modifier id to check + * @return + */ override def isSemanticallyValid(modifierId: ModifierId): ModifierSemanticValidity = { historyStorage.getIndex(validityKey(modifierId)) match { case Some(b) if b.headOption.contains(Valid) => ModifierSemanticValidity.Valid diff --git a/src/main/scala/org/ergoplatform/nodeView/mempool/ErgoMemPool.scala b/src/main/scala/org/ergoplatform/nodeView/mempool/ErgoMemPool.scala index abd12c6a3b..45b105c5ec 100644 --- a/src/main/scala/org/ergoplatform/nodeView/mempool/ErgoMemPool.scala +++ b/src/main/scala/org/ergoplatform/nodeView/mempool/ErgoMemPool.scala @@ -6,7 +6,6 @@ import org.ergoplatform.modifiers.mempool.ErgoTransaction import org.ergoplatform.nodeView.mempool.OrderedTxPool.WeightedTxId import org.ergoplatform.nodeView.state.{ErgoState, UtxoState} import org.ergoplatform.settings.{ErgoSettings, MonetarySettings, NodeConfigurationSettings} -import scorex.core.transaction.MemoryPool import scorex.core.transaction.state.TransactionValidation import scorex.util.{ModifierId, ScorexLogging, bytesToId} import OrderedTxPool.weighted @@ -27,7 +26,7 @@ import scala.util.Try */ class ErgoMemPool private[mempool](pool: OrderedTxPool, private[mempool] val stats : MemPoolStatistics)(implicit settings: ErgoSettings) - extends MemoryPool[ErgoMemPool] with ErgoMemPoolReader with ScorexLogging { + extends ErgoMemPoolReader with ScorexLogging { import ErgoMemPool._ import EmissionRules.CoinsInOneErgo @@ -70,28 +69,36 @@ class ErgoMemPool private[mempool](pool: OrderedTxPool, */ override def getAllPrioritized: Seq[ErgoTransaction] = pool.orderedTransactions.values.toSeq - override def put(tx: ErgoTransaction): Try[ErgoMemPool] = put(Seq(tx)) + /** + * Method to put a transaction into the memory pool. Validation of tha transactions against + * the state is done in NodeVieHolder. This put() method can check whether a transaction is valid + * @param tx + * @return Success(updatedPool), if transaction successfully added to the pool, Failure(_) otherwise + */ + def put(tx: ErgoTransaction): Try[ErgoMemPool] = put(Seq(tx)) - override def put(txs: Iterable[ErgoTransaction]): Try[ErgoMemPool] = Try { + def put(txs: Iterable[ErgoTransaction]): Try[ErgoMemPool] = Try { putWithoutCheck(txs.filterNot(tx => pool.contains(tx.id))) } - override def putWithoutCheck(txs: Iterable[ErgoTransaction]): ErgoMemPool = { + def putWithoutCheck(txs: Iterable[ErgoTransaction]): ErgoMemPool = { val updatedPool = txs.toSeq.distinct.foldLeft(pool) { case (acc, tx) => acc.put(tx) } new ErgoMemPool(updatedPool, stats) } - override def remove(tx: ErgoTransaction): ErgoMemPool = { + def remove(tx: ErgoTransaction): ErgoMemPool = { val wtx = pool.transactionsRegistry.get(tx.id) val updStats = wtx.map(wgtx => stats.add(System.currentTimeMillis(), wgtx)) .getOrElse(MemPoolStatistics(System.currentTimeMillis(), 0, System.currentTimeMillis())) new ErgoMemPool(pool.remove(tx), updStats) } - override def filter(condition: ErgoTransaction => Boolean): ErgoMemPool = { + def filter(condition: ErgoTransaction => Boolean): ErgoMemPool = { new ErgoMemPool(pool.filter(condition), stats) } + def filter(txs: Seq[ErgoTransaction]): ErgoMemPool = filter(t => !txs.exists(_.id == t.id)) + /** * Invalidate transaction and delete it from pool * @@ -230,6 +237,11 @@ class ErgoMemPool private[mempool](pool: OrderedTxPool, 0 } } + + /** + * @return read-only copy of this history + */ + def getReader: ErgoMemPoolReader = this } object ErgoMemPool { diff --git a/src/main/scala/org/ergoplatform/nodeView/mempool/ErgoMemPoolReader.scala b/src/main/scala/org/ergoplatform/nodeView/mempool/ErgoMemPoolReader.scala index ce641320da..611ed53d2d 100644 --- a/src/main/scala/org/ergoplatform/nodeView/mempool/ErgoMemPoolReader.scala +++ b/src/main/scala/org/ergoplatform/nodeView/mempool/ErgoMemPoolReader.scala @@ -3,16 +3,17 @@ package org.ergoplatform.nodeView.mempool import org.ergoplatform.ErgoBox.BoxId import org.ergoplatform.modifiers.mempool.ErgoTransaction import org.ergoplatform.nodeView.mempool.OrderedTxPool.WeightedTxId -import scorex.core.transaction.MempoolReader +import scorex.core.NodeViewComponent +import scorex.core.consensus.ContainsModifiers import scorex.util.ModifierId -trait ErgoMemPoolReader extends MempoolReader { +trait ErgoMemPoolReader extends NodeViewComponent with ContainsModifiers[ErgoTransaction] { - override def contains(id: ModifierId): Boolean + def contains(id: ModifierId): Boolean - override def getAll(ids: Seq[ModifierId]): Seq[ErgoTransaction] + def getAll(ids: Seq[ModifierId]): Seq[ErgoTransaction] - override def size: Int + def size: Int /** * @return inputs spent by the mempool transactions diff --git a/src/main/scala/org/ergoplatform/nodeView/wallet/ErgoWallet.scala b/src/main/scala/org/ergoplatform/nodeView/wallet/ErgoWallet.scala index febc3bf7a8..d1838ee308 100644 --- a/src/main/scala/org/ergoplatform/nodeView/wallet/ErgoWallet.scala +++ b/src/main/scala/org/ergoplatform/nodeView/wallet/ErgoWallet.scala @@ -9,16 +9,13 @@ import org.ergoplatform.nodeView.wallet.ErgoWalletActor._ import org.ergoplatform.settings.{ErgoSettings, Parameters} import org.ergoplatform.wallet.boxes.{ReemissionData, ReplaceCompactCollectBoxSelector} import scorex.core.VersionTag -import scorex.core.transaction.wallet.Vault import scorex.util.ScorexLogging import scala.util.{Failure, Success, Try} class ErgoWallet(historyReader: ErgoHistoryReader, settings: ErgoSettings, parameters: Parameters) (implicit val actorSystem: ActorSystem) - extends Vault[ErgoTransaction, ErgoPersistentModifier, ErgoWallet] - with ErgoWalletReader - with ScorexLogging { + extends ErgoWalletReader with ScorexLogging { private val walletSettings = settings.walletSettings @@ -39,17 +36,17 @@ class ErgoWallet(historyReader: ErgoHistoryReader, settings: ErgoSettings, param override val walletActor: ActorRef = ErgoWalletActor(settings, parameters, new ErgoWalletServiceImpl(settings), boxSelector, historyReader) - override def scanOffchain(tx: ErgoTransaction): ErgoWallet = { + def scanOffchain(tx: ErgoTransaction): ErgoWallet = { walletActor ! ScanOffChain(tx) this } - override def scanOffchain(txs: Seq[ErgoTransaction]): ErgoWallet = { + def scanOffchain(txs: Seq[ErgoTransaction]): ErgoWallet = { txs.foreach(tx => scanOffchain(tx)) this } - override def scanPersistent(modifier: ErgoPersistentModifier): ErgoWallet = { + def scanPersistent(modifier: ErgoPersistentModifier): ErgoWallet = { modifier match { case fb: ErgoFullBlock => walletActor ! ScanOnChain(fb) @@ -60,7 +57,13 @@ class ErgoWallet(historyReader: ErgoHistoryReader, settings: ErgoSettings, param this } - override def rollback(to: VersionTag): Try[ErgoWallet] = + def scanPersistent(modifiers: Option[ErgoPersistentModifier]): ErgoWallet = { + modifiers.foldLeft(this) { case (v, mod) => + v.scanPersistent(mod) + } + } + + def rollback(to: VersionTag): Try[ErgoWallet] = historyReader.heightOf(scorex.core.versionToId(to)) match { case Some(_) => walletActor ! Rollback(to) @@ -71,6 +74,11 @@ class ErgoWallet(historyReader: ErgoHistoryReader, settings: ErgoSettings, param case None => Failure(new Exception(s"Height of a modifier with id $to not found")) } + + /** + * @return read-only copy of this state + */ + def getReader: ErgoWalletReader = this } diff --git a/src/main/scala/org/ergoplatform/nodeView/wallet/ErgoWalletActor.scala b/src/main/scala/org/ergoplatform/nodeView/wallet/ErgoWalletActor.scala index 98b8230f6c..6e95385e02 100644 --- a/src/main/scala/org/ergoplatform/nodeView/wallet/ErgoWalletActor.scala +++ b/src/main/scala/org/ergoplatform/nodeView/wallet/ErgoWalletActor.scala @@ -72,7 +72,7 @@ class ErgoWalletActor(settings: ErgoSettings, ErgoWalletState.initial(settings, parameters) match { case Success(state) => context.system.eventStream.subscribe(self, classOf[ChangedState]) - context.system.eventStream.subscribe(self, classOf[ChangedMempool[_]]) + context.system.eventStream.subscribe(self, classOf[ChangedMempool]) self ! ReadWallet(state) case Failure(ex) => log.error("Unable to initialize wallet", ex) diff --git a/src/main/scala/org/ergoplatform/nodeView/wallet/ErgoWalletReader.scala b/src/main/scala/org/ergoplatform/nodeView/wallet/ErgoWalletReader.scala index dc53ff9436..8752edd59a 100644 --- a/src/main/scala/org/ergoplatform/nodeView/wallet/ErgoWalletReader.scala +++ b/src/main/scala/org/ergoplatform/nodeView/wallet/ErgoWalletReader.scala @@ -18,14 +18,14 @@ import org.ergoplatform.wallet.boxes.ChainStatus import org.ergoplatform.wallet.boxes.ChainStatus.{OffChain, OnChain} import org.ergoplatform.wallet.Constants.ScanId import org.ergoplatform.wallet.interpreter.TransactionHintsBag -import scorex.core.transaction.wallet.VaultReader +import scorex.core.NodeViewComponent import scorex.util.ModifierId import sigmastate.Values.SigmaBoolean import scala.concurrent.Future import scala.util.Try -trait ErgoWalletReader extends VaultReader { +trait ErgoWalletReader extends NodeViewComponent { val walletActor: ActorRef diff --git a/src/main/scala/scorex/core/consensus/History.scala b/src/main/scala/scorex/core/consensus/History.scala index b84767fad8..f75984e3f2 100644 --- a/src/main/scala/scorex/core/consensus/History.scala +++ b/src/main/scala/scorex/core/consensus/History.scala @@ -1,56 +1,10 @@ package scorex.core.consensus -import org.ergoplatform.modifiers.ErgoPersistentModifier -import scorex.core.consensus.History.ProgressInfo import scorex.core.utils.ScorexEncoder import scorex.core.{ModifierTypeId, PersistentNodeViewModifier} import scorex.util.ModifierId -import scala.util.Try -/** - * History of a blockchain system is some blocktree in fact - * (like this: http://image.slidesharecdn.com/sfbitcoindev-chepurnoy-2015-150322043044-conversion-gate01/95/proofofstake-its-improvements-san-francisco-bitcoin-devs-hackathon-12-638.jpg), - * where longest chain is being considered as canonical one, containing right kind of history. - * - * In cryptocurrencies of today blocktree view is usually implicit, means code supports only linear history, - * but other options are possible. - * - * To say "longest chain" is the canonical one is simplification, usually some kind of "cumulative difficulty" - * function has been used instead. - */ - -trait History[HT <: History[HT]] extends HistoryReader { - - /** - * @return append modifier to history - */ - def append(modifier: ErgoPersistentModifier): Try[(HT, ProgressInfo[ErgoPersistentModifier])] - - /** - * Report that modifier is valid from point of view of the state component - * - * @param modifier - valid modifier - * @return modified history - */ - def reportModifierIsValid(modifier: ErgoPersistentModifier): Try[HT] - - /** - * Report that modifier is invalid from other nodeViewHolder components point of view - * - * @param modifier - invalid modifier - * @param progressInfo - what suffix failed to be applied because of an invalid modifier - * @return modified history and new progress info - */ - def reportModifierIsInvalid(modifier: ErgoPersistentModifier, progressInfo: ProgressInfo[ErgoPersistentModifier]): Try[(HT, ProgressInfo[ErgoPersistentModifier])] - - - /** - * @return read-only copy of this history - */ - def getReader: HistoryReader = this - -} object History { diff --git a/src/main/scala/scorex/core/consensus/HistoryReader.scala b/src/main/scala/scorex/core/consensus/HistoryReader.scala deleted file mode 100644 index 016a83353f..0000000000 --- a/src/main/scala/scorex/core/consensus/HistoryReader.scala +++ /dev/null @@ -1,48 +0,0 @@ -package scorex.core.consensus - -import org.ergoplatform.modifiers.ErgoPersistentModifier -import org.ergoplatform.nodeView.history.ErgoSyncInfo -import scorex.core.NodeViewComponent -import scorex.util.ModifierId - -import scala.util.Try - - -trait HistoryReader extends NodeViewComponent with ContainsModifiers[ErgoPersistentModifier] { - - import History._ - - /** - * Is there's no history, even genesis block - */ - def isEmpty: Boolean - - /** - * Whether a modifier could be applied to the history - * - * @param modifier - modifier to apply - * @return `Success` if modifier can be applied, `Failure(ModifierError)` if can not - */ - def applicableTry(modifier: ErgoPersistentModifier): Try[Unit] - - /** - * Return semantic validity status of modifier with id == modifierId - * - * @param modifierId - modifier id to check - * @return - */ - def isSemanticallyValid(modifierId: ModifierId): ModifierSemanticValidity - - /** - * Ids of modifiers, that node with info should download and apply to synchronize - */ - def continuationIds(info: ErgoSyncInfo, size: Int): ModifierIds - - /** - * Whether another's node syncinfo shows that another node is ahead or behind ours - * - * @param other other's node sync info - * @return Equal if nodes have the same history, Younger if another node is behind, Older if a new node is ahead - */ - def compare(other: ErgoSyncInfo): HistoryComparisonResult -} diff --git a/src/main/scala/scorex/core/transaction/MemoryPool.scala b/src/main/scala/scorex/core/transaction/MemoryPool.scala deleted file mode 100644 index 261a80397f..0000000000 --- a/src/main/scala/scorex/core/transaction/MemoryPool.scala +++ /dev/null @@ -1,35 +0,0 @@ -package scorex.core.transaction - -import org.ergoplatform.modifiers.mempool.ErgoTransaction - -import scala.util.Try - -/** - * Unconfirmed transactions pool - * - */ -trait MemoryPool[M <: MemoryPool[M]] extends MempoolReader { - - /** - * Method to put a transaction into the memory pool. Validation of tha transactions against - * the state is done in NodeVieHolder. This put() method can check whether a transaction is valid - * @param tx - * @return Success(updatedPool), if transaction successfully added to the pool, Failure(_) otherwise - */ - def put(tx: ErgoTransaction): Try[M] - - def put(txs: Iterable[ErgoTransaction]): Try[M] - - def putWithoutCheck(txs: Iterable[ErgoTransaction]): M - - def remove(tx: ErgoTransaction): M - - def filter(txs: Seq[ErgoTransaction]): M = filter(t => !txs.exists(_.id == t.id)) - - def filter(condition: ErgoTransaction => Boolean): M - - /** - * @return read-only copy of this history - */ - def getReader: MempoolReader = this -} diff --git a/src/main/scala/scorex/core/transaction/MempoolReader.scala b/src/main/scala/scorex/core/transaction/MempoolReader.scala deleted file mode 100644 index ad64b1094e..0000000000 --- a/src/main/scala/scorex/core/transaction/MempoolReader.scala +++ /dev/null @@ -1,25 +0,0 @@ -package scorex.core.transaction - -import org.ergoplatform.modifiers.mempool.ErgoTransaction -import scorex.core.consensus.ContainsModifiers -import scorex.core.NodeViewComponent -import scorex.util.ModifierId - -/** - * Unconfirmed transactions pool - * - */ -trait MempoolReader extends NodeViewComponent with ContainsModifiers[ErgoTransaction] { - - //getters - override def modifierById(modifierId: ModifierId): Option[ErgoTransaction] - - def contains(id: ModifierId): Boolean - - def getAll(ids: Seq[ModifierId]): Seq[ErgoTransaction] - - def size: Int - - def take(limit: Int): Iterable[ErgoTransaction] - -} diff --git a/src/main/scala/scorex/core/transaction/wallet/Vault.scala b/src/main/scala/scorex/core/transaction/wallet/Vault.scala deleted file mode 100644 index 4b4d4e0769..0000000000 --- a/src/main/scala/scorex/core/transaction/wallet/Vault.scala +++ /dev/null @@ -1,32 +0,0 @@ -package scorex.core.transaction.wallet - -import scorex.core.transaction.Transaction -import scorex.core.{PersistentNodeViewModifier, VersionTag} - -import scala.util.Try - -/** - * Abstract interface for Vault, a storage for node-specific information - */ - -trait Vault[TX <: Transaction, PMOD <: PersistentNodeViewModifier, V <: Vault[TX, PMOD, V]] extends VaultReader { - self: V => - - def scanOffchain(tx: TX): V - - def scanOffchain(txs: Seq[TX]): V - - def scanPersistent(modifier: PMOD): V - - def scanPersistent(modifiers: Option[PMOD]): V = modifiers.foldLeft(this) { case (v, mod) => - v.scanPersistent(mod) - } - - def rollback(to: VersionTag): Try[V] - - /** - * @return read-only copy of this state - */ - def getReader: VaultReader = this - -} \ No newline at end of file diff --git a/src/main/scala/scorex/core/transaction/wallet/VaultReader.scala b/src/main/scala/scorex/core/transaction/wallet/VaultReader.scala deleted file mode 100644 index 29bdb63d47..0000000000 --- a/src/main/scala/scorex/core/transaction/wallet/VaultReader.scala +++ /dev/null @@ -1,9 +0,0 @@ -package scorex.core.transaction.wallet - -import scorex.core.NodeViewComponent - -/** - * Reader for vault. - * As vault is implementation-specific component, it does not contain any mandatory methods. - */ -trait VaultReader extends NodeViewComponent \ No newline at end of file From cec2745be333ae21369dea6f953c98ed3e71ad26 Mon Sep 17 00:00:00 2001 From: Alex Chepurnoy Date: Mon, 4 Jul 2022 19:05:15 +0300 Subject: [PATCH 4/8] traits Proposition and Box removed --- .../wallet/requests/AssetIssueRequest.scala | 7 +++---- .../scorex/core/transaction/box/Box.scala | 20 ------------------- .../box/proposition/Proposition.scala | 5 ----- 3 files changed, 3 insertions(+), 29 deletions(-) delete mode 100644 src/main/scala/scorex/core/transaction/box/Box.scala delete mode 100644 src/main/scala/scorex/core/transaction/box/proposition/Proposition.scala diff --git a/src/main/scala/org/ergoplatform/nodeView/wallet/requests/AssetIssueRequest.scala b/src/main/scala/org/ergoplatform/nodeView/wallet/requests/AssetIssueRequest.scala index 785d7223e9..714e8cb61f 100644 --- a/src/main/scala/org/ergoplatform/nodeView/wallet/requests/AssetIssueRequest.scala +++ b/src/main/scala/org/ergoplatform/nodeView/wallet/requests/AssetIssueRequest.scala @@ -7,7 +7,6 @@ import org.ergoplatform.ErgoBox.NonMandatoryRegisterId import org.ergoplatform.http.api.ApiCodecs import org.ergoplatform.nodeView.wallet.ErgoAddressJsonEncoder import org.ergoplatform.settings.ErgoSettings -import scorex.core.transaction.box.Box.Amount import sigmastate.SType import sigmastate.Values.EvaluatedValue @@ -24,7 +23,7 @@ import sigmastate.Values.EvaluatedValue */ case class AssetIssueRequest(addressOpt: Option[ErgoAddress], valueOpt: Option[Long], - amount: Amount, + amount: Long, name: String, description: String, decimals: Int, @@ -35,7 +34,7 @@ object AssetIssueRequest { def apply(address: ErgoAddress, valueOpt: Option[Long], - amount: Amount, + amount: Long, name: String, description: String, decimals: Int, @@ -71,7 +70,7 @@ class AssetIssueRequestDecoder(settings: ErgoSettings) extends Decoder[AssetIssu for { address <- cursor.downField("address").as[Option[ErgoAddress]] value <- cursor.downField("ergValue").as[Option[Long]] - amount <- cursor.downField("amount").as[Amount] + amount <- cursor.downField("amount").as[Long] name <- cursor.downField("name").as[String] description <- cursor.downField("description").as[String] decimals <- cursor.downField("decimals").as[Int] diff --git a/src/main/scala/scorex/core/transaction/box/Box.scala b/src/main/scala/scorex/core/transaction/box/Box.scala deleted file mode 100644 index 64bda2c971..0000000000 --- a/src/main/scala/scorex/core/transaction/box/Box.scala +++ /dev/null @@ -1,20 +0,0 @@ -package scorex.core.transaction.box - -import scorex.core.serialization.BytesSerializable -import scorex.core.transaction.box.proposition.Proposition -import scorex.crypto.authds._ - -/** - * Box is a state element locked by some proposition. - */ -trait Box[P <: Proposition] extends BytesSerializable { - val value: Box.Amount - val proposition: P - - val id: ADKey -} - -object Box { - type Amount = Long -} - diff --git a/src/main/scala/scorex/core/transaction/box/proposition/Proposition.scala b/src/main/scala/scorex/core/transaction/box/proposition/Proposition.scala deleted file mode 100644 index 0d9a076fc1..0000000000 --- a/src/main/scala/scorex/core/transaction/box/proposition/Proposition.scala +++ /dev/null @@ -1,5 +0,0 @@ -package scorex.core.transaction.box.proposition - -import scorex.core.serialization.BytesSerializable - -trait Proposition extends BytesSerializable From 2465f861f76e93790a988c188c52d026c49962f1 Mon Sep 17 00:00:00 2001 From: Alex Chepurnoy Date: Mon, 4 Jul 2022 23:58:52 +0300 Subject: [PATCH 5/8] History object eliminated --- .../network/ErgoNodeViewSynchronizer.scala | 2 +- .../ergoplatform/network/ErgoPeerStatus.scala | 2 +- .../network/ErgoSyncTracker.scala | 2 +- .../nodeView/ErgoNodeViewHolder.scala | 2 +- .../nodeView/history/ErgoHistory.scala | 2 +- .../nodeView/history/ErgoHistoryReader.scala | 8 +-- .../BlockSectionProcessor.scala | 2 +- .../EmptyBlockSectionProcessor.scala | 2 +- .../FullBlockProcessor.scala | 2 +- .../FullBlockSectionProcessor.scala | 2 +- .../modifierprocessors/HeadersProcessor.scala | 2 +- .../UTXOSnapshotChunkProcessor.scala | 2 +- .../popow/EmptyPoPoWProofsProcessor.scala | 2 +- .../popow/FullPoPoWProofsProcessor.scala | 2 +- .../popow/PoPoWProofsProcessor.scala | 2 +- .../scala/scorex/core/consensus/History.scala | 53 ------------------- .../consensus/HistoryComparisonResult.scala | 16 ++++++ .../scorex/core/consensus/ProgressInfo.scala | 31 +++++++++++ .../ErgoSyncTrackerSpecification.scala | 2 +- .../NonVerifyADHistorySpecification.scala | 2 +- .../VerifyADHistorySpecification.scala | 2 +- .../VerifyNonADHistorySpecification.scala | 2 +- 22 files changed, 69 insertions(+), 75 deletions(-) delete mode 100644 src/main/scala/scorex/core/consensus/History.scala create mode 100644 src/main/scala/scorex/core/consensus/HistoryComparisonResult.scala create mode 100644 src/main/scala/scorex/core/consensus/ProgressInfo.scala diff --git a/src/main/scala/org/ergoplatform/network/ErgoNodeViewSynchronizer.scala b/src/main/scala/org/ergoplatform/network/ErgoNodeViewSynchronizer.scala index 8684e99a85..fab6158302 100644 --- a/src/main/scala/org/ergoplatform/network/ErgoNodeViewSynchronizer.scala +++ b/src/main/scala/org/ergoplatform/network/ErgoNodeViewSynchronizer.scala @@ -17,7 +17,7 @@ import org.ergoplatform.nodeView.mempool.{ErgoMemPool, ErgoMemPoolReader} import org.ergoplatform.settings.{Constants, ErgoSettings} import org.ergoplatform.nodeView.ErgoNodeViewHolder.ReceivableMessages.{ChainIsHealthy, ChainIsStuck, GetNodeViewChanges, IsChainHealthy, ModifiersFromRemote, TransactionsFromRemote} import org.ergoplatform.nodeView.ErgoNodeViewHolder._ -import scorex.core.consensus.History.{Equal, Fork, Nonsense, Older, Unknown, Younger} +import scorex.core.consensus.{Equal, Fork, Nonsense, Older, Unknown, Younger} import scorex.core.network.ModifiersStatus.Requested import scorex.core.{ModifierTypeId, NodeViewModifier, PersistentNodeViewModifier, idsToString} import scorex.core.network.NetworkController.ReceivableMessages.{PenalizePeer, RegisterMessageSpecs} diff --git a/src/main/scala/org/ergoplatform/network/ErgoPeerStatus.scala b/src/main/scala/org/ergoplatform/network/ErgoPeerStatus.scala index ebb9811efa..879695cbf0 100644 --- a/src/main/scala/org/ergoplatform/network/ErgoPeerStatus.scala +++ b/src/main/scala/org/ergoplatform/network/ErgoPeerStatus.scala @@ -3,7 +3,7 @@ package org.ergoplatform.network import io.circe.{Encoder, Json} import org.ergoplatform.nodeView.history.ErgoHistory.Height import scorex.core.app.Version -import scorex.core.consensus.History.HistoryComparisonResult +import scorex.core.consensus.HistoryComparisonResult import scorex.core.network.ConnectedPeer import scorex.core.utils.TimeProvider.Time diff --git a/src/main/scala/org/ergoplatform/network/ErgoSyncTracker.scala b/src/main/scala/org/ergoplatform/network/ErgoSyncTracker.scala index 521574fb6a..e008b006aa 100644 --- a/src/main/scala/org/ergoplatform/network/ErgoSyncTracker.scala +++ b/src/main/scala/org/ergoplatform/network/ErgoSyncTracker.scala @@ -5,7 +5,7 @@ import java.net.InetSocketAddress import akka.actor.ActorSystem import org.ergoplatform.nodeView.history.ErgoHistory import org.ergoplatform.nodeView.history.ErgoHistory.Height -import scorex.core.consensus.History.{Fork, HistoryComparisonResult, Older, Unknown} +import scorex.core.consensus.{Fork, HistoryComparisonResult, Older, Unknown} import org.ergoplatform.network.ErgoNodeViewSynchronizer.Events.{BetterNeighbourAppeared, NoBetterNeighbour} import scorex.core.network.ConnectedPeer import scorex.core.settings.NetworkSettings diff --git a/src/main/scala/org/ergoplatform/nodeView/ErgoNodeViewHolder.scala b/src/main/scala/org/ergoplatform/nodeView/ErgoNodeViewHolder.scala index bcd446b0f4..9eb5002d54 100644 --- a/src/main/scala/org/ergoplatform/nodeView/ErgoNodeViewHolder.scala +++ b/src/main/scala/org/ergoplatform/nodeView/ErgoNodeViewHolder.scala @@ -19,7 +19,7 @@ import scorex.core._ import org.ergoplatform.network.ErgoNodeViewSynchronizer.ReceivableMessages._ import org.ergoplatform.nodeView.ErgoNodeViewHolder.{BlockAppliedTransactions, CurrentView, DownloadRequest} import org.ergoplatform.nodeView.ErgoNodeViewHolder.ReceivableMessages._ -import scorex.core.consensus.History.ProgressInfo +import scorex.core.consensus.ProgressInfo import scorex.core.settings.ScorexSettings import scorex.core.utils.{NetworkTimeProvider, ScorexEncoding} import scorex.core.validation.RecoverableModifierError diff --git a/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistory.scala b/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistory.scala index 6be580882f..5dc208784a 100644 --- a/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistory.scala +++ b/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistory.scala @@ -13,7 +13,7 @@ import org.ergoplatform.nodeView.history.storage.modifierprocessors._ import org.ergoplatform.nodeView.history.storage.modifierprocessors.popow.{EmptyPoPoWProofsProcessor, FullPoPoWProofsProcessor} import org.ergoplatform.settings._ import org.ergoplatform.utils.LoggingUtil -import scorex.core.consensus.History.ProgressInfo +import scorex.core.consensus.ProgressInfo import scorex.core.utils.NetworkTimeProvider import scorex.core.validation.RecoverableModifierError import scorex.util.{ModifierId, ScorexLogging, idToBytes} diff --git a/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistoryReader.scala b/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistoryReader.scala index 3c72c24898..3273aa5949 100644 --- a/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistoryReader.scala +++ b/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistoryReader.scala @@ -11,9 +11,8 @@ import org.ergoplatform.nodeView.history.storage._ import org.ergoplatform.nodeView.history.storage.modifierprocessors._ import org.ergoplatform.nodeView.history.storage.modifierprocessors.popow.PoPoWProofsProcessor import org.ergoplatform.settings.ErgoSettings -import scorex.core.NodeViewComponent -import scorex.core.consensus.{ContainsModifiers, ModifierSemanticValidity} -import scorex.core.consensus.History._ +import scorex.core.{ModifierTypeId, NodeViewComponent} +import scorex.core.consensus.{ContainsModifiers, Equal, Fork, HistoryComparisonResult, ModifierSemanticValidity, Older, Unknown, Younger} import scorex.core.utils.ScorexEncoding import scorex.core.validation.MalformedModifierError import scorex.util.{ModifierId, ScorexLogging} @@ -21,7 +20,6 @@ import scorex.util.{ModifierId, ScorexLogging} import scala.annotation.tailrec import scala.reflect.ClassTag import scala.util.{Failure, Try} -import scorex.core.consensus.History._ /** * Read-only copy of ErgoHistory @@ -36,6 +34,8 @@ trait ErgoHistoryReader with ScorexLogging with ScorexEncoding { + type ModifierIds = Seq[(ModifierTypeId, ModifierId)] + protected[history] val historyStorage: HistoryStorage protected val settings: ErgoSettings diff --git a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/BlockSectionProcessor.scala b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/BlockSectionProcessor.scala index e6518a16d1..f1a258b665 100644 --- a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/BlockSectionProcessor.scala +++ b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/BlockSectionProcessor.scala @@ -1,7 +1,7 @@ package org.ergoplatform.nodeView.history.storage.modifierprocessors import org.ergoplatform.modifiers.{BlockSection, ErgoPersistentModifier} -import scorex.core.consensus.History.ProgressInfo +import scorex.core.consensus.ProgressInfo import scorex.core.utils.ScorexEncoding import scala.util.Try diff --git a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/EmptyBlockSectionProcessor.scala b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/EmptyBlockSectionProcessor.scala index fd9c88ff64..91f44c2a9f 100644 --- a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/EmptyBlockSectionProcessor.scala +++ b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/EmptyBlockSectionProcessor.scala @@ -1,7 +1,7 @@ package org.ergoplatform.nodeView.history.storage.modifierprocessors import org.ergoplatform.modifiers.{BlockSection, ErgoPersistentModifier} -import scorex.core.consensus.History.ProgressInfo +import scorex.core.consensus.ProgressInfo import scala.util.{Failure, Success, Try} diff --git a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/FullBlockProcessor.scala b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/FullBlockProcessor.scala index b69eefacbd..6095eb6257 100644 --- a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/FullBlockProcessor.scala +++ b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/FullBlockProcessor.scala @@ -5,7 +5,7 @@ import org.ergoplatform.modifiers.history.header.Header import org.ergoplatform.modifiers.{ErgoFullBlock, ErgoPersistentModifier} import org.ergoplatform.nodeView.history.ErgoHistory import org.ergoplatform.settings.Algos -import scorex.core.consensus.History.ProgressInfo +import scorex.core.consensus.ProgressInfo import scorex.db.ByteArrayWrapper import scorex.util.{ModifierId, bytesToId, idToBytes} diff --git a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/FullBlockSectionProcessor.scala b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/FullBlockSectionProcessor.scala index 90ac059aeb..dc6c4c37d8 100644 --- a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/FullBlockSectionProcessor.scala +++ b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/FullBlockSectionProcessor.scala @@ -6,7 +6,7 @@ import org.ergoplatform.modifiers.history.header.Header import org.ergoplatform.modifiers.{BlockSection, ErgoFullBlock, ErgoPersistentModifier} import org.ergoplatform.settings.ValidationRules._ import org.ergoplatform.settings.{Algos, ErgoValidationSettings} -import scorex.core.consensus.History.ProgressInfo +import scorex.core.consensus.ProgressInfo import scorex.core.utils.ScorexEncoding import scorex.core.validation.{ModifierValidator, _} import scorex.util.ModifierId diff --git a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/HeadersProcessor.scala b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/HeadersProcessor.scala index 60ec277c71..b79724928d 100644 --- a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/HeadersProcessor.scala +++ b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/HeadersProcessor.scala @@ -14,7 +14,7 @@ import org.ergoplatform.nodeView.history.storage.HistoryStorage import org.ergoplatform.settings.Constants.HashLength import org.ergoplatform.settings.ValidationRules._ import org.ergoplatform.settings._ -import scorex.core.consensus.History.ProgressInfo +import scorex.core.consensus.ProgressInfo import scorex.core.consensus.ModifierSemanticValidity import scorex.core.utils.ScorexEncoding import scorex.core.validation.{ModifierValidator, ValidationResult, ValidationState} diff --git a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/UTXOSnapshotChunkProcessor.scala b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/UTXOSnapshotChunkProcessor.scala index 70b55652fc..1ba0546a77 100644 --- a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/UTXOSnapshotChunkProcessor.scala +++ b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/UTXOSnapshotChunkProcessor.scala @@ -3,7 +3,7 @@ package org.ergoplatform.nodeView.history.storage.modifierprocessors import org.ergoplatform.modifiers.ErgoPersistentModifier import org.ergoplatform.modifiers.state.UTXOSnapshotChunk import org.ergoplatform.nodeView.history.storage.HistoryStorage -import scorex.core.consensus.History.ProgressInfo +import scorex.core.consensus.ProgressInfo import scorex.core.utils.ScorexEncoding import scorex.util.ScorexLogging diff --git a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/popow/EmptyPoPoWProofsProcessor.scala b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/popow/EmptyPoPoWProofsProcessor.scala index 2fd9604c09..ae18dc4d8a 100644 --- a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/popow/EmptyPoPoWProofsProcessor.scala +++ b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/popow/EmptyPoPoWProofsProcessor.scala @@ -2,7 +2,7 @@ package org.ergoplatform.nodeView.history.storage.modifierprocessors.popow import org.ergoplatform.modifiers.ErgoPersistentModifier import org.ergoplatform.modifiers.history.NipopowProofModifier -import scorex.core.consensus.History.ProgressInfo +import scorex.core.consensus.ProgressInfo import scala.util.{Failure, Success, Try} diff --git a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/popow/FullPoPoWProofsProcessor.scala b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/popow/FullPoPoWProofsProcessor.scala index 764104f1fa..0bc2479886 100644 --- a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/popow/FullPoPoWProofsProcessor.scala +++ b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/popow/FullPoPoWProofsProcessor.scala @@ -3,7 +3,7 @@ package org.ergoplatform.nodeView.history.storage.modifierprocessors.popow import org.ergoplatform.modifiers.ErgoPersistentModifier import org.ergoplatform.modifiers.history.NipopowProofModifier import org.ergoplatform.nodeView.history.storage.modifierprocessors.HeadersProcessor -import scorex.core.consensus.History.ProgressInfo +import scorex.core.consensus.ProgressInfo import scala.util.{Success, Try} diff --git a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/popow/PoPoWProofsProcessor.scala b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/popow/PoPoWProofsProcessor.scala index 1299df0995..6fdf3d4e44 100644 --- a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/popow/PoPoWProofsProcessor.scala +++ b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/popow/PoPoWProofsProcessor.scala @@ -3,7 +3,7 @@ package org.ergoplatform.nodeView.history.storage.modifierprocessors.popow import org.ergoplatform.modifiers.ErgoPersistentModifier import org.ergoplatform.modifiers.history.{HeaderChain, NipopowProofModifier} import org.ergoplatform.nodeView.history.storage.modifierprocessors.HeadersProcessor -import scorex.core.consensus.History.ProgressInfo +import scorex.core.consensus.ProgressInfo import scorex.util.ScorexLogging import scala.util.Try diff --git a/src/main/scala/scorex/core/consensus/History.scala b/src/main/scala/scorex/core/consensus/History.scala deleted file mode 100644 index f75984e3f2..0000000000 --- a/src/main/scala/scorex/core/consensus/History.scala +++ /dev/null @@ -1,53 +0,0 @@ -package scorex.core.consensus - -import scorex.core.utils.ScorexEncoder -import scorex.core.{ModifierTypeId, PersistentNodeViewModifier} -import scorex.util.ModifierId - - - -object History { - - type ModifierIds = Seq[(ModifierTypeId, ModifierId)] - - sealed trait HistoryComparisonResult - - case object Equal extends HistoryComparisonResult - - case object Younger extends HistoryComparisonResult - - case object Fork extends HistoryComparisonResult - - case object Older extends HistoryComparisonResult - - case object Nonsense extends HistoryComparisonResult - - case object Unknown extends HistoryComparisonResult - - /** - * Info returned by history to nodeViewHolder after modifier application - * - * @param branchPoint - branch point in case of rollback - * @param toRemove - modifiers to remove from current node view - * @param toApply - modifiers to apply to current node view - * @param toDownload - modifiers to download from other nodes - * @tparam PM - type of used modifier - */ - case class ProgressInfo[PM <: PersistentNodeViewModifier](branchPoint: Option[ModifierId], - toRemove: Seq[PM], - toApply: Seq[PM], - toDownload: Seq[(ModifierTypeId, ModifierId)]) - (implicit encoder: ScorexEncoder) { - - if (toRemove.nonEmpty) - require(branchPoint.isDefined, s"Branch point should be defined for non-empty `toRemove`") - - lazy val chainSwitchingNeeded: Boolean = toRemove.nonEmpty - - override def toString: String = { - s"ProgressInfo(BranchPoint: ${branchPoint.map(encoder.encodeId)}, " + - s" to remove: ${toRemove.map(_.encodedId)}, to apply: ${toApply.map(_.encodedId)})" - } - } - -} diff --git a/src/main/scala/scorex/core/consensus/HistoryComparisonResult.scala b/src/main/scala/scorex/core/consensus/HistoryComparisonResult.scala new file mode 100644 index 0000000000..b5c36b8c72 --- /dev/null +++ b/src/main/scala/scorex/core/consensus/HistoryComparisonResult.scala @@ -0,0 +1,16 @@ +package scorex.core.consensus + + +sealed trait HistoryComparisonResult + +case object Equal extends HistoryComparisonResult + +case object Younger extends HistoryComparisonResult + +case object Fork extends HistoryComparisonResult + +case object Older extends HistoryComparisonResult + +case object Nonsense extends HistoryComparisonResult + +case object Unknown extends HistoryComparisonResult diff --git a/src/main/scala/scorex/core/consensus/ProgressInfo.scala b/src/main/scala/scorex/core/consensus/ProgressInfo.scala new file mode 100644 index 0000000000..d540d897ef --- /dev/null +++ b/src/main/scala/scorex/core/consensus/ProgressInfo.scala @@ -0,0 +1,31 @@ +package scorex.core.consensus + +import scorex.core.utils.ScorexEncoder +import scorex.core.{ModifierTypeId, PersistentNodeViewModifier} +import scorex.util.ModifierId + +/** + * Info returned by history to nodeViewHolder after modifier application + * + * @param branchPoint - branch point in case of rollback + * @param toRemove - modifiers to remove from current node view + * @param toApply - modifiers to apply to current node view + * @param toDownload - modifiers to download from other nodes + * @tparam PM - type of used modifier + */ +case class ProgressInfo[PM <: PersistentNodeViewModifier](branchPoint: Option[ModifierId], + toRemove: Seq[PM], + toApply: Seq[PM], + toDownload: Seq[(ModifierTypeId, ModifierId)]) + (implicit encoder: ScorexEncoder) { + + if (toRemove.nonEmpty) + require(branchPoint.isDefined, s"Branch point should be defined for non-empty `toRemove`") + + lazy val chainSwitchingNeeded: Boolean = toRemove.nonEmpty + + override def toString: String = { + s"ProgressInfo(BranchPoint: ${branchPoint.map(encoder.encodeId)}, " + + s" to remove: ${toRemove.map(_.encodedId)}, to apply: ${toApply.map(_.encodedId)})" + } +} diff --git a/src/test/scala/org/ergoplatform/network/ErgoSyncTrackerSpecification.scala b/src/test/scala/org/ergoplatform/network/ErgoSyncTrackerSpecification.scala index b49e23560b..cfaac414ab 100644 --- a/src/test/scala/org/ergoplatform/network/ErgoSyncTrackerSpecification.scala +++ b/src/test/scala/org/ergoplatform/network/ErgoSyncTrackerSpecification.scala @@ -2,7 +2,7 @@ package org.ergoplatform.network import akka.actor.ActorSystem import org.ergoplatform.utils.ErgoPropertyTest -import scorex.core.consensus.History.{Older, Younger} +import scorex.core.consensus.{Older, Younger} import scorex.core.network.{ConnectedPeer, ConnectionId, Incoming} import scorex.core.network.peer.PeerInfo diff --git a/src/test/scala/org/ergoplatform/nodeView/history/NonVerifyADHistorySpecification.scala b/src/test/scala/org/ergoplatform/nodeView/history/NonVerifyADHistorySpecification.scala index c021234e35..43e3560112 100644 --- a/src/test/scala/org/ergoplatform/nodeView/history/NonVerifyADHistorySpecification.scala +++ b/src/test/scala/org/ergoplatform/nodeView/history/NonVerifyADHistorySpecification.scala @@ -9,8 +9,8 @@ import org.ergoplatform.modifiers.state.UTXOSnapshotChunk import org.ergoplatform.nodeView.state.StateType import org.ergoplatform.settings.Algos import org.ergoplatform.utils.HistoryTestHelpers -import scorex.core.consensus.History._ import scorex.crypto.hash.Digest32 +import scorex.core.consensus.{Older, Younger, Fork, Equal} import scala.util.Random diff --git a/src/test/scala/org/ergoplatform/nodeView/history/VerifyADHistorySpecification.scala b/src/test/scala/org/ergoplatform/nodeView/history/VerifyADHistorySpecification.scala index 81d7591e24..682b2d74a7 100644 --- a/src/test/scala/org/ergoplatform/nodeView/history/VerifyADHistorySpecification.scala +++ b/src/test/scala/org/ergoplatform/nodeView/history/VerifyADHistorySpecification.scala @@ -7,7 +7,7 @@ import org.ergoplatform.modifiers.{ErgoFullBlock, ErgoPersistentModifier} import org.ergoplatform.nodeView.ErgoModifiersCache import org.ergoplatform.nodeView.state.StateType import org.ergoplatform.utils.HistoryTestHelpers -import scorex.core.consensus.History.ProgressInfo +import scorex.core.consensus.ProgressInfo import scorex.core.consensus.ModifierSemanticValidity.{Absent, Invalid, Unknown, Valid} import scorex.testkit.utils.NoShrink diff --git a/src/test/scala/org/ergoplatform/nodeView/history/VerifyNonADHistorySpecification.scala b/src/test/scala/org/ergoplatform/nodeView/history/VerifyNonADHistorySpecification.scala index f03f6933b8..ce63ea22c5 100644 --- a/src/test/scala/org/ergoplatform/nodeView/history/VerifyNonADHistorySpecification.scala +++ b/src/test/scala/org/ergoplatform/nodeView/history/VerifyNonADHistorySpecification.scala @@ -9,7 +9,7 @@ import org.ergoplatform.nodeView.state.StateType import org.ergoplatform.settings.Algos import org.ergoplatform.utils.HistoryTestHelpers import scorex.core.ModifierTypeId -import scorex.core.consensus.History.ProgressInfo +import scorex.core.consensus.ProgressInfo class VerifyNonADHistorySpecification extends HistoryTestHelpers { import ToDownloadProcessor._ From c7aa9933098d4f057956a59fec1aeea836b2c87d Mon Sep 17 00:00:00 2001 From: Alex Chepurnoy Date: Tue, 5 Jul 2022 10:51:29 +0300 Subject: [PATCH 6/8] public API url removed --- src/main/resources/application.conf | 3 --- .../http/api/ErgoPeersApiRoute.scala | 9 +++---- .../local/ErgoStatsCollector.scala | 13 +++------- .../core/network/PeerConnectionHandler.scala | 3 +-- .../scala/scorex/core/network/PeerSpec.scala | 25 +++---------------- .../scorex/core/network/peer/PeerInfo.scala | 2 +- .../scala/scorex/core/settings/Settings.scala | 5 ++-- src/test/resources/application.conf | 6 ----- .../http/routes/ErgoPeersApiRouteSpec.scala | 5 +--- .../http/routes/TransactionApiRouteSpec.scala | 2 +- .../http/routes/UtilsApiRouteSpec.scala | 2 +- .../PeerFilteringRuleSpecification.scala | 2 +- .../settings/ErgoSettingsSpecification.scala | 5 ++-- .../utils/ErgoTestConstants.scala | 3 +-- .../testkit/generators/ObjectGenerators.scala | 4 +-- 15 files changed, 23 insertions(+), 66 deletions(-) diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index 1726c383ba..551d639f50 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -375,9 +375,6 @@ scorex { # request processing timeout timeout = 5s - - # node which exposes restApi in firewall should define publicly accessible URL of it - # publicUrl = "https://example.com:80" } # P2P Network settings diff --git a/src/main/scala/org/ergoplatform/http/api/ErgoPeersApiRoute.scala b/src/main/scala/org/ergoplatform/http/api/ErgoPeersApiRoute.scala index 5cc9aba07c..edefc4cc56 100644 --- a/src/main/scala/org/ergoplatform/http/api/ErgoPeersApiRoute.scala +++ b/src/main/scala/org/ergoplatform/http/api/ErgoPeersApiRoute.scala @@ -59,8 +59,7 @@ class ErgoPeersApiRoute(peerManager: ActorRef, lastMessage = con.lastMessage, lastHandshake = peerInfo.lastHandshake, name = peerInfo.peerSpec.nodeName, - connectionType = peerInfo.connectionType.map(_.toString), - restApiUrl = peerInfo.peerSpec.restApiUrl.map(_.toString) + connectionType = peerInfo.connectionType.map(_.toString) ) } } @@ -117,8 +116,7 @@ object ErgoPeersApiRoute { lastMessage: Long, lastHandshake: Long, name: String, - connectionType: Option[String], - restApiUrl: Option[String]) + connectionType: Option[String]) object PeerInfoResponse { def fromAddressAndInfo(address: InetSocketAddress, peerInfo: PeerInfo): PeerInfoResponse = PeerInfoResponse( @@ -126,8 +124,7 @@ object ErgoPeersApiRoute { 0, peerInfo.lastHandshake, peerInfo.peerSpec.nodeName, - peerInfo.connectionType.map(_.toString), - peerInfo.peerSpec.restApiUrl.map(_.toString) + peerInfo.connectionType.map(_.toString) ) @SuppressWarnings(Array("org.wartremover.warts.PublicInference")) diff --git a/src/main/scala/org/ergoplatform/local/ErgoStatsCollector.scala b/src/main/scala/org/ergoplatform/local/ErgoStatsCollector.scala index d3c5fb7fdf..189e4bc640 100644 --- a/src/main/scala/org/ergoplatform/local/ErgoStatsCollector.scala +++ b/src/main/scala/org/ergoplatform/local/ErgoStatsCollector.scala @@ -21,7 +21,6 @@ import scorex.core.utils.TimeProvider.Time import scorex.util.ScorexLogging import scorex.core.network.peer.PeersStatus -import java.net.URL import scala.concurrent.ExecutionContextExecutor import scala.concurrent.duration._ @@ -68,8 +67,7 @@ class ErgoStatsCollector(readersHolder: ActorRef, lastIncomingMessageTime = networkTime(), None, LaunchParameters, - eip27Supported = true, - settings.scorexSettings.restApi.publicUrl) + eip27Supported = true) override def receive: Receive = onConnectedPeers orElse @@ -195,16 +193,13 @@ object ErgoStatsCollector { lastIncomingMessageTime: Long, genesisBlockIdOpt: Option[String], parameters: Parameters, - eip27Supported: Boolean, - restApiUrl: Option[URL]) + eip27Supported: Boolean) object NodeInfo extends ApiCodecs { implicit val paramsEncoder: Encoder[Parameters] = org.ergoplatform.settings.ParametersSerializer.jsonEncoder implicit val jsonEncoder: Encoder[NodeInfo] = (ni: NodeInfo) => { - val optionalFields = - ni.restApiUrl.map(_.toString).map(restApiUrl => Map("restApiUrl" -> restApiUrl.asJson)).getOrElse(Map.empty) - (Map( + Map( "name" -> ni.nodeName.asJson, "appVersion" -> Version.VersionString.asJson, "network" -> ni.network.asJson, @@ -228,7 +223,7 @@ object ErgoStatsCollector { "genesisBlockId" -> ni.genesisBlockIdOpt.asJson, "parameters" -> ni.parameters.asJson, "eip27Supported" -> ni.eip27Supported.asJson - ) ++ optionalFields).asJson + ).asJson } } diff --git a/src/main/scala/scorex/core/network/PeerConnectionHandler.scala b/src/main/scala/scorex/core/network/PeerConnectionHandler.scala index d7203d5486..f98055417c 100644 --- a/src/main/scala/scorex/core/network/PeerConnectionHandler.scala +++ b/src/main/scala/scorex/core/network/PeerConnectionHandler.scala @@ -245,8 +245,7 @@ class PeerConnectionHandler(scorexSettings: ScorexSettings, Version(networkSettings.appVersion), networkSettings.nodeName, ownSocketAddress, - localFeatures, - scorexSettings.restApi.publicUrl + localFeatures ), scorexContext.timeProvider.time() ) diff --git a/src/main/scala/scorex/core/network/PeerSpec.scala b/src/main/scala/scorex/core/network/PeerSpec.scala index cb17929603..ffb84dae4d 100644 --- a/src/main/scala/scorex/core/network/PeerSpec.scala +++ b/src/main/scala/scorex/core/network/PeerSpec.scala @@ -1,6 +1,6 @@ package scorex.core.network -import java.net.{InetAddress, InetSocketAddress, URL} +import java.net.{InetAddress, InetSocketAddress} import scorex.core.app.{ApplicationVersionSerializer, Version} import scorex.core.network.peer.LocalAddressPeerFeature import scorex.core.serialization.ScorexSerializer @@ -23,8 +23,7 @@ case class PeerSpec(agentName: String, protocolVersion: Version, nodeName: String, declaredAddress: Option[InetSocketAddress], - features: Seq[PeerFeature], - restApiUrl: Option[URL]) { + features: Seq[PeerFeature]) { lazy val localAddressOpt: Option[InetSocketAddress] = { features.collectFirst { case LocalAddressPeerFeature(addr) => addr } @@ -65,12 +64,6 @@ class PeerSpecSerializer(featureSerializers: PeerFeature.Serializers) extends Sc w.putUShort(fBytes.length.toShortExact) w.putBytes(fBytes) } - - w.putOption(obj.restApiUrl: Option[URL]) { (writer, url) => - val addr = url.toString.getBytes("UTF-8") - writer.put(addr.size.toByteExact) - writer.putBytes(addr) - } } override def parse(r: Reader): PeerSpec = { @@ -99,20 +92,8 @@ class PeerSpecSerializer(featureSerializers: PeerFeature.Serializers) extends Sc featureSerializer.parseTry(r.newReader(featChunk)).toOption } } - // backward compatibility hack, as writer.putOption does put(0.toByte) - // so old blobs has 0 missing in case of restApiUrl = None - val restApiUrlOpt = - if (r.remaining > 0) { - r.getOption { - val fas = r.getUByte() - val fa = r.getBytes(fas) - new URL(new String(fa)) - } - } else { - None - } - PeerSpec(appName, protocolVersion, nodeName, declaredAddressOpt, feats, restApiUrlOpt) + PeerSpec(appName, protocolVersion, nodeName, declaredAddressOpt, feats) } } diff --git a/src/main/scala/scorex/core/network/peer/PeerInfo.scala b/src/main/scala/scorex/core/network/peer/PeerInfo.scala index 23ef5f43c4..36ceeee4f8 100644 --- a/src/main/scala/scorex/core/network/peer/PeerInfo.scala +++ b/src/main/scala/scorex/core/network/peer/PeerInfo.scala @@ -36,7 +36,7 @@ object PeerInfo { * (e.g. we got this information from config or from API) */ def fromAddress(address: InetSocketAddress): PeerInfo = { - val peerSpec = PeerSpec("unknown", Version.initial, s"unknown-$address", Some(address), Seq(), None) + val peerSpec = PeerSpec("unknown", Version.initial, s"unknown-$address", Some(address), Seq()) PeerInfo(peerSpec, 0L, None) } diff --git a/src/main/scala/scorex/core/settings/Settings.scala b/src/main/scala/scorex/core/settings/Settings.scala index 5c88942e63..6546f356a2 100644 --- a/src/main/scala/scorex/core/settings/Settings.scala +++ b/src/main/scala/scorex/core/settings/Settings.scala @@ -1,7 +1,7 @@ package scorex.core.settings import java.io.File -import java.net.{InetSocketAddress, URL} +import java.net.InetSocketAddress import com.typesafe.config.{Config, ConfigFactory} import net.ceedubs.ficus.Ficus._ import net.ceedubs.ficus.readers.ArbitraryTypeReader._ @@ -16,8 +16,7 @@ case class LoggingSettings(level: String) case class RESTApiSettings(bindAddress: InetSocketAddress, apiKeyHash: Option[String], corsAllowedOrigin: Option[String], - timeout: FiniteDuration, - publicUrl: Option[URL]) + timeout: FiniteDuration) case class NetworkSettings(nodeName: String, addedMaxDelay: Option[FiniteDuration], diff --git a/src/test/resources/application.conf b/src/test/resources/application.conf index 2e5697b1a3..dce6fd602d 100644 --- a/src/test/resources/application.conf +++ b/src/test/resources/application.conf @@ -184,12 +184,6 @@ ergo { } -scorex { - restApi { - apiKeyHash = null - publicUrl = "https://example.com:80" - } -} akka { test { diff --git a/src/test/scala/org/ergoplatform/http/routes/ErgoPeersApiRouteSpec.scala b/src/test/scala/org/ergoplatform/http/routes/ErgoPeersApiRouteSpec.scala index 0c4b7f18c8..873379c0f8 100644 --- a/src/test/scala/org/ergoplatform/http/routes/ErgoPeersApiRouteSpec.scala +++ b/src/test/scala/org/ergoplatform/http/routes/ErgoPeersApiRouteSpec.scala @@ -36,7 +36,7 @@ class ErgoPeersApiRouteSpec extends AnyFlatSpec implicit val actorTimeout: Timeout = Timeout(15.seconds.dilated) implicit val routeTimeout: RouteTestTimeout = RouteTestTimeout(15.seconds.dilated) - val restApiSettings = RESTApiSettings(new InetSocketAddress("localhost", 8080), None, None, 10.seconds, None) + val restApiSettings = RESTApiSettings(new InetSocketAddress("localhost", 8080), None, None, 10.seconds) val peerManagerProbe = TestProbe() it should "return connected peers" in { @@ -56,9 +56,6 @@ class ErgoPeersApiRouteSpec extends AnyFlatSpec peer.peerInfo.get.peerSpec.address.foreach { address => c.downField("address").as[String] shouldEqual Right(address.toString) } - peer.peerInfo.get.peerSpec.restApiUrl.foreach { address => - c.downField("restApiUrl").as[String] shouldEqual Right(address.toString) - } c.downField("lastMessage").as[Long] shouldEqual Right(0L) c.downField("lastHandshake").as[Long] shouldEqual Right(0L) diff --git a/src/test/scala/org/ergoplatform/http/routes/TransactionApiRouteSpec.scala b/src/test/scala/org/ergoplatform/http/routes/TransactionApiRouteSpec.scala index 6d1a6d49c8..3aadefeacf 100644 --- a/src/test/scala/org/ergoplatform/http/routes/TransactionApiRouteSpec.scala +++ b/src/test/scala/org/ergoplatform/http/routes/TransactionApiRouteSpec.scala @@ -28,7 +28,7 @@ class TransactionApiRouteSpec extends AnyFlatSpec val prefix = "/transactions" - val restApiSettings = RESTApiSettings(new InetSocketAddress("localhost", 8080), None, None, 10.seconds, None) + val restApiSettings = RESTApiSettings(new InetSocketAddress("localhost", 8080), None, None, 10.seconds) val route: Route = TransactionsApiRoute(utxoReadersRef, nodeViewRef, settings).route val inputBox: ErgoBox = utxoState.takeBoxes(1).head diff --git a/src/test/scala/org/ergoplatform/http/routes/UtilsApiRouteSpec.scala b/src/test/scala/org/ergoplatform/http/routes/UtilsApiRouteSpec.scala index ea4f0e01ba..4953e21ae8 100644 --- a/src/test/scala/org/ergoplatform/http/routes/UtilsApiRouteSpec.scala +++ b/src/test/scala/org/ergoplatform/http/routes/UtilsApiRouteSpec.scala @@ -26,7 +26,7 @@ class UtilsApiRouteSpec extends AnyFlatSpec val prefix = "/utils" - val restApiSettings = RESTApiSettings(new InetSocketAddress("localhost", 8080), None, None, 10.seconds, None) + val restApiSettings = RESTApiSettings(new InetSocketAddress("localhost", 8080), None, None, 10.seconds) val route: Route = ErgoUtilsApiRoute(settings).route val p2pkaddress = P2PKAddress(defaultMinerPk) val p2shaddress = Pay2SHAddress(feeProp) diff --git a/src/test/scala/org/ergoplatform/network/PeerFilteringRuleSpecification.scala b/src/test/scala/org/ergoplatform/network/PeerFilteringRuleSpecification.scala index 01b7f4ab6c..7ff9ed7883 100644 --- a/src/test/scala/org/ergoplatform/network/PeerFilteringRuleSpecification.scala +++ b/src/test/scala/org/ergoplatform/network/PeerFilteringRuleSpecification.scala @@ -11,7 +11,7 @@ class PeerFilteringRuleSpecification extends ErgoPropertyTest { private def peerWithVersion(version: Version): ConnectedPeer = { val ref = ActorRef.noSender - val peerSpec = PeerSpec("", version, "", None, Seq.empty, None) + val peerSpec = PeerSpec("", version, "", None, Seq.empty) val peerInfo = PeerInfo(peerSpec, lastHandshake = 0L, None) ConnectedPeer(ConnectionId(null, null, null), ref, lastMessage = 0L, Some(peerInfo)) } diff --git a/src/test/scala/org/ergoplatform/settings/ErgoSettingsSpecification.scala b/src/test/scala/org/ergoplatform/settings/ErgoSettingsSpecification.scala index 7f82d50afc..79d1aca4bd 100644 --- a/src/test/scala/org/ergoplatform/settings/ErgoSettingsSpecification.scala +++ b/src/test/scala/org/ergoplatform/settings/ErgoSettingsSpecification.scala @@ -4,7 +4,7 @@ import org.ergoplatform.nodeView.state.StateType import org.ergoplatform.utils.ErgoPropertyTest import scorex.core.settings.RESTApiSettings -import java.net.{InetSocketAddress, URL} +import java.net.InetSocketAddress import scala.concurrent.duration._ class ErgoSettingsSpecification extends ErgoPropertyTest { @@ -62,8 +62,7 @@ class ErgoSettingsSpecification extends ErgoPropertyTest { bindAddress = new InetSocketAddress("0.0.0.0", 9052), apiKeyHash = None, corsAllowedOrigin = Some("*"), - timeout = 5.seconds, - publicUrl = Some(new URL("https://example.com:80")) + timeout = 5.seconds ) } diff --git a/src/test/scala/org/ergoplatform/utils/ErgoTestConstants.scala b/src/test/scala/org/ergoplatform/utils/ErgoTestConstants.scala index 3147219b48..db4e4a547e 100644 --- a/src/test/scala/org/ergoplatform/utils/ErgoTestConstants.scala +++ b/src/test/scala/org/ergoplatform/utils/ErgoTestConstants.scala @@ -109,8 +109,7 @@ trait ErgoTestConstants extends ScorexLogging { Version(settings.scorexSettings.network.appVersion), settings.scorexSettings.network.nodeName, None, - Seq.empty, - None + Seq.empty ) } diff --git a/src/test/scala/scorex/testkit/generators/ObjectGenerators.scala b/src/test/scala/scorex/testkit/generators/ObjectGenerators.scala index c8242315fd..763feb75ea 100644 --- a/src/test/scala/scorex/testkit/generators/ObjectGenerators.scala +++ b/src/test/scala/scorex/testkit/generators/ObjectGenerators.scala @@ -119,8 +119,8 @@ trait ObjectGenerators { def peerSpecGen: Gen[PeerSpec] = for { declaredAddress <- Gen.frequency(5 -> const(None), 5 -> some(inetSocketAddressGen)) - restApiUrl <- Gen.frequency(5 -> const(None), 5 -> some(urlGen)) features <- Gen.frequency(5 -> const(None), 5 -> some(Gen.oneOf(Seq(FullNodePeerFeature)))) version <- appVersionGen - } yield PeerSpec("ergoref", version, "ergo-node", declaredAddress, features.toSeq, restApiUrl) + } yield PeerSpec("ergoref", version, "ergo-node", declaredAddress, features.toSeq) + } From 55697591fd46cf5c396dad0f32d8884fe30e75e9 Mon Sep 17 00:00:00 2001 From: Alex Chepurnoy Date: Tue, 5 Jul 2022 11:11:17 +0300 Subject: [PATCH 7/8] fixing InfoApiRoutesSpec --- .../scala/org/ergoplatform/http/routes/InfoApiRoutesSpec.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/scala/org/ergoplatform/http/routes/InfoApiRoutesSpec.scala b/src/test/scala/org/ergoplatform/http/routes/InfoApiRoutesSpec.scala index a599cb4ca6..774d6ae4e2 100644 --- a/src/test/scala/org/ergoplatform/http/routes/InfoApiRoutesSpec.scala +++ b/src/test/scala/org/ergoplatform/http/routes/InfoApiRoutesSpec.scala @@ -59,7 +59,6 @@ class InfoApiRoutesSpec extends AnyFlatSpec c.downField("isMining").as[Boolean] shouldEqual Right(settings.nodeSettings.mining) c.downField("launchTime").as[Long] shouldEqual Right(fakeTimeProvider.time()) c.downField("eip27Supported").as[Boolean] shouldEqual Right(true) - c.downField("restApiUrl").as[String] shouldEqual Right("https://example.com:80") } } From 64b0940a6047ea894eddf66f074bb1e3504701aa Mon Sep 17 00:00:00 2001 From: Alex Chepurnoy Date: Tue, 5 Jul 2022 11:17:19 +0300 Subject: [PATCH 8/8] fixing ErgoSettingsSpecification --- src/test/resources/application.conf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/resources/application.conf b/src/test/resources/application.conf index dce6fd602d..33f6cb8b30 100644 --- a/src/test/resources/application.conf +++ b/src/test/resources/application.conf @@ -184,6 +184,12 @@ ergo { } +scorex { + restApi { + apiKeyHash = null + } +} + akka { test {