From 4fc43c5ca06b3f3f9c03b13d695e26ab4416b543 Mon Sep 17 00:00:00 2001
From: Alexander Chepurnoy <alex.chepurnoy@iohk.io>
Date: Fri, 18 Oct 2024 16:05:18 +0300
Subject: [PATCH] reworked LocallyGeneratedInputBlock signature

---
 .../nodeView/LocallyGeneratedInputBlock.scala        |  5 +++--
 .../org/ergoplatform/mining/CandidateGenerator.scala | 12 ++++++++----
 .../ergoplatform/nodeView/ErgoNodeViewHolder.scala   |  8 +++++---
 .../modifierprocessors/SubBlocksProcessor.scala      |  4 ++++
 4 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/ergo-core/src/main/scala/org/ergoplatform/nodeView/LocallyGeneratedInputBlock.scala b/ergo-core/src/main/scala/org/ergoplatform/nodeView/LocallyGeneratedInputBlock.scala
index 0c5be7ead1..8a554e3f99 100644
--- a/ergo-core/src/main/scala/org/ergoplatform/nodeView/LocallyGeneratedInputBlock.scala
+++ b/ergo-core/src/main/scala/org/ergoplatform/nodeView/LocallyGeneratedInputBlock.scala
@@ -1,5 +1,6 @@
 package org.ergoplatform.nodeView
 
-import org.ergoplatform.modifiers.ErgoFullBlock
+import org.ergoplatform.network.message.subblocks.SubBlockTransactionsData
+import org.ergoplatform.subblocks.SubBlockInfo
 
-case class LocallyGeneratedInputBlock(efb: ErgoFullBlock)
+case class LocallyGeneratedInputBlock(sbi: SubBlockInfo, sbt: SubBlockTransactionsData)
diff --git a/src/main/scala/org/ergoplatform/mining/CandidateGenerator.scala b/src/main/scala/org/ergoplatform/mining/CandidateGenerator.scala
index caa12cd204..66de02ec39 100644
--- a/src/main/scala/org/ergoplatform/mining/CandidateGenerator.scala
+++ b/src/main/scala/org/ergoplatform/mining/CandidateGenerator.scala
@@ -13,6 +13,7 @@ import org.ergoplatform.modifiers.history.header.{Header, HeaderWithoutPow}
 import org.ergoplatform.modifiers.history.popow.NipopowAlgos
 import org.ergoplatform.modifiers.mempool.{ErgoTransaction, UnconfirmedTransaction}
 import org.ergoplatform.network.ErgoNodeViewSynchronizerMessages._
+import org.ergoplatform.network.message.subblocks.SubBlockTransactionsData
 import org.ergoplatform.nodeView.ErgoNodeViewHolder.ReceivableMessages.EliminateTransactions
 import org.ergoplatform.nodeView.ErgoReadersHolder.{GetReaders, Readers}
 import org.ergoplatform.nodeView.{LocallyGeneratedInputBlock, LocallyGeneratedOrderingBlock}
@@ -66,11 +67,11 @@ class CandidateGenerator(
   }
 
   /** Send solved input block to processing */
-  private def sendInputToNodeView(newBlock: ErgoFullBlock): Unit = {
+  private def sendInputToNodeView(sbi: SubBlockInfo, sbt: SubBlockTransactionsData): Unit = {
     log.info(
-      s"New input block ${newBlock.id} w. nonce ${Longs.fromByteArray(newBlock.header.powSolution.n)}"
+      s"New input block ${sbi.subBlock.id} w. nonce ${Longs.fromByteArray(sbi.subBlock.powSolution.n)}"
     )
-    viewHolderRef ! LocallyGeneratedInputBlock(newBlock)
+    viewHolderRef ! LocallyGeneratedInputBlock(sbi, sbt)
   }
 
   override def receive: Receive = {
@@ -209,7 +210,10 @@ class CandidateGenerator(
             val powValid = SubBlockAlgos.checkInputBlockPoW(newBlock.header)
             // todo: check links?
             // todo: update candidate generator state
-            sendInputToNodeView(newBlock)
+            // todo: form and send real data
+            val sbi: SubBlockInfo = null
+            val sbt : SubBlockTransactionsData = null
+            sendInputToNodeView(sbi, sbt)
             StatusReply.error(
               new Exception(s"Input block found! PoW valid: $powValid")
             )
diff --git a/src/main/scala/org/ergoplatform/nodeView/ErgoNodeViewHolder.scala b/src/main/scala/org/ergoplatform/nodeView/ErgoNodeViewHolder.scala
index df47773158..6424690e14 100644
--- a/src/main/scala/org/ergoplatform/nodeView/ErgoNodeViewHolder.scala
+++ b/src/main/scala/org/ergoplatform/nodeView/ErgoNodeViewHolder.scala
@@ -684,9 +684,11 @@ abstract class ErgoNodeViewHolder[State <: ErgoState[State]](settings: ErgoSetti
       sectionsToApply.foreach { section =>
         pmodModify(section, local = true)
       }
-    case LocallyGeneratedInputBlock(efb) =>
-      log.info(s"Got locally generated input block ${efb.id}")
-      // todo: real processing
+    case LocallyGeneratedInputBlock(sbi, sbt) =>
+      log.info(s"Got locally generated input block ${sbi.subBlock.id}")
+      history().applySubBlockHeader(sbi)
+      history().applySubBlockTransactions(sbi.subBlock.id, sbt.transactions)
+      // todo: finish processing
   }
 
   protected def getCurrentInfo: Receive = {
diff --git a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/SubBlocksProcessor.scala b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/SubBlocksProcessor.scala
index 99aeceede0..d18033026c 100644
--- a/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/SubBlocksProcessor.scala
+++ b/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/SubBlocksProcessor.scala
@@ -8,7 +8,11 @@ import scala.collection.mutable
 
 trait SubBlocksProcessor extends ScorexLogging {
 
+  /**
+    * Pointer to a best input-block known
+    */
   var _bestSubblock: Option[SubBlockInfo] = None
+
   val subBlockRecords = mutable.Map[ModifierId, SubBlockInfo]()
   val subBlockTransactions = mutable.Map[ModifierId, Seq[ErgoTransaction]]()