Skip to content

Commit

Permalink
SubBlockTransactionsRequestSpec, completing processSubblock stub
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Sep 4, 2024
1 parent 15ca997 commit 222c850
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.ergoplatform.network.message.subblocks

import org.ergoplatform.network.message.MessageConstants.MessageCode
import org.ergoplatform.network.message.MessageSpecInitial
import org.ergoplatform.network.message.{InvData, MessageSpecInitial, MessageSpecSubblocks}
import org.ergoplatform.subblocks.SubBlockInfo
import scorex.util.serialization.{Reader, Writer}

/**
* Message that is informing about sub block produced.
* Contains header and link to previous sub block ().
*/
object SubBlockMessageSpec extends MessageSpecInitial[SubBlockInfo] {
object SubBlockMessageSpec extends MessageSpecSubblocks[SubBlockInfo] {

val MaxMessageSize = 10000

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.ergoplatform.network.message.subblocks

import org.ergoplatform.network.message.MessageConstants.MessageCode
import org.ergoplatform.network.message.MessageSpecSubblocks
import scorex.util.{ModifierId, bytesToId, idToBytes}
import scorex.util.serialization.{Reader, Writer}

object SubBlockTransactionsRequestSpec extends MessageSpecSubblocks[ModifierId] {
/**
* Code which identifies what message type is contained in the payload
*/
override val messageCode: MessageCode = 91: Byte

/**
* Name of this message type. For debug purposes only.
*/
override val messageName: String = "SubBlockTxsReq"

override def serialize(subBlockId: ModifierId, w: Writer): Unit = {
w.putBytes(idToBytes(subBlockId))
}

override def parse(r: Reader): ModifierId = {
bytesToId(r.getBytes(32))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import org.ergoplatform.consensus.{Equal, Fork, Nonsense, Older, Unknown, Younge
import org.ergoplatform.modifiers.history.{ADProofs, ADProofsSerializer, BlockTransactions, BlockTransactionsSerializer}
import org.ergoplatform.modifiers.history.extension.{Extension, ExtensionSerializer}
import org.ergoplatform.modifiers.transaction.TooHighCostError
import org.ergoplatform.network.message.subblocks.SubBlockMessageSpec
import org.ergoplatform.network.message.subblocks.{SubBlockMessageSpec, SubBlockTransactionsRequestSpec}
import org.ergoplatform.serialization.{ErgoSerializer, ManifestSerializer, SubtreeSerializer}
import org.ergoplatform.subblocks.SubBlockInfo
import scorex.crypto.authds.avltree.batch.VersionedLDBAVLStorage.splitDigest
Expand Down Expand Up @@ -1081,13 +1081,11 @@ class ErgoNodeViewSynchronizer(networkControllerRef: ActorRef,
if (subBlockHeader.height == hr.fullBlockHeight + 1) {
if (subBlockInfo.valid()) {
val prevSbIdOpt = subBlockInfo.prevSubBlockId.map(bytesToId) // link to previous sub-block

prevSbIdOpt match {
case Some(prevSubBlockId) =>
log.debug(s"Processing valid sub-block ${subBlockHeader.id} with parent sub-block ${prevSubBlockId}")
case None =>
log.debug(s"Processing valid sub-block ${subBlockHeader.id} with parent block ${subBlockHeader.parentId}")
}
log.debug(s"Processing valid sub-block ${subBlockHeader.id} with parent sub-block $prevSbIdOpt and parent block ${subBlockHeader.parentId}")
// write sub-block to db, ask for transactions in it
viewHolderRef ! ProcessSubblock(subBlockInfo)
val msg = Message(SubBlockTransactionsRequestSpec, Right(subBlockInfo.subBlock.id), None)
networkControllerRef ! SendToNetwork(msg, SendToPeer(remote))
} else {
log.warn(s"Sub-block ${subBlockHeader.id} is invalid")
penalizeMisbehavingPeer(remote)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import scorex.core.network.ConnectedPeer
import scorex.util.ModifierId
import org.ergoplatform.ErgoLikeContext.Height
import org.ergoplatform.modifiers.history.popow.NipopowProof
import org.ergoplatform.subblocks.SubBlockInfo

/**
* Repository of messages processed ErgoNodeViewSynchronizer actor
Expand Down Expand Up @@ -142,4 +143,6 @@ object ErgoNodeViewSynchronizerMessages {
* @param nipopowProof - proof to initialize history from
*/
case class ProcessNipopow(nipopowProof: NipopowProof)

case class ProcessSubblock(subblock: SubBlockInfo)
}
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ abstract class ErgoNodeViewHolder[State <: ErgoState[State]](settings: ErgoSetti
updateNodeView(updatedHistory = Some(history()))
}
}

// subblocks related logic
case ProcessSubblock(sbi) =>
history().applySubBlockHeader(sbi)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.ergoplatform.modifiers.{BlockSection, ErgoFullBlock, NetworkObjectTyp
import org.ergoplatform.nodeView.history.ErgoHistoryUtils.{EmptyHistoryHeight, GenesisHeight, Height}
import org.ergoplatform.nodeView.history.extra.ExtraIndex
import org.ergoplatform.nodeView.history.storage._
import org.ergoplatform.nodeView.history.storage.modifierprocessors.{BlockSectionProcessor, HeadersProcessor}
import org.ergoplatform.nodeView.history.storage.modifierprocessors.{BlockSectionProcessor, HeadersProcessor, SubBlocksProcessor}
import org.ergoplatform.settings.{ErgoSettings, NipopowSettings}
import org.ergoplatform.validation.MalformedModifierError
import scorex.util.{ModifierId, ScorexLogging}
Expand All @@ -26,6 +26,7 @@ trait ErgoHistoryReader
with ContainsModifiers[BlockSection]
with HeadersProcessor
with BlockSectionProcessor
with SubBlocksProcessor
with ScorexLogging {

type ModifierIds = Seq[(NetworkObjectTypeId.Value, ModifierId)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.ergoplatform.local.{CorrectNipopowProofVerificationResult, NipopowPro
import org.ergoplatform.modifiers.BlockSection
import org.ergoplatform.modifiers.history.extension.Extension
import org.ergoplatform.modifiers.history.header.Header
import org.ergoplatform.modifiers.history.popow.{NipopowAlgos, NipopowProverWithDbAlgs, NipopowProof, NipopowProofSerializer, PoPowHeader, PoPowParams}
import org.ergoplatform.modifiers.history.popow.{NipopowAlgos, NipopowProof, NipopowProofSerializer, NipopowProverWithDbAlgs, PoPowHeader, PoPowParams}
import org.ergoplatform.nodeView.history.ErgoHistoryUtils
import org.ergoplatform.nodeView.history.ErgoHistoryReader
import org.ergoplatform.settings.{ChainSettings, NipopowSettings}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.ergoplatform.nodeView.history.storage.modifierprocessors

import org.ergoplatform.subblocks.SubBlockInfo

trait SubBlocksProcessor {

// sub-blocks related logic
def applySubBlockHeader(sbi: SubBlockInfo): Unit = {
// todo: implement
}
}

0 comments on commit 222c850

Please sign in to comment.