Skip to content

Commit

Permalink
[ETCM-746] PR comments applied - Fixed some renaming and imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonor Boga committed Apr 15, 2021
1 parent 487a22f commit d511ed5
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions crypto/src/main/scala/io/iohk/ethereum/crypto/package.scala
Expand Up @@ -41,10 +41,10 @@ package object crypto {
def kec256(input: ByteString): ByteString =
ByteString(kec256(input.toArray))

def kec256PoW(header: Array[Byte], once: Array[Byte]): Array[Byte] = {
def kec256PoW(header: Array[Byte], nonce: Array[Byte]): Array[Byte] = {
val digest = new KeccakDigest(256)
digest.update(header, 0, header.length)
digest.update(once, 0, once.length)
digest.update(nonce, 0, nonce.length)
val output = Array.ofDim[Byte](32)
digest.doFinal(output, 0)
output
Expand Down
Expand Up @@ -2,7 +2,7 @@ package io.iohk.ethereum.ets.blockchain

import akka.util.ByteString
import io.iohk.ethereum.consensus.Protocol.NoAdditionalPoWData
import io.iohk.ethereum.consensus.pow.PoWConsensus
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
Expand All @@ -18,19 +18,20 @@ import io.iohk.ethereum.utils.BigIntExtensionMethods._
import io.iohk.ethereum.utils.{BlockchainConfig, Config}
import monix.execution.Scheduler
import org.bouncycastle.util.encoders.Hex

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

object ScenarioSetup {
val testContext = Scheduler.fixedPool("scenario-setup-pool", 4)
val specificConfig = pow.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
): pow.PoWConsensus = {
): PoWConsensus = {
val consensus = PoWConsensus(vm, blockchain, blockchainConfig, fullConfig, validators, NoAdditionalPoWData)
consensus
}
Expand Down
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
Expand Up @@ -6,6 +6,8 @@ import io.iohk.ethereum.utils.ByteUtils

object KeccakCalculation {

final val difficultyNumerator: BigInt = BigInt(2).pow(256)

/**
* Computation of mixHash = keccak256(keccak256(rlp(unsealed header)), nonce)
* @param hashHeader the rlp(unsealed header)
Expand All @@ -27,7 +29,7 @@ object KeccakCalculation {
*/
def isMixHashValid(mixHash: ByteString, difficulty: BigInt): Boolean = {
val mixHashInt = BigInt.apply(mixHash.toArray)
val threshold = BigInt(2).pow(256) / difficulty
val threshold = difficultyNumerator / difficulty
mixHashInt <= threshold
}

Expand Down
Expand Up @@ -75,7 +75,7 @@ class PoWBlockGeneratorImpl(
beneficiary: Address,
x: Ommers,
initialWorldStateBeforeExecution: Option[InMemoryWorldStateProxy]
): PendingBlockAndState = ConsensusMetrics.EthashBlockGeneratorTiming.record { () =>
): PendingBlockAndState = ConsensusMetrics.PoWBlockGeneratorTiming.record { () =>
val pHeader = parent.header
val blockNumber = pHeader.number + 1
val parentHash = pHeader.hash
Expand Down
Expand Up @@ -36,7 +36,7 @@ class RestrictedPoWBlockGeneratorImpl(
beneficiary: Address,
ommers: Ommers,
initialWorldStateBeforeExecution: Option[InMemoryWorldStateProxy]
): PendingBlockAndState = ConsensusMetrics.RestrictedEthashBlockGeneratorTiming.record { () =>
): PendingBlockAndState = ConsensusMetrics.RestrictedPoWBlockGeneratorTiming.record { () =>
val pHeader = parent.header
val blockNumber = pHeader.number + 1
val parentHash = pHeader.hash
Expand Down

0 comments on commit d511ed5

Please sign in to comment.