Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed broadcasting MicroBlockInv #3915

Open
wants to merge 5 commits into
base: version-1.5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,22 @@ class MicroBlockMinerImpl(
}
}

private def appendAndBroadcastMicroBlock(
account: KeyPair,
block: Block,
transactions: Seq[Transaction],
constraint: 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 (constraint.isFull) Stop
else Success(signedBlock, constraint)

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

Expand Down