Skip to content

Commit 3a3195c

Browse files
author
Łukasz Gąsior
committed
Merge remote-tracking branch 'origin/feature/consensus_as_a_service_EC458' into feature/testmode
2 parents 69baedd + 44fcd0f commit 3a3195c

File tree

119 files changed

+3651
-2816
lines changed

Some content is hidden

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

119 files changed

+3651
-2816
lines changed

.circleci/config.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
version: 2
22
jobs:
33
build:
4+
environment:
5+
- SBT: "sbt -v -mem 1024"
46
docker:
57
- image: rtkaczyk/mantis-circleci:v4
68
steps:
@@ -17,24 +19,24 @@ jobs:
1719
1820
- run:
1921
name: scalastyle
20-
command: sbt scalastyle test:scalastyle
22+
command: $SBT scalastyle test:scalastyle
2123

2224
- run:
2325
name: unit tests
24-
command: sbt coverage test
26+
command: $SBT coverage test
2527

2628
- run:
2729
name: EVM tests
2830
# coverage ???
29-
command: sbt coverage evm:test
31+
command: $SBT coverage evm:test
3032

3133
- run:
3234
name: integration tests
33-
command: sbt coverageOff it:test
35+
command: $SBT coverageOff it:test
3436

3537
- run:
3638
name: coverage report
37-
command: sbt coverageReport coverageAggregate coveralls
39+
command: $SBT coverageReport coverageAggregate coveralls
3840

3941
- store_artifacts:
4042
path: target/scala-2.12/coverage-report
@@ -53,7 +55,7 @@ jobs:
5355
name: additional compilation & dist
5456
# this step builds parts of the codebase which are not tested in CI
5557
# so as to prevent compilation regression
56-
command: sbt benchmark:compile snappy:compile dist
58+
command: $SBT benchmark:compile snappy:compile dist
5759

5860
- save_cache:
5961
key: mantis-{{ checksum "build.sbt" }}-{{ checksum "project/build.properties" }}-{{ checksum "project/plugins.sbt" }}

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ val commonSettings = Seq(
44
name := "mantis",
55
version := "1.0-daedalus-rc1",
66
scalaVersion := "2.12.1",
7-
testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-l", "MinerSpec") // miner tests disabled by default
7+
testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-l", "EthashMinerSpec") // miner tests disabled by default
88
)
99

1010
// Temp resolver for LevelDB fork

src/ets/scala/io/iohk/ethereum/ets/blockchain/BlockchainSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ class BlockchainSuite extends FreeSpec with Matchers with BeforeAndAfterAll with
9595
val expectedState = getExpectedState()
9696
val resultState = getResultState()
9797

98-
resultState should contain theSameElementsAs expectedState
9998
lastBlock.get.header.hash shouldEqual scenario.lastblockhash
99+
resultState should contain theSameElementsAs expectedState
100100
lastBlock.get.header.stateRoot shouldEqual expectedWorldStateHash
101101
}
102102
}

src/ets/scala/io/iohk/ethereum/ets/blockchain/ScenarioSetup.scala

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,54 @@
11
package io.iohk.ethereum.ets.blockchain
22

3-
import io.iohk.ethereum.blockchain.sync.EphemBlockchainTestSetup
4-
import io.iohk.ethereum.consensus.ethash.validators.EthashBlockHeaderValidator
3+
import io.iohk.ethereum.consensus.ethash.EthashConsensus
4+
import io.iohk.ethereum.consensus.{ConsensusConfig, FullConsensusConfig, TestConsensus, ethash}
5+
import io.iohk.ethereum.db.components.Storages.PruningModeComponent
6+
import io.iohk.ethereum.db.components.{SharedEphemDataSources, Storages}
7+
import io.iohk.ethereum.db.storage.pruning.{ArchivePruning, PruningMode}
58
import io.iohk.ethereum.domain.Block.BlockDec
6-
import io.iohk.ethereum.domain.{Account, Address, Block, UInt256}
9+
import io.iohk.ethereum.domain._
710
import io.iohk.ethereum.ets.common.AccountState
811
import io.iohk.ethereum.ledger.Ledger.VMImpl
912
import io.iohk.ethereum.ledger._
1013
import io.iohk.ethereum.network.p2p.messages.PV62.BlockBody
11-
import io.iohk.ethereum.nodebuilder._
1214
import io.iohk.ethereum.utils.BigIntExtensionMethods._
13-
import io.iohk.ethereum.utils.BlockchainConfig
14-
import io.iohk.ethereum.validators._
15+
import io.iohk.ethereum.utils.{BlockchainConfig, Config}
1516
import org.spongycastle.util.encoders.Hex
1617

1718
import scala.util.{Failure, Success, Try}
1819

1920
object ScenarioSetup {
20-
// FIXME: this is a temporary (hopefully) fix for BlockchainSuite. It avoids using `ValidatorsBuilder` which causes
21-
// the tests to run into OOM errors (for reason currently unknown)
22-
def getValidators(blockchainConfig: BlockchainConfig) = new Validators {
23-
val blockValidator: BlockValidator = BlockValidator
24-
val blockHeaderValidator: BlockHeaderValidator = new EthashBlockHeaderValidator(blockchainConfig)
25-
val ommersValidator: OmmersValidator = new OmmersValidatorImpl(blockchainConfig, blockHeaderValidator)
26-
val signedTransactionValidator: SignedTransactionValidator = new SignedTransactionValidatorImpl(blockchainConfig)
21+
def loadEthashConsensus(vm: VMImpl, blockchain: BlockchainImpl, blockchainConfig: BlockchainConfig): ethash.EthashConsensus = {
22+
val specificConfig = ethash.EthashConfig(Config.config)
23+
val fullConfig = FullConsensusConfig(ConsensusConfig(Config.config)(null), specificConfig)
24+
val consensus = EthashConsensus(vm, blockchain, blockchainConfig, fullConfig)
25+
consensus
26+
}
27+
28+
29+
trait Pruning extends PruningModeComponent {
30+
override val pruningMode: PruningMode = ArchivePruning
31+
}
32+
33+
34+
def getBlockchain(): BlockchainImpl = {
35+
val storagesInstance = new SharedEphemDataSources with Pruning with Storages.DefaultStorages
36+
BlockchainImpl(storagesInstance.storages)
2737
}
2838
}
2939

30-
abstract class ScenarioSetup(vm: VMImpl, scenario: BlockchainScenario)
31-
extends EphemBlockchainTestSetup
32-
with SyncConfigBuilder
33-
with BlockchainConfigBuilder {
40+
abstract class ScenarioSetup(_vm: VMImpl, scenario: BlockchainScenario) {
3441

35-
val emptyWorld = blockchain.getWorldStateProxy(-1, UInt256.Zero, None)
42+
val blockchainConfig = buildBlockchainConfig(scenario.network)
3643

37-
override lazy val blockchainConfig = buildBlockchainConfig(scenario.network)
44+
//val validators = StdEthashValidators(blockchainConfig)
45+
val blockchain = ScenarioSetup.getBlockchain()
3846

39-
val validators = ScenarioSetup.getValidators(blockchainConfig)
47+
val consensus: TestConsensus = ScenarioSetup.loadEthashConsensus(_vm, blockchain, blockchainConfig)
4048

41-
val ledger = new LedgerImpl(vm, blockchain, blockchainConfig, syncConfig, validators)
49+
val emptyWorld = blockchain.getWorldStateProxy(-1, UInt256.Zero, None)
50+
51+
val ledger = new LedgerImpl(blockchain, new BlockQueue(blockchain, 10, 10), blockchainConfig, consensus)
4252

4353
def loadGenesis(): Block = {
4454
val genesisBlock = scenario.genesisRLP match {
@@ -63,7 +73,7 @@ abstract class ScenarioSetup(vm: VMImpl, scenario: BlockchainScenario)
6373
val finalWorld: InMemoryWorldStateProxy = InMemoryWorldStateProxy.persistState(getWorldState(scenario.postState))
6474

6575
def getBestBlock(): Option[Block] = {
66-
val bestBlockNumber = storagesInstance.storages.appStateStorage.getBestBlockNumber()
76+
val bestBlockNumber = blockchain.getBestBlockNumber()
6777
blockchain.getBlockByNumber(bestBlockNumber)
6878
}
6979

@@ -72,14 +82,14 @@ abstract class ScenarioSetup(vm: VMImpl, scenario: BlockchainScenario)
7282
}
7383

7484
def getResultState(): List[(Address, Option[Account])] = {
75-
val bestBlockNumber = storagesInstance.storages.appStateStorage.getBestBlockNumber()
85+
val bestBlockNumber = blockchain.getBestBlockNumber()
7686
scenario.postState.map(addAcc => addAcc._1 -> blockchain.getAccount(addAcc._1, bestBlockNumber)).toList
7787
}
7888

79-
private def buildBlockchainConfig(network: String): BlockchainConfig = network match {
80-
case "EIP150" => new Eip150Config
81-
case "Frontier" => new FrontierConfig
82-
case "Homestead" => new HomesteadConfig
89+
private def buildBlockchainConfig(network: String): BlockchainConfig = network match {
90+
case "EIP150" => new Eip150Config
91+
case "Frontier" => new FrontierConfig
92+
case "Homestead" => new HomesteadConfig
8393
case "FrontierToHomesteadAt5" => new FrontierToHomesteadAt5
8494
case "HomesteadToEIP150At5" => new HomesteadToEIP150At5
8595
case "EIP158" => new Eip158Config
@@ -98,7 +108,9 @@ abstract class ScenarioSetup(vm: VMImpl, scenario: BlockchainScenario)
98108
private def decodeBlock(s: String): Option[Block] = {
99109
Try(decode(s).toBlock) match {
100110
case Success(block) => Some(block)
101-
case Failure(ex) => {ex.printStackTrace(); None}
111+
case Failure(ex) => {
112+
ex.printStackTrace(); None
113+
}
102114
}
103115
}
104116

src/it/scala/io/iohk/ethereum/SimulateTransactionTest/SimulateTransactionTest.scala

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ package io.iohk.ethereum.ledger
22

33
import akka.util.ByteString
44
import io.iohk.ethereum.blockchain.sync.EphemBlockchainTestSetup
5-
import io.iohk.ethereum.consensus.{ConsensusBuilder, ConsensusConfigBuilder}
65
import io.iohk.ethereum.crypto.ECDSASignature
76
import io.iohk.ethereum.domain._
8-
import io.iohk.ethereum.nodebuilder.{BlockchainConfigBuilder, ShutdownHookBuilder, SyncConfigBuilder, ValidatorsBuilder}
97
import org.scalatest._
108
import io.iohk.ethereum.utils._
119
import org.spongycastle.util.encoders.Hex
@@ -100,15 +98,7 @@ class SimulateTransactionTest extends FlatSpec with Matchers with Logger {
10098
}
10199
}
102100

103-
trait ScenarioSetup
104-
extends EphemBlockchainTestSetup
105-
with ValidatorsBuilder
106-
with SyncConfigBuilder
107-
with BlockchainConfigBuilder
108-
with ConsensusBuilder
109-
with ConsensusConfigBuilder
110-
with ShutdownHookBuilder
111-
with Logger {
101+
trait ScenarioSetup extends EphemBlockchainTestSetup {
112102

113103
override lazy val blockchainConfig = new BlockchainConfig{
114104
override val eip155BlockNumber: BigInt = 0
@@ -130,10 +120,9 @@ trait ScenarioSetup
130120
override val ethCompatibleStorage: Boolean = true
131121
}
132122

133-
val emptyWorld = blockchain.getWorldStateProxy(-1, UInt256.Zero, None)
123+
override lazy val ledger: LedgerImpl = newLedger()
134124

135-
val vm = new Ledger.VMImpl
136-
val ledger = new LedgerImpl(vm, blockchain, blockchainConfig, syncConfig, validators)
125+
val emptyWorld = blockchain.getWorldStateProxy(-1, UInt256.Zero, None)
137126

138127
val existingAddress = Address(10)
139128
val existingAccount = Account(nonce = UInt256.Zero, balance = UInt256(10))
Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package io.iohk.ethereum.txExecTest
22

3-
import io.iohk.ethereum.domain.{BlockchainImpl, Receipt}
3+
import io.iohk.ethereum.domain.Receipt
44
import io.iohk.ethereum.ledger.{Ledger, LedgerImpl}
55
import io.iohk.ethereum.txExecTest.util.FixtureProvider
66
import io.iohk.ethereum.utils.Config.SyncConfig
77
import io.iohk.ethereum.utils.{BlockchainConfig, Config}
8-
import io.iohk.ethereum.validators._
98
import org.scalatest.{FlatSpec, Matchers}
109

1110
class ContractTest extends FlatSpec with Matchers {
@@ -14,50 +13,40 @@ class ContractTest extends FlatSpec with Matchers {
1413
val vm = new Ledger.VMImpl
1514

1615
val noErrors = a[Right[_, Seq[Receipt]]]
17-
val validators = new Validators {
18-
val blockValidator: BlockValidator = BlockValidator
19-
val blockHeaderValidator: BlockHeaderValidator = new BlockHeaderValidatorImpl(blockchainConfig)
20-
val ommersValidator: OmmersValidator = new OmmersValidatorImpl(blockchainConfig, blockHeaderValidator)
21-
val signedTransactionValidator: SignedTransactionValidator = new SignedTransactionValidatorImpl(blockchainConfig)
22-
}
2316

24-
"Ledger" should "transfer ether" in {
17+
"Ledger" should "transfer ether" in new ScenarioSetup {
2518
val fixtures: FixtureProvider.Fixture = FixtureProvider.loadFixtures("/txExecTest/purchaseContract")
2619

27-
val storage = FixtureProvider.prepareStorages(0, fixtures)
28-
val blockchain = BlockchainImpl(storage)
20+
val testBlockchainStorages = FixtureProvider.prepareStorages(0, fixtures)
2921

3022
//block only with ether transfers
31-
new LedgerImpl(vm, blockchain, blockchainConfig, syncConfig, validators).executeBlock(fixtures.blockByNumber(1)) shouldBe noErrors
23+
new LedgerImpl(blockchain, blockchainConfig, syncConfig, consensus).executeBlock(fixtures.blockByNumber(1)) shouldBe noErrors
3224
}
3325

34-
it should "deploy contract" in {
26+
it should "deploy contract" in new ScenarioSetup {
3527
val fixtures: FixtureProvider.Fixture = FixtureProvider.loadFixtures("/txExecTest/purchaseContract")
3628

37-
val storage = FixtureProvider.prepareStorages(1, fixtures)
38-
val blockchain = BlockchainImpl(storage)
29+
val testBlockchainStorages = FixtureProvider.prepareStorages(1, fixtures)
3930

4031
//contract creation
41-
new LedgerImpl(vm, blockchain, blockchainConfig, syncConfig, validators).executeBlock(fixtures.blockByNumber(2)) shouldBe noErrors
32+
new LedgerImpl(blockchain, blockchainConfig, syncConfig, consensus).executeBlock(fixtures.blockByNumber(2)) shouldBe noErrors
4233
}
4334

44-
it should "execute contract call" in {
35+
it should "execute contract call" in new ScenarioSetup {
4536
val fixtures: FixtureProvider.Fixture = FixtureProvider.loadFixtures("/txExecTest/purchaseContract")
4637

47-
val storage = FixtureProvider.prepareStorages(2, fixtures)
48-
val blockchain = BlockchainImpl(storage)
38+
val testBlockchainStorages = FixtureProvider.prepareStorages(2, fixtures)
4939

5040
//block with ether transfers and contract call
51-
new LedgerImpl(vm, blockchain, blockchainConfig, syncConfig, validators).executeBlock(fixtures.blockByNumber(3)) shouldBe noErrors
41+
new LedgerImpl(blockchain, blockchainConfig, syncConfig, consensus).executeBlock(fixtures.blockByNumber(3)) shouldBe noErrors
5242
}
5343

54-
it should "execute contract that pays 2 accounts" in {
44+
it should "execute contract that pays 2 accounts" in new ScenarioSetup {
5545
val fixtures: FixtureProvider.Fixture = FixtureProvider.loadFixtures("/txExecTest/purchaseContract")
5646

57-
val storage = FixtureProvider.prepareStorages(2, fixtures)
58-
val blockchain = BlockchainImpl(storage)
47+
val testBlockchainStorages = FixtureProvider.prepareStorages(2, fixtures)
5948

6049
//block contains contract paying 2 accounts
61-
new LedgerImpl(vm, blockchain, blockchainConfig, syncConfig, validators).executeBlock(fixtures.blockByNumber(3)) shouldBe noErrors
50+
new LedgerImpl(blockchain, blockchainConfig, syncConfig, consensus).executeBlock(fixtures.blockByNumber(3)) shouldBe noErrors
6251
}
6352
}

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

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,37 @@ package io.iohk.ethereum.txExecTest
33
import io.iohk.ethereum.domain.{BlockchainImpl, Receipt, UInt256}
44
import io.iohk.ethereum.ledger.{Ledger, LedgerImpl}
55
import io.iohk.ethereum.txExecTest.util.FixtureProvider
6-
import io.iohk.ethereum.utils.Config.SyncConfig
7-
import io.iohk.ethereum.utils.{BlockchainConfig, Config, DaoForkConfig, MonetaryPolicyConfig}
8-
import io.iohk.ethereum.validators._
6+
import io.iohk.ethereum.utils.{BlockchainConfig, DaoForkConfig, MonetaryPolicyConfig}
97
import org.scalatest.{FlatSpec, Matchers}
108

119
class ECIP1017Test extends FlatSpec with Matchers {
1210

1311
val EraDuration = 3
1412

15-
val blockchainConfig = new BlockchainConfig {
16-
override val monetaryPolicyConfig: MonetaryPolicyConfig = MonetaryPolicyConfig(EraDuration, 0.2, 5000000000000000000L)
13+
trait TestSetup extends ScenarioSetup {
14+
override lazy val blockchainConfig = new BlockchainConfig {
15+
override val monetaryPolicyConfig: MonetaryPolicyConfig = MonetaryPolicyConfig(EraDuration, 0.2, 5000000000000000000L)
1716

18-
// unused
19-
override val maxCodeSize: Option[BigInt] = None
20-
override val chainId: Byte = 0x3d
21-
override val frontierBlockNumber: BigInt = 0
22-
override val homesteadBlockNumber: BigInt = 1150000
23-
override val eip106BlockNumber: BigInt = Long.MaxValue
24-
override val eip150BlockNumber: BigInt = 2500000
25-
override val eip160BlockNumber: BigInt = 3000000
26-
override val eip155BlockNumber: BigInt = 3000000
27-
override val eip161BlockNumber: BigInt = Long.MaxValue
28-
override val customGenesisFileOpt: Option[String] = None
29-
override val daoForkConfig: Option[DaoForkConfig] = None
30-
override val difficultyBombPauseBlockNumber: BigInt = Long.MaxValue
31-
override val difficultyBombContinueBlockNumber: BigInt = Long.MaxValue
32-
override val accountStartNonce: UInt256 = UInt256.Zero
33-
override val gasTieBreaker: Boolean = false
34-
override val ethCompatibleStorage: Boolean = true
35-
}
36-
37-
val syncConfig = SyncConfig(Config.config)
38-
39-
val noErrors = a[Right[_, Seq[Receipt]]]
17+
// unused
18+
override val maxCodeSize: Option[BigInt] = None
19+
override val chainId: Byte = 0x3d
20+
override val frontierBlockNumber: BigInt = 0
21+
override val homesteadBlockNumber: BigInt = 1150000
22+
override val eip106BlockNumber: BigInt = Long.MaxValue
23+
override val eip150BlockNumber: BigInt = 2500000
24+
override val eip160BlockNumber: BigInt = 3000000
25+
override val eip155BlockNumber: BigInt = 3000000
26+
override val eip161BlockNumber: BigInt = Long.MaxValue
27+
override val customGenesisFileOpt: Option[String] = None
28+
override val daoForkConfig: Option[DaoForkConfig] = None
29+
override val difficultyBombPauseBlockNumber: BigInt = Long.MaxValue
30+
override val difficultyBombContinueBlockNumber: BigInt = Long.MaxValue
31+
override val accountStartNonce: UInt256 = UInt256.Zero
32+
val gasTieBreaker: Boolean = false
33+
override val ethCompatibleStorage: Boolean = true
34+
}
4035

41-
val validators = new Validators {
42-
val blockValidator: BlockValidator = BlockValidator
43-
val blockHeaderValidator: BlockHeaderValidator = new BlockHeaderValidatorImpl(blockchainConfig)
44-
val ommersValidator: OmmersValidator = new OmmersValidatorImpl(blockchainConfig, blockHeaderValidator)
45-
val signedTransactionValidator: SignedTransactionValidator = new SignedTransactionValidatorImpl(blockchainConfig)
36+
val noErrors = a[Right[_, Seq[Receipt]]]
4637
}
4738

4839
val vm = new Ledger.VMImpl
@@ -53,16 +44,18 @@ class ECIP1017Test extends FlatSpec with Matchers {
5344
* as the reward reaches zero at era 193 (which starts at block number 579), given an eraDuration of 3,
5445
* a rewardReductionRate of 0.2 and a firstEraBlockReward of 5 ether.
5546
*/
56-
"Ledger" should "execute blocks with respect to block reward changed by ECIP 1017" in {
47+
"Ledger" should "execute blocks with respect to block reward changed by ECIP 1017" in new TestSetup {
5748
val fixtures: FixtureProvider.Fixture = FixtureProvider.loadFixtures("/txExecTest/ecip1017Test")
5849

5950
val startBlock = 1
6051
val endBlock = 602
6152

53+
protected val testBlockchainStorages = FixtureProvider.prepareStorages(startBlock, fixtures)
54+
6255
(startBlock to endBlock) foreach { blockToExecute =>
6356
val storages = FixtureProvider.prepareStorages(blockToExecute - 1, fixtures)
6457
val blockchain = BlockchainImpl(storages)
65-
val ledger = new LedgerImpl(vm, blockchain, blockchainConfig, syncConfig, validators)
58+
val ledger = new LedgerImpl(blockchain, blockchainConfig, syncConfig, consensus)
6659

6760
ledger.executeBlock(fixtures.blockByNumber(blockToExecute)) shouldBe noErrors
6861
}

0 commit comments

Comments
 (0)