From 15ca997b1f2182f7a6a5e29c942ab12a49f7ad5b Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Wed, 4 Sep 2024 00:55:59 +0300 Subject: [PATCH] subblock height check --- .../network/ErgoNodeViewSynchronizer.scala | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/scala/org/ergoplatform/network/ErgoNodeViewSynchronizer.scala b/src/main/scala/org/ergoplatform/network/ErgoNodeViewSynchronizer.scala index 9f2385c752..93cdf1deca 100644 --- a/src/main/scala/org/ergoplatform/network/ErgoNodeViewSynchronizer.scala +++ b/src/main/scala/org/ergoplatform/network/ErgoNodeViewSynchronizer.scala @@ -1077,18 +1077,24 @@ class ErgoNodeViewSynchronizer(networkControllerRef: ActorRef, } def processSubblock(subBlockInfo: SubBlockInfo, hr: ErgoHistoryReader, remote: ConnectedPeer): Unit = { - 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 ${subBlockInfo.subBlock.id} with parent sub-block ${prevSubBlockId}") - case None => - log.debug(s"Processing valid sub-block ${subBlockInfo.subBlock.id} with parent block ${subBlockInfo.subBlock.parentId}") + val subBlockHeader = subBlockInfo.subBlock + 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}") + } + } else { + log.warn(s"Sub-block ${subBlockHeader.id} is invalid") + penalizeMisbehavingPeer(remote) } } else { - log.warn(s"Sub-block ${subBlockInfo.subBlock.id} is invalid") - penalizeMisbehavingPeer(remote) + log.info(s"Got sub-block for height ${subBlockHeader.height}, while height of our best full-block is ${hr.fullBlockHeight}") + // just ignore the subblock } }