Add timer metrics for EVM operations (#551)

* Add timer metrics for EVM operations.

* Rename ProtocolScheduleBuilder to ProtocolScheduleFactory.

* Sort category names alphabetically.
Adrian Sutton 6 years ago committed by GitHub
parent fcb9e16e1a
commit 525aa19d50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      consensus/clique/build.gradle
  2. 10
      consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolSchedule.java
  3. 6
      consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolScheduleTest.java
  4. 3
      consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java
  5. 7
      consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueMinerExecutorTest.java
  6. 1
      consensus/ibft/build.gradle
  7. 3
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextFactory.java
  8. 9
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftProtocolSchedule.java
  9. 4
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/blockcreation/IbftBlockCreatorTest.java
  10. 1
      consensus/ibftlegacy/build.gradle
  11. 9
      consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/IbftProtocolSchedule.java
  12. 4
      consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java
  13. 1
      ethereum/blockcreation/build.gradle
  14. 4
      ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/BlockTransactionSelectorTest.java
  15. 10
      ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/EthHashBlockCreatorTest.java
  16. 9
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/development/DevelopmentProtocolSchedule.java
  17. 26
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetEvmRegistries.java
  18. 12
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolSchedule.java
  19. 14
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/ProtocolScheduleFactory.java
  20. 15
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/ProtocolSpecBuilder.java
  21. 20
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/vm/EVM.java
  22. 9
      ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java
  23. 7
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/GenesisStateTest.java
  24. 4
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/development/DevelopmentProtocolScheduleTest.java
  25. 12
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolScheduleTest.java
  26. 4
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java
  27. 6
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/ReferenceTestProtocolSchedules.java
  28. 5
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/VMReferenceTest.java
  29. 4
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/operations/ConstantinopleSStoreOperationGasCostTest.java
  30. 4
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java
  31. 4
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTestUtil.java
  32. 4
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/ethtaskutils/BlockchainSetupUtil.java
  33. 4
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockBodiesMessageTest.java
  34. 4
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockHeadersMessageTest.java
  35. 4
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/NewBlockMessageTest.java
  36. 3
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/ChainHeadTrackerTest.java
  37. 3
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java
  38. 3
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java
  39. 3
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java
  40. 3
      ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/BlockchainImporter.java
  41. 2
      ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java
  42. 4
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java
  43. 3
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java
  44. 2
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceRpcApisTest.java
  45. 3
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java
  46. 13
      metrics/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java
  47. 48
      metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java
  48. 2
      pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonControllerBuilder.java
  49. 2
      pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java
  50. 2
      pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftLegacyPantheonController.java
  51. 2
      pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java
  52. 2
      pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonController.java
  53. 6
      pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java

@ -39,6 +39,7 @@ dependencies {
implementation project(':ethereum:p2p')
implementation project(':services:kvstore')
implementation project(':consensus:common')
implementation project(':metrics')
implementation project(':util')
implementation 'io.vertx:vertx-core'

@ -24,8 +24,9 @@ import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockBodyValidator;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockImporter;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleBuilder;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleFactory;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpecBuilder;
import tech.pegasys.pantheon.metrics.MetricsSystem;
/** Defines the protocol behaviours for a blockchain using Clique. */
public class CliqueProtocolSchedule {
@ -33,14 +34,17 @@ public class CliqueProtocolSchedule {
private static final int DEFAULT_CHAIN_ID = 4;
public static ProtocolSchedule<CliqueContext> create(
final GenesisConfigOptions config, final KeyPair nodeKeys) {
final GenesisConfigOptions config,
final KeyPair nodeKeys,
final MetricsSystem metricsSystem) {
final CliqueConfigOptions cliqueConfig = config.getCliqueConfigOptions();
final Address localNodeAddress = Util.publicKeyToAddress(nodeKeys.getPublicKey());
final EpochManager epochManager = new EpochManager(cliqueConfig.getEpochLength());
return new ProtocolScheduleBuilder<>(
return new ProtocolScheduleFactory<>(
metricsSystem,
config,
DEFAULT_CHAIN_ID,
builder ->

@ -20,6 +20,7 @@ import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpec;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import org.junit.Test;
@ -41,7 +42,7 @@ public class CliqueProtocolScheduleTest {
final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions();
final ProtocolSchedule<CliqueContext> protocolSchedule =
CliqueProtocolSchedule.create(config, NODE_KEYS);
CliqueProtocolSchedule.create(config, NODE_KEYS, new NoOpMetricsSystem());
final ProtocolSpec<CliqueContext> homesteadSpec = protocolSchedule.getByBlockNumber(1);
final ProtocolSpec<CliqueContext> tangerineWhistleSpec = protocolSchedule.getByBlockNumber(2);
@ -56,7 +57,8 @@ public class CliqueProtocolScheduleTest {
@Test
public void parametersAlignWithMainnetWithAdjustments() {
final ProtocolSpec<CliqueContext> homestead =
CliqueProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions(), NODE_KEYS)
CliqueProtocolSchedule.create(
GenesisConfigFile.DEFAULT.getConfigOptions(), NODE_KEYS, new NoOpMetricsSystem())
.getByBlockNumber(0);
assertThat(homestead.getName()).isEqualTo("Frontier");

@ -43,6 +43,7 @@ import tech.pegasys.pantheon.ethereum.core.Util;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.db.WorldStateArchive;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.util.List;
@ -69,7 +70,7 @@ public class CliqueBlockCreatorTest {
public void setup() {
protocolSchedule =
CliqueProtocolSchedule.create(
GenesisConfigFile.DEFAULT.getConfigOptions(), proposerKeyPair);
GenesisConfigFile.DEFAULT.getConfigOptions(), proposerKeyPair, new NoOpMetricsSystem());
final Address otherAddress = Util.publicKeyToAddress(otherKeyPair.getPublicKey());
validatorList.add(otherAddress);

@ -36,6 +36,7 @@ import tech.pegasys.pantheon.ethereum.core.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.Util;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.util.List;
@ -85,7 +86,8 @@ public class CliqueMinerExecutorTest {
new CliqueMinerExecutor(
cliqueProtocolContext,
Executors.newSingleThreadExecutor(),
CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerKeyPair),
CliqueProtocolSchedule.create(
GENESIS_CONFIG_OPTIONS, proposerKeyPair, new NoOpMetricsSystem()),
new PendingTransactions(1),
proposerKeyPair,
new MiningParameters(AddressHelpers.ofValue(1), Wei.ZERO, wrappedVanityData, false),
@ -115,7 +117,8 @@ public class CliqueMinerExecutorTest {
new CliqueMinerExecutor(
cliqueProtocolContext,
Executors.newSingleThreadExecutor(),
CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerKeyPair),
CliqueProtocolSchedule.create(
GENESIS_CONFIG_OPTIONS, proposerKeyPair, new NoOpMetricsSystem()),
new PendingTransactions(1),
proposerKeyPair,
new MiningParameters(AddressHelpers.ofValue(1), Wei.ZERO, wrappedVanityData, false),

@ -35,6 +35,7 @@ dependencies {
implementation project(':ethereum:jsonrpc')
implementation project(':ethereum:rlp')
implementation project(':ethereum:p2p')
implementation project(':metrics')
implementation project(':services:kvstore')
implementation 'io.vertx:vertx-core'

@ -60,6 +60,7 @@ import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.db.WorldStateArchive;
import tech.pegasys.pantheon.ethereum.mainnet.BlockHeaderValidator;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.util.Subscribers;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import tech.pegasys.pantheon.util.uint.UInt256;
@ -202,7 +203,7 @@ public class TestContextFactory {
genesisConfigOptions.byzantiumBlock(0);
final ProtocolSchedule<IbftContext> protocolSchedule =
IbftProtocolSchedule.create(genesisConfigOptions);
IbftProtocolSchedule.create(genesisConfigOptions, new NoOpMetricsSystem());
/////////////////////////////////////////////////////////////////////////////////////
// From here down is BASICALLY taken from IbftPantheonController

@ -22,8 +22,9 @@ import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockBodyValidator;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockImporter;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleBuilder;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleFactory;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpecBuilder;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import java.math.BigInteger;
@ -32,13 +33,15 @@ public class IbftProtocolSchedule {
private static final int DEFAULT_CHAIN_ID = 1;
public static ProtocolSchedule<IbftContext> create(final GenesisConfigOptions config) {
public static ProtocolSchedule<IbftContext> create(
final GenesisConfigOptions config, final MetricsSystem metricsSystem) {
final IbftConfigOptions ibftConfig = config.getIbftConfigOptions();
final long epochLength = ibftConfig.getEpochLength();
final long blockPeriod = ibftConfig.getBlockPeriodSeconds();
final EpochManager epochManager = new EpochManager(epochLength);
return new ProtocolScheduleBuilder<>(
return new ProtocolScheduleFactory<>(
metricsSystem,
config,
DEFAULT_CHAIN_ID,
builder -> applyIbftChanges(blockPeriod, epochManager, builder))

@ -38,6 +38,7 @@ import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.BlockHeaderValidator;
import tech.pegasys.pantheon.ethereum.mainnet.HeaderValidationMode;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.time.Instant;
@ -73,7 +74,8 @@ public class IbftBlockCreatorTest {
final ProtocolSchedule<IbftContext> protocolSchedule =
IbftProtocolSchedule.create(
GenesisConfigFile.fromConfig("{\"config\": {\"spuriousDragonBlock\":0}}")
.getConfigOptions());
.getConfigOptions(),
new NoOpMetricsSystem());
final ProtocolContext<IbftContext> protContext =
new ProtocolContext<>(
blockchain,

@ -23,6 +23,7 @@ dependencies {
implementation project(':ethereum:jsonrpc')
implementation project(':ethereum:rlp')
implementation project(':ethereum:p2p')
implementation project(':metrics')
implementation project(':services:kvstore')
implementation 'com.google.guava:guava'

@ -24,8 +24,9 @@ import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockBodyValidator;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockImporter;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleBuilder;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleFactory;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpecBuilder;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import java.math.BigInteger;
@ -34,13 +35,15 @@ public class IbftProtocolSchedule {
private static final int DEFAULT_CHAIN_ID = 1;
public static ProtocolSchedule<IbftContext> create(final GenesisConfigOptions config) {
public static ProtocolSchedule<IbftContext> create(
final GenesisConfigOptions config, final MetricsSystem metricsSystem) {
final IbftConfigOptions ibftConfig = config.getIbftConfigOptions();
final long epochLength = ibftConfig.getEpochLength();
final long blockPeriod = ibftConfig.getBlockPeriodSeconds();
final EpochManager epochManager = new EpochManager(epochLength);
return new ProtocolScheduleBuilder<>(
return new ProtocolScheduleFactory<>(
metricsSystem,
config,
DEFAULT_CHAIN_ID,
builder -> applyIbftChanges(blockPeriod, epochManager, builder))

@ -38,6 +38,7 @@ import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.BlockHeaderValidator;
import tech.pegasys.pantheon.ethereum.mainnet.HeaderValidationMode;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.time.Instant;
@ -79,7 +80,8 @@ public class IbftBlockCreatorTest {
final ProtocolSchedule<IbftContext> protocolSchedule =
IbftProtocolSchedule.create(
GenesisConfigFile.fromConfig("{\"config\": {\"spuriousDragonBlock\":0}}")
.getConfigOptions());
.getConfigOptions(),
new NoOpMetricsSystem());
final ProtocolContext<IbftContext> protContext =
new ProtocolContext<>(
blockchain,

@ -26,6 +26,7 @@ dependencies {
testImplementation project(path: ':config', configuration: 'testSupportArtifacts')
testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
testImplementation project(path: ':ethereum:core', configuration: 'testArtifacts')
testImplementation project(path: ':metrics')
testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'

@ -45,6 +45,7 @@ import tech.pegasys.pantheon.ethereum.mainnet.ValidationResult;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.ethereum.vm.TestBlockchain;
import tech.pegasys.pantheon.ethereum.worldstate.DefaultMutableWorldState;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import tech.pegasys.pantheon.util.uint.UInt256;
@ -63,7 +64,8 @@ public class BlockTransactionSelectorTest {
@Test
public void emptyPendingTransactionsResultsInEmptyVettingResult() {
final ProtocolSchedule<Void> protocolSchedule =
DevelopmentProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions());
DevelopmentProtocolSchedule.create(
GenesisConfigFile.DEFAULT.getConfigOptions(), new NoOpMetricsSystem());
final Blockchain blockchain = new TestBlockchain();
final TransactionProcessor transactionProcessor =
protocolSchedule.getByBlockNumber(0).getTransactionProcessor();

@ -20,8 +20,9 @@ import tech.pegasys.pantheon.ethereum.core.PendingTransactions;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.EthHashSolver;
import tech.pegasys.pantheon.ethereum.mainnet.EthHasher.Light;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleBuilder;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleFactory;
import tech.pegasys.pantheon.ethereum.mainnet.ValidationTestUtils;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.io.IOException;
@ -46,8 +47,11 @@ public class EthHashBlockCreatorTest {
private final ExecutionContextTestFixture executionContextTestFixture =
ExecutionContextTestFixture.builder()
.protocolSchedule(
new ProtocolScheduleBuilder<>(
GenesisConfigFile.DEFAULT.getConfigOptions(), 42, Function.identity())
new ProtocolScheduleFactory<>(
new NoOpMetricsSystem(),
GenesisConfigFile.DEFAULT.getConfigOptions(),
42,
Function.identity())
.createProtocolSchedule())
.build();

@ -16,13 +16,16 @@ import static tech.pegasys.pantheon.ethereum.mainnet.MainnetTransactionValidator
import tech.pegasys.pantheon.config.GenesisConfigOptions;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleBuilder;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleFactory;
import tech.pegasys.pantheon.metrics.MetricsSystem;
/** A ProtocolSchedule which behaves similarly to MainNet, but with a much reduced difficulty. */
public class DevelopmentProtocolSchedule {
public static ProtocolSchedule<Void> create(final GenesisConfigOptions config) {
return new ProtocolScheduleBuilder<>(
public static ProtocolSchedule<Void> create(
final GenesisConfigOptions config, final MetricsSystem metricsSystem) {
return new ProtocolScheduleFactory<>(
metricsSystem,
config,
NO_CHAIN_ID,
builder -> builder.difficultyCalculator(DevelopmentDifficultyCalculators.DEVELOPER))

@ -91,6 +91,7 @@ import tech.pegasys.pantheon.ethereum.vm.operations.SubOperation;
import tech.pegasys.pantheon.ethereum.vm.operations.SwapOperation;
import tech.pegasys.pantheon.ethereum.vm.operations.TimestampOperation;
import tech.pegasys.pantheon.ethereum.vm.operations.XorOperation;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import java.util.List;
import java.util.function.Function;
@ -116,7 +117,9 @@ public abstract class MainnetEvmRegistries {
}
private static EVM createAndPopulate(
final List<OperationFactory> factories, final GasCalculator gasCalculator) {
final List<OperationFactory> factories,
final GasCalculator gasCalculator,
final MetricsSystem metricsSystem) {
final OperationRegistry registry = new OperationRegistry();
for (final OperationFactory factory : factories) {
@ -124,23 +127,26 @@ public abstract class MainnetEvmRegistries {
registry.put(operation.getOpcode(), operation);
}
return new EVM(registry, new InvalidOperation(gasCalculator));
return new EVM(registry, new InvalidOperation(gasCalculator), metricsSystem);
}
public static EVM frontier(final GasCalculator gasCalculator) {
return createAndPopulate(FRONTIER_OPERATION_FACTORIES, gasCalculator);
public static EVM frontier(final GasCalculator gasCalculator, final MetricsSystem metricsSystem) {
return createAndPopulate(FRONTIER_OPERATION_FACTORIES, gasCalculator, metricsSystem);
}
public static EVM homestead(final GasCalculator gasCalculator) {
return createAndPopulate(HOMESTEAD_OPERATION_FACTORIES, gasCalculator);
public static EVM homestead(
final GasCalculator gasCalculator, final MetricsSystem metricsSystem) {
return createAndPopulate(HOMESTEAD_OPERATION_FACTORIES, gasCalculator, metricsSystem);
}
public static EVM byzantium(final GasCalculator gasCalculator) {
return createAndPopulate(BYZANTIUM_OPERATION_FACTORIES, gasCalculator);
public static EVM byzantium(
final GasCalculator gasCalculator, final MetricsSystem metricsSystem) {
return createAndPopulate(BYZANTIUM_OPERATION_FACTORIES, gasCalculator, metricsSystem);
}
public static EVM constantinople(final GasCalculator gasCalculator) {
return createAndPopulate(CONSTANTINOPLE_OPERATION_FACTORIES, gasCalculator);
public static EVM constantinople(
final GasCalculator gasCalculator, final MetricsSystem metricsSystem) {
return createAndPopulate(CONSTANTINOPLE_OPERATION_FACTORIES, gasCalculator, metricsSystem);
}
private static List<OperationFactory> buildFrontierFactories() {

@ -14,6 +14,7 @@ package tech.pegasys.pantheon.ethereum.mainnet;
import tech.pegasys.pantheon.config.GenesisConfigFile;
import tech.pegasys.pantheon.config.GenesisConfigOptions;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import java.util.function.Function;
@ -22,8 +23,8 @@ public class MainnetProtocolSchedule {
public static final int DEFAULT_CHAIN_ID = 1;
public static ProtocolSchedule<Void> create() {
return fromConfig(GenesisConfigFile.mainnet().getConfigOptions());
public static ProtocolSchedule<Void> create(final MetricsSystem metricsSystem) {
return fromConfig(GenesisConfigFile.mainnet().getConfigOptions(), metricsSystem);
}
/**
@ -31,10 +32,13 @@ public class MainnetProtocolSchedule {
*
* @param config {@link GenesisConfigOptions} containing the config options for the milestone
* starting points
* @param metricsSystem the {@link MetricsSystem} to use to record metrics
* @return A configured mainnet protocol schedule
*/
public static ProtocolSchedule<Void> fromConfig(final GenesisConfigOptions config) {
return new ProtocolScheduleBuilder<>(config, DEFAULT_CHAIN_ID, Function.identity())
public static ProtocolSchedule<Void> fromConfig(
final GenesisConfigOptions config, final MetricsSystem metricsSystem) {
return new ProtocolScheduleFactory<>(
metricsSystem, config, DEFAULT_CHAIN_ID, Function.identity())
.createProtocolSchedule();
}
}

@ -13,20 +13,24 @@
package tech.pegasys.pantheon.ethereum.mainnet;
import tech.pegasys.pantheon.config.GenesisConfigOptions;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import java.util.OptionalLong;
import java.util.function.Function;
public class ProtocolScheduleBuilder<C> {
public class ProtocolScheduleFactory<C> {
private final MetricsSystem metricsSystem;
private final GenesisConfigOptions config;
private final Function<ProtocolSpecBuilder<Void>, ProtocolSpecBuilder<C>> protocolSpecAdapter;
private final int defaultChainId;
public ProtocolScheduleBuilder(
public ProtocolScheduleFactory(
final MetricsSystem metricsSystem,
final GenesisConfigOptions config,
final int defaultChainId,
final Function<ProtocolSpecBuilder<Void>, ProtocolSpecBuilder<C>> protocolSpecAdapter) {
this.metricsSystem = metricsSystem;
this.config = config;
this.protocolSpecAdapter = protocolSpecAdapter;
this.defaultChainId = defaultChainId;
@ -91,6 +95,10 @@ public class ProtocolScheduleBuilder<C> {
blockNumber.ifPresent(
number ->
protocolSchedule.putMilestone(
number, protocolSpecAdapter.apply(definition).build(protocolSchedule)));
number,
protocolSpecAdapter
.apply(definition)
.metricsSystem(metricsSystem)
.build(protocolSchedule)));
}
}

@ -20,6 +20,7 @@ import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockProcessor.TransactionReceiptFactory;
import tech.pegasys.pantheon.ethereum.vm.EVM;
import tech.pegasys.pantheon.ethereum.vm.GasCalculator;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import java.util.function.BiFunction;
import java.util.function.Function;
@ -31,7 +32,7 @@ public class ProtocolSpecBuilder<T> {
private BlockHashFunction blockHashFunction;
private TransactionReceiptFactory transactionReceiptFactory;
private DifficultyCalculator<T> difficultyCalculator;
private Function<GasCalculator, EVM> evmBuilder;
private BiFunction<GasCalculator, MetricsSystem, EVM> evmBuilder;
private Function<GasCalculator, TransactionValidator> transactionValidatorBuilder;
private Function<DifficultyCalculator<T>, BlockHeaderValidator<T>> blockHeaderValidatorBuilder;
private Function<DifficultyCalculator<T>, BlockHeaderValidator<T>> ommerHeaderValidatorBuilder;
@ -46,6 +47,7 @@ public class ProtocolSpecBuilder<T> {
private TransactionReceiptType transactionReceiptType;
private String name;
private MiningBeneficiaryCalculator miningBeneficiaryCalculator;
private MetricsSystem metricsSystem;
public ProtocolSpecBuilder<T> gasCalculator(final Supplier<GasCalculator> gasCalculatorBuilder) {
this.gasCalculatorBuilder = gasCalculatorBuilder;
@ -74,7 +76,8 @@ public class ProtocolSpecBuilder<T> {
return this;
}
public ProtocolSpecBuilder<T> evmBuilder(final Function<GasCalculator, EVM> evmBuilder) {
public ProtocolSpecBuilder<T> evmBuilder(
final BiFunction<GasCalculator, MetricsSystem, EVM> evmBuilder) {
this.evmBuilder = evmBuilder;
return this;
}
@ -160,6 +163,11 @@ public class ProtocolSpecBuilder<T> {
return this;
}
public ProtocolSpecBuilder<T> metricsSystem(final MetricsSystem metricsSystem) {
this.metricsSystem = metricsSystem;
return this;
}
public <R> ProtocolSpecBuilder<R> changeConsensusContextType(
final Function<DifficultyCalculator<R>, BlockHeaderValidator<R>> blockHeaderValidatorBuilder,
final Function<DifficultyCalculator<R>, BlockHeaderValidator<R>> ommerHeaderValidatorBuilder,
@ -208,9 +216,10 @@ public class ProtocolSpecBuilder<T> {
checkNotNull(name, "Missing name");
checkNotNull(miningBeneficiaryCalculator, "Missing Mining Beneficiary Calculator");
checkNotNull(protocolSchedule, "Missing protocol schedule");
checkNotNull(metricsSystem, "Missing metrics system");
final GasCalculator gasCalculator = gasCalculatorBuilder.get();
final EVM evm = evmBuilder.apply(gasCalculator);
final EVM evm = evmBuilder.apply(gasCalculator, metricsSystem);
final TransactionValidator transactionValidator =
transactionValidatorBuilder.apply(gasCalculator);
final AbstractMessageProcessor contractCreationProcessor =

@ -19,6 +19,11 @@ import tech.pegasys.pantheon.ethereum.core.Gas;
import tech.pegasys.pantheon.ethereum.vm.MessageFrame.State;
import tech.pegasys.pantheon.ethereum.vm.ehalt.ExceptionalHaltException;
import tech.pegasys.pantheon.ethereum.vm.ehalt.ExceptionalHaltManager;
import tech.pegasys.pantheon.metrics.LabelledMetric;
import tech.pegasys.pantheon.metrics.MetricCategory;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import tech.pegasys.pantheon.metrics.OperationTimer;
import tech.pegasys.pantheon.metrics.OperationTimer.TimingContext;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.util.EnumSet;
@ -33,10 +38,17 @@ public class EVM {
private static final int STOP_OPCODE = 0x00;
private final OperationRegistry operations;
private final Operation invalidOperation;
private final LabelledMetric<OperationTimer> labelledTimer;
public EVM(final OperationRegistry operations, final Operation invalidOperation) {
public EVM(
final OperationRegistry operations,
final Operation invalidOperation,
final MetricsSystem metricsSystem) {
this.operations = operations;
this.invalidOperation = invalidOperation;
labelledTimer =
metricsSystem.createLabelledTimer(
MetricCategory.EVM, "operation_execution", "Timing for EVM operations", "operation");
}
public void runToHalt(final MessageFrame frame, final OperationTracer operationTracer)
@ -70,7 +82,11 @@ public class EVM {
checkForExceptionalHalt(frame);
logState(frame, currentGasCost);
decrementRemainingGas(frame, currentGasCost);
frame.getCurrentOperation().execute(frame);
final Operation currentOperation = frame.getCurrentOperation();
try (final TimingContext ignored =
labelledTimer.labels(currentOperation.getName()).startTimer()) {
currentOperation.execute(frame);
}
incrementProgramCounter(frame);
});
}

@ -21,7 +21,7 @@ import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain;
import tech.pegasys.pantheon.ethereum.db.WorldStateArchive;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleBuilder;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleFactory;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.ethereum.worldstate.DefaultMutableWorldState;
@ -112,8 +112,11 @@ public class ExecutionContextTestFixture {
public ExecutionContextTestFixture build() {
if (protocolSchedule == null) {
protocolSchedule =
new ProtocolScheduleBuilder<>(
new StubGenesisConfigOptions().constantinopleBlock(0), 42, Function.identity())
new ProtocolScheduleFactory<>(
new NoOpMetricsSystem(),
new StubGenesisConfigOptions().constantinopleBlock(0),
42,
Function.identity())
.createProtocolSchedule();
}
if (keyValueStorage == null) {

@ -22,6 +22,7 @@ import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule;
import tech.pegasys.pantheon.ethereum.rlp.BytesValueRLPOutput;
import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.ethereum.worldstate.DefaultMutableWorldState;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage;
import tech.pegasys.pantheon.util.bytes.BytesValue;
@ -45,7 +46,7 @@ public final class GenesisStateTest {
final GenesisState genesisState =
GenesisState.fromJson(
Resources.toString(GenesisStateTest.class.getResource("genesis1.json"), Charsets.UTF_8),
MainnetProtocolSchedule.create());
MainnetProtocolSchedule.create(new NoOpMetricsSystem()));
final BlockHeader header = genesisState.getBlock().getHeader();
assertThat(header.getStateRoot())
.isEqualTo(
@ -75,7 +76,7 @@ public final class GenesisStateTest {
final GenesisState genesisState =
GenesisState.fromJson(
Resources.toString(GenesisStateTest.class.getResource("genesis2.json"), Charsets.UTF_8),
MainnetProtocolSchedule.create());
MainnetProtocolSchedule.create(new NoOpMetricsSystem()));
final BlockHeader header = genesisState.getBlock().getHeader();
assertThat(header.getStateRoot()).isEqualTo(Hash.EMPTY_TRIE_HASH);
assertThat(header.getTransactionsRoot()).isEqualTo(Hash.EMPTY_TRIE_HASH);
@ -91,7 +92,7 @@ public final class GenesisStateTest {
GenesisState.fromJson(
Resources.toString(
GenesisStateTest.class.getResource("genesis-olympic.json"), Charsets.UTF_8),
MainnetProtocolSchedule.create());
MainnetProtocolSchedule.create(new NoOpMetricsSystem()));
final BytesValueRLPOutput tmp = new BytesValueRLPOutput();
genesisState.getBlock().writeTo(tmp);
assertThat(Hex.toHexString(genesisState.getBlock().getHeader().getHash().extractArray()))

@ -18,6 +18,7 @@ import tech.pegasys.pantheon.config.GenesisConfigFile;
import tech.pegasys.pantheon.ethereum.core.BlockHeader;
import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import org.junit.Test;
@ -27,7 +28,8 @@ public class DevelopmentProtocolScheduleTest {
public void reportedDifficultyForAllBlocksIsAFixedValue() {
final ProtocolSchedule<Void> schedule =
DevelopmentProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions());
DevelopmentProtocolSchedule.create(
GenesisConfigFile.DEFAULT.getConfigOptions(), new NoOpMetricsSystem());
final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture();

@ -13,6 +13,7 @@
package tech.pegasys.pantheon.ethereum.mainnet;
import tech.pegasys.pantheon.config.GenesisConfigFile;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import java.nio.charset.StandardCharsets;
@ -25,7 +26,7 @@ public class MainnetProtocolScheduleTest {
@Test
public void shouldReturnDefaultProtocolSpecsWhenCustomNumbersAreNotUsed() {
final ProtocolSchedule<Void> sched = MainnetProtocolSchedule.create();
final ProtocolSchedule<Void> sched = MainnetProtocolSchedule.create(new NoOpMetricsSystem());
Assertions.assertThat(sched.getByBlockNumber(1L).getName()).isEqualTo("Frontier");
Assertions.assertThat(sched.getByBlockNumber(1_150_000L).getName()).isEqualTo("Homestead");
Assertions.assertThat(sched.getByBlockNumber(1_920_000L).getName())
@ -46,7 +47,8 @@ public class MainnetProtocolScheduleTest {
public void shouldOnlyUseFrontierWhenEmptyJsonConfigIsUsed() {
final JsonObject json = new JsonObject("{}");
final ProtocolSchedule<Void> sched =
MainnetProtocolSchedule.fromConfig(GenesisConfigFile.fromConfig(json).getConfigOptions());
MainnetProtocolSchedule.fromConfig(
GenesisConfigFile.fromConfig(json).getConfigOptions(), new NoOpMetricsSystem());
Assertions.assertThat(sched.getByBlockNumber(1L).getName()).isEqualTo("Frontier");
Assertions.assertThat(sched.getByBlockNumber(Long.MAX_VALUE).getName()).isEqualTo("Frontier");
}
@ -57,7 +59,8 @@ public class MainnetProtocolScheduleTest {
new JsonObject(
"{\"config\": {\"homesteadBlock\": 2, \"daoForkBlock\": 3, \"eip150Block\": 14, \"eip158Block\": 15, \"byzantiumBlock\": 16, \"constantinopleBlock\": 18, \"chainId\":1234}}");
final ProtocolSchedule<Void> sched =
MainnetProtocolSchedule.fromConfig(GenesisConfigFile.fromConfig(json).getConfigOptions());
MainnetProtocolSchedule.fromConfig(
GenesisConfigFile.fromConfig(json).getConfigOptions(), new NoOpMetricsSystem());
Assertions.assertThat(sched.getByBlockNumber(1).getName()).isEqualTo("Frontier");
Assertions.assertThat(sched.getByBlockNumber(2).getName()).isEqualTo("Homestead");
Assertions.assertThat(sched.getByBlockNumber(3).getName()).isEqualTo("DaoRecoveryInit");
@ -76,7 +79,8 @@ public class MainnetProtocolScheduleTest {
GenesisConfigFile.fromConfig(
Resources.toString(
Resources.getResource("ropsten.json"), StandardCharsets.UTF_8))
.getConfigOptions());
.getConfigOptions(),
new NoOpMetricsSystem());
Assertions.assertThat(sched.getByBlockNumber(0).getName()).isEqualTo("TangerineWhistle");
Assertions.assertThat(sched.getByBlockNumber(1).getName()).isEqualTo("TangerineWhistle");
Assertions.assertThat(sched.getByBlockNumber(10).getName()).isEqualTo("SpuriousDragon");

@ -22,6 +22,7 @@ import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction;
import tech.pegasys.pantheon.ethereum.mainnet.ValidationTestUtils;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.util.uint.UInt256;
import java.io.IOException;
@ -109,7 +110,8 @@ public class ProofOfWorkValidationRuleTest {
}
private BlockHashFunction mainnetBlockHashFunction() {
final ProtocolSchedule<Void> protocolSchedule = MainnetProtocolSchedule.create();
final ProtocolSchedule<Void> protocolSchedule =
MainnetProtocolSchedule.create(new NoOpMetricsSystem());
return ScheduleBasedBlockHashFunction.create(protocolSchedule);
}
}

@ -15,7 +15,8 @@ package tech.pegasys.pantheon.ethereum.vm;
import tech.pegasys.pantheon.config.GenesisConfigOptions;
import tech.pegasys.pantheon.config.StubGenesisConfigOptions;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleBuilder;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleFactory;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import java.util.Map;
import java.util.function.Function;
@ -60,7 +61,8 @@ public class ReferenceTestProtocolSchedules {
}
private static ProtocolSchedule<Void> createSchedule(final GenesisConfigOptions options) {
return new ProtocolScheduleBuilder<>(options, CHAIN_ID, Function.identity())
return new ProtocolScheduleFactory<>(
new NoOpMetricsSystem(), options, CHAIN_ID, Function.identity())
.createProtocolSchedule();
}
}

@ -25,6 +25,7 @@ import tech.pegasys.pantheon.ethereum.mainnet.MutableProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpec;
import tech.pegasys.pantheon.ethereum.vm.ehalt.ExceptionalHaltException;
import tech.pegasys.pantheon.ethereum.worldstate.DefaultMutableWorldState;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.testutil.JsonTestParameters;
import java.util.ArrayDeque;
@ -115,7 +116,9 @@ public class VMReferenceTest extends AbstractRetryingTest {
final EnvironmentInformation execEnv = spec.getExec();
final ProtocolSpec<Void> protocolSpec =
MainnetProtocolSpecs.frontierDefinition().build(new MutableProtocolSchedule<>(CHAIN_ID));
MainnetProtocolSpecs.frontierDefinition()
.metricsSystem(new NoOpMetricsSystem())
.build(new MutableProtocolSchedule<>(CHAIN_ID));
final TestBlockchain blockchain = new TestBlockchain(execEnv.getBlockHeader().getNumber());
final MessageFrame frame =

@ -21,6 +21,7 @@ import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.vm.MessageFrame;
import tech.pegasys.pantheon.ethereum.vm.MessageFrame.State;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.util.uint.UInt256;
import org.junit.Before;
@ -34,7 +35,8 @@ import org.junit.runners.Parameterized.Parameters;
public class ConstantinopleSStoreOperationGasCostTest {
private static final ProtocolSchedule<Void> protocolSchedule =
MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions().constantinopleBlock(0));
MainnetProtocolSchedule.fromConfig(
new StubGenesisConfigOptions().constantinopleBlock(0), new NoOpMetricsSystem());
@Parameters(name = "Code: {0}, Original: {1}")
public static Object[][] scenarios() {

@ -54,6 +54,7 @@ import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection;
import tech.pegasys.pantheon.ethereum.p2p.wire.Capability;
import tech.pegasys.pantheon.ethereum.p2p.wire.DefaultMessage;
import tech.pegasys.pantheon.ethereum.p2p.wire.RawMessage;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.util.uint.UInt256;
import java.util.ArrayList;
@ -692,7 +693,8 @@ public final class EthProtocolManagerTest {
.isEqualTo(Collections.singletonList(EthProtocol.ETH63));
// assert that all messages transmitted contain the expected block & total difficulty.
final ProtocolSchedule<Void> protocolSchdeule = MainnetProtocolSchedule.create();
final ProtocolSchedule<Void> protocolSchdeule =
MainnetProtocolSchedule.create(new NoOpMetricsSystem());
for (final NewBlockMessage msg : messageSentCaptor.getAllValues()) {
assertThat(msg.block(protocolSchdeule)).isEqualTo(minedBlock);
assertThat(msg.totalDifficulty(protocolSchdeule)).isEqualTo(expectedTotalDifficulty);

@ -24,6 +24,7 @@ import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData;
import tech.pegasys.pantheon.ethereum.p2p.wire.DefaultMessage;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.util.uint.UInt256;
public class EthProtocolManagerTestUtil {
@ -41,7 +42,8 @@ public class EthProtocolManagerTestUtil {
}
public static EthProtocolManager create() {
final ProtocolSchedule<Void> protocolSchedule = MainnetProtocolSchedule.create();
final ProtocolSchedule<Void> protocolSchedule =
MainnetProtocolSchedule.create(new NoOpMetricsSystem());
final GenesisConfigFile config = GenesisConfigFile.mainnet();
final GenesisState genesisState = GenesisState.fromConfig(config, protocolSchedule);
final Blockchain blockchain = createInMemoryBlockchain(genesisState.getBlock());

@ -31,6 +31,7 @@ import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpec;
import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction;
import tech.pegasys.pantheon.ethereum.util.RawBlockIterator;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import java.io.IOException;
import java.net.URL;
@ -92,7 +93,8 @@ public class BlockchainSetupUtil<C> {
}
public static BlockchainSetupUtil<Void> forTesting() {
final ProtocolSchedule<Void> protocolSchedule = MainnetProtocolSchedule.create();
final ProtocolSchedule<Void> protocolSchedule =
MainnetProtocolSchedule.create(new NoOpMetricsSystem());
final TemporaryFolder temp = new TemporaryFolder();
try {
temp.create();

@ -23,6 +23,7 @@ import tech.pegasys.pantheon.ethereum.p2p.wire.RawMessage;
import tech.pegasys.pantheon.ethereum.rlp.BytesValueRLPInput;
import tech.pegasys.pantheon.ethereum.rlp.RLP;
import tech.pegasys.pantheon.ethereum.rlp.RLPInput;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.io.IOException;
@ -65,7 +66,8 @@ public final class BlockBodiesMessageTest {
final Iterator<BlockBody> readBodies =
message
.bodies(
DevelopmentProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions()))
DevelopmentProtocolSchedule.create(
GenesisConfigFile.DEFAULT.getConfigOptions(), new NoOpMetricsSystem()))
.iterator();
for (int i = 0; i < 50; ++i) {
Assertions.assertThat(readBodies.next()).isEqualTo(bodies.get(i));

@ -21,6 +21,7 @@ import tech.pegasys.pantheon.ethereum.p2p.wire.RawMessage;
import tech.pegasys.pantheon.ethereum.rlp.BytesValueRLPInput;
import tech.pegasys.pantheon.ethereum.rlp.RLP;
import tech.pegasys.pantheon.ethereum.rlp.RLPInput;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.io.IOException;
@ -58,7 +59,8 @@ public final class BlockHeadersMessageTest {
final BlockHeadersMessage message = BlockHeadersMessage.readFrom(raw);
final Iterator<BlockHeader> readHeaders =
message.getHeaders(
DevelopmentProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions()));
DevelopmentProtocolSchedule.create(
GenesisConfigFile.DEFAULT.getConfigOptions(), new NoOpMetricsSystem()));
for (int i = 0; i < 50; ++i) {
Assertions.assertThat(readHeaders.next()).isEqualTo(headers.get(i));
}

@ -21,13 +21,15 @@ import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.p2p.wire.RawMessage;
import tech.pegasys.pantheon.ethereum.rlp.BytesValueRLPOutput;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import tech.pegasys.pantheon.util.uint.UInt256;
import org.junit.Test;
public class NewBlockMessageTest {
private static final ProtocolSchedule<Void> protocolSchedule = MainnetProtocolSchedule.create();
private static final ProtocolSchedule<Void> protocolSchedule =
MainnetProtocolSchedule.create(new NoOpMetricsSystem());
@Test
public void roundTripNewBlockMessage() {

@ -44,7 +44,8 @@ public class ChainHeadTrackerTest {
blockchain.getChainHead().getTotalDifficulty(),
0);
private final ProtocolSchedule<Void> protocolSchedule =
DevelopmentProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions());
DevelopmentProtocolSchedule.create(
GenesisConfigFile.DEFAULT.getConfigOptions(), new NoOpMetricsSystem());
private final TrailingPeerLimiter trailingPeerLimiter = mock(TrailingPeerLimiter.class);
private final ChainHeadTracker chainHeadTracker =
new ChainHeadTracker(

@ -53,7 +53,8 @@ import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class DetermineCommonAncestorTaskParameterizedTest {
private final ProtocolSchedule<Void> protocolSchedule = MainnetProtocolSchedule.create();
private final ProtocolSchedule<Void> protocolSchedule =
MainnetProtocolSchedule.create(new NoOpMetricsSystem());
private static final BlockDataGenerator blockDataGenerator = new BlockDataGenerator();
private final LabelledMetric<OperationTimer> ethTasksTimer =
NoOpMetricsSystem.NO_OP_LABELLED_TIMER;

@ -57,7 +57,8 @@ import org.junit.Test;
public class DetermineCommonAncestorTaskTest {
private final ProtocolSchedule<Void> protocolSchedule = MainnetProtocolSchedule.create();
private final ProtocolSchedule<Void> protocolSchedule =
MainnetProtocolSchedule.create(new NoOpMetricsSystem());
private final BlockDataGenerator blockDataGenerator = new BlockDataGenerator();
private final LabelledMetric<OperationTimer> ethTasksTimer =
NoOpMetricsSystem.NO_OP_LABELLED_TIMER;

@ -91,7 +91,8 @@ public class TestNode implements Closeable {
final GenesisConfigFile genesisConfigFile = GenesisConfigFile.development();
final ProtocolSchedule<Void> protocolSchedule =
DevelopmentProtocolSchedule.create(genesisConfigFile.getConfigOptions());
DevelopmentProtocolSchedule.create(
genesisConfigFile.getConfigOptions(), new NoOpMetricsSystem());
final GenesisState genesisState = GenesisState.fromConfig(genesisConfigFile, protocolSchedule);
final BlockHashFunction blockHashFunction =
ScheduleBasedBlockHashFunction.create(protocolSchedule);

@ -20,6 +20,7 @@ import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHashFunction;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.util.RawBlockIterator;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import java.net.URL;
import java.nio.file.Paths;
@ -40,7 +41,7 @@ public class BlockchainImporter {
public BlockchainImporter(final URL blocksUrl, final String genesisJson) throws Exception {
protocolSchedule =
MainnetProtocolSchedule.fromConfig(
GenesisConfigFile.fromConfig(genesisJson).getConfigOptions());
GenesisConfigFile.fromConfig(genesisJson).getConfigOptions(), new NoOpMetricsSystem());
blocks = new ArrayList<>();
try (final RawBlockIterator iterator =

@ -88,7 +88,7 @@ public class JsonRpcTestMethodsFactory {
peerDiscovery,
blockchainQueries,
synchronizer,
MainnetProtocolSchedule.create(),
MainnetProtocolSchedule.create(new NoOpMetricsSystem()),
filterManager,
transactionPool,
miningCoordinator,

@ -108,7 +108,7 @@ public abstract class AbstractEthJsonRpcHttpServiceTest {
@BeforeClass
public static void setupConstants() throws Exception {
PROTOCOL_SCHEDULE = MainnetProtocolSchedule.create();
PROTOCOL_SCHEDULE = MainnetProtocolSchedule.create(new NoOpMetricsSystem());
final URL blocksUrl =
EthJsonRpcHttpBySpecTest.class
@ -177,7 +177,7 @@ public abstract class AbstractEthJsonRpcHttpServiceTest {
peerDiscoveryMock,
blockchainQueries,
synchronizerMock,
MainnetProtocolSchedule.create(),
MainnetProtocolSchedule.create(new NoOpMetricsSystem()),
filterManager,
transactionPoolMock,
miningCoordinatorMock,

@ -88,7 +88,8 @@ public class JsonRpcHttpServiceHostWhitelistTest {
blockchainQueries,
synchronizer,
MainnetProtocolSchedule.fromConfig(
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID)),
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID),
new NoOpMetricsSystem()),
mock(FilterManager.class),
mock(TransactionPool.class),
mock(EthHashMiningCoordinator.class),

@ -170,7 +170,7 @@ public class JsonRpcHttpServiceRpcApisTest {
mock(P2PNetwork.class),
blockchainQueries,
mock(Synchronizer.class),
MainnetProtocolSchedule.create(),
MainnetProtocolSchedule.create(new NoOpMetricsSystem()),
mock(FilterManager.class),
mock(TransactionPool.class),
mock(EthHashMiningCoordinator.class),

@ -117,7 +117,8 @@ public class JsonRpcHttpServiceTest {
blockchainQueries,
synchronizer,
MainnetProtocolSchedule.fromConfig(
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID)),
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID),
new NoOpMetricsSystem()),
mock(FilterManager.class),
mock(TransactionPool.class),
mock(EthHashMiningCoordinator.class),

@ -13,14 +13,15 @@
package tech.pegasys.pantheon.metrics;
public enum MetricCategory {
PEERS("peers"),
RPC("rpc"),
JVM("jvm", false),
PROCESS("process", false),
BLOCKCHAIN("blockchain"),
SYNCHRONIZER("synchronizer"),
EVM("evm"),
JVM("jvm", false),
NETWORK("network"),
ROCKSDB("rocksdb");
PEERS("peers"),
PROCESS("process", false),
ROCKSDB("rocksdb"),
RPC("rpc"),
SYNCHRONIZER("synchronizer");
private final String name;
private final boolean pantheonSpecific;

@ -49,6 +49,10 @@ public class PrometheusMetricsSystem implements MetricsSystem {
private static final String PANTHEON_PREFIX = "pantheon_";
private final Map<MetricCategory, Collection<Collector>> collectors = new ConcurrentHashMap<>();
private final CollectorRegistry registry = new CollectorRegistry(true);
private final Map<String, LabelledMetric<tech.pegasys.pantheon.metrics.Counter>>
labelledCounters = new ConcurrentHashMap<>();
private final Map<String, LabelledMetric<tech.pegasys.pantheon.metrics.OperationTimer>>
labelledTimers = new ConcurrentHashMap<>();
PrometheusMetricsSystem() {}
@ -73,12 +77,16 @@ public class PrometheusMetricsSystem implements MetricsSystem {
final String name,
final String help,
final String... labelNames) {
final Counter counter =
Counter.build(convertToPrometheusName(category, name), help)
.labelNames(labelNames)
.create();
addCollector(category, counter);
return new PrometheusCounter(counter);
return labelledCounters.computeIfAbsent(
name,
key -> {
final Counter counter =
Counter.build(convertToPrometheusName(category, name), help)
.labelNames(labelNames)
.create();
addCollector(category, counter);
return new PrometheusCounter(counter);
});
}
@Override
@ -87,18 +95,22 @@ public class PrometheusMetricsSystem implements MetricsSystem {
final String name,
final String help,
final String... labelNames) {
final Summary summary =
Summary.build(convertToPrometheusName(category, name), help)
.quantile(0.2, 0.02)
.quantile(0.5, 0.05)
.quantile(0.8, 0.02)
.quantile(0.95, 0.005)
.quantile(0.99, 0.001)
.quantile(1.0, 0)
.labelNames(labelNames)
.create();
addCollector(category, summary);
return new PrometheusTimer(summary);
return labelledTimers.computeIfAbsent(
name,
key -> {
final Summary summary =
Summary.build(convertToPrometheusName(category, name), help)
.quantile(0.2, 0.02)
.quantile(0.5, 0.05)
.quantile(0.8, 0.02)
.quantile(0.95, 0.005)
.quantile(0.99, 0.001)
.quantile(1.0, 0)
.labelNames(labelNames)
.create();
addCollector(category, summary);
return new PrometheusTimer(summary);
});
}
@Override

@ -94,7 +94,7 @@ public class PantheonControllerBuilder {
return MainnetPantheonController.init(
storageProvider,
genesisConfig,
DevelopmentProtocolSchedule.create(genesisConfig.getConfigOptions()),
DevelopmentProtocolSchedule.create(genesisConfig.getConfigOptions(), metricsSystem),
synchronizerConfiguration,
miningParameters,
nodeKeys,

@ -118,7 +118,7 @@ public class CliquePantheonController implements PantheonController<CliqueContex
final EpochManager epochManger = new EpochManager(blocksPerEpoch);
final ProtocolSchedule<CliqueContext> protocolSchedule =
CliqueProtocolSchedule.create(genesisConfig.getConfigOptions(), nodeKeys);
CliqueProtocolSchedule.create(genesisConfig.getConfigOptions(), nodeKeys, metricsSystem);
final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule);
final BlockchainStorage blockchainStorage =
storageProvider.createBlockchainStorage(protocolSchedule);

@ -109,7 +109,7 @@ public class IbftLegacyPantheonController implements PantheonController<IbftCont
final KeyPair nodeKeys,
final MetricsSystem metricsSystem) {
final ProtocolSchedule<IbftContext> protocolSchedule =
IbftProtocolSchedule.create(genesisConfig.getConfigOptions());
IbftProtocolSchedule.create(genesisConfig.getConfigOptions(), metricsSystem);
final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule);
final BlockchainStorage blockchainStorage =
storageProvider.createBlockchainStorage(protocolSchedule);

@ -133,7 +133,7 @@ public class IbftPantheonController implements PantheonController<IbftContext> {
final KeyPair nodeKeys,
final MetricsSystem metricsSystem) {
final ProtocolSchedule<IbftContext> protocolSchedule =
IbftProtocolSchedule.create(genesisConfig.getConfigOptions());
IbftProtocolSchedule.create(genesisConfig.getConfigOptions(), metricsSystem);
final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule);
final BlockchainStorage blockchainStorage =
storageProvider.createBlockchainStorage(protocolSchedule);

@ -55,7 +55,7 @@ public interface PantheonController<C> extends Closeable {
return MainnetPantheonController.init(
storageProvider,
genesisConfigFile,
MainnetProtocolSchedule.fromConfig(configOptions),
MainnetProtocolSchedule.fromConfig(configOptions, metricsSystem),
syncConfig,
miningParameters,
nodeKeys,

@ -103,7 +103,7 @@ public final class RunnerTest {
MainnetPantheonController.init(
createKeyValueStorageProvider(dbAhead),
GenesisConfigFile.mainnet(),
MainnetProtocolSchedule.create(),
MainnetProtocolSchedule.create(new NoOpMetricsSystem()),
fastSyncConfig,
new MiningParametersTestBuilder().enabled(false).build(),
aheadDbNodeKeys,
@ -116,7 +116,7 @@ public final class RunnerTest {
MainnetPantheonController.init(
createKeyValueStorageProvider(dbAhead),
GenesisConfigFile.mainnet(),
MainnetProtocolSchedule.create(),
MainnetProtocolSchedule.create(new NoOpMetricsSystem()),
fastSyncConfig,
new MiningParametersTestBuilder().enabled(false).build(),
aheadDbNodeKeys,
@ -159,7 +159,7 @@ public final class RunnerTest {
MainnetPantheonController.init(
new InMemoryStorageProvider(),
GenesisConfigFile.mainnet(),
MainnetProtocolSchedule.create(),
MainnetProtocolSchedule.create(new NoOpMetricsSystem()),
fastSyncConfig,
new MiningParametersTestBuilder().enabled(false).build(),
KeyPair.generate(),

Loading…
Cancel
Save