Skip to content

Commit

Permalink
sendInputToNodeView stub (pre-refactoring)
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Oct 15, 2024
1 parent b908142 commit 08c52d6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/scala/org/ergoplatform/mining/CandidateGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class CandidateGenerator(
}

/** Send solved block to local blockchain controller */
private def sendToNodeView(newBlock: ErgoFullBlock): Unit = {
private def sendOrderingToNodeView(newBlock: ErgoFullBlock): Unit = {
log.info(
s"New block ${newBlock.id} w. nonce ${Longs.fromByteArray(newBlock.header.powSolution.n)}"
s"New ordering block ${newBlock.id} w. nonce ${Longs.fromByteArray(newBlock.header.powSolution.n)}"
)
viewHolderRef ! LocallyGeneratedModifier(newBlock.header)
val sectionsToApply = if (ergoSettings.nodeSettings.stateType == StateType.Digest) {
Expand All @@ -71,6 +71,12 @@ class CandidateGenerator(
sectionsToApply.foreach(viewHolderRef ! LocallyGeneratedModifier(_))
}

private def sendInputToNodeView(newBlock: ErgoFullBlock): Unit = {
log.info(
s"New input block ${newBlock.id} w. nonce ${Longs.fromByteArray(newBlock.header.powSolution.n)}"
)
}

override def receive: Receive = {

// first we need to get Readers to have some initial state to work with
Expand Down Expand Up @@ -188,10 +194,10 @@ class CandidateGenerator(
val newBlock = completeOrderingBlock(state.cache.get.candidateBlock, solution)
log.info(s"New block mined, header: ${newBlock.header}")
ergoSettings.chainSettings.powScheme
.validate(newBlock.header)
.validate(newBlock.header) // check header PoW only
.map(_ => newBlock) match {
case Success(newBlock) =>
sendToNodeView(newBlock)
sendOrderingToNodeView(newBlock)
context.become(initialized(state.copy(solvedBlock = Some(newBlock))))
StatusReply.success(())
case Failure(exception) =>
Expand All @@ -206,6 +212,7 @@ class CandidateGenerator(
val newBlock = completeInputBlock(state.cache.get.candidateBlock, solution)
val powValid = SubBlockAlgos.checkInputBlockPoW(newBlock.header)
// todo: check links? send to node view, update state
sendInputToNodeView(newBlock)
StatusReply.error(
new Exception(s"Input block found! PoW valid: $powValid")
)
Expand Down

0 comments on commit 08c52d6

Please sign in to comment.