Skip to content

Commit

Permalink
Fix descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
AnastasiiaL committed Feb 25, 2021
1 parent 217aceb commit bf28b94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
14 changes: 7 additions & 7 deletions src/it/scala/io/iohk/ethereum/ledger/BlockImporterItSpec.scala
Expand Up @@ -129,7 +129,7 @@ class BlockImporterItSpec extends MockFactory with TestSetupWithVmAndValidators
blockchain.getBestBlock().get shouldEqual oldBlock4
}

it should "return a correct new best block after reorganising longer chain to a shorter one" in {
it should "return a correct new best block after reorganising longer chain to a shorter one if its weight is bigger" in {

//returning discarded initial chain
blockchain.save(oldBlock2, Nil, oldWeight2, saveAsBestBlock = true)
Expand All @@ -145,8 +145,8 @@ class BlockImporterItSpec extends MockFactory with TestSetupWithVmAndValidators

it should "switch to a branch with a checkpoint" in {

val chackpoint = ObjectGenerators.fakeCheckpointGen(3, 3).sample.get
val oldBlock5WithCheckpoint: Block = checkpointBlockGenerator.generate(oldBlock4, chackpoint)
val checkpoint = ObjectGenerators.fakeCheckpointGen(3, 3).sample.get
val oldBlock5WithCheckpoint: Block = checkpointBlockGenerator.generate(oldBlock4, checkpoint)
blockchain.save(oldBlock5WithCheckpoint, Nil, oldWeight4, saveAsBestBlock = true)

val newBranch = List(newBlock2, newBlock3)
Expand All @@ -158,10 +158,10 @@ class BlockImporterItSpec extends MockFactory with TestSetupWithVmAndValidators
blockchain.getLatestCheckpointBlockNumber() shouldEqual oldBlock5WithCheckpoint.header.number
}

it should "return a correct checkpointed block after reorganising longer chain to a shorter one and back" in {
it should "switch to a branch with a newer checkpoint" in {

val chackpoint = ObjectGenerators.fakeCheckpointGen(3, 3).sample.get
val newBlock4WithCheckpoint: Block = checkpointBlockGenerator.generate(newBlock3, chackpoint)
val checkpoint = ObjectGenerators.fakeCheckpointGen(3, 3).sample.get
val newBlock4WithCheckpoint: Block = checkpointBlockGenerator.generate(newBlock3, checkpoint)
blockchain.save(newBlock4WithCheckpoint, Nil, newWeight3, saveAsBestBlock = true)

val newBranch = List(newBlock4WithCheckpoint)
Expand All @@ -173,7 +173,7 @@ class BlockImporterItSpec extends MockFactory with TestSetupWithVmAndValidators
blockchain.getLatestCheckpointBlockNumber() shouldEqual newBlock4WithCheckpoint.header.number
}

it should "return a correct checkpointed block after receiving a new chackpoint from morpho" in {
it should "return a correct checkpointed block after receiving a request for generating a new checkpoint" in {

val parent = blockchain.getBestBlock().get
val newBlock5: Block = getBlock(genesisBlock.number + 5, difficulty = 104, parent = parent.header.hash)
Expand Down
23 changes: 10 additions & 13 deletions src/main/scala/io/iohk/ethereum/ledger/BlockExecution.scala
Expand Up @@ -6,9 +6,7 @@ import io.iohk.ethereum.ledger.Ledger.BlockResult
import io.iohk.ethereum.utils.{BlockchainConfig, DaoForkConfig, Logger}
import io.iohk.ethereum.vm.EvmConfig
import scala.annotation.tailrec
import scala.util.Try
import akka.util.ByteString
import io.iohk.ethereum.mpt.MerklePatriciaTrie.MissingNodeException
import cats.implicits._

class BlockExecution(
blockchain: BlockchainImpl,
Expand Down Expand Up @@ -62,9 +60,8 @@ class BlockExecution(
.getBlockHeaderByHash(block.header.parentHash)
.toRight(MissingParentError) // Should not never occur because validated earlier
execResult <- executeBlockTransactions(block, parent)
worldToPersist <- Try {
blockPreparator.payBlockReward(block, execResult.worldState)
}.toEither.left.map(BlockExecutionError.MPTError(_))
worldToPersist <- Either.catchOnly[Throwable](blockPreparator.payBlockReward(block, execResult.worldState))
.leftMap(BlockExecutionError.MPTError.apply)
// State root hash needs to be up-to-date for validateBlockAfterExecution
worldPersisted = InMemoryWorldStateProxy.persistState(worldToPersist)
} yield execResult.copy(worldState = worldPersisted)
Expand Down Expand Up @@ -174,21 +171,21 @@ sealed trait BlockExecutionError {

sealed trait BlockExecutionSuccess

case object BlockExecutionSuccess extends BlockExecutionSuccess
final case object BlockExecutionSuccess extends BlockExecutionSuccess

object BlockExecutionError {
case class ValidationBeforeExecError(reason: Any) extends BlockExecutionError
final case class ValidationBeforeExecError(reason: Any) extends BlockExecutionError

case class StateBeforeFailure(worldState: InMemoryWorldStateProxy, acumGas: BigInt, acumReceipts: Seq[Receipt])
final case class StateBeforeFailure(worldState: InMemoryWorldStateProxy, acumGas: BigInt, acumReceipts: Seq[Receipt])

case class TxsExecutionError(stx: SignedTransaction, stateBeforeError: StateBeforeFailure, reason: String)
final case class TxsExecutionError(stx: SignedTransaction, stateBeforeError: StateBeforeFailure, reason: String)
extends BlockExecutionError

case class ValidationAfterExecError(reason: String) extends BlockExecutionError
final case class ValidationAfterExecError(reason: String) extends BlockExecutionError

case object MissingParentError extends BlockExecutionError {
final case object MissingParentError extends BlockExecutionError {
override val reason: Any = "Cannot find parent"
}

case class MPTError(reason: Throwable) extends BlockExecutionError
final case class MPTError(reason: Throwable) extends BlockExecutionError
}

0 comments on commit bf28b94

Please sign in to comment.