Skip to content

Commit

Permalink
Fixed broadcasting MicroBlockInv
Browse files Browse the repository at this point in the history
  • Loading branch information
xrtm000 committed Nov 30, 2023
1 parent c087618 commit 861be8f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
6 changes: 1 addition & 5 deletions node/src/main/scala/com/wavesplatform/mining/Miner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,8 @@ class MinerImpl(
}.uncancelable

for {
elapsed <- waitBlockAppendedTask.timed.map(_._1)
newOffset = (offset - elapsed).max(Duration.Zero)

_ <- Task(microBlockAttempt := SerialCancelable()).delayExecution(newOffset)
_ <- waitBlockAppendedTask
result <- Task(forgeBlock(account)).executeOn(minerScheduler)

_ <- result match {
case Right((block, totalConstraint)) =>
appendTask(block, totalConstraint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,15 @@ class MicroBlockMinerImpl(
for {
_ <- Task.now(if (delay > Duration.Zero) log.trace(s"Sleeping ${delay.toMillis} ms before applying microBlock"))
_ <- Task.sleep(delay)
_ = log.trace(s"Generating microBlock for ${account.toAddress}, constraints: $updatedTotalConstraint")
blocks <- forgeBlocks(account, accumulatedBlock, unconfirmed, stateHash)
.leftWiden[Throwable]
.liftTo[Task]
(signedBlock, microBlock) = blocks
blockId <- appendMicroBlock(microBlock)
_ = BlockStats.mined(microBlock, blockId)
_ <- broadcastMicroBlock(account, microBlock, blockId)
} yield {
if (updatedTotalConstraint.isFull) Stop
else Success(signedBlock, updatedTotalConstraint)
}
r <-
if (blockchainUpdater.lastBlockId.forall(_ == accumulatedBlock.id())) {
log.trace(s"Generating microBlock for ${account.toAddress}, constraints: $updatedTotalConstraint")
appendAndBroadcastMicroBlock(account, accumulatedBlock, unconfirmed, updatedTotalConstraint, stateHash)
} else {
log.trace(s"Stopping generating microBlock for ${account.toAddress}, new key block was appended")
Task(Stop)
}
} yield r

case (_, updatedTotalConstraint, _) =>
if (updatedTotalConstraint.isFull) {
Expand All @@ -142,6 +139,24 @@ class MicroBlockMinerImpl(
}
}

private def appendAndBroadcastMicroBlock(
account: KeyPair,
block: Block,
transactions: Seq[Transaction],
updatedTotalConstraint: MiningConstraint,
stateHash: Option[BlockId]
): Task[MicroBlockMiningResult] =
for {
(signedBlock, microBlock) <- forgeBlocks(account, block, transactions, stateHash)
.leftWiden[Throwable]
.liftTo[Task]
blockId <- appendMicroBlock(microBlock)
_ = BlockStats.mined(microBlock, blockId)
_ <- broadcastMicroBlock(account, microBlock, blockId)
} yield
if (updatedTotalConstraint.isFull) Stop
else Success(signedBlock, updatedTotalConstraint)

private def broadcastMicroBlock(account: KeyPair, microBlock: MicroBlock, blockId: BlockId): Task[Unit] =
Task(if (allChannels != null) allChannels.broadcast(MicroBlockInv(account, blockId, microBlock.reference)))

Expand Down

0 comments on commit 861be8f

Please sign in to comment.