Skip to content

Commit b9be290

Browse files
author
Nicolas Tallar
committed
[Fix] Non checkpoint blocks after ECIP1098 should have HefPostEcip1097 extra fields
1 parent 1667f33 commit b9be290

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

src/main/scala/io/iohk/ethereum/consensus/blocks/BlockGeneratorSkeleton.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ abstract class BlockGeneratorSkeleton(
4646
x: Ommers
4747
): BlockHeader = {
4848
val extraFields =
49-
if (blockNumber >= blockchainConfig.ecip1098BlockNumber)
49+
if (blockNumber >= blockchainConfig.ecip1097BlockNumber)
50+
HefPostEcip1097(consensusConfig.treasuryOptOut, None)
51+
else if (blockNumber >= blockchainConfig.ecip1098BlockNumber)
5052
HefPostEcip1098(consensusConfig.treasuryOptOut)
5153
else
5254
HefEmpty

src/test/scala/io/iohk/ethereum/consensus/BlockGeneratorSpec.scala

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package io.iohk.ethereum.consensus
22

33
import java.time.Instant
44
import java.util.concurrent.Executors
5+
56
import akka.util.ByteString
67
import io.iohk.ethereum.blockchain.data.GenesisDataLoader
78
import io.iohk.ethereum.blockchain.sync.EphemBlockchainTestSetup
@@ -10,6 +11,8 @@ import io.iohk.ethereum.consensus.ethash.validators.ValidatorsExecutor
1011
import io.iohk.ethereum.consensus.validators._
1112
import io.iohk.ethereum.crypto
1213
import io.iohk.ethereum.crypto._
14+
import io.iohk.ethereum.domain.BlockHeader.HeaderExtraFields
15+
import io.iohk.ethereum.domain.BlockHeader.HeaderExtraFields.{HefEmpty, HefPostEcip1097, HefPostEcip1098}
1316
import io.iohk.ethereum.domain.SignedTransaction.FirstByteOfAddress
1417
import io.iohk.ethereum.domain._
1518
import io.iohk.ethereum.ledger.{BlockExecution, BlockQueue, BlockValidation}
@@ -19,6 +22,7 @@ import org.bouncycastle.crypto.AsymmetricCipherKeyPair
1922
import org.bouncycastle.crypto.params.ECPublicKeyParameters
2023
import org.bouncycastle.util.encoders.Hex
2124
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
25+
2226
import scala.concurrent.duration.Duration
2327
import scala.concurrent.{Await, ExecutionContext}
2428
import org.scalatest.flatspec.AnyFlatSpec
@@ -412,31 +416,39 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
412416
fullBlock.header.extraData shouldBe headerExtraData
413417
}
414418

415-
it should "build blocks with the correct opt-out" in {
416-
val table = Table[Boolean, Boolean, Option[Boolean]](
417-
("ecip1098Activated", "selectedOptOut", "expectedOptOut"),
418-
// Already activated
419-
(true, true, Some(true)),
420-
(true, false, Some(false)),
421-
// Not yet activated
422-
(false, true, None),
423-
(false, false, None)
419+
it should "generate blocks with the correct extra fields" in {
420+
val table = Table[Boolean, Boolean, Boolean, HeaderExtraFields](
421+
("ecip1098Activated", "ecip1097Activated", "selectedOptOut", "expectedExtraFields"),
422+
// No ecip activated
423+
(false, false, true, HefEmpty),
424+
(false, false, false, HefEmpty),
425+
// ECIP 1098 activated
426+
(true, false, true, HefPostEcip1098(true)),
427+
(true, false, false, HefPostEcip1098(false)),
428+
// ECIP 1097 and 1098 activated
429+
(true, true, true, HefPostEcip1097(true, None)),
430+
(true, true, false, HefPostEcip1097(false, None)),
424431
)
425432

426-
forAll(table) { case (ecip1098Activated, selectedOptOut, expectedOptOut) =>
433+
forAll(table) { case (ecip1098Activated, ecip1097Activated, selectedOptOut, headerExtraFields) =>
427434
val testSetup = new TestSetup {
428-
override lazy val blockchainConfig = baseBlockchainConfig.copy(ecip1098BlockNumber = 10000000)
435+
override lazy val blockchainConfig = baseBlockchainConfig.copy(ecip1098BlockNumber = 1000, ecip1097BlockNumber = 2000)
429436

430437
override lazy val consensusConfig = buildConsensusConfig().copy(treasuryOptOut = selectedOptOut)
431438
}
432439
import testSetup._
433440

434441
val blockNumber =
435-
if (ecip1098Activated) blockchainConfig.ecip1098BlockNumber * 2 else blockchainConfig.ecip1098BlockNumber / 2
442+
if (ecip1098Activated && ecip1097Activated)
443+
blockchainConfig.ecip1097BlockNumber * 2
444+
else if (ecip1098Activated)
445+
(blockchainConfig.ecip1097BlockNumber + blockchainConfig.ecip1098BlockNumber) / 2
446+
else
447+
blockchainConfig.ecip1098BlockNumber / 2
436448
val parentBlock = bestBlock.copy(header = bestBlock.header.copy(number = blockNumber - 1))
437449
val generatedBlock = blockGenerator.generateBlock(parentBlock, Nil, Address(testAddress), blockGenerator.emptyX)
438450

439-
generatedBlock.block.header.treasuryOptOut shouldBe expectedOptOut
451+
generatedBlock.block.header.extraFields shouldBe headerExtraFields
440452
}
441453

442454
}

0 commit comments

Comments
 (0)