Skip to content

Commit d3bc48d

Browse files
author
Aurélien Richez
committed
Merge branch 'origin/develop' into refactor/ETCM-943-split-reading-part
2 parents e54ad4f + 67d7870 commit d3bc48d

File tree

51 files changed

+644
-478
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+644
-478
lines changed

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,15 @@ class BlockImporterItSpec
5959
val pendingTransactionsManagerProbe = TestProbe()
6060
val supervisor = TestProbe()
6161

62-
val emptyWorld: InMemoryWorldStateProxy =
63-
blockchain.getWorldStateProxy(
64-
-1,
65-
UInt256.Zero,
66-
ByteString(MerklePatriciaTrie.EmptyRootHash),
67-
noEmptyAccounts = false,
68-
ethCompatibleStorage = true
69-
)
62+
val emptyWorld = InMemoryWorldStateProxy(
63+
storagesInstance.storages.evmCodeStorage,
64+
blockchain.getBackingMptStorage(-1),
65+
(number: BigInt) => blockchainReader.getBlockHeaderByNumber(number).map(_.hash),
66+
blockchainConfig.accountStartNonce,
67+
ByteString(MerklePatriciaTrie.EmptyRootHash),
68+
noEmptyAccounts = false,
69+
ethCompatibleStorage = true
70+
)
7071

7172
override protected lazy val successValidators: Validators = new Mocks.MockValidatorsAlwaysSucceed {
7273
override val ommersValidator: OmmersValidator = (
@@ -82,7 +83,14 @@ class BlockImporterItSpec
8283

8384
override lazy val ledger = new TestLedgerImpl(successValidators) {
8485
override private[ledger] lazy val blockExecution =
85-
new BlockExecution(blockchain, blockchainReader, blockchainConfig, consensus.blockPreparator, blockValidation) {
86+
new BlockExecution(
87+
blockchain,
88+
blockchainReader,
89+
storagesInstance.storages.evmCodeStorage,
90+
blockchainConfig,
91+
consensus.blockPreparator,
92+
blockValidation
93+
) {
8694
override def executeAndValidateBlock(
8795
block: Block,
8896
alreadyValidated: Boolean = false
@@ -134,7 +142,7 @@ class BlockImporterItSpec
134142
"BlockImporter" should "not discard blocks of the main chain if the reorganisation failed" in {
135143

136144
//ledger with not mocked blockExecution
137-
val ledger = new TestLedgerImpl(successValidators)
145+
val ledger = new TestLedgerImplNotMockedBlockExecution(successValidators)
138146
val blockImporter = system.actorOf(
139147
BlockImporter.props(
140148
fetcherProbe.ref,
@@ -246,7 +254,7 @@ class BlockImporterItSpec
246254
val newBlock: Block = getBlock(genesisBlock.number + 5, difficulty = 104, parent = parent.header.hash)
247255
val invalidBlock = newBlock.copy(header = newBlock.header.copy(beneficiary = Address(111).bytes))
248256

249-
val ledger = new TestLedgerImpl(successValidators)
257+
val ledger = new TestLedgerImplNotMockedBlockExecution(successValidators)
250258
val blockImporter = system.actorOf(
251259
BlockImporter.props(
252260
fetcherProbe.ref,
@@ -264,7 +272,6 @@ class BlockImporterItSpec
264272
blockImporter ! BlockFetcher.PickedBlocks(NonEmptyList.fromListUnsafe(List(invalidBlock)))
265273

266274
eventually {
267-
268275
val msg = fetcherProbe
269276
.fishForMessage(Timeouts.longTimeout) {
270277
case BlockFetcher.FetchStateNode(_, _) => true

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import io.iohk.ethereum.db.components.{RocksDbDataSourceComponent, Storages}
1414
import io.iohk.ethereum.db.dataSource.{RocksDbConfig, RocksDbDataSource}
1515
import io.iohk.ethereum.db.storage.pruning.{ArchivePruning, PruningMode}
1616
import io.iohk.ethereum.db.storage.{AppStateStorage, Namespaces}
17-
import io.iohk.ethereum.domain.{Block, Blockchain, BlockchainImpl, BlockchainReader, ChainWeight}
17+
import io.iohk.ethereum.domain.{Block, Blockchain, BlockchainImpl, BlockchainReader, ChainWeight, UInt256}
1818
import io.iohk.ethereum.security.SecureRandomBuilder
1919
import io.iohk.ethereum.ledger.InMemoryWorldStateProxy
2020
import io.iohk.ethereum.mpt.MerklePatriciaTrie
@@ -244,10 +244,12 @@ abstract class CommonFakePeer(peerName: String, fakePeerCustomConfig: FakePeerCu
244244
)
245245

246246
private def getMptForBlock(block: Block) = {
247-
bl.getWorldStateProxy(
248-
blockNumber = block.number,
249-
accountStartNonce = blockchainConfig.accountStartNonce,
250-
stateRootHash = block.header.stateRoot,
247+
InMemoryWorldStateProxy(
248+
storagesInstance.storages.evmCodeStorage,
249+
bl.getBackingMptStorage(block.number),
250+
(number: BigInt) => blockchainReader.getBlockHeaderByNumber(number).map(_.hash),
251+
blockchainConfig.accountStartNonce,
252+
block.header.stateRoot,
251253
noEmptyAccounts = EvmConfig.forBlock(block.number, blockchainConfig).noEmptyAccounts,
252254
ethCompatibleStorage = blockchainConfig.ethCompatibleStorage
253255
)

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ import io.iohk.ethereum.sync.util.SyncCommonItSpecUtils.FakePeerCustomConfig.def
3232
import io.iohk.ethereum.sync.util.SyncCommonItSpecUtils._
3333
import io.iohk.ethereum.transactions.PendingTransactionsManager
3434
import io.iohk.ethereum.utils._
35-
import io.iohk.ethereum.vm.EvmConfig
3635
import monix.eval.Task
3736
import monix.execution.Scheduler
3837
import akka.actor.typed.scaladsl.adapter._
3938
import io.iohk.ethereum.blockchain.sync.regular.BlockFetcher.AdaptedMessageFromEventBus
39+
import io.iohk.ethereum.mpt.MerklePatriciaTrie
4040

4141
import scala.concurrent.duration._
4242
object RegularSyncItSpecUtils {
@@ -63,6 +63,7 @@ object RegularSyncItSpecUtils {
6363
val consensus =
6464
PoWConsensus(
6565
vm,
66+
storagesInstance.storages.evmCodeStorage,
6667
bl,
6768
blockchainReader,
6869
blockchainConfig,
@@ -81,7 +82,15 @@ object RegularSyncItSpecUtils {
8182
)
8283

8384
lazy val ledger: Ledger =
84-
new LedgerImpl(bl, blockchainReader, blockchainConfig, syncConfig, buildEthashConsensus(), Scheduler.global)
85+
new LedgerImpl(
86+
bl,
87+
blockchainReader,
88+
storagesInstance.storages.evmCodeStorage,
89+
blockchainConfig,
90+
syncConfig,
91+
buildEthashConsensus(),
92+
Scheduler.global
93+
)
8594

8695
lazy val ommersPool: ActorRef = system.actorOf(OmmersPool.props(blockchainReader, 1), "ommers-pool")
8796

@@ -207,12 +216,14 @@ object RegularSyncItSpecUtils {
207216
}
208217

209218
private def getMptForBlock(block: Block) = {
210-
bl.getWorldStateProxy(
211-
blockNumber = block.number,
212-
accountStartNonce = blockchainConfig.accountStartNonce,
213-
stateRootHash = block.header.stateRoot,
214-
noEmptyAccounts = EvmConfig.forBlock(block.number, blockchainConfig).noEmptyAccounts,
215-
ethCompatibleStorage = blockchainConfig.ethCompatibleStorage
219+
InMemoryWorldStateProxy(
220+
storagesInstance.storages.evmCodeStorage,
221+
bl.getBackingMptStorage(block.number),
222+
(number: BigInt) => blockchainReader.getBlockHeaderByNumber(number).map(_.hash),
223+
UInt256.Zero,
224+
ByteString(MerklePatriciaTrie.EmptyRootHash),
225+
noEmptyAccounts = false,
226+
ethCompatibleStorage = true
216227
)
217228
}
218229

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,40 @@
11
package io.iohk.ethereum.txExecTest
22

3-
import java.util.concurrent.Executors
4-
5-
import io.iohk.ethereum.domain.Receipt
6-
import io.iohk.ethereum.ledger.{BlockExecution, BlockQueue, BlockValidation, Ledger}
3+
import io.iohk.ethereum.domain.{BlockchainImpl, BlockchainReader, Receipt}
4+
import io.iohk.ethereum.ledger.{BlockExecution, BlockQueue, BlockValidation}
75
import io.iohk.ethereum.txExecTest.util.FixtureProvider
86
import io.iohk.ethereum.utils.Config
97
import org.scalatest.flatspec.AnyFlatSpec
108
import org.scalatest.matchers.should.Matchers
119

12-
import scala.concurrent.ExecutionContext
13-
1410
class ContractTest extends AnyFlatSpec with Matchers {
1511
val blockchainConfig = Config.blockchains.blockchainConfig
1612
val syncConfig = Config.SyncConfig(Config.config)
17-
val vm = new Ledger.VMImpl
18-
val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(4))
1913
val noErrors = a[Right[_, Seq[Receipt]]]
2014

21-
"Ledger" should "transfer ether" in new ScenarioSetup {
15+
"Ledger" should "execute and validate" in new ScenarioSetup {
2216
val fixtures: FixtureProvider.Fixture = FixtureProvider.loadFixtures("/txExecTest/purchaseContract")
23-
24-
val testBlockchainStorages = FixtureProvider.prepareStorages(0, fixtures)
17+
lazy val testBlockchainStorages = FixtureProvider.prepareStorages(2, fixtures)
2518

2619
//block only with ether transfers
2720
val blockValidation =
2821
new BlockValidation(consensus, blockchainReader, BlockQueue(blockchain, syncConfig))
2922
val blockExecution =
30-
new BlockExecution(blockchain, blockchainReader, blockchainConfig, consensus.blockPreparator, blockValidation)
23+
new BlockExecution(
24+
blockchain,
25+
blockchainReader,
26+
testBlockchainStorages.evmCodeStorage,
27+
blockchainConfig,
28+
consensus.blockPreparator,
29+
blockValidation
30+
)
3131
blockExecution.executeAndValidateBlock(fixtures.blockByNumber(1)) shouldBe noErrors
32-
}
33-
34-
it should "deploy contract" in new ScenarioSetup {
35-
val fixtures: FixtureProvider.Fixture = FixtureProvider.loadFixtures("/txExecTest/purchaseContract")
36-
37-
val testBlockchainStorages = FixtureProvider.prepareStorages(1, fixtures)
3832

39-
//contract creation
40-
val blockValidation =
41-
new BlockValidation(consensus, blockchainReader, BlockQueue(blockchain, syncConfig))
42-
val blockExecution =
43-
new BlockExecution(blockchain, blockchainReader, blockchainConfig, consensus.blockPreparator, blockValidation)
33+
// deploy contract
4434
blockExecution.executeAndValidateBlock(fixtures.blockByNumber(2)) shouldBe noErrors
45-
}
46-
47-
it should "execute contract call" in new ScenarioSetup {
48-
val fixtures: FixtureProvider.Fixture = FixtureProvider.loadFixtures("/txExecTest/purchaseContract")
4935

50-
val testBlockchainStorages = FixtureProvider.prepareStorages(2, fixtures)
51-
52-
//block with ether transfers and contract call
53-
val blockValidation =
54-
new BlockValidation(consensus, blockchainReader, BlockQueue(blockchain, syncConfig))
55-
val blockExecution =
56-
new BlockExecution(blockchain, blockchainReader, blockchainConfig, consensus.blockPreparator, blockValidation)
57-
blockExecution.executeAndValidateBlock(fixtures.blockByNumber(3)) shouldBe noErrors
58-
}
59-
60-
it should "execute contract that pays 2 accounts" in new ScenarioSetup {
61-
val fixtures: FixtureProvider.Fixture = FixtureProvider.loadFixtures("/txExecTest/purchaseContract")
62-
63-
val testBlockchainStorages = FixtureProvider.prepareStorages(2, fixtures)
64-
65-
//block contains contract paying 2 accounts
66-
val blockValidation =
67-
new BlockValidation(consensus, blockchainReader, BlockQueue(blockchain, syncConfig))
68-
val blockExecution =
69-
new BlockExecution(blockchain, blockchainReader, blockchainConfig, consensus.blockPreparator, blockValidation)
36+
// execute contract call
37+
// execute contract that pays 2 accounts
7038
blockExecution.executeAndValidateBlock(fixtures.blockByNumber(3)) shouldBe noErrors
7139
}
7240
}

src/it/scala/io/iohk/ethereum/txExecTest/ECIP1017Test.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package io.iohk.ethereum.txExecTest
22

3-
import java.util.concurrent.Executors
43
import io.iohk.ethereum.domain.{Address, BlockchainImpl, BlockchainReader, Receipt, UInt256}
5-
import io.iohk.ethereum.ledger._
4+
import io.iohk.ethereum.ledger.{BlockExecution, BlockQueue, BlockValidation}
65
import io.iohk.ethereum.txExecTest.util.FixtureProvider
76
import io.iohk.ethereum.utils.{BlockchainConfig, ForkBlockNumbers, MonetaryPolicyConfig}
87
import org.scalatest.flatspec.AnyFlatSpec
98
import org.scalatest.matchers.should.Matchers
109

11-
import scala.concurrent.ExecutionContext
12-
1310
class ECIP1017Test extends AnyFlatSpec with Matchers {
1411

1512
val EraDuration = 3
@@ -53,13 +50,9 @@ class ECIP1017Test extends AnyFlatSpec with Matchers {
5350
gasTieBreaker = false,
5451
treasuryAddress = Address(0)
5552
)
56-
val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(4))
57-
5853
val noErrors = a[Right[_, Seq[Receipt]]]
5954
}
6055

61-
val vm = new Ledger.VMImpl
62-
6356
/**
6457
* Tests the block reward calculation through out all the monetary policy through all the eras till block
6558
* mining reward goes to zero. Block mining reward is tested till era 200 (that starts at block number 602)
@@ -72,7 +65,7 @@ class ECIP1017Test extends AnyFlatSpec with Matchers {
7265
val startBlock = 1
7366
val endBlock = 602
7467

75-
protected val testBlockchainStorages = FixtureProvider.prepareStorages(startBlock, fixtures)
68+
protected val testBlockchainStorages = FixtureProvider.prepareStorages(endBlock, fixtures)
7669

7770
(startBlock to endBlock) foreach { blockToExecute =>
7871
val storages = FixtureProvider.prepareStorages(blockToExecute - 1, fixtures)
@@ -81,7 +74,14 @@ class ECIP1017Test extends AnyFlatSpec with Matchers {
8174
val blockValidation =
8275
new BlockValidation(consensus, blockchainReader, BlockQueue(blockchain, syncConfig))
8376
val blockExecution =
84-
new BlockExecution(blockchain, blockchainReader, blockchainConfig, consensus.blockPreparator, blockValidation)
77+
new BlockExecution(
78+
blockchain,
79+
blockchainReader,
80+
testBlockchainStorages.evmCodeStorage,
81+
blockchainConfig,
82+
consensus.blockPreparator,
83+
blockValidation
84+
)
8585
blockExecution.executeAndValidateBlock(fixtures.blockByNumber(blockToExecute)) shouldBe noErrors
8686
}
8787
}

src/it/scala/io/iohk/ethereum/txExecTest/ForksTest.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import io.iohk.ethereum.utils.{BlockchainConfig, ForkBlockNumbers, MonetaryPolic
88
import org.scalatest.flatspec.AnyFlatSpec
99
import org.scalatest.matchers.should.Matchers
1010

11-
import scala.concurrent.ExecutionContext
12-
13-
// scalastyle:off magic.number
1411
class ForksTest extends AnyFlatSpec with Matchers {
1512

1613
trait TestSetup extends ScenarioSetup {
@@ -52,9 +49,7 @@ class ForksTest extends AnyFlatSpec with Matchers {
5249
ethCompatibleStorage = true,
5350
treasuryAddress = Address(0)
5451
)
55-
5652
val noErrors = a[Right[_, Seq[Receipt]]]
57-
val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(4))
5853
}
5954

6055
"Ledger" should "execute blocks with respect to forks" in new TestSetup {
@@ -63,7 +58,7 @@ class ForksTest extends AnyFlatSpec with Matchers {
6358
val startBlock = 1
6459
val endBlock = 11
6560

66-
protected val testBlockchainStorages = FixtureProvider.prepareStorages(startBlock, fixtures)
61+
protected val testBlockchainStorages = FixtureProvider.prepareStorages(endBlock, fixtures)
6762

6863
(startBlock to endBlock) foreach { blockToExecute =>
6964
val storages = FixtureProvider.prepareStorages(blockToExecute - 1, fixtures)
@@ -72,7 +67,14 @@ class ForksTest extends AnyFlatSpec with Matchers {
7267
val blockValidation =
7368
new BlockValidation(consensus, blockchainReader, BlockQueue(blockchain, syncConfig))
7469
val blockExecution =
75-
new BlockExecution(blockchain, blockchainReader, blockchainConfig, consensus.blockPreparator, blockValidation)
70+
new BlockExecution(
71+
blockchain,
72+
blockchainReader,
73+
testBlockchainStorages.evmCodeStorage,
74+
blockchainConfig,
75+
consensus.blockPreparator,
76+
blockValidation
77+
)
7678
blockExecution.executeAndValidateBlock(fixtures.blockByNumber(blockToExecute)) shouldBe noErrors
7779
}
7880
}

src/it/scala/io/iohk/ethereum/txExecTest/ScenarioSetup.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package io.iohk.ethereum.txExecTest
22

3-
import io.iohk.ethereum.blockchain.sync
3+
import io.iohk.ethereum.blockchain.sync.EphemBlockchainTestSetup
44
import io.iohk.ethereum.domain.{BlockchainImpl, BlockchainReader, BlockchainStorages}
55
import io.iohk.ethereum.ledger.Ledger.VMImpl
66

7-
trait ScenarioSetup extends sync.ScenarioSetup {
7+
trait ScenarioSetup extends EphemBlockchainTestSetup {
88
protected val testBlockchainStorages: BlockchainStorages
99

1010
override lazy val blockchainReader: BlockchainReader = BlockchainReader(testBlockchainStorages)

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

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import io.iohk.ethereum.db.components.{RocksDbDataSourceComponent, Storages}
1111
import io.iohk.ethereum.db.dataSource.{DataSourceBatchUpdate}
1212
import io.iohk.ethereum.db.storage.NodeStorage.{NodeEncoded, NodeHash}
1313
import io.iohk.ethereum.db.storage.pruning.{ArchivePruning, PruningMode}
14-
import io.iohk.ethereum.db.storage.AppStateStorage
14+
import io.iohk.ethereum.db.storage.{AppStateStorage, MptStorage, StateStorage}
1515
import io.iohk.ethereum.domain.BlockHeader.HeaderExtraFields.HefEmpty
1616
import io.iohk.ethereum.domain.{Blockchain, UInt256, _}
1717
import io.iohk.ethereum.jsonrpc.ProofService.{EmptyStorageValueProof, StorageProof, StorageProofKey}
@@ -186,22 +186,6 @@ class BlockchainMock(genesisHash: ByteString) extends Blockchain {
186186
override type S = InMemoryWorldStateProxyStorage
187187
override type WS = InMemoryWorldStateProxy
188188

189-
override def getWorldStateProxy(
190-
blockNumber: BigInt,
191-
accountStartNonce: UInt256,
192-
stateRootHash: ByteString,
193-
noEmptyAccounts: Boolean,
194-
ethCompatibleStorage: Boolean
195-
): InMemoryWorldStateProxy = ???
196-
197-
override def getReadOnlyWorldStateProxy(
198-
blockNumber: Option[BigInt],
199-
accountStartNonce: UInt256,
200-
stateRootHash: ByteString,
201-
noEmptyAccounts: Boolean,
202-
ethCompatibleStorage: Boolean
203-
): InMemoryWorldStateProxy = ???
204-
205189
def getBestBlockNumber(): BigInt = ???
206190

207191
def saveBlockNumber(number: BigInt, hash: NodeHash): Unit = ???
@@ -219,4 +203,8 @@ class BlockchainMock(genesisHash: ByteString) extends Blockchain {
219203
override def genesisHeader: BlockHeader = ???
220204

221205
override def genesisBlock: Block = ???
206+
207+
override def getBackingMptStorage(blockNumber: BigInt): MptStorage = ???
208+
209+
override def getReadOnlyMptStorage(): MptStorage = ???
222210
}

0 commit comments

Comments
 (0)