Skip to content

Commit

Permalink
Stabilized AlternativeChainTestSuite
Browse files Browse the repository at this point in the history
  • Loading branch information
vsuharnikov committed Nov 14, 2024
1 parent 1229157 commit 69b5306
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import units.docker.WavesNodeContainer

class AlternativeChainTestSuite extends BaseDockerTestSuite {
"L2-383 Start an alternative chain after not getting an EL-block" in {
step("Wait miner #1 forge at least one block")
def getLastContractBlock = chainContract.getLastBlockMeta(0).getOrElse(fail("Can't get last block"))
retry {
getLastContractBlock.height > 0
}

step("EL miner #2 join")
waves1.api.broadcastAndWait(
ChainContract.join(
Expand All @@ -19,7 +25,7 @@ class AlternativeChainTestSuite extends BaseDockerTestSuite {
waitMinerEpoch(miner21Account)

step("Issue miner #2 block confirmation")
val lastContractBlock = chainContract.getLastBlockMeta(0).getOrElse(fail("Can't get last block"))
val lastContractBlock = getLastContractBlock
val lastWavesBlock = waves1.api.blockHeader(waves1.api.height).getOrElse(fail("Can't get current block header"))
waves1.api.broadcastAndWait(
ChainContract.extendMainChain(
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/units/ELUpdater.scala
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,10 @@ class ELUpdater(

private def rollbackTo(prevState: Working[ChainStatus], target: L2BlockLike, finalizedBlock: ContractBlock): JobResult[Working[ChainStatus]] = {
val targetHash = target.hash
logger.info(s"Starting rollback to $targetHash")
for {
rollbackBlock <- mkRollbackBlock(targetHash)
_ = logger.info(s"Starting rollback to $targetHash using rollback block ${rollbackBlock.hash}")
_ = logger.info(s"Intermediate rollback block: ${rollbackBlock.hash}")
fixedFinalizedBlock = if (finalizedBlock.height > rollbackBlock.parentBlock.height) rollbackBlock.parentBlock else finalizedBlock
_ <- confirmBlock(rollbackBlock.hash, fixedFinalizedBlock.hash)
_ <- confirmBlock(target, fixedFinalizedBlock)
Expand All @@ -286,7 +287,7 @@ class ELUpdater(
setState("10", newState)
newState
}
}
}.left.map(e => ClientError(s"Error during rollback: ${e.message}"))

private def startBuildingPayload(
epochInfo: EpochInfo,
Expand Down

0 comments on commit 69b5306

Please sign in to comment.