Skip to content

Commit

Permalink
[FIX] Added suffix to variables and comment indicating order of blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Tallar committed Nov 4, 2020
1 parent eab3d15 commit 64b1b41
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/main/scala/io/iohk/ethereum/ledger/BlockExecution.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,33 +123,33 @@ class BlockExecution(
* @param blocks blocks to be executed
* @param parentTd transaction difficulty of the parent
*
* @return a list of blocks that were correctly executed and an optional [[BlockExecutionError]]
* @return a list of blocks in incremental order that were correctly executed and an optional [[BlockExecutionError]]
*/
def executeAndValidateBlocks(
blocks: List[Block],
parentTd: BigInt
): (List[BlockData], Option[BlockExecutionError]) = {
@tailrec
def go(
executedBlocks: List[BlockData],
remainingBlocks: List[Block],
executedBlocksDecOrder: List[BlockData],
remainingBlocksIncOrder: List[Block],
parentTd: BigInt,
error: Option[BlockExecutionError]
): (List[BlockData], Option[BlockExecutionError]) = {
if (remainingBlocks.isEmpty) {
(executedBlocks.reverse, None)
if (remainingBlocksIncOrder.isEmpty) {
(executedBlocksDecOrder.reverse, None)
} else if (error.isDefined) {
(executedBlocks.reverse, error)
(executedBlocksDecOrder.reverse, error)
} else {
val blockToExecute = remainingBlocks.head
val blockToExecute = remainingBlocksIncOrder.head
executeAndValidateBlock(blockToExecute, alreadyValidated = true) match {
case Right(receipts) =>
val td = parentTd + blockToExecute.header.difficulty
val newBlockData = BlockData(blockToExecute, receipts, td)
blockchain.save(newBlockData.block, newBlockData.receipts, newBlockData.td, saveAsBestBlock = true)
go(newBlockData :: executedBlocks, remainingBlocks.tail, td, None)
go(newBlockData :: executedBlocksDecOrder, remainingBlocksIncOrder.tail, td, None)
case Left(executionError) =>
go(executedBlocks, remainingBlocks, 0, Some(executionError))
go(executedBlocksDecOrder, remainingBlocksIncOrder, 0, Some(executionError))
}
}
}
Expand Down

0 comments on commit 64b1b41

Please sign in to comment.