Skip to content

Commit

Permalink
[ETCM-43][ETCM-46] Rename BlockHeader's optOut for treasuryOptOut
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Tallar committed Sep 21, 2020
1 parent bcad249 commit 4153c9a
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 51 deletions.
Expand Up @@ -135,7 +135,7 @@ class GenesisDataLoader(
extraData = genesisData.extraData,
mixHash = genesisData.mixHash.getOrElse(zeros(hashLength)),
nonce = genesisData.nonce,
optOut = None
treasuryOptOut = None
)

private def zeros(length: Int) =
Expand Down
Expand Up @@ -70,7 +70,7 @@ abstract class BlockGeneratorSkeleton(
extraData = blockchainConfig.daoForkConfig.flatMap(daoForkConfig => daoForkConfig.getExtraData(blockNumber)).getOrElse(headerExtraData),
mixHash = ByteString.empty,
nonce = ByteString.empty,
optOut = optOut
treasuryOptOut = optOut
)
}

Expand Down
Expand Up @@ -165,14 +165,14 @@ abstract class BlockHeaderValidatorSkeleton(blockchainConfig: BlockchainConfig)
else Left(HeaderNumberError)

/**
* Validates [[io.iohk.ethereum.domain.BlockHeader.optOut]] is only defined if ECIP1098 is enabled at the block's number
* Validates [[io.iohk.ethereum.domain.BlockHeader.treasuryOptOut]] is only defined if ECIP1098 is enabled at the block's number
*
* @param blockHeader BlockHeader to validate.
* @return BlockHeader if valid, an [[HeaderOptOutError]] otherwise
*/
private def validateOptOut(blockHeader: BlockHeader): Either[BlockHeaderError, BlockHeaderValid] = {
val isEcip1098Activated = blockHeader.number >= blockchainConfig.ecip1098BlockNumber
val isOptOutDefined = blockHeader.optOut.isDefined
val isOptOutDefined = blockHeader.treasuryOptOut.isDefined

if (isEcip1098Activated && isOptOutDefined) Right(BlockHeaderValid)
else if (!isEcip1098Activated && !isOptOutDefined) Right(BlockHeaderValid)
Expand Down
Expand Up @@ -81,6 +81,6 @@ object BlockHeadersStorage {
blockHeader.extraData,
blockHeader.mixHash,
blockHeader.nonce,
blockHeader.optOut
blockHeader.treasuryOptOut
)}
}
10 changes: 5 additions & 5 deletions src/main/scala/io/iohk/ethereum/domain/BlockHeader.scala
Expand Up @@ -23,7 +23,7 @@ case class BlockHeader(
extraData: ByteString,
mixHash: ByteString,
nonce: ByteString,
optOut: Option[Boolean]) {
treasuryOptOut: Option[Boolean]) {

override def toString: String = {
s"""BlockHeader {
Expand All @@ -42,7 +42,7 @@ case class BlockHeader(
|extraData: ${Hex.toHexString(extraData.toArray[Byte])}
|mixHash: ${Hex.toHexString(mixHash.toArray[Byte])}
|nonce: ${Hex.toHexString(nonce.toArray[Byte])},
|optOut: $optOut
|treasuryOptOut: $treasuryOptOut
|}""".stripMargin
}

Expand All @@ -64,11 +64,11 @@ object BlockHeader {

def getEncodedWithoutNonce(blockHeader: BlockHeader): Array[Byte] = {
val rlpEncoded = blockHeader.toRLPEncodable match {
case rlpList: RLPList if blockHeader.optOut.isEmpty =>
case rlpList: RLPList if blockHeader.treasuryOptOut.isEmpty =>
// Pre ECIP1098 block
RLPList(rlpList.items.dropRight(2): _*)

case rlpList: RLPList if blockHeader.optOut.isDefined =>
case rlpList: RLPList if blockHeader.treasuryOptOut.isDefined =>
// Post ECIP1098 block
val rlpItemsWithoutNonce = rlpList.items.dropRight(3) :+ rlpList.items.last
RLPList(rlpItemsWithoutNonce: _*)
Expand All @@ -81,7 +81,7 @@ object BlockHeader {
implicit class BlockHeaderEnc(blockHeader: BlockHeader) extends RLPSerializable {
override def toRLPEncodable: RLPEncodeable = {
import blockHeader._
optOut match {
treasuryOptOut match {
case Some(definedOptOut) =>
// Post ECIP1098 block, whole block is encoded
val encodedOptOut = if(definedOptOut) 1 else 0
Expand Down
10 changes: 5 additions & 5 deletions src/test/scala/io/iohk/ethereum/Fixtures.scala
Expand Up @@ -42,7 +42,7 @@ object Fixtures {
extraData = ByteString(Hex.decode("d5830104098650617269747986312e31332e30826c69")),
mixHash = ByteString(Hex.decode("be90ac33b3f6d0316e60eef505ff5ec7333c9f3c85c1a36fc2523cd6b75ddb8a")),
nonce = ByteString(Hex.decode("2b0fb0c002946392")),
optOut = None
treasuryOptOut = None
)

val body = BlockBody(
Expand Down Expand Up @@ -131,7 +131,7 @@ object Fixtures {
extraData = ByteString(Hex.decode("11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa")),
mixHash = ByteString(Hex.decode("0000000000000000000000000000000000000000000000000000000000000000")),
nonce = ByteString(Hex.decode("0000000000000042")),
optOut = None
treasuryOptOut = None
)
override val body: BlockBody = BlockBody(
transactionList = Seq[SignedTransaction](
Expand Down Expand Up @@ -160,7 +160,7 @@ object Fixtures {
extraData = ByteString(Hex.decode("e4b883e5bda9e7a59ee4bb99e9b1bc")),
mixHash = ByteString(Hex.decode("c52daa7054babe515b17ee98540c0889cf5e1595c5dd77496997ca84a68c8da1")),
nonce = ByteString(Hex.decode("05276a600980199d")),
optOut = None
treasuryOptOut = None
)
override val body: BlockBody = BlockBody(
transactionList = Seq[SignedTransaction](
Expand Down Expand Up @@ -249,7 +249,7 @@ object Fixtures {
extraData = ByteString(Hex.decode("64616f2d686172642d666f726b")),
mixHash = ByteString(Hex.decode("5b5acbf4bf305f948bd7be176047b20623e1417f75597341a059729165b92397")),
nonce = ByteString(Hex.decode("bede87201de42426")),
optOut = None
treasuryOptOut = None
)
override lazy val body: BlockBody = BlockBody(
transactionList = Seq[SignedTransaction](
Expand Down Expand Up @@ -336,7 +336,7 @@ object Fixtures {
extraData = ByteString(Hex.decode("4477617266506f6f6c")),
mixHash = ByteString(Hex.decode("7f9ac1ddeafff0f926ed9887b8cf7d50c3f919d902e618b957022c46c8b404a6")),
nonce = ByteString(Hex.decode("60832709c8979daa")),
optOut = None
treasuryOptOut = None
)
override lazy val body: BlockBody = BlockBody.empty
override lazy val transactionHashes: Seq[ByteString] = ???
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/io/iohk/ethereum/ObjectGenerators.scala
Expand Up @@ -171,7 +171,7 @@ trait ObjectGenerators {
extraData = extraData,
mixHash = mixHash,
nonce = nonce,
optOut = optOut
treasuryOptOut = optOut
)

def seqBlockHeaderGen: Gen[Seq[BlockHeader]] = Gen.listOf(blockHeaderGen)
Expand Down
Expand Up @@ -431,7 +431,7 @@ class BlockGeneratorSpec extends FlatSpec with Matchers with ScalaCheckPropertyC
blockGenerator.generateBlock(parentBlock, Nil, Address(testAddress), blockGenerator.emptyX)
generatedBlock shouldBe a[Right[_, Block]]

generatedBlock.right.foreach(b => b.block.header.optOut shouldBe expectedOptOut)
generatedBlock.right.foreach(b => b.block.header.treasuryOptOut shouldBe expectedOptOut)
}

}
Expand Down
Expand Up @@ -87,7 +87,7 @@ abstract class MinerSpecSetup(implicit system: ActorSystem) extends ScenarioSetu
extraData = consensusConfig.headerExtraData,
mixHash = ByteString.empty,
nonce = ByteString.empty,
optOut = None
treasuryOptOut = None
),
BlockBody(transactions, Nil)
)
Expand Down
Expand Up @@ -184,7 +184,7 @@ class BlockHeaderValidatorSpec
val blockchainConfigWithECIP1098Enabled: BlockchainConfig = blockchainConfig.copy(ecip1098BlockNumber = ecip1098BlockNumber)
val blockHeaderValidator = new BlockValidatorWithPowMocked(blockchainConfigWithECIP1098Enabled)

val validHeader = validBlockHeader.copy(optOut = Some(true))
val validHeader = validBlockHeader.copy(treasuryOptOut = Some(true))

val validationResult = blockHeaderValidator.validate(validHeader, validParentBlockHeader)
validationResult shouldBe Right(BlockHeaderValid)
Expand All @@ -195,7 +195,7 @@ class BlockHeaderValidatorSpec
val blockchainConfigWithECIP1098Disabled: BlockchainConfig = blockchainConfig.copy(ecip1098BlockNumber = ecip1098BlockNumber)
val blockHeaderValidator = new BlockValidatorWithPowMocked(blockchainConfigWithECIP1098Disabled)

val headerWithOptOutInvalidlyOn = validBlockHeader.copy(optOut = Some(true))
val headerWithOptOutInvalidlyOn = validBlockHeader.copy(treasuryOptOut = Some(true))

val validationResult = blockHeaderValidator.validate(headerWithOptOutInvalidlyOn, validParentBlockHeader)
validationResult shouldBe Left(HeaderOptOutError(ecip1098Activated = false, optOutDefined = true))
Expand All @@ -206,7 +206,7 @@ class BlockHeaderValidatorSpec
val blockchainConfigWithECIP1098Enabled: BlockchainConfig = blockchainConfig.copy(ecip1098BlockNumber = ecip1098BlockNumber)
val blockHeaderValidator = new BlockValidatorWithPowMocked(blockchainConfigWithECIP1098Enabled)

val headerWithOptOutInvalidlyOn = validBlockHeader.copy(optOut = None)
val headerWithOptOutInvalidlyOn = validBlockHeader.copy(treasuryOptOut = None)

val validationResult = blockHeaderValidator.validate(headerWithOptOutInvalidlyOn, validParentBlockHeader)
validationResult shouldBe Left(HeaderOptOutError(ecip1098Activated = true, optOutDefined = false))
Expand Down Expand Up @@ -287,7 +287,7 @@ class BlockHeaderValidatorSpec
extraData = ByteString(Hex.decode("d58301050b8650617269747986312e31352e31826c69")),
mixHash = ByteString(Hex.decode("7d2db22c3dfaccb1b6927f5675ec24a41991ee4bcffdc564f940a45c1fce8acb")),
nonce = ByteString(Hex.decode("81d6a5e8029f9446")),
optOut = None
treasuryOptOut = None
)

val pausedDifficultyBombBlockParent = BlockHeader(
Expand All @@ -306,7 +306,7 @@ class BlockHeaderValidatorSpec
extraData = ByteString(Hex.decode("d58301050c8650617269747986312e31362e30826c69")),
mixHash = ByteString(Hex.decode("d10215664192800200eab9ca7b90f9ceb8d8428200c2b4e6aebe2191c2a52c0e")),
nonce = ByteString(Hex.decode("83e2d9b401cdfa77")),
optOut = None
treasuryOptOut = None
)

val afterRewardReductionBlockHeader = BlockHeader(
Expand All @@ -325,7 +325,7 @@ class BlockHeaderValidatorSpec
extraData = ByteString(Hex.decode("657468706f6f6c2e6f7267202855533129")),
mixHash = ByteString(Hex.decode("8f86617d6422c26a89b8b349b160973ca44f90326e758f1ef669c4046741dd06")),
nonce = ByteString(Hex.decode("2cc9a5500763ce09")),
optOut = None
treasuryOptOut = None
)

val afterRewardReductionParentBlockHeader = BlockHeader(
Expand All @@ -344,7 +344,7 @@ class BlockHeaderValidatorSpec
extraData = ByteString(Hex.decode("73656f3130")),
mixHash = ByteString(Hex.decode("8f86617d6422c26a89b8b349b160973ca44f90326e758f1ef669c4046741dd06")),
nonce = ByteString(Hex.decode("b9fa123002b9407d")),
optOut = None
treasuryOptOut = None
)

val validBlockHeader = BlockHeader(
Expand All @@ -363,7 +363,7 @@ class BlockHeaderValidatorSpec
extraData = ByteString(Hex.decode("d783010507846765746887676f312e372e33856c696e7578")),
mixHash = ByteString(Hex.decode("6bc729364c9b682cfa923ba9480367ebdfa2a9bca2a652fe975e8d5958f696dd")),
nonce = ByteString(Hex.decode("797a8f3a494f937b")),
optOut = None
treasuryOptOut = None
)

val validParentBlockHeader = BlockHeader(
Expand All @@ -382,7 +382,7 @@ class BlockHeaderValidatorSpec
extraData = ByteString(Hex.decode("d783010507846765746887676f312e372e33856c696e7578")),
mixHash = ByteString(Hex.decode("7f9ac1ddeafff0f926ed9887b8cf7d50c3f919d902e618b957022c46c8b404a6")),
nonce = ByteString(Hex.decode("3fc7bc671f7cee70")),
optOut = None
treasuryOptOut = None
)

val validParentBlockBody = BlockBody(Seq.empty, Seq.empty)
Expand Down Expand Up @@ -449,7 +449,7 @@ class BlockHeaderValidatorSpec
extraData = ByteString(Hex.decode("64616f2d686172642d666f726b")),
mixHash = ByteString(Hex.decode("e73421390c1b084a9806754b238715ec333cdccc8d09b90cb6e38a9d1e247d6f")),
nonce = ByteString(Hex.decode("c207c8381305bef2")),
optOut = None
treasuryOptOut = None
)

val ProDaoBlock1920009Header = BlockHeader(
Expand All @@ -472,7 +472,7 @@ class BlockHeaderValidatorSpec
extraData = ByteString(Hex.decode("64616f2d686172642d666f726b")),
mixHash = ByteString(Hex.decode("5bde79f4dc5be28af2d956e748a0d6ebc1f8eb5c1397e76729269e730611cb99")),
nonce = ByteString(Hex.decode("2b4b464c0a4da82a")),
optOut = None
treasuryOptOut = None
)

val ProDaoBlock1920010Header = BlockHeader(
Expand All @@ -495,7 +495,7 @@ class BlockHeaderValidatorSpec
extraData = ByteString(Hex.decode("657468706f6f6c2e6f7267202855533129")),
mixHash = ByteString(Hex.decode("8f86617d6422c26a89b8b349b160973ca44f90326e758f1ef669c4046741dd06")),
nonce = ByteString(Hex.decode("c7de19e00a8c3e32")),
optOut = None
treasuryOptOut = None
)

}
Expand Up @@ -84,7 +84,7 @@ class BlockValidatorSpec extends FlatSpec with Matchers {
extraData = ByteString(Hex.decode("d5830104098650617269747986312e31332e30826c69")),
mixHash = ByteString(Hex.decode("be90ac33b3f6d0316e60eef505ff5ec7333c9f3c85c1a36fc2523cd6b75ddb8a")),
nonce = ByteString(Hex.decode("2b0fb0c002946392")),
optOut = None
treasuryOptOut = None
)

val validBlockBody = BlockBody(
Expand Down
Expand Up @@ -99,7 +99,7 @@ class OmmersValidatorSpec extends FlatSpec with Matchers with ScalaCheckProperty
extraData = ByteString(Hex.decode("426974636f696e2069732054484520426c6f636b636861696e2e")),
mixHash = ByteString(Hex.decode("c6d695926546d3d679199303a6d1fc983fe3f09f44396619a24c4271830a7b95")),
nonce = ByteString(Hex.decode("62bc3dca012c1b27")),
optOut = None
treasuryOptOut = None
)
val ommer2 = BlockHeader(
parentHash = ByteString(Hex.decode("fd07e36cfaf327801e5696134b36678f6a89fb1e8f017f2411a29d0ae810ab8b")),
Expand All @@ -121,7 +121,7 @@ class OmmersValidatorSpec extends FlatSpec with Matchers with ScalaCheckProperty
extraData = ByteString(Hex.decode("476574682f76312e302e302f6c696e75782f676f312e342e32")),
mixHash = ByteString(Hex.decode("8c1ed8037984be0fe9065f8f8663c3baeeb6436868ac6915dd3c2cd5fd46fa96")),
nonce = ByteString(Hex.decode("40b0b2c0b6d14706")),
optOut = None
treasuryOptOut = None
)
val ommers: Seq[BlockHeader] = Seq[BlockHeader](ommer1, ommer2)
val ommersBlockNumber = 97
Expand All @@ -147,7 +147,7 @@ class OmmersValidatorSpec extends FlatSpec with Matchers with ScalaCheckProperty
extraData = ByteString(Hex.decode("476574682f6b6c6f737572652f76312e302e302d66633739643332642f6c696e")),
mixHash = ByteString(Hex.decode("f28f1b53323dc8a6a4fe73495e71e81947366b68d8a217daa4e349b0c939401f")),
nonce = ByteString(Hex.decode("f91fd0cc60d6948c")),
optOut = None
treasuryOptOut = None
),
BlockBody(Seq.empty, Seq.empty)
)
Expand All @@ -172,7 +172,7 @@ class OmmersValidatorSpec extends FlatSpec with Matchers with ScalaCheckProperty
extraData = ByteString(Hex.decode("476574682f76312e302e302f6c696e75782f676f312e342e32")),
mixHash = ByteString(Hex.decode("eadd3fbbb336d073a33e4fb9faa97be8b0e904aeb8b65eeae243e1e35d86e6c3")),
nonce = ByteString(Hex.decode("20fdc1504ec955a0")),
optOut = None
treasuryOptOut = None
),
BlockBody(Seq.empty, Seq.empty)
)
Expand All @@ -197,7 +197,7 @@ class OmmersValidatorSpec extends FlatSpec with Matchers with ScalaCheckProperty
extraData = ByteString(Hex.decode("476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32")),
mixHash = ByteString(Hex.decode("afd3d088f65607ad7404837db220add9cf54ca0f4fb107e3f6bee9d0aca18e7f")),
nonce = ByteString(Hex.decode("dd7e335a44c7e9c9")),
optOut = None
treasuryOptOut = None
),
BlockBody(Seq.empty, Seq.empty)
)
Expand All @@ -222,7 +222,7 @@ class OmmersValidatorSpec extends FlatSpec with Matchers with ScalaCheckProperty
extraData = ByteString(Hex.decode("476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32")),
mixHash = ByteString(Hex.decode("631f88fd52a9a7ee3cc3a08945eb2ab8f4da37d7cf96592dac9af514f28365bc")),
nonce = ByteString(Hex.decode("cdc4e60cbd67b791")),
optOut = None
treasuryOptOut = None
),
BlockBody(
Seq.empty,
Expand All @@ -248,7 +248,7 @@ class OmmersValidatorSpec extends FlatSpec with Matchers with ScalaCheckProperty
extraData = ByteString(Hex.decode("476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32")),
mixHash = ByteString(Hex.decode("7e0b76b9b1698947617c1ea7cb7c36f47aefc2c4095c6df90aa6e2b3da6e49ac")),
nonce = ByteString(Hex.decode("edcbf5efad298bb3")),
optOut = None
treasuryOptOut = None
)
)
)
Expand All @@ -274,7 +274,7 @@ class OmmersValidatorSpec extends FlatSpec with Matchers with ScalaCheckProperty
extraData = ByteString(Hex.decode("476574682f6b6c6f737572652f76312e302e302d66633739643332642f6c696e")),
mixHash = ByteString(Hex.decode("33fe497dae796c62f261d10304786b0c63cd59030a0f96c811a88e90e7d02b0f")),
nonce = ByteString(Hex.decode("36da15d93277d947")),
optOut = None
treasuryOptOut = None
),
BlockBody(
Seq.empty,
Expand All @@ -300,7 +300,7 @@ class OmmersValidatorSpec extends FlatSpec with Matchers with ScalaCheckProperty
extraData = ByteString(Hex.decode("476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32")),
mixHash = ByteString(Hex.decode("0688a1217172b2f81b168a25459a2cad5cc2337aab1d17b30c7d803c565bf0b3")),
nonce = ByteString(Hex.decode("efc94c53e5ad946a")),
optOut = None
treasuryOptOut = None
)
)
)
Expand All @@ -326,7 +326,7 @@ class OmmersValidatorSpec extends FlatSpec with Matchers with ScalaCheckProperty
extraData = ByteString(Hex.decode("476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32")),
mixHash = ByteString(Hex.decode("d1ed067b52da47010ab970117677233d9da738b22fe955899f9ed2e4360fc924")),
nonce = ByteString(Hex.decode("75d5ff831690242a")),
optOut = None
treasuryOptOut = None
),
BlockBody(Seq.empty, Seq.empty)
)
Expand All @@ -351,7 +351,7 @@ class OmmersValidatorSpec extends FlatSpec with Matchers with ScalaCheckProperty
extraData = ByteString(Hex.decode("426974636f696e2069732054484520426c6f636b636861696e2e")),
mixHash = ByteString(Hex.decode("b4f571ecf4dcebe75260f4929a01de8b2c19c161bea20dda91bfb92298f7262f")),
nonce = ByteString(Hex.decode("1dbc948cb756c2b9")),
optOut = None
treasuryOptOut = None
),
BlockBody(Seq.empty, Seq.empty)
)
Expand All @@ -377,7 +377,7 @@ class OmmersValidatorSpec extends FlatSpec with Matchers with ScalaCheckProperty
extraData = ByteString(Hex.decode("426974636f696e2069732054484520426c6f636b636861696e2e")),
mixHash = ByteString(Hex.decode("d7c06ea893693857f10675f02502ce63d74fe80b3bce9749b507888f3acd0b5d")),
nonce = ByteString(Hex.decode("1d48377931a68d12")),
optOut = None
treasuryOptOut = None
),
BlockBody(Seq.empty, Seq.empty)
)
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/io/iohk/ethereum/domain/BlockHeaderSpec.scala
Expand Up @@ -49,7 +49,7 @@ class BlockHeaderSpec extends FreeSpec with Matchers with ScalaCheckPropertyChec
extraData = ByteString(Hex.decode("d783010507846765746887676f312e372e33856c696e7578")),
mixHash = ByteString(Hex.decode("6bc729364c9b682cfa923ba9480367ebdfa2a9bca2a652fe975e8d5958f696dd")),
nonce = ByteString(Hex.decode("797a8f3a494f937b")),
optOut = None
treasuryOptOut = None
)

val block2 = BlockHeader(
Expand All @@ -68,7 +68,7 @@ class BlockHeaderSpec extends FreeSpec with Matchers with ScalaCheckPropertyChec
extraData = ByteString(Hex.decode("d783010507846765746887676f312e372e33856c696e7578")),
mixHash = ByteString(Hex.decode("7f9ac1ddeafff0f926ed9887b8cf7d50c3f919d902e618b957022c46c8b404a6")),
nonce = ByteString(Hex.decode("3fc7bc671f7cee70")),
optOut = None
treasuryOptOut = None
)
}

Expand Down

0 comments on commit 4153c9a

Please sign in to comment.