@@ -6,9 +6,7 @@ import io.iohk.ethereum.ledger.Ledger.BlockResult
6
6
import io .iohk .ethereum .utils .{BlockchainConfig , DaoForkConfig , Logger }
7
7
import io .iohk .ethereum .vm .EvmConfig
8
8
import scala .annotation .tailrec
9
- import scala .util .Try
10
- import akka .util .ByteString
11
- import io .iohk .ethereum .mpt .MerklePatriciaTrie .MissingNodeException
9
+ import cats .implicits ._
12
10
13
11
class BlockExecution (
14
12
blockchain : BlockchainImpl ,
@@ -62,9 +60,8 @@ class BlockExecution(
62
60
.getBlockHeaderByHash(block.header.parentHash)
63
61
.toRight(MissingParentError ) // Should not never occur because validated earlier
64
62
execResult <- executeBlockTransactions(block, parent)
65
- worldToPersist <- Try {
66
- blockPreparator.payBlockReward(block, execResult.worldState)
67
- }.toEither.left.map(BlockExecutionError .MPTError (_))
63
+ worldToPersist <- Either .catchOnly[Throwable ](blockPreparator.payBlockReward(block, execResult.worldState))
64
+ .leftMap(BlockExecutionError .MPTError .apply)
68
65
// State root hash needs to be up-to-date for validateBlockAfterExecution
69
66
worldPersisted = InMemoryWorldStateProxy .persistState(worldToPersist)
70
67
} yield execResult.copy(worldState = worldPersisted)
@@ -174,21 +171,21 @@ sealed trait BlockExecutionError {
174
171
175
172
sealed trait BlockExecutionSuccess
176
173
177
- case object BlockExecutionSuccess extends BlockExecutionSuccess
174
+ final case object BlockExecutionSuccess extends BlockExecutionSuccess
178
175
179
176
object BlockExecutionError {
180
- case class ValidationBeforeExecError (reason : Any ) extends BlockExecutionError
177
+ final case class ValidationBeforeExecError (reason : Any ) extends BlockExecutionError
181
178
182
- case class StateBeforeFailure (worldState : InMemoryWorldStateProxy , acumGas : BigInt , acumReceipts : Seq [Receipt ])
179
+ final case class StateBeforeFailure (worldState : InMemoryWorldStateProxy , acumGas : BigInt , acumReceipts : Seq [Receipt ])
183
180
184
- case class TxsExecutionError (stx : SignedTransaction , stateBeforeError : StateBeforeFailure , reason : String )
181
+ final case class TxsExecutionError (stx : SignedTransaction , stateBeforeError : StateBeforeFailure , reason : String )
185
182
extends BlockExecutionError
186
183
187
- case class ValidationAfterExecError (reason : String ) extends BlockExecutionError
184
+ final case class ValidationAfterExecError (reason : String ) extends BlockExecutionError
188
185
189
- case object MissingParentError extends BlockExecutionError {
186
+ final case object MissingParentError extends BlockExecutionError {
190
187
override val reason : Any = " Cannot find parent"
191
188
}
192
189
193
- case class MPTError (reason : Throwable ) extends BlockExecutionError
190
+ final case class MPTError (reason : Throwable ) extends BlockExecutionError
194
191
}
0 commit comments