From 88e0aedde74c9aff805a2e20ecea7a4749e2ea3c Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Thu, 10 Oct 2024 12:05:00 +0300 Subject: [PATCH] lazy segmentThreshold --- src/main/scala/org/ergoplatform/ErgoApp.scala | 17 +++++++++-------- .../http/api/BlockchainApiRoute.scala | 10 +++++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/scala/org/ergoplatform/ErgoApp.scala b/src/main/scala/org/ergoplatform/ErgoApp.scala index 323bd5f227..cf8ad93170 100644 --- a/src/main/scala/org/ergoplatform/ErgoApp.scala +++ b/src/main/scala/org/ergoplatform/ErgoApp.scala @@ -106,14 +106,6 @@ class ErgoApp(args: Args) extends ScorexLogging { None } - // Create an instance of ExtraIndexer actor (will start if "extraIndex = true" in config) - private val indexerOpt: Option[ActorRef] = - if (ergoSettings.nodeSettings.extraIndex) { - Some(ExtraIndexer(ergoSettings.chainSettings, ergoSettings.cacheSettings)) - } else { - None - } - private val syncTracker = ErgoSyncTracker(scorexSettings.network) private val deliveryTracker: DeliveryTracker = DeliveryTracker.empty(ergoSettings) @@ -144,6 +136,7 @@ class ErgoApp(args: Args) extends ScorexLogging { ManifestSpec.messageCode -> ergoNodeViewSynchronizerRef, GetUtxoSnapshotChunkSpec.messageCode-> ergoNodeViewSynchronizerRef, UtxoSnapshotChunkSpec.messageCode -> ergoNodeViewSynchronizerRef, + // nipopows exchange related messages GetNipopowProofSpec.messageCode -> ergoNodeViewSynchronizerRef, NipopowProofSpec.messageCode -> ergoNodeViewSynchronizerRef ) @@ -179,6 +172,14 @@ class ErgoApp(args: Args) extends ScorexLogging { ergoSettings ) + // Create an instance of ExtraIndexer actor (will start if "extraIndex = true" in config) + private val indexerOpt: Option[ActorRef] = + if (ergoSettings.nodeSettings.extraIndex) { + Some(ExtraIndexer(ergoSettings.chainSettings, ergoSettings.cacheSettings)) + } else { + None + } + private val apiRoutes: Seq[ApiRoute] = Seq( EmissionApiRoute(ergoSettings), ErgoUtilsApiRoute(ergoSettings), diff --git a/src/main/scala/org/ergoplatform/http/api/BlockchainApiRoute.scala b/src/main/scala/org/ergoplatform/http/api/BlockchainApiRoute.scala index 355efd2912..7e05ecdd8e 100644 --- a/src/main/scala/org/ergoplatform/http/api/BlockchainApiRoute.scala +++ b/src/main/scala/org/ergoplatform/http/api/BlockchainApiRoute.scala @@ -32,7 +32,7 @@ case class BlockchainApiRoute(readersHolder: ActorRef, ergoSettings: ErgoSetting val settings: RESTApiSettings = ergoSettings.scorexSettings.restApi - private implicit val segmentTreshold: Int = indexerOpt.map { indexer => + private lazy val segmentTreshold: Int = indexerOpt.map { indexer => Await.result[Int]((indexer ? GetSegmentThreshold).asInstanceOf[Future[Int]], Duration(3, SECONDS)) }.getOrElse(0) @@ -152,7 +152,7 @@ case class BlockchainApiRoute(readersHolder: ActorRef, ergoSettings: ErgoSetting private def getTxsByAddress(addr: ErgoAddress, offset: Int, limit: Int): Future[(Seq[IndexedErgoTransaction],Long)] = getHistory.map { history => getAddress(addr)(history) match { - case Some(addr) => (addr.retrieveTxs(history, offset, limit), addr.txCount) + case Some(addr) => (addr.retrieveTxs(history, offset, limit)(segmentTreshold), addr.txCount(segmentTreshold)) case None => (Seq.empty[IndexedErgoTransaction], 0L) } } @@ -220,7 +220,7 @@ case class BlockchainApiRoute(readersHolder: ActorRef, ergoSettings: ErgoSetting private def getBoxesByAddress(addr: ErgoAddress, offset: Int, limit: Int): Future[(Seq[IndexedErgoBox],Long)] = getHistory.map { history => getAddress(addr)(history) match { - case Some(addr) => (addr.retrieveBoxes(history, offset, limit).reverse, addr.boxCount) + case Some(addr) => (addr.retrieveBoxes(history, offset, limit)(segmentTreshold).reverse, addr.boxCount(segmentTreshold)) case None => (Seq.empty[IndexedErgoBox], 0L) } } @@ -312,7 +312,7 @@ case class BlockchainApiRoute(readersHolder: ActorRef, ergoSettings: ErgoSetting private def getBoxesByErgoTree(tree: ErgoTree, offset: Int, limit: Int): Future[(Seq[IndexedErgoBox],Long)] = getHistory.map { history => getAddress(tree)(history) match { - case Some(iEa) => (iEa.retrieveBoxes(history, offset, limit).reverse, iEa.boxCount) + case Some(iEa) => (iEa.retrieveBoxes(history, offset, limit)(segmentTreshold).reverse, iEa.boxCount(segmentTreshold)) case None => (Seq.empty[IndexedErgoBox], 0L) } } @@ -365,7 +365,7 @@ case class BlockchainApiRoute(readersHolder: ActorRef, ergoSettings: ErgoSetting private def getBoxesByTokenId(id: ModifierId, offset: Int, limit: Int): Future[(Seq[IndexedErgoBox],Long)] = getHistory.map { history => history.typedExtraIndexById[IndexedToken](uniqueId(id)) match { - case Some(token) => (token.retrieveBoxes(history, offset, limit), token.boxCount) + case Some(token) => (token.retrieveBoxes(history, offset, limit)(segmentTreshold), token.boxCount(segmentTreshold)) case None => (Seq.empty[IndexedErgoBox], 0L) } }