Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@ val nixBuild = sys.props.isDefinedAt("nix")
val mantisDev = sys.props.get("mantisDev").contains("true") || sys.env.get("MANTIS_DEV").contains("true")

lazy val compilerOptimizationsForProd = Seq(
"-opt:l:method", // method-local optimizations
"-opt:l:inline", // inlining optimizations
"-opt:l:method", // method-local optimizations
"-opt:l:inline", // inlining optimizations
"-opt-inline-from:io.iohk.**" // inlining the project only
)

// Releasing. https://github.com/olafurpg/sbt-ci-release
inThisBuild(List(
organization := "io.iohk",
homepage := Some(url("https://github.com/input-output-hk/mantis")),
scmInfo := Some(ScmInfo(url("https://github.com/input-output-hk/mantis"), "[email protected]:input-output-hk/mantis.git")),
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
developers := List()
))
inThisBuild(
List(
organization := "io.iohk",
homepage := Some(url("https://github.com/input-output-hk/mantis")),
scmInfo := Some(
ScmInfo(url("https://github.com/input-output-hk/mantis"), "[email protected]:input-output-hk/mantis.git")
),
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
developers := List()
)
)

// https://github.com/sbt/sbt/issues/3570
updateOptions := updateOptions.value.withGigahorse(false)
Expand Down
2 changes: 1 addition & 1 deletion bytes/src/main/scala/io/iohk/ethereum/utils/Hex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ object Hex {

def decode(hex: String): Array[Byte] =
hex.toSeq.sliding(2, 2).toArray.map { s =>
Integer.parseInt(s.mkString(""), 16).toByte
Integer.parseInt(s.mkString(""), 16).toByte
}
}
9 changes: 9 additions & 0 deletions crypto/src/main/scala/io/iohk/ethereum/crypto/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ package object crypto {
def kec256(input: ByteString): ByteString =
ByteString(kec256(input.toArray))

def kec256PoW(header: Array[Byte], nonce: Array[Byte]): Array[Byte] = {
val digest = new KeccakDigest(256)
digest.update(header, 0, header.length)
digest.update(nonce, 0, nonce.length)
val output = Array.ofDim[Byte](32)
digest.doFinal(output, 0)
output
}

def kec512(input: Array[Byte]): Array[Byte] = synchronized {
val out = Array.ofDim[Byte](kec512.getDigestSize)
kec512.update(input, 0, input.length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.iohk.ethereum.ets.blockchain

import akka.util.ByteString
import io.iohk.ethereum.consensus.Protocol
import io.iohk.ethereum.consensus.validators.std.ValidatorsExecutor
import io.iohk.ethereum.consensus.pow.validators.ValidatorsExecutor
import io.iohk.ethereum.domain.{Address, UInt256}
import io.iohk.ethereum.utils.{BlockchainConfig, DaoForkConfig, MonetaryPolicyConfig}
import org.bouncycastle.util.encoders.Hex
Expand Down Expand Up @@ -46,7 +46,8 @@ object BlockchainTestConfig {
ecip1098BlockNumber = Long.MaxValue,
treasuryAddress = Address(0),
ecip1097BlockNumber = Long.MaxValue,
ecip1099BlockNumber = Long.MaxValue
ecip1099BlockNumber = Long.MaxValue,
ecip1049BlockNumber = None
)

val FrontierConfig = BaseBlockchainConfig.copy(
Expand Down Expand Up @@ -316,19 +317,19 @@ object BlockchainTestConfig {
object Validators {
import BlockchainTestConfig._

val frontierValidators = ValidatorsExecutor(FrontierConfig, Protocol.Ethash)
val homesteadValidators = ValidatorsExecutor(HomesteadConfig, Protocol.Ethash)
val eip150Validators = ValidatorsExecutor(Eip150Config, Protocol.Ethash)
val frontierToHomesteadValidators = ValidatorsExecutor(FrontierToHomesteadAt5, Protocol.Ethash)
val homesteadToEipValidators = ValidatorsExecutor(HomesteadToEIP150At5, Protocol.Ethash)
val homesteadToDaoValidators = ValidatorsExecutor(HomesteadToDaoAt5, Protocol.Ethash)
val eip158Validators = ValidatorsExecutor(Eip158Config, Protocol.Ethash)
val byzantiumValidators = ValidatorsExecutor(ByzantiumConfig, Protocol.Ethash)
val constantinopleValidators = ValidatorsExecutor(ConstantinopleConfig, Protocol.Ethash)
val constantinopleFixValidators = ValidatorsExecutor(ConstantinopleFixConfig, Protocol.Ethash)
val istanbulValidators = ValidatorsExecutor(IstanbulConfig, Protocol.Ethash)
val eip158ToByzantiumValidators = ValidatorsExecutor(Eip158ToByzantiumAt5Config, Protocol.Ethash)
val byzantiumToConstantinopleAt5 = ValidatorsExecutor(ByzantiumToConstantinopleAt5, Protocol.Ethash)
val frontierValidators = ValidatorsExecutor(FrontierConfig, Protocol.PoW)
val homesteadValidators = ValidatorsExecutor(HomesteadConfig, Protocol.PoW)
val eip150Validators = ValidatorsExecutor(Eip150Config, Protocol.PoW)
val frontierToHomesteadValidators = ValidatorsExecutor(FrontierToHomesteadAt5, Protocol.PoW)
val homesteadToEipValidators = ValidatorsExecutor(HomesteadToEIP150At5, Protocol.PoW)
val homesteadToDaoValidators = ValidatorsExecutor(HomesteadToDaoAt5, Protocol.PoW)
val eip158Validators = ValidatorsExecutor(Eip158Config, Protocol.PoW)
val byzantiumValidators = ValidatorsExecutor(ByzantiumConfig, Protocol.PoW)
val constantinopleValidators = ValidatorsExecutor(ConstantinopleConfig, Protocol.PoW)
val constantinopleFixValidators = ValidatorsExecutor(ConstantinopleFixConfig, Protocol.PoW)
val istanbulValidators = ValidatorsExecutor(IstanbulConfig, Protocol.PoW)
val eip158ToByzantiumValidators = ValidatorsExecutor(Eip158ToByzantiumAt5Config, Protocol.PoW)
val byzantiumToConstantinopleAt5 = ValidatorsExecutor(ByzantiumToConstantinopleAt5, Protocol.PoW)
}

// Connected with: https://github.com/ethereum/tests/issues/480
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package io.iohk.ethereum.ets.blockchain

import io.iohk.ethereum.consensus.difficulty.DifficultyCalculator
import io.iohk.ethereum.consensus.ethash.validators.EthashBlockHeaderValidator
import io.iohk.ethereum.consensus.validators.{ BlockHeaderError, BlockHeaderValid, BlockHeaderValidatorSkeleton }
import io.iohk.ethereum.consensus.pow.validators.EthashBlockHeaderValidator
import io.iohk.ethereum.consensus.validators.{BlockHeaderError, BlockHeaderValid, BlockHeaderValidatorSkeleton}
import io.iohk.ethereum.domain.BlockHeader
import io.iohk.ethereum.utils.BlockchainConfig

class EthashTestBlockHeaderValidator(blockchainConfig: BlockchainConfig) extends BlockHeaderValidatorSkeleton(blockchainConfig) {
class EthashTestBlockHeaderValidator(blockchainConfig: BlockchainConfig)
extends BlockHeaderValidatorSkeleton(blockchainConfig) {
import EthashBlockHeaderValidator._

// NOTE the below comment is from before PoW decoupling
// we need concurrent map since validators can be used from multiple places
protected val powCaches: java.util.concurrent.ConcurrentMap[Long, PowCacheData] = new java.util.concurrent.ConcurrentHashMap[Long, PowCacheData]()
protected val powCaches: java.util.concurrent.ConcurrentMap[Long, PowCacheData] =
new java.util.concurrent.ConcurrentHashMap[Long, PowCacheData]()

protected def difficulty: DifficultyCalculator = DifficultyCalculator(blockchainConfig)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.iohk.ethereum.ets.blockchain

import akka.util.ByteString
import io.iohk.ethereum.consensus.Protocol.NoAdditionalEthashData
import io.iohk.ethereum.consensus.ethash.EthashConsensus
import io.iohk.ethereum.consensus.validators.std.ValidatorsExecutor
import io.iohk.ethereum.consensus.{ConsensusConfig, FullConsensusConfig, TestConsensus, ethash}
import io.iohk.ethereum.consensus.Protocol.NoAdditionalPoWData
import io.iohk.ethereum.consensus.pow.{EthashConfig, PoWConsensus}
import io.iohk.ethereum.consensus.pow.validators.ValidatorsExecutor
import io.iohk.ethereum.consensus.{ConsensusConfig, FullConsensusConfig, TestConsensus, pow}
import io.iohk.ethereum.db.components.Storages.PruningModeComponent
import io.iohk.ethereum.db.components.{EphemDataSourceComponent, Storages}
import io.iohk.ethereum.db.storage.pruning.{ArchivePruning, PruningMode}
Expand All @@ -23,16 +23,16 @@ import scala.util.{Failure, Success, Try}

object ScenarioSetup {
val testContext = Scheduler.fixedPool("scenario-setup-pool", 4)
val specificConfig = ethash.EthashConfig(Config.config)
val specificConfig = EthashConfig(Config.config)
val fullConfig = FullConsensusConfig(ConsensusConfig(Config.config), specificConfig)

def loadEthashConsensus(
vm: VMImpl,
blockchain: BlockchainImpl,
blockchainConfig: BlockchainConfig,
validators: ValidatorsExecutor
): ethash.EthashConsensus = {
val consensus = EthashConsensus(vm, blockchain, blockchainConfig, fullConfig, validators, NoAdditionalEthashData)
): PoWConsensus = {
val consensus = PoWConsensus(vm, blockchain, blockchainConfig, fullConfig, validators, NoAdditionalPoWData)
consensus
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import io.iohk.ethereum.blockchain.sync.regular.{BlockFetcher, BlockImporter}
import io.iohk.ethereum.checkpointing.CheckpointingTestHelpers
import io.iohk.ethereum.consensus.{GetBlockHeaderByHash, GetNBlocksBack}
import io.iohk.ethereum.consensus.blocks.CheckpointBlockGenerator
import io.iohk.ethereum.consensus.ethash.validators.OmmersValidator
import io.iohk.ethereum.consensus.pow.validators.{OmmersValidator, StdOmmersValidator}
import io.iohk.ethereum.consensus.validators.Validators
import io.iohk.ethereum.consensus.validators.std.StdOmmersValidator
import io.iohk.ethereum.domain._
import io.iohk.ethereum.mpt.MerklePatriciaTrie
import io.iohk.ethereum.utils.Config.SyncConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import io.iohk.ethereum.blockchain.sync.regular.{
import io.iohk.ethereum.blockchain.sync.regular.RegularSync.NewCheckpoint
import io.iohk.ethereum.blockchain.sync.{PeersClient, SyncProtocol}
import io.iohk.ethereum.checkpointing.CheckpointingTestHelpers
import io.iohk.ethereum.consensus.Protocol.NoAdditionalEthashData
import io.iohk.ethereum.consensus.Protocol.NoAdditionalPoWData
import io.iohk.ethereum.consensus.blocks.CheckpointBlockGenerator
import io.iohk.ethereum.consensus.ethash.{EthashConfig, EthashConsensus}
import io.iohk.ethereum.consensus.{ConsensusConfig, FullConsensusConfig, ethash}
import io.iohk.ethereum.consensus.pow.{EthashConfig, PoWConsensus}
import io.iohk.ethereum.consensus.{ConsensusConfig, FullConsensusConfig, pow}
import io.iohk.ethereum.crypto
import io.iohk.ethereum.domain._
import io.iohk.ethereum.ledger._
Expand Down Expand Up @@ -54,13 +54,13 @@ object RegularSyncItSpecUtils {
class FakePeer(peerName: String, fakePeerCustomConfig: FakePeerCustomConfig)
extends CommonFakePeer(peerName, fakePeerCustomConfig) {

def buildEthashConsensus(): ethash.EthashConsensus = {
def buildEthashConsensus(): pow.PoWConsensus = {
val consensusConfig: ConsensusConfig = ConsensusConfig(Config.config)
val specificConfig: EthashConfig = ethash.EthashConfig(config)
val specificConfig: EthashConfig = pow.EthashConfig(config)
val fullConfig = FullConsensusConfig(consensusConfig, specificConfig)
val vm = VmSetup.vm(VmConfig(config), blockchainConfig, testMode = false)
val consensus =
EthashConsensus(vm, bl, blockchainConfig, fullConfig, ValidatorsExecutorAlwaysSucceed, NoAdditionalEthashData)
PoWConsensus(vm, bl, blockchainConfig, fullConfig, ValidatorsExecutorAlwaysSucceed, NoAdditionalPoWData)
consensus
}

Expand Down
3 changes: 2 additions & 1 deletion src/it/scala/io/iohk/ethereum/txExecTest/ECIP1017Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class ECIP1017Test extends AnyFlatSpec with Matchers {
ecip1098BlockNumber = Long.MaxValue,
treasuryAddress = Address(0),
ecip1097BlockNumber = Long.MaxValue,
ecip1099BlockNumber = Long.MaxValue
ecip1099BlockNumber = Long.MaxValue,
ecip1049BlockNumber = None
)
val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(4))

Expand Down
3 changes: 2 additions & 1 deletion src/it/scala/io/iohk/ethereum/txExecTest/ForksTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class ForksTest extends AnyFlatSpec with Matchers {
ecip1098BlockNumber = Long.MaxValue,
treasuryAddress = Address(0),
ecip1097BlockNumber = Long.MaxValue,
ecip1099BlockNumber = Long.MaxValue
ecip1099BlockNumber = Long.MaxValue,
ecip1049BlockNumber = None
)

val noErrors = a[Right[_, Seq[Receipt]]]
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/conf/base-testnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mantis {
consensus {
coinbase = "0011223344556677889900112233445566778899" # has to be changed for each node
mining-enabled = false
protocol = "restricted-ethash"
protocol = "restricted-pow"
}

network {
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/conf/base.conf
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ mantis {
# Declaring the protocol here means that a more protocol-specific configuration
# is pulled from the corresponding consensus implementation.
# For example, in case of ethash, a section named `ethash` is used.
# Available protocols: ethash, mocked, restricted-ethash
# Available protocols: pow, mocked, restricted-pow
# In case of mocked, remember to enable qa api
protocol = ethash
protocol = pow

# If true then the consensus protocol uses this node for mining.
# In the case of ethash PoW, this means mining new blocks, as specified by Ethereum.
Expand All @@ -305,7 +305,7 @@ mantis {

# This is the section dedicated to Ethash mining.
# This consensus protocol is selected by setting `mantis.consensus.protocol = ethash`.
ethash {
pow {
# Maximum number of ommers kept in the pool
ommers-pool-size = 30

Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/conf/chains/etc-chain.conf
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
# https://ecips.ethereumclassic.org/ECIPs/ecip-1099
ecip1099-block-number = "11700000"

# ECIP-1049 soft fork block number
# https://ecips.ethereumclassic.org/ECIPs/ecip-1049
# https://github.com/ethereumclassic/ECIPs/issues/394
# ecip1049-block-number = "0" // TODO to be determined

# DAO fork configuration (Ethereum HF/Classic split)
# https://blog.ethereum.org/2016/07/20/hard-fork-completed/
dao {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/conf/chains/test-chain.conf
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
# Set of initial nodes
bootstrap-nodes = []

# List of hex encoded public keys of miners which can extend chain (only used when using restricted-ethash consensus)
# List of hex encoded public keys of miners which can extend chain (only used when using restricted-pow consensus)
# empty means that everybody can mine
allowed-miners = []
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
# List of hex encoded public keys of Checkpoint Authorities
checkpoint-public-keys = []

# List of hex encoded public keys of miners which can extend chain (only used when using restricted-ethash consensus)
# List of hex encoded public keys of miners which can extend chain (only used when using restricted-pow consensus)
# empty means that everybody can mine
include "testnet-allowed-miners"
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"5355fc1bba22b121c3954b0174c8ebfd52efe95e3d062980a916770aec1316c6116a46af591f47f07074f48564cb31c15c90498f2ff9fadf86639e60f3cb2c0d"
]

# List of hex encoded public keys of miners which can extend chain (only used when using restricted-ethash consensus)
# List of hex encoded public keys of miners which can extend chain (only used when using restricted-pow consensus)
# empty means that everybody can mine
include "testnet-allowed-miners"
}
2 changes: 1 addition & 1 deletion src/main/scala/io/iohk/ethereum/consensus/Consensus.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.iohk.ethereum.consensus

import io.iohk.ethereum.consensus.blocks.{BlockGenerator, TestBlockGenerator}
import io.iohk.ethereum.consensus.difficulty.DifficultyCalculator
import io.iohk.ethereum.consensus.ethash.{MinerProtocol, MinerResponse}
import io.iohk.ethereum.consensus.pow.{MinerProtocol, MinerResponse}
import io.iohk.ethereum.consensus.validators.Validators
import io.iohk.ethereum.ledger.BlockPreparator
import io.iohk.ethereum.ledger.Ledger.VMImpl
Expand Down
24 changes: 12 additions & 12 deletions src/main/scala/io/iohk/ethereum/consensus/ConsensusBuilder.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.iohk.ethereum.consensus

import io.iohk.ethereum.consensus.Protocol.{NoAdditionalEthashData, RestrictedEthashMinerData}
import io.iohk.ethereum.consensus.ethash.EthashConsensus
import io.iohk.ethereum.consensus.validators.std.ValidatorsExecutor
import io.iohk.ethereum.consensus.Protocol.{NoAdditionalPoWData, RestrictedPoWMinerData}
import io.iohk.ethereum.consensus.pow.PoWConsensus
import io.iohk.ethereum.consensus.pow.validators.ValidatorsExecutor
import io.iohk.ethereum.nodebuilder._
import io.iohk.ethereum.utils.{Config, Logger}

Expand All @@ -15,7 +15,7 @@ trait ConsensusBuilder {
* This is done dynamically when Mantis boots, based on its configuration.
*
* @see [[io.iohk.ethereum.consensus.Consensus Consensus]],
* [[io.iohk.ethereum.consensus.ethash.EthashConsensus EthashConsensus]],
* [[io.iohk.ethereum.consensus.pow.PoWConsensus PoWConsensus]],
*/
trait StdConsensusBuilder extends ConsensusBuilder {
self: VmBuilder
Expand All @@ -31,19 +31,19 @@ trait StdConsensusBuilder extends ConsensusBuilder {
FullConsensusConfig(consensusConfig, c)

//TODO [ETCM-397] refactor configs to avoid possibility of running mocked or
// restricted-ethash consensus on real network like ETC or Mordor
protected def buildEthashConsensus(): ethash.EthashConsensus = {
val specificConfig = ethash.EthashConfig(mantisConfig)
// restricted-pow consensus on real network like ETC or Mordor
protected def buildPoWConsensus(): pow.PoWConsensus = {
val specificConfig = pow.EthashConfig(mantisConfig)

val fullConfig = newConfig(specificConfig)

val validators = ValidatorsExecutor(blockchainConfig, consensusConfig.protocol)

val additionalEthashData = consensusConfig.protocol match {
case Protocol.Ethash | Protocol.MockedPow => NoAdditionalEthashData
case Protocol.RestrictedEthash => RestrictedEthashMinerData(nodeKey)
val additionalPoWData = consensusConfig.protocol match {
case Protocol.PoW | Protocol.MockedPow => NoAdditionalPoWData
case Protocol.RestrictedPoW => RestrictedPoWMinerData(nodeKey)
}
val consensus = EthashConsensus(vm, blockchain, blockchainConfig, fullConfig, validators, additionalEthashData)
val consensus = PoWConsensus(vm, blockchain, blockchainConfig, fullConfig, validators, additionalPoWData)
consensus
}

Expand All @@ -53,7 +53,7 @@ trait StdConsensusBuilder extends ConsensusBuilder {

val consensus =
config.protocol match {
case Protocol.Ethash | Protocol.MockedPow | Protocol.RestrictedEthash => buildEthashConsensus()
case Protocol.PoW | Protocol.MockedPow | Protocol.RestrictedPoW => buildPoWConsensus()
}

log.info(s"Using '${protocol.name}' consensus [${consensus.getClass.getName}]")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ object ConsensusConfig extends Logger {
}

final val AllowedProtocols = Set(
Protocol.Names.Ethash,
Protocol.Names.PoW,
Protocol.Names.MockedPow,
Protocol.Names.RestrictedEthash
Protocol.Names.RestrictedPoW
)

final val AllowedProtocolsError = (s: String) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import io.iohk.ethereum.metrics.MetricsContainer

object ConsensusMetrics extends MetricsContainer {
private final val blockGenTimer = "consensus.blocks.generate.timer"
final val EthashBlockGeneratorTiming = metrics.timer(blockGenTimer, "class", "EthashBlockGenerator")
final val RestrictedEthashBlockGeneratorTiming =
metrics.timer(blockGenTimer, "class", "RestrictedEthashBlockGenerator")
final val PoWBlockGeneratorTiming = metrics.timer(blockGenTimer, "class", "PoWBlockGenerator")
final val RestrictedPoWBlockGeneratorTiming =
metrics.timer(blockGenTimer, "class", "RestrictedPoWBlockGenerator")
final val NoOmmersBlockGeneratorTiming = metrics.timer(blockGenTimer, "class", "NoOmmersBlockGenerator")

final val MinedBlockEvaluationTimer = metrics.timer("consensus.minedblocks.evaluation.timer")
Expand Down
Loading