Skip to content

Commit

Permalink
initial version of best subblock selection
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Sep 18, 2024
1 parent e8bcdfa commit 647b6db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ object CandidateGenerator extends ScorexLogging {
val bestExtensionOpt: Option[Extension] = bestHeaderOpt
.flatMap(h => history.typedModifierById[Extension](h.extensionId))

val lastSubblockOpt:Option[SubBlockInfo] = history.bestSubblock()
val lastSubblockOpt: Option[SubBlockInfo] = history.bestSubblock()

// there was sub-block generated before for this block
val continueSubblock = lastSubblockOpt.exists(sbi => bestHeaderOpt.map(_.id).contains(sbi.subBlock.parentId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,42 @@ package org.ergoplatform.nodeView.history.storage.modifierprocessors

import org.ergoplatform.modifiers.mempool.ErgoTransaction
import org.ergoplatform.subblocks.SubBlockInfo
import scorex.util.ModifierId
import scorex.util.{ModifierId, ScorexLogging, bytesToId}

trait SubBlocksProcessor {
import scala.collection.mutable

val subBlockRecords = Map[ModifierId, SubBlockInfo]()
val subBlockTransactions = Map[ModifierId, Seq[ErgoTransaction]]()
trait SubBlocksProcessor extends ScorexLogging {

var _bestSubblock: Option[SubBlockInfo] = None
val subBlockRecords = mutable.Map[ModifierId, SubBlockInfo]()
val subBlockTransactions = mutable.Map[ModifierId, Seq[ErgoTransaction]]()

// sub-blocks related logic
def applySubBlockHeader(sbi: SubBlockInfo): Unit = {
// todo: implement
subBlockRecords.put(sbi.subBlock.id, sbi)

// todo: currently only one chain of subblocks considered,
// in fact there could be multiple trees here (one subblocks tree per header)
_bestSubblock match {
case None => _bestSubblock = Some(sbi)
case Some(maybeParent) if (sbi.prevSubBlockId.map(bytesToId).contains(maybeParent.subBlock.id)) =>
_bestSubblock = Some(sbi)
case _ =>
// todo: record it
log.debug(s"Applying non-best subblock id: ${sbi.subBlock.id}")
}
}

def applySubBlockTransactions(sbId: ModifierId, transactions: Seq[ErgoTransaction]): Unit = {
// todo: implement
subBlockTransactions.put(sbId, transactions)
}

def getSubBlockTransactions(sbId: ModifierId): Option[Seq[ErgoTransaction]] = {
subBlockTransactions.get(sbId)
}

def bestSubblock(): Option[SubBlockInfo] = {
???
_bestSubblock
}

}

0 comments on commit 647b6db

Please sign in to comment.