Skip to content

Commit e43749a

Browse files
author
Łukasz Gąsior
committed
Fix ethCompatibleStorage param in blockPreparator; remove default value
1 parent 2e2be41 commit e43749a

File tree

11 files changed

+42
-26
lines changed

11 files changed

+42
-26
lines changed

src/main/scala/io/iohk/ethereum/domain/Blockchain.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,15 @@ trait Blockchain {
181181

182182
def getWorldStateProxy(blockNumber: BigInt,
183183
accountStartNonce: UInt256,
184-
stateRootHash: Option[ByteString] = None,
185-
noEmptyAccounts: Boolean = false,
186-
ethCompatibleStorage: Boolean = true): WS
184+
stateRootHash: Option[ByteString],
185+
noEmptyAccounts: Boolean,
186+
ethCompatibleStorage: Boolean): WS
187187

188188
def getReadOnlyWorldStateProxy(blockNumber: Option[BigInt],
189189
accountStartNonce: UInt256,
190-
stateRootHash: Option[ByteString] = None,
191-
noEmptyAccounts: Boolean = false,
192-
ethCompatibleStorage: Boolean = true): WS
190+
stateRootHash: Option[ByteString],
191+
noEmptyAccounts: Boolean,
192+
ethCompatibleStorage: Boolean): WS
193193

194194
def pruneState(blockNumber: BigInt): Unit
195195

@@ -316,24 +316,24 @@ class BlockchainImpl(
316316
override def getWorldStateProxy(blockNumber: BigInt,
317317
accountStartNonce: UInt256,
318318
stateRootHash: Option[ByteString],
319-
noEmptyAccount: Boolean = false,
320-
ethCompatibleStorage: Boolean = true): InMemoryWorldStateProxy =
319+
noEmptyAccounts: Boolean,
320+
ethCompatibleStorage: Boolean): InMemoryWorldStateProxy =
321321
InMemoryWorldStateProxy(
322322
evmCodeStorage,
323323
nodesKeyValueStorageFor(Some(blockNumber)),
324324
accountStartNonce,
325325
(number: BigInt) => getBlockHeaderByNumber(number).map(_.hash),
326326
stateRootHash,
327-
noEmptyAccount,
327+
noEmptyAccounts,
328328
ethCompatibleStorage
329329
)
330330

331331
//FIXME Maybe we can use this one in regular execution too and persist underlying storage when block execution is successful
332332
override def getReadOnlyWorldStateProxy(blockNumber: Option[BigInt],
333333
accountStartNonce: UInt256,
334334
stateRootHash: Option[ByteString],
335-
noEmptyAccount: Boolean = false,
336-
ethCompatibleStorage: Boolean = true): InMemoryWorldStateProxy =
335+
noEmptyAccounts: Boolean,
336+
ethCompatibleStorage: Boolean): InMemoryWorldStateProxy =
337337
InMemoryWorldStateProxy(
338338
evmCodeStorage,
339339
ReadOnlyNodeStorage(nodesKeyValueStorageFor(blockNumber)),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ class EthService(
600600
Future {
601601
resolveBlock(req.block).map { case ResolvedBlock(block, _) =>
602602
val world = blockchain.getWorldStateProxy(block.header.number, blockchainConfig.accountStartNonce, Some(block.header.stateRoot),
603+
noEmptyAccounts = false,
603604
ethCompatibleStorage = blockchainConfig.ethCompatibleStorage)
604605
GetCodeResponse(world.getCode(req.address))
605606
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ class BlockPreparator(
294294

295295
def prepareBlock(block: Block): BlockPreparationResult = {
296296
val parentStateRoot = blockchain.getBlockHeaderByHash(block.header.parentHash).map(_.stateRoot)
297-
val initialWorld = blockchain.getReadOnlyWorldStateProxy(None, blockchainConfig.accountStartNonce, parentStateRoot)
297+
val initialWorld = blockchain.getReadOnlyWorldStateProxy(None, blockchainConfig.accountStartNonce, parentStateRoot,
298+
noEmptyAccounts = false,
299+
ethCompatibleStorage = blockchainConfig.ethCompatibleStorage)
298300
val prepared = executePreparedTransactions(block.body.transactionList, initialWorld, block.header)
299301

300302
prepared match {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ class LedgerImpl(
461461
override def simulateTransaction(stx: SignedTransaction, blockHeader: BlockHeader, world: Option[InMemoryWorldStateProxy]): TxResult = {
462462

463463
val world1 = world.getOrElse(blockchain.getReadOnlyWorldStateProxy(None, blockchainConfig.accountStartNonce, Some(blockHeader.stateRoot),
464+
noEmptyAccounts = false,
464465
ethCompatibleStorage = blockchainConfig.ethCompatibleStorage))
465466

466467
val world2 =

src/test/scala/io/iohk/ethereum/Mocks.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ object Mocks {
3131
Right(Nil)
3232
else
3333
Left(TxsExecutionError(Fixtures.Blocks.Block3125369.body.transactionList.head,
34-
StateBeforeFailure(blockchain.getWorldStateProxy(0, UInt256.Zero),0,Nil),
34+
StateBeforeFailure(blockchain.getWorldStateProxy(0, UInt256.Zero, stateRootHash = None,
35+
noEmptyAccounts = false, ethCompatibleStorage = true), 0, Nil),
3536
"StubLedger was set to fail for this case"))
3637
}
3738

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ class EthServiceSpec extends FlatSpec with Matchers with ScalaFutures with MockF
422422
blockchain.save(blockToRequest)
423423
(appStateStorage.getBestBlockNumber _).expects().returning(blockToRequest.header.number)
424424

425-
val txResult = TxResult(BlockchainImpl(storagesInstance.storages).getWorldStateProxy(-1, UInt256.Zero, None), 123, Nil, ByteString("return_value"), None)
425+
val txResult = TxResult(BlockchainImpl(storagesInstance.storages).getWorldStateProxy(-1, UInt256.Zero, None,
426+
noEmptyAccounts = false, ethCompatibleStorage = true), 123, Nil, ByteString("return_value"), None)
426427
(ledger.simulateTransaction _).expects(*, *, *).returning(txResult)
427428

428429
val tx = CallTx(
@@ -1011,7 +1012,8 @@ class EthServiceSpec extends FlatSpec with Matchers with ScalaFutures with MockF
10111012

10121013
val txToRequest = Fixtures.Blocks.Block3125369.body.transactionList.head
10131014
val txToRequestHash = txToRequest.hash
1014-
val fakeWorld = blockchain.getReadOnlyWorldStateProxy(None, UInt256.Zero, None)
1015+
val fakeWorld = blockchain.getReadOnlyWorldStateProxy(None, UInt256.Zero, None,
1016+
noEmptyAccounts = false, ethCompatibleStorage = true)
10151017
}
10161018

10171019
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ class BlockRewardSpec extends FlatSpec with Matchers with MockFactory {
6969
val minerTwoOmmersReward = BigInt("5312500000000000000")
7070
val ommerFiveBlocksDifferenceReward = BigInt("1875000000000000000")
7171

72-
val worldState: InMemoryWorldStateProxy = BlockchainImpl(storagesInstance.storages).getWorldStateProxy(-1, UInt256.Zero, None)
72+
val worldState: InMemoryWorldStateProxy = BlockchainImpl(storagesInstance.storages).getWorldStateProxy(-1, UInt256.Zero, None,
73+
noEmptyAccounts = false, ethCompatibleStorage = true)
7374
.saveAccount(validAccountAddress, Account(balance = 10))
7475
.saveAccount(validAccountAddress2, Account(balance = 20))
7576
.saveAccount(validAccountAddress3, Account(balance = 30))

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class DeleteAccountsSpec extends FlatSpec with Matchers with MockFactory {
6161
val accountAddresses = Set(validAccountAddress, validAccountAddress2, validAccountAddress3)
6262

6363
val worldStateWithoutPersist: InMemoryWorldStateProxy =
64-
BlockchainImpl(storagesInstance.storages).getWorldStateProxy(-1, UInt256.Zero, None)
64+
BlockchainImpl(storagesInstance.storages).getWorldStateProxy(-1, UInt256.Zero, None,
65+
noEmptyAccounts = false, ethCompatibleStorage = true)
6566
.saveAccount(validAccountAddress, Account(balance = 10))
6667
.saveAccount(validAccountAddress2, Account(balance = 20))
6768
.saveAccount(validAccountAddress3, Account(balance = 30))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,15 @@ class DeleteTouchedAccountsSpec extends FlatSpec with Matchers with MockFactory
131131
val accountAddresses = Set(validAccountAddress, validAccountAddress2, validAccountAddress3, validEmptyAccountAddress, validEmptyAccountAddress1)
132132

133133
val worldStateWithoutPersist: InMemoryWorldStateProxy =
134-
BlockchainImpl(storagesInstance.storages).getWorldStateProxy(-1, UInt256.Zero, None, postEip161Config.noEmptyAccounts)
134+
BlockchainImpl(storagesInstance.storages).getWorldStateProxy(-1, UInt256.Zero, None, postEip161Config.noEmptyAccounts, ethCompatibleStorage = true)
135135
.saveAccount(validAccountAddress, Account(balance = validAccountBalance))
136136
.saveAccount(validAccountAddress2, Account(balance = 20))
137137
.saveAccount(validAccountAddress3, Account(balance = 30))
138138
.saveAccount(validEmptyAccountAddress, Account.empty())
139139
.saveAccount(validEmptyAccountAddress1, Account.empty())
140140

141141
val worldStateWithoutPersistPreEIP161: InMemoryWorldStateProxy =
142-
BlockchainImpl(storagesInstance.storages).getWorldStateProxy(-1, UInt256.Zero, None, postEip160Config.noEmptyAccounts)
142+
BlockchainImpl(storagesInstance.storages).getWorldStateProxy(-1, UInt256.Zero, None, postEip160Config.noEmptyAccounts, ethCompatibleStorage = true)
143143
.saveAccount(validAccountAddress, Account(balance = validAccountBalance))
144144
.saveAccount(validAccountAddress2, Account(balance = 20))
145145
.saveAccount(validAccountAddress3, Account(balance = 30))

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ class InMemoryWorldStateProxySpec extends FlatSpec with Matchers {
112112
validateInitialWorld(persistedWorldState)
113113

114114
// Create a new WS instance based on storages and new root state and check
115-
val newWorldState = BlockchainImpl(storagesInstance.storages).getWorldStateProxy(-1, UInt256.Zero, Some(persistedWorldState.stateRootHash))
115+
val newWorldState = BlockchainImpl(storagesInstance.storages).getWorldStateProxy(-1, UInt256.Zero, Some(persistedWorldState.stateRootHash),
116+
noEmptyAccounts = true, ethCompatibleStorage = true)
116117
validateInitialWorld(newWorldState)
117118

118119
// Update this new WS check everything is ok
@@ -234,7 +235,8 @@ class InMemoryWorldStateProxySpec extends FlatSpec with Matchers {
234235
val persistedWorldStateWithAnAccount = InMemoryWorldStateProxy.persistState(worldStateWithAnAccount)
235236

236237
val readWorldState =
237-
blockchain.getReadOnlyWorldStateProxy(None, UInt256.Zero, Some(persistedWorldStateWithAnAccount.stateRootHash))
238+
blockchain.getReadOnlyWorldStateProxy(None, UInt256.Zero, Some(persistedWorldStateWithAnAccount.stateRootHash),
239+
noEmptyAccounts = false, ethCompatibleStorage = false)
238240

239241
readWorldState.getAccount(address1) shouldEqual Some(account)
240242

@@ -247,7 +249,8 @@ class InMemoryWorldStateProxySpec extends FlatSpec with Matchers {
247249
changedReadState
248250
)
249251

250-
val newReadWorld = blockchain.getReadOnlyWorldStateProxy(None, UInt256.Zero, Some(changedReadWorld.stateRootHash))
252+
val newReadWorld = blockchain.getReadOnlyWorldStateProxy(None, UInt256.Zero, Some(changedReadWorld.stateRootHash),
253+
noEmptyAccounts = false, ethCompatibleStorage = false)
251254

252255
assertThrows[MPTException] {
253256
newReadWorld.getAccount(address1) shouldEqual Some(changedAccount)
@@ -259,8 +262,10 @@ class InMemoryWorldStateProxySpec extends FlatSpec with Matchers {
259262
trait TestSetup extends EphemBlockchainTestSetup {
260263
val postEip161Config = EvmConfig.PostEIP161ConfigBuilder(io.iohk.ethereum.vm.Fixtures.blockchainConfig)
261264

262-
val worldState = blockchain.getWorldStateProxy(-1, UInt256.Zero, None)
263-
val postEIP161WorldState = blockchain.getWorldStateProxy(-1, UInt256.Zero, None, postEip161Config.noEmptyAccounts)
265+
val worldState = blockchain.getWorldStateProxy(-1, UInt256.Zero, None,
266+
noEmptyAccounts = false, ethCompatibleStorage = true)
267+
val postEIP161WorldState = blockchain.getWorldStateProxy(-1, UInt256.Zero, None,
268+
noEmptyAccounts = postEip161Config.noEmptyAccounts, ethCompatibleStorage = false)
264269

265270
val address1 = Address(0x123456)
266271
val address2 = Address(0xabcdef)

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class LedgerSpec extends FlatSpec with PropertyChecks with Matchers with MockFac
5353
case object DeleteAccount extends Changes
5454

5555
def applyChanges(stateRootHash: ByteString, blockchainStorages: BlockchainStorages, changes: Seq[(Address, Changes)]): ByteString = {
56-
val initialWorld = BlockchainImpl(blockchainStorages).getWorldStateProxy(-1, UInt256.Zero, Some(stateRootHash))
56+
val initialWorld = BlockchainImpl(blockchainStorages).getWorldStateProxy(-1, UInt256.Zero, Some(stateRootHash),
57+
noEmptyAccounts = false, ethCompatibleStorage = true)
5758
val newWorld = changes.foldLeft[InMemoryWorldStateProxy](initialWorld){ case (recWorld, (address, change)) =>
5859
change match {
5960
case UpdateBalance(balanceIncrease) =>
@@ -731,7 +732,8 @@ class LedgerSpec extends FlatSpec with PropertyChecks with Matchers with MockFac
731732
val defaultGasLimit: UInt256 = 1000000
732733
val defaultValue: BigInt = 1000
733734

734-
val emptyWorld = BlockchainImpl(storagesInstance.storages).getWorldStateProxy(-1, UInt256.Zero, None)
735+
val emptyWorld = BlockchainImpl(storagesInstance.storages).getWorldStateProxy(-1, UInt256.Zero, None,
736+
noEmptyAccounts = false, ethCompatibleStorage = true)
735737

736738
val worldWithMinerAndOriginAccounts = InMemoryWorldStateProxy.persistState(emptyWorld
737739
.saveAccount(originAddress, Account(nonce = UInt256(initialOriginNonce), balance = initialOriginBalance))

0 commit comments

Comments
 (0)