Skip to content

Commit 355e8ec

Browse files
author
Nicolas Tallar
committed
[ETCM-143] Redefine block header structure and encoding
1 parent d818fd9 commit 355e8ec

33 files changed

+371
-255
lines changed

src/ets/scala/io/iohk/ethereum/ets/blockchain/Scenario.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ case class BlockHeaderDef(
5555
) {
5656

5757
def toBlockHeader: BlockHeader =
58-
BlockHeader(parentHash, uncleHash, coinbase, stateRoot, transactionsTrie, receiptTrie, bloom, difficulty, number,
59-
gasLimit, gasUsed, timestamp, extraData, mixHash, nonce, None
58+
BlockHeader.buildPreECIP1098Header(parentHash, uncleHash, coinbase, stateRoot, transactionsTrie, receiptTrie, bloom,
59+
difficulty, number, gasLimit, gasUsed, timestamp, extraData, mixHash, nonce
6060
)
6161
}
6262

src/ets/scala/io/iohk/ethereum/ets/vm/ScenarioBuilder.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ object ScenarioBuilder {
3636
}
3737

3838
def prepareHeader(env: Env): BlockHeader =
39-
BlockHeader(
39+
BlockHeader.buildPreECIP1098Header(
4040
env.previousHash.getOrElse(bEmpty),
4141
bEmpty,
4242
env.currentCoinbase.bytes,
@@ -51,8 +51,7 @@ object ScenarioBuilder {
5151
env.currentTimestamp,
5252
bEmpty,
5353
bEmpty,
54-
bEmpty,
55-
None
54+
bEmpty
5655
)
5756

5857
def prepareWorld(accounts: Map[Address, AccountState], blockNumber: BigInt, exec: Exec): MockWorldState = {

src/it/scala/io/iohk/ethereum/txExecTest/util/DumpChainActor.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import akka.actor.{Actor, ActorRef, _}
77
import akka.util.ByteString
88
import io.iohk.ethereum.crypto.kec256
99
import io.iohk.ethereum.domain.{BlockBody, BlockHeader, Receipt}
10-
import io.iohk.ethereum.domain.BlockHeader._
10+
import io.iohk.ethereum.domain.BlockHeaderImplicits._
1111
import io.iohk.ethereum.network.{Peer, PeerManagerActor}
1212
import io.iohk.ethereum.network.PeerActor.SendMessage
1313
import io.iohk.ethereum.network.PeerManagerActor.{GetPeers, Peers}

src/it/scala/io/iohk/ethereum/txExecTest/util/DumpChainApp.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import io.iohk.ethereum.db.dataSource.DataSourceBatchUpdate
2626
import org.bouncycastle.util.encoders.Hex
2727

2828
import scala.concurrent.duration._
29+
import io.iohk.ethereum.domain.BlockHeader.HeaderExtraFields.HefPreEcip1098
2930

3031
object DumpChainApp extends App with NodeKeyBuilder with SecureRandomBuilder with AuthHandshakerBuilder {
3132
val conf = ConfigFactory.load("txExecTest/chainDump.conf")
@@ -103,7 +104,7 @@ object DumpChainApp extends App with NodeKeyBuilder with SecureRandomBuilder wit
103104
class BlockchainMock(genesisHash: ByteString) extends Blockchain {
104105

105106
class FakeHeader() extends BlockHeader(ByteString.empty, ByteString.empty, ByteString.empty, ByteString.empty,
106-
ByteString.empty, ByteString.empty, ByteString.empty, 0, 0, 0, 0, 0, ByteString.empty, ByteString.empty, ByteString.empty, None) {
107+
ByteString.empty, ByteString.empty, ByteString.empty, 0, 0, 0, 0, 0, ByteString.empty, ByteString.empty, ByteString.empty, HefPreEcip1098) {
107108
override lazy val hash: ByteString = genesisHash
108109
}
109110

src/it/scala/io/iohk/ethereum/txExecTest/util/FixtureProvider.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import java.io.Closeable
55
import akka.util.ByteString
66
import io.iohk.ethereum.db.storage._
77
import io.iohk.ethereum.domain._
8-
import io.iohk.ethereum.domain.BlockHeader._
8+
import io.iohk.ethereum.domain.BlockHeaderImplicits._
99
import io.iohk.ethereum.domain.BlockBody._
1010
import io.iohk.ethereum.network.p2p.messages.PV63._
1111
import MptNodeEncoders._

src/main/scala/io/iohk/ethereum/blockchain/data/GenesisDataLoader.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class GenesisDataLoader(
119119
}
120120

121121
private def prepareHeader(genesisData: GenesisData, stateMptRootHash: Array[Byte]) =
122-
BlockHeader(
122+
BlockHeader.buildPreECIP1098Header(
123123
parentHash = zeros(hashLength),
124124
ommersHash = ByteString(crypto.kec256(rlp.encode(RLPList()))),
125125
beneficiary = genesisData.coinbase,
@@ -134,8 +134,7 @@ class GenesisDataLoader(
134134
unixTimestamp = BigInt(genesisData.timestamp.replace("0x", ""), 16).toLong,
135135
extraData = genesisData.extraData,
136136
mixHash = genesisData.mixHash.getOrElse(zeros(hashLength)),
137-
nonce = genesisData.nonce,
138-
treasuryOptOut = None
137+
nonce = genesisData.nonce
139138
)
140139

141140
private def zeros(length: Int) =

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import io.iohk.ethereum.crypto.kec256
1111
import io.iohk.ethereum.db.dataSource.EphemDataSource
1212
import io.iohk.ethereum.db.storage.StateStorage
1313
import io.iohk.ethereum.domain._
14+
import io.iohk.ethereum.domain.BlockHeader.HeaderExtraFields._
1415
import io.iohk.ethereum.consensus.ethash.blocks.OmmersSeqEnc
1516
import io.iohk.ethereum.ledger.Ledger.{BlockPreparationResult, BlockResult}
1617
import io.iohk.ethereum.ledger.{BlockPreparator, BloomFilter}
@@ -51,7 +52,11 @@ abstract class BlockGeneratorSkeleton(
5152
blockTimestamp: Long,
5253
x: Ommers
5354
): BlockHeader = {
54-
val optOut = if(blockNumber >= blockchainConfig.ecip1098BlockNumber) Some(consensusConfig.treasuryOptOut) else None
55+
val extraFields =
56+
if(blockNumber >= blockchainConfig.ecip1098BlockNumber)
57+
HefPostEcip1098(consensusConfig.treasuryOptOut)
58+
else
59+
HefPreEcip1098
5560

5661
BlockHeader(
5762
parentHash = parent.header.hash,
@@ -70,7 +75,7 @@ abstract class BlockGeneratorSkeleton(
7075
extraData = blockchainConfig.daoForkConfig.flatMap(daoForkConfig => daoForkConfig.getExtraData(blockNumber)).getOrElse(headerExtraData),
7176
mixHash = ByteString.empty,
7277
nonce = ByteString.empty,
73-
treasuryOptOut = optOut
78+
extraFields = extraFields
7479
)
7580
}
7681

src/main/scala/io/iohk/ethereum/consensus/ethash/blocks/package.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package io.iohk.ethereum.consensus.ethash
22

33
import io.iohk.ethereum.consensus.ethash.validators.OmmersValidator.OmmersError
44
import io.iohk.ethereum.domain.BlockHeader
5+
import io.iohk.ethereum.domain.BlockHeaderImplicits._
56
import io.iohk.ethereum.ledger.BlockPreparationError
67
import io.iohk.ethereum.rlp.{RLPEncodeable, RLPList, RLPSerializable}
78

src/main/scala/io/iohk/ethereum/consensus/validators/BlockHeaderValidatorSkeleton.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import io.iohk.ethereum.consensus.GetBlockHeaderByHash
44
import io.iohk.ethereum.consensus.difficulty.DifficultyCalculator
55
import io.iohk.ethereum.consensus.validators.BlockHeaderError._
66
import io.iohk.ethereum.domain.BlockHeader
7+
import io.iohk.ethereum.domain.BlockHeader.HeaderExtraFields.HefPreEcip1098
78
import io.iohk.ethereum.utils.{BlockchainConfig, DaoForkConfig}
89

910
/**
@@ -172,7 +173,7 @@ abstract class BlockHeaderValidatorSkeleton(blockchainConfig: BlockchainConfig)
172173
*/
173174
private def validateOptOut(blockHeader: BlockHeader): Either[BlockHeaderError, BlockHeaderValid] = {
174175
val isEcip1098Activated = blockHeader.number >= blockchainConfig.ecip1098BlockNumber
175-
val isOptOutDefined = blockHeader.treasuryOptOut.isDefined
176+
val isOptOutDefined = blockHeader.extraFields != HefPreEcip1098
176177

177178
if (isEcip1098Activated && isOptOutDefined) Right(BlockHeaderValid)
178179
else if (!isEcip1098Activated && !isOptOutDefined) Right(BlockHeaderValid)

src/main/scala/io/iohk/ethereum/db/storage/BlockBodiesStorage.scala

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import java.nio.ByteBuffer
44

55
import akka.util.ByteString
66
import boopickle.Default.{Pickle, Unpickle}
7-
import io.iohk.ethereum.crypto.ECDSASignature
87
import io.iohk.ethereum.db.dataSource.DataSource
98
import io.iohk.ethereum.db.storage.BlockBodiesStorage.BlockBodyHash
10-
import io.iohk.ethereum.domain.{Address, BlockBody, BlockHeader, Checkpoint, SignedTransaction, Transaction}
9+
import io.iohk.ethereum.domain.BlockBody
1110
import io.iohk.ethereum.utils.ByteUtils.compactPickledBytes
11+
import io.iohk.ethereum.utils.Picklers._
1212

1313
/**
1414
* This class is used to store the BlockBody, by using:
@@ -30,20 +30,4 @@ class BlockBodiesStorage(val dataSource: DataSource) extends TransactionalKeyVal
3030

3131
object BlockBodiesStorage {
3232
type BlockBodyHash = ByteString
33-
34-
import boopickle.DefaultBasic._
35-
36-
implicit val byteStringPickler: Pickler[ByteString] = transformPickler[ByteString, Array[Byte]](ByteString(_))(_.toArray[Byte])
37-
implicit val addressPickler: Pickler[Address] =
38-
transformPickler[Address, ByteString](bytes => Address(bytes))(address => address.bytes)
39-
implicit val transactionPickler: Pickler[Transaction] = generatePickler[Transaction]
40-
implicit val ecdsaSignaturePickler: Pickler[ECDSASignature] = generatePickler[ECDSASignature]
41-
implicit val checkpointPickler: Pickler[Checkpoint] = generatePickler[Checkpoint]
42-
implicit val signedTransactionPickler: Pickler[SignedTransaction] = transformPickler[SignedTransaction, (Transaction, ECDSASignature)]
43-
{ case (tx, signature) => new SignedTransaction(tx, signature) }{ stx => (stx.tx, stx.signature)}
44-
45-
implicit val blockHeaderPickler: Pickler[BlockHeader] = generatePickler[BlockHeader]
46-
implicit val blockBodyPickler: Pickler[BlockBody] = transformPickler[BlockBody, (Seq[SignedTransaction], Seq[BlockHeader])]
47-
{case (stx, nodes) => BlockBody(stx, nodes) }{ blockBody => (blockBody.transactionList, blockBody.uncleNodesList) }
48-
4933
}

0 commit comments

Comments
 (0)