Skip to content

Commit

Permalink
Create alt chain after invalid prevRandao (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mashonskiy authored Sep 4, 2024
1 parent b5d9ec5 commit 5639545
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/scala/units/ELUpdater.scala
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ class ELUpdater(
}
}

private def checkRandao(networkBlock: NetworkL2Block, epochNumber: Int): Either[String, Unit] =
private def validateRandao(networkBlock: NetworkL2Block, epochNumber: Int): Either[String, Unit] =
blockchain.vrf(epochNumber) match {
case None => s"VRF of $epochNumber epoch is empty".asLeft
case Some(vrf) =>
val expectedPrevRandao = calculateRandao(vrf, networkBlock.parentHash)
Either.cond(
expectedPrevRandao == networkBlock.prevRandao,
(),
s"expected prevRandao $expectedPrevRandao, got ${networkBlock.prevRandao}, VRF=$vrf of $epochNumber. Wrong epoch?"
s"expected prevRandao $expectedPrevRandao, got ${networkBlock.prevRandao}, VRF=$vrf of $epochNumber"
)
}

Expand Down Expand Up @@ -980,7 +980,7 @@ class ELUpdater(
s"block miner ${networkBlock.minerRewardL2Address} doesn't equal to ${epochInfo.rewardAddress}"
)
_ <- checkSignature(networkBlock, isConfirmed)
_ <- checkRandao(networkBlock, contractBlock.fold(epochInfo.number)(_.epoch))
_ <- if (contractBlock.isEmpty) validateRandao(networkBlock, epochInfo.number) else Either.unit
result <- preValidateWithdrawals(networkBlock, epochInfo, contractBlock)
} yield result).leftMap { err =>
s"Block ${networkBlock.hash} validation error: $err, ignoring block"
Expand All @@ -990,12 +990,14 @@ class ELUpdater(
private def validateBlock(
networkBlock: NetworkL2Block,
parentEcBlock: EcBlock,
contractBlock: Option[ContractBlock],
expectReward: Boolean,
chainContractOptions: ChainContractOptions
): Job[Unit] = {
(for {
_ <- validateTimestamp(networkBlock, parentEcBlock)
_ <- validateWithdrawals(networkBlock, parentEcBlock, expectReward, chainContractOptions)
_ <- contractBlock.fold(Either.unit[String])(cb => validateRandao(networkBlock, cb.epoch))
} yield ()).leftMap(err => ClientError(s"Network block ${networkBlock.hash} validation error: $err"))
}

Expand Down Expand Up @@ -1084,7 +1086,7 @@ class ELUpdater(
logger.debug(err)
case Right(preValidationResult) =>
val applyResult = for {
_ <- validateBlock(networkBlock, expectedParent, preValidationResult.expectReward, prevState.options)
_ <- validateBlock(networkBlock, expectedParent, contractBlock, preValidationResult.expectReward, prevState.options)
_ = logger.debug(s"Block ${networkBlock.hash} was successfully validated, trying to apply and broadcast")
_ <- engineApiClient.applyNewPayload(networkBlock.payload)
} yield ()
Expand Down

0 comments on commit 5639545

Please sign in to comment.