Skip to content

Commit 9c52217

Browse files
Igor Grahovacdzajkowski
authored andcommitted
ETCM-697: Fixed issue related to genesis data loading
1 parent 922b205 commit 9c52217

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ class GenesisDataLoader(blockchain: Blockchain, blockchainConfig: BlockchainConf
9090
val initalRootHash = MerklePatriciaTrie.EmptyRootHash
9191

9292
val stateMptRootHash = genesisData.alloc.zipWithIndex.foldLeft(initalRootHash) {
93-
case (rootHash, (((address, genesisAccount), idx))) =>
93+
case (rootHash, ((address, genesisAccount), _)) =>
9494
val mpt = MerklePatriciaTrie[Array[Byte], Account](rootHash, storage)
9595
val paddedAddress = address.reverse.padTo(addressLength, "0").reverse.mkString
9696
val stateRoot = mpt
9797
.put(
9898
crypto.kec256(Hex.decode(paddedAddress)),
99-
Account(nonce = genesisAccount.nonce, balance = genesisAccount.balance, codeHash = genesisAccount.code)
99+
Account(nonce = genesisAccount.nonce, balance = genesisAccount.balance)
100100
)
101101
.getRootHash
102102
stateRoot

src/main/scala/io/iohk/ethereum/jsonrpc/JsonMethodsImplicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ trait JsonMethodsImplicits {
3030
def encodeAsHex(input: BigInt): JString =
3131
JString(s"0x${input.toString(16)}")
3232

33-
protected def decode(s: String): Array[Byte] = {
33+
def decode(s: String): Array[Byte] = {
3434
val stripped = s.replaceFirst("^0x", "")
3535
val normalized = if (stripped.length % 2 == 1) "0" + stripped else stripped
3636
Hex.decode(normalized)

src/main/scala/io/iohk/ethereum/jsonrpc/TestJsonMethodsImplicits.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,14 @@ object TestJsonMethodsImplicits extends JsonMethodsImplicits {
7474
private def extractGenesis(genesisJson: JValue): Either[JsonRpcError, GenesisParams] = {
7575
for {
7676
author <- extractBytes((genesisJson \ "author").extract[String])
77+
difficulty = (genesisJson \ "difficulty").extractOrElse("0")
7778
extraData <- extractBytes((genesisJson \ "extraData").extract[String])
7879
gasLimit <- extractQuantity(genesisJson \ "gasLimit")
7980
parentHash <- extractBytes((genesisJson \ "parentHash").extractOrElse(""))
8081
timestamp <- extractBytes((genesisJson \ "timestamp").extract[String])
81-
} yield GenesisParams(author, extraData, gasLimit, parentHash, timestamp)
82+
nonce <- extractBytes((genesisJson \ "nonce").extract[String])
83+
mixHash <- extractBytes((genesisJson \ "mixHash").extract[String])
84+
} yield GenesisParams(author, difficulty, extraData, gasLimit, parentHash, timestamp, nonce, mixHash)
8285
}
8386

8487
def decodeJson(params: Option[JArray]): Either[JsonRpcError, SetChainParamsRequest] =

src/main/scala/io/iohk/ethereum/jsonrpc/TestService.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ import scala.util.{Failure, Success, Try}
2323
object TestService {
2424
case class GenesisParams(
2525
author: ByteString,
26+
difficulty: String,
2627
extraData: ByteString,
2728
gasLimit: BigInt,
2829
parentHash: ByteString,
29-
timestamp: ByteString
30+
timestamp: ByteString,
31+
nonce: ByteString,
32+
mixHash: ByteString
3033
)
3134
case class BlockchainParams(
3235
EIP150ForkBlock: BigInt,
@@ -89,9 +92,9 @@ class TestService(
8992
)
9093

9194
val genesisData = GenesisData(
92-
nonce = ByteString(Hex.decode("00")),
93-
mixHash = None,
94-
difficulty = "0",
95+
nonce = request.chainParams.genesis.nonce,
96+
mixHash = Some(request.chainParams.genesis.mixHash),
97+
difficulty = request.chainParams.genesis.difficulty,
9598
extraData = request.chainParams.genesis.extraData,
9699
gasLimit = "0x" + request.chainParams.genesis.gasLimit.toString(16),
97100
coinbase = request.chainParams.genesis.author,
@@ -159,8 +162,8 @@ class TestService(
159162
private def handleResult(blockImportResult: BlockImportResult): ServiceResponse[ImportRawBlockResponse] = {
160163
blockImportResult match {
161164
case BlockImportedToTop(blockImportData) => {
162-
consensus.blockTimestamp += 1
163-
Task.now(Right(ImportRawBlockResponse(ByteStringUtils.hash2string(blockImportData.head.block.hash))))
165+
val blockHash = s"0x${ByteStringUtils.hash2string(blockImportData.head.block.header.hash)}"
166+
Task.now(Right(ImportRawBlockResponse(blockHash)))
164167
}
165168
case _ => Task.now(Left(JsonRpcError(-1, "block validation failed!", None)))
166169
}

0 commit comments

Comments
 (0)