Skip to content

Commit

Permalink
Better code
Browse files Browse the repository at this point in the history
  • Loading branch information
xrtm000 committed Nov 30, 2023
1 parent 861be8f commit 51f585a
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,17 @@ class MicroBlockMinerImpl(
account: KeyPair,
block: Block,
transactions: Seq[Transaction],
updatedTotalConstraint: MiningConstraint,
constraint: MiningConstraint,
stateHash: Option[BlockId]
): Task[MicroBlockMiningResult] =
for {
(signedBlock, microBlock) <- forgeBlocks(account, block, transactions, stateHash)
.leftWiden[Throwable]
.liftTo[Task]
blockId <- appendMicroBlock(microBlock)
(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)
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

0 comments on commit 51f585a

Please sign in to comment.