@@ -6,6 +6,7 @@ import io.iohk.ethereum.blockchain.data.GenesisDataLoader.JsonSerializers.{
6
6
ByteStringJsonSerializer ,
7
7
UInt256JsonSerializer
8
8
}
9
+ import io .iohk .ethereum .db .storage .MptStorage
9
10
import io .iohk .ethereum .db .storage .StateStorage .GenesisDataLoad
10
11
import io .iohk .ethereum .rlp .RLPList
11
12
import io .iohk .ethereum .utils .BlockchainConfig
@@ -92,24 +93,7 @@ class GenesisDataLoader(blockchain: Blockchain, blockchainConfig: BlockchainConf
92
93
val storage = stateStorage.getReadOnlyStorage
93
94
val initalRootHash = MerklePatriciaTrie .EmptyRootHash
94
95
95
- val stateMptRootHash = genesisData.alloc.zipWithIndex.foldLeft(initalRootHash) {
96
- case (rootHash, ((address, genesisAccount), _)) =>
97
- val mpt = MerklePatriciaTrie [Array [Byte ], Account ](rootHash, storage)
98
- val paddedAddress = address.reverse.padTo(addressLength, " 0" ).reverse.mkString
99
- val stateRoot = mpt
100
- .put(
101
- crypto.kec256(Hex .decode(paddedAddress)),
102
- Account (
103
- nonce = genesisAccount.nonce
104
- .getOrElse(blockchainConfig.accountStartNonce),
105
- balance = genesisAccount.balance,
106
- codeHash = genesisAccount.code.map(codeValue => crypto.kec256(codeValue)).getOrElse(Account .EmptyCodeHash )
107
- )
108
- )
109
- .getRootHash
110
- stateRoot
111
- }
112
-
96
+ val stateMptRootHash = getGenesisStateRoot(genesisData, initalRootHash, storage)
113
97
val header : BlockHeader = prepareHeader(genesisData, stateMptRootHash)
114
98
115
99
log.debug(s " Prepared genesis header: $header" )
@@ -138,6 +122,27 @@ class GenesisDataLoader(blockchain: Blockchain, blockchainConfig: BlockchainConf
138
122
}
139
123
}
140
124
125
+ private def getGenesisStateRoot (genesisData : GenesisData , initalRootHash : Array [Byte ], storage : MptStorage ) = {
126
+ import MerklePatriciaTrie .defaultByteArraySerializable
127
+
128
+ genesisData.alloc.zipWithIndex.foldLeft(initalRootHash) { case (rootHash, ((address, genesisAccount), _)) =>
129
+ val mpt = MerklePatriciaTrie [Array [Byte ], Account ](rootHash, storage)
130
+ val paddedAddress = address.reverse.padTo(addressLength, " 0" ).reverse.mkString
131
+ val stateRoot = mpt
132
+ .put(
133
+ crypto.kec256(Hex .decode(paddedAddress)),
134
+ Account (
135
+ nonce = genesisAccount.nonce
136
+ .getOrElse(blockchainConfig.accountStartNonce),
137
+ balance = genesisAccount.balance,
138
+ codeHash = genesisAccount.code.map(codeValue => crypto.kec256(codeValue)).getOrElse(Account .EmptyCodeHash )
139
+ )
140
+ )
141
+ .getRootHash
142
+ stateRoot
143
+ }
144
+ }
145
+
141
146
private def prepareHeader (genesisData : GenesisData , stateMptRootHash : Array [Byte ]) =
142
147
BlockHeader (
143
148
parentHash = zeros(hashLength),
0 commit comments