Skip to content

Commit

Permalink
lazy segmentThreshold
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Oct 10, 2024
1 parent 003bb84 commit 88e0aed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
17 changes: 9 additions & 8 deletions src/main/scala/org/ergoplatform/ErgoApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 88e0aed

Please sign in to comment.