Skip to content

Commit

Permalink
Broadcast only last block after apply (#3878)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mashonskiy authored Oct 20, 2023
1 parent e311af4 commit d6f9f8f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 0 additions & 1 deletion node/src/main/scala/com/wavesplatform/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ class Application(val actorSystem: ActorSystem, val settings: WavesSettings, con
utxStorage.resetPriorityPool()
blockchainUpdater.removeAfter(blockId)
}.executeOn(appenderScheduler)
.asyncBoundary
.map {
case Right(discardedBlocks) =>
allChannels.broadcast(LocalScoreChanged(blockchainUpdater.score))
Expand Down
7 changes: 5 additions & 2 deletions node/src/main/scala/com/wavesplatform/mining/Miner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,11 @@ class MinerImpl(
case Right(Applied(_, score)) =>
log.debug(s"Forged and applied $block with cumulative score $score")
BlockStats.mined(block, blockchainUpdater.height)
allChannels.broadcast(BlockForged(block))
if (ngEnabled && !totalConstraint.isFull) startMicroBlockMining(account, block, totalConstraint)

if (blockchainUpdater.isLastBlockId(block.id())) {
allChannels.broadcast(BlockForged(block))
if (ngEnabled && !totalConstraint.isFull) startMicroBlockMining(account, block, totalConstraint)
}
Task.unit

case Right(Ignored) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ object BlockAppender extends ScorexLogging {
validApplication <- EitherT(apply(blockchainUpdater, time, utxStorage, pos, scheduler)(newBlock))
} yield validApplication).value

val handle = append.asyncBoundary.map {
val handle = append.map {
case Right(Ignored) => // block already appended
case Right(Applied(_, _)) =>
log.debug(s"${id(ch)} Appended $newBlock")

span.markNtp("block.applied")
span.finishNtp()
BlockStats.applied(newBlock, BlockStats.Source.Broadcast, blockchainUpdater.height)
if (newBlock.transactionData.isEmpty) allChannels.broadcast(BlockForged(newBlock), Some(ch)) // Key block
if (blockchainUpdater.isLastBlockId(newBlock.id()) && newBlock.transactionData.isEmpty)
allChannels.broadcast(BlockForged(newBlock), Some(ch)) // Key block

case Left(is: InvalidSignature) =>
peerDatabase.blacklistAndClose(ch, s"Could not append $newBlock: $is")
Expand Down

0 comments on commit d6f9f8f

Please sign in to comment.