Skip to content

Commit 7e80892

Browse files
author
Leonor Boga
committed
ETCM-944 Pass getBlockHashByNumber field directly to InMemoryWorldStateProxy
1 parent a7833bd commit 7e80892

20 files changed

+29
-29
lines changed

src/it/scala/io/iohk/ethereum/ledger/BlockImporterItSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class BlockImporterItSpec
6262
val emptyWorld = InMemoryWorldStateProxy(
6363
storagesInstance.storages.evmCodeStorage,
6464
blockchain.getBackingStorage(-1),
65-
blockchain,
65+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
6666
blockchainConfig.accountStartNonce,
6767
ByteString(MerklePatriciaTrie.EmptyRootHash),
6868
noEmptyAccounts = false,

src/it/scala/io/iohk/ethereum/sync/util/CommonFakePeer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ abstract class CommonFakePeer(peerName: String, fakePeerCustomConfig: FakePeerCu
244244
InMemoryWorldStateProxy(
245245
storagesInstance.storages.evmCodeStorage,
246246
bl.getBackingStorage(block.number),
247-
bl,
247+
(number: BigInt) => bl.getBlockHeaderByNumber(number).map(_.hash),
248248
blockchainConfig.accountStartNonce,
249249
block.header.stateRoot,
250250
noEmptyAccounts = EvmConfig.forBlock(block.number, blockchainConfig).noEmptyAccounts,

src/it/scala/io/iohk/ethereum/sync/util/RegularSyncItSpecUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ object RegularSyncItSpecUtils {
215215
InMemoryWorldStateProxy(
216216
storagesInstance.storages.evmCodeStorage,
217217
bl.getBackingStorage(block.number),
218-
bl,
218+
(number: BigInt) => bl.getBlockHeaderByNumber(number).map(_.hash),
219219
UInt256.Zero,
220220
ByteString(MerklePatriciaTrie.EmptyRootHash),
221221
noEmptyAccounts = false,

src/main/resources/conf/base.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ mantis {
386386
nodes-per-request = 384
387387

388388
# Minimum number of peers required to start fast-sync (by determining the pivot block)
389-
min-peers-to-choose-pivot-block = 3
389+
min-peers-to-choose-pivot-block = 1
390390

391391
# Number of additional peers used to determine pivot block during fast-sync
392392
# Number of peers used to reach consensus = min-peers-to-choose-pivot-block + peers-to-choose-pivot-block-margin

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class EthUserService(
3535
val world = InMemoryWorldStateProxy(
3636
evmCodeStorage,
3737
blockchain.getBackingStorage(block.header.number),
38-
blockchain,
38+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
3939
blockchainConfig.accountStartNonce,
4040
block.header.stateRoot,
4141
noEmptyAccounts = false,

src/main/scala/io/iohk/ethereum/ledger/BlockExecution.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class BlockExecution(
6565
initialWorld = InMemoryWorldStateProxy(
6666
evmCodeStorage = evmCodeStorage,
6767
blockchain.getBackingStorage(block.header.number),
68-
blockchain,
68+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
6969
accountStartNonce = blockchainConfig.accountStartNonce,
7070
stateRootHash = parentHeader.stateRoot,
7171
noEmptyAccounts = EvmConfig.forBlock(parentHeader.number, blockchainConfig).noEmptyAccounts,

src/main/scala/io/iohk/ethereum/ledger/BlockPreparator.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ class BlockPreparator(
382382
InMemoryWorldStateProxy(
383383
evmCodeStorage = evmCodeStorage,
384384
mptStorage = blockchain.getReadOnlyStorage(),
385-
blockchain = blockchain,
385+
getBlockHashByNumber = (number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
386386
accountStartNonce = blockchainConfig.accountStartNonce,
387387
stateRootHash = parent.stateRoot,
388388
noEmptyAccounts = EvmConfig.forBlock(block.header.number, blockchainConfig).noEmptyAccounts,

src/main/scala/io/iohk/ethereum/ledger/InMemoryWorldStateProxy.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object InMemoryWorldStateProxy {
1616
def apply(
1717
evmCodeStorage: EvmCodeStorage,
1818
mptStorage: MptStorage,
19-
blockchain: Blockchain,
19+
getBlockHashByNumber: BigInt => Option[ByteString],
2020
accountStartNonce: UInt256,
2121
stateRootHash: ByteString,
2222
noEmptyAccounts: Boolean,
@@ -25,7 +25,7 @@ object InMemoryWorldStateProxy {
2525
evmCodeStorage,
2626
mptStorage,
2727
accountStartNonce,
28-
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
28+
getBlockHashByNumber,
2929
stateRootHash,
3030
noEmptyAccounts,
3131
ethCompatibleStorage

src/main/scala/io/iohk/ethereum/ledger/StxLedger.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class StxLedger(
2424
InMemoryWorldStateProxy(
2525
evmCodeStorage = evmCodeStorage,
2626
mptStorage = blockchain.getReadOnlyStorage(),
27-
blockchain = blockchain,
27+
getBlockHashByNumber = (number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
2828
accountStartNonce = blockchainConfig.accountStartNonce,
2929
stateRootHash = blockHeader.stateRoot,
3030
noEmptyAccounts = EvmConfig.forBlock(blockHeader.number, blockchainConfig).noEmptyAccounts,

src/test/scala/io/iohk/ethereum/blockchain/sync/StateSyncUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object StateSyncUtils extends EphemBlockchainTestSetup {
3535
val init = InMemoryWorldStateProxy(
3636
evmCodeStorage,
3737
blockchain.getBackingStorage(1),
38-
blockchain,
38+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
3939
blockchainConfig.accountStartNonce,
4040
existingTree.getOrElse(ByteString(MerklePatriciaTrie.EmptyRootHash)),
4141
noEmptyAccounts = true,

src/test/scala/io/iohk/ethereum/jsonrpc/EthBlocksServiceSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ class EthBlocksServiceSpec
432432
val fakeWorld = InMemoryWorldStateProxy(
433433
storagesInstance.storages.evmCodeStorage,
434434
blockchain.getBackingStorage(-1),
435-
blockchain,
435+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
436436
UInt256.Zero,
437437
ByteString.empty,
438438
noEmptyAccounts = false,

src/test/scala/io/iohk/ethereum/jsonrpc/EthInfoServiceSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class EthServiceSpec
9898
val worldStateProxy = InMemoryWorldStateProxy(
9999
storagesInstance.storages.evmCodeStorage,
100100
blockchain.getBackingStorage(-1),
101-
blockchain,
101+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
102102
UInt256.Zero,
103103
ByteString.empty,
104104
noEmptyAccounts = false,

src/test/scala/io/iohk/ethereum/jsonrpc/EthMiningServiceSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class EthMiningServiceSpec
307307
val fakeWorld = InMemoryWorldStateProxy(
308308
storagesInstance.storages.evmCodeStorage,
309309
blockchain.getReadOnlyStorage(),
310-
blockchain,
310+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
311311
UInt256.Zero,
312312
ByteString.empty,
313313
noEmptyAccounts = false,

src/test/scala/io/iohk/ethereum/jsonrpc/JsonRpcControllerFixture.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class JsonRpcControllerFixture(implicit system: ActorSystem)
177177
val fakeWorld = InMemoryWorldStateProxy(
178178
storagesInstance.storages.evmCodeStorage,
179179
blockchain.getReadOnlyStorage(),
180-
blockchain,
180+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
181181
blockchainConfig.accountStartNonce,
182182
ByteString.empty,
183183
noEmptyAccounts = false,

src/test/scala/io/iohk/ethereum/ledger/BlockRewardSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class BlockRewardSpec extends AnyFlatSpec with Matchers with ScalaCheckPropertyC
194194
val worldState = InMemoryWorldStateProxy(
195195
storagesInstance.storages.evmCodeStorage,
196196
blockchain.getBackingStorage(-1),
197-
blockchain,
197+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
198198
UInt256.Zero,
199199
ByteString(MerklePatriciaTrie.EmptyRootHash),
200200
noEmptyAccounts = false,

src/test/scala/io/iohk/ethereum/ledger/DeleteAccountsSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class DeleteAccountsSpec extends AnyFlatSpec with Matchers with MockFactory {
6868
val worldStateWithoutPersist = InMemoryWorldStateProxy(
6969
storagesInstance.storages.evmCodeStorage,
7070
blockchain.getBackingStorage(-1),
71-
blockchain,
71+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
7272
UInt256.Zero,
7373
ByteString(MerklePatriciaTrie.EmptyRootHash),
7474
noEmptyAccounts = false,

src/test/scala/io/iohk/ethereum/ledger/DeleteTouchedAccountsSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class DeleteTouchedAccountsSpec extends AnyFlatSpec with Matchers {
151151
val worldStateWithoutPersist = InMemoryWorldStateProxy(
152152
storagesInstance.storages.evmCodeStorage,
153153
blockchain.getBackingStorage(-1),
154-
blockchain,
154+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
155155
UInt256.Zero,
156156
ByteString(MerklePatriciaTrie.EmptyRootHash),
157157
noEmptyAccounts = postEip161Config.noEmptyAccounts,
@@ -166,7 +166,7 @@ class DeleteTouchedAccountsSpec extends AnyFlatSpec with Matchers {
166166
val worldStateWithoutPersistPreEIP161 = InMemoryWorldStateProxy(
167167
storagesInstance.storages.evmCodeStorage,
168168
blockchain.getBackingStorage(-1),
169-
blockchain,
169+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
170170
UInt256.Zero,
171171
ByteString(MerklePatriciaTrie.EmptyRootHash),
172172
noEmptyAccounts = postEip160Config.noEmptyAccounts,

src/test/scala/io/iohk/ethereum/ledger/InMemoryWorldStateProxySpec.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class InMemoryWorldStateProxySpec extends AnyFlatSpec with Matchers {
126126
val newWorldState = InMemoryWorldStateProxy(
127127
storagesInstance.storages.evmCodeStorage,
128128
blockchain.getBackingStorage(-1),
129-
blockchain,
129+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
130130
UInt256.Zero,
131131
persistedWorldState.stateRootHash,
132132
noEmptyAccounts = true,
@@ -258,7 +258,7 @@ class InMemoryWorldStateProxySpec extends AnyFlatSpec with Matchers {
258258
val readWorldState = InMemoryWorldStateProxy(
259259
storagesInstance.storages.evmCodeStorage,
260260
blockchain.getReadOnlyStorage(),
261-
blockchain,
261+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
262262
UInt256.Zero,
263263
persistedWorldStateWithAnAccount.stateRootHash,
264264
noEmptyAccounts = false,
@@ -280,7 +280,7 @@ class InMemoryWorldStateProxySpec extends AnyFlatSpec with Matchers {
280280
val newReadWorld = InMemoryWorldStateProxy(
281281
storagesInstance.storages.evmCodeStorage,
282282
blockchain.getReadOnlyStorage(),
283-
blockchain,
283+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
284284
UInt256.Zero,
285285
changedReadWorld.stateRootHash,
286286
noEmptyAccounts = false,
@@ -309,7 +309,7 @@ class InMemoryWorldStateProxySpec extends AnyFlatSpec with Matchers {
309309
val world2 = InMemoryWorldStateProxy(
310310
storagesInstance.storages.evmCodeStorage,
311311
blockchain.getBackingStorage(-1),
312-
blockchain,
312+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
313313
UInt256.Zero,
314314
world1.stateRootHash,
315315
noEmptyAccounts = false,
@@ -335,7 +335,7 @@ class InMemoryWorldStateProxySpec extends AnyFlatSpec with Matchers {
335335
val worldState = InMemoryWorldStateProxy(
336336
storagesInstance.storages.evmCodeStorage,
337337
blockchain.getBackingStorage(-1),
338-
blockchain,
338+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
339339
UInt256.Zero,
340340
ByteString(MerklePatriciaTrie.EmptyRootHash),
341341
noEmptyAccounts = false,
@@ -345,7 +345,7 @@ class InMemoryWorldStateProxySpec extends AnyFlatSpec with Matchers {
345345
val postEIP161WorldState = InMemoryWorldStateProxy(
346346
storagesInstance.storages.evmCodeStorage,
347347
blockchain.getBackingStorage(-1),
348-
blockchain,
348+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
349349
UInt256.Zero,
350350
ByteString(MerklePatriciaTrie.EmptyRootHash),
351351
noEmptyAccounts = postEip161Config.noEmptyAccounts,

src/test/scala/io/iohk/ethereum/ledger/LedgerTestSetup.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ trait TestSetup extends SecureRandomBuilder with EphemBlockchainTestSetup {
8585
val emptyWorld: InMemoryWorldStateProxy = InMemoryWorldStateProxy(
8686
storagesInstance.storages.evmCodeStorage,
8787
blockchain.getBackingStorage(-1),
88-
blockchain,
88+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
8989
UInt256.Zero,
9090
ByteString(MerklePatriciaTrie.EmptyRootHash),
9191
noEmptyAccounts = false,
@@ -138,7 +138,7 @@ trait TestSetup extends SecureRandomBuilder with EphemBlockchainTestSetup {
138138
val initialWorld = InMemoryWorldStateProxy(
139139
storagesInstance.storages.evmCodeStorage,
140140
blockchain.getBackingStorage(-1),
141-
blockchain,
141+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
142142
UInt256.Zero,
143143
stateRootHash,
144144
noEmptyAccounts = false,
@@ -302,7 +302,7 @@ trait TestSetupWithVmAndValidators extends EphemBlockchainTestSetup {
302302
val emptyWorld = InMemoryWorldStateProxy(
303303
storagesInstance.storages.evmCodeStorage,
304304
blockchain.getBackingStorage(-1),
305-
blockchain,
305+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
306306
blockchainConfig.accountStartNonce,
307307
ByteString(MerklePatriciaTrie.EmptyRootHash),
308308
noEmptyAccounts = false,

src/test/scala/io/iohk/ethereum/ledger/StxLedgerSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ trait ScenarioSetup extends EphemBlockchainTestSetup {
155155
InMemoryWorldStateProxy(
156156
storagesInstance.storages.evmCodeStorage,
157157
blockchain.getBackingStorage(-1),
158-
blockchain,
158+
(number: BigInt) => blockchain.getBlockHeaderByNumber(number).map(_.hash),
159159
UInt256.Zero,
160160
ByteString(MerklePatriciaTrie.EmptyRootHash),
161161
noEmptyAccounts = false,

0 commit comments

Comments
 (0)