diff --git a/consensus/clique/build.gradle b/consensus/clique/build.gradle index ed3a79de17..b08972ccbb 100644 --- a/consensus/clique/build.gradle +++ b/consensus/clique/build.gradle @@ -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' diff --git a/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolSchedule.java b/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolSchedule.java index acb4f440ad..b8497f6fdc 100644 --- a/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolSchedule.java +++ b/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolSchedule.java @@ -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 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 -> diff --git a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolScheduleTest.java b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolScheduleTest.java index fcec092441..2f555b2fdd 100644 --- a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolScheduleTest.java +++ b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/CliqueProtocolScheduleTest.java @@ -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 protocolSchedule = - CliqueProtocolSchedule.create(config, NODE_KEYS); + CliqueProtocolSchedule.create(config, NODE_KEYS, new NoOpMetricsSystem()); final ProtocolSpec homesteadSpec = protocolSchedule.getByBlockNumber(1); final ProtocolSpec tangerineWhistleSpec = protocolSchedule.getByBlockNumber(2); @@ -56,7 +57,8 @@ public class CliqueProtocolScheduleTest { @Test public void parametersAlignWithMainnetWithAdjustments() { final ProtocolSpec homestead = - CliqueProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions(), NODE_KEYS) + CliqueProtocolSchedule.create( + GenesisConfigFile.DEFAULT.getConfigOptions(), NODE_KEYS, new NoOpMetricsSystem()) .getByBlockNumber(0); assertThat(homestead.getName()).isEqualTo("Frontier"); diff --git a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java index d372c19cb8..545aafd202 100644 --- a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java +++ b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java @@ -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); diff --git a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueMinerExecutorTest.java b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueMinerExecutorTest.java index fd767332ec..6241b823a5 100644 --- a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueMinerExecutorTest.java +++ b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueMinerExecutorTest.java @@ -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), diff --git a/consensus/ibft/build.gradle b/consensus/ibft/build.gradle index 8852844017..2f6f02d7f0 100644 --- a/consensus/ibft/build.gradle +++ b/consensus/ibft/build.gradle @@ -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' diff --git a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextFactory.java b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextFactory.java index 179b585c35..ed96e87277 100644 --- a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextFactory.java +++ b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextFactory.java @@ -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 protocolSchedule = - IbftProtocolSchedule.create(genesisConfigOptions); + IbftProtocolSchedule.create(genesisConfigOptions, new NoOpMetricsSystem()); ///////////////////////////////////////////////////////////////////////////////////// // From here down is BASICALLY taken from IbftPantheonController diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftProtocolSchedule.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftProtocolSchedule.java index d914d214a8..1f741c7fe1 100644 --- a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftProtocolSchedule.java +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftProtocolSchedule.java @@ -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 create(final GenesisConfigOptions config) { + public static ProtocolSchedule 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)) diff --git a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/blockcreation/IbftBlockCreatorTest.java b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/blockcreation/IbftBlockCreatorTest.java index 71f45a372d..1d5ff6aa5b 100644 --- a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/blockcreation/IbftBlockCreatorTest.java +++ b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/blockcreation/IbftBlockCreatorTest.java @@ -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 protocolSchedule = IbftProtocolSchedule.create( GenesisConfigFile.fromConfig("{\"config\": {\"spuriousDragonBlock\":0}}") - .getConfigOptions()); + .getConfigOptions(), + new NoOpMetricsSystem()); final ProtocolContext protContext = new ProtocolContext<>( blockchain, diff --git a/consensus/ibftlegacy/build.gradle b/consensus/ibftlegacy/build.gradle index b3f572e6c6..e45c0bb85a 100644 --- a/consensus/ibftlegacy/build.gradle +++ b/consensus/ibftlegacy/build.gradle @@ -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' diff --git a/consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/IbftProtocolSchedule.java b/consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/IbftProtocolSchedule.java index 4c62feb0fc..dccd76b2eb 100644 --- a/consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/IbftProtocolSchedule.java +++ b/consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/IbftProtocolSchedule.java @@ -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 create(final GenesisConfigOptions config) { + public static ProtocolSchedule 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)) diff --git a/consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java b/consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java index b9553a696d..0a89b113b2 100644 --- a/consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java +++ b/consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java @@ -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 protocolSchedule = IbftProtocolSchedule.create( GenesisConfigFile.fromConfig("{\"config\": {\"spuriousDragonBlock\":0}}") - .getConfigOptions()); + .getConfigOptions(), + new NoOpMetricsSystem()); final ProtocolContext protContext = new ProtocolContext<>( blockchain, diff --git a/ethereum/blockcreation/build.gradle b/ethereum/blockcreation/build.gradle index 1e2a7e74f0..72a8e02797 100644 --- a/ethereum/blockcreation/build.gradle +++ b/ethereum/blockcreation/build.gradle @@ -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' diff --git a/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/BlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/BlockTransactionSelectorTest.java index 99d833852e..4bfd474865 100644 --- a/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/BlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/BlockTransactionSelectorTest.java @@ -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 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(); diff --git a/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/EthHashBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/EthHashBlockCreatorTest.java index 4ec2f5ea04..e75eac35f4 100644 --- a/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/EthHashBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/EthHashBlockCreatorTest.java @@ -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(); diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/development/DevelopmentProtocolSchedule.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/development/DevelopmentProtocolSchedule.java index dda7cf7d28..f9fb00faf1 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/development/DevelopmentProtocolSchedule.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/development/DevelopmentProtocolSchedule.java @@ -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 create(final GenesisConfigOptions config) { - return new ProtocolScheduleBuilder<>( + public static ProtocolSchedule create( + final GenesisConfigOptions config, final MetricsSystem metricsSystem) { + return new ProtocolScheduleFactory<>( + metricsSystem, config, NO_CHAIN_ID, builder -> builder.difficultyCalculator(DevelopmentDifficultyCalculators.DEVELOPER)) diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetEvmRegistries.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetEvmRegistries.java index 3ce5242a25..b04ab77b16 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetEvmRegistries.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetEvmRegistries.java @@ -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 factories, final GasCalculator gasCalculator) { + final List 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 buildFrontierFactories() { diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolSchedule.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolSchedule.java index b2a5739dbf..a497575a44 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolSchedule.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolSchedule.java @@ -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 create() { - return fromConfig(GenesisConfigFile.mainnet().getConfigOptions()); + public static ProtocolSchedule 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 fromConfig(final GenesisConfigOptions config) { - return new ProtocolScheduleBuilder<>(config, DEFAULT_CHAIN_ID, Function.identity()) + public static ProtocolSchedule fromConfig( + final GenesisConfigOptions config, final MetricsSystem metricsSystem) { + return new ProtocolScheduleFactory<>( + metricsSystem, config, DEFAULT_CHAIN_ID, Function.identity()) .createProtocolSchedule(); } } diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/ProtocolScheduleBuilder.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/ProtocolScheduleFactory.java similarity index 88% rename from ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/ProtocolScheduleBuilder.java rename to ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/ProtocolScheduleFactory.java index 33d5f6e9b5..ec3dccf568 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/ProtocolScheduleBuilder.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/ProtocolScheduleFactory.java @@ -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 { +public class ProtocolScheduleFactory { + private final MetricsSystem metricsSystem; private final GenesisConfigOptions config; private final Function, ProtocolSpecBuilder> protocolSpecAdapter; private final int defaultChainId; - public ProtocolScheduleBuilder( + public ProtocolScheduleFactory( + final MetricsSystem metricsSystem, final GenesisConfigOptions config, final int defaultChainId, final Function, ProtocolSpecBuilder> protocolSpecAdapter) { + this.metricsSystem = metricsSystem; this.config = config; this.protocolSpecAdapter = protocolSpecAdapter; this.defaultChainId = defaultChainId; @@ -91,6 +95,10 @@ public class ProtocolScheduleBuilder { blockNumber.ifPresent( number -> protocolSchedule.putMilestone( - number, protocolSpecAdapter.apply(definition).build(protocolSchedule))); + number, + protocolSpecAdapter + .apply(definition) + .metricsSystem(metricsSystem) + .build(protocolSchedule))); } } diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/ProtocolSpecBuilder.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/ProtocolSpecBuilder.java index 33616b56aa..a95cd0ad4e 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/ProtocolSpecBuilder.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/ProtocolSpecBuilder.java @@ -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 { private BlockHashFunction blockHashFunction; private TransactionReceiptFactory transactionReceiptFactory; private DifficultyCalculator difficultyCalculator; - private Function evmBuilder; + private BiFunction evmBuilder; private Function transactionValidatorBuilder; private Function, BlockHeaderValidator> blockHeaderValidatorBuilder; private Function, BlockHeaderValidator> ommerHeaderValidatorBuilder; @@ -46,6 +47,7 @@ public class ProtocolSpecBuilder { private TransactionReceiptType transactionReceiptType; private String name; private MiningBeneficiaryCalculator miningBeneficiaryCalculator; + private MetricsSystem metricsSystem; public ProtocolSpecBuilder gasCalculator(final Supplier gasCalculatorBuilder) { this.gasCalculatorBuilder = gasCalculatorBuilder; @@ -74,7 +76,8 @@ public class ProtocolSpecBuilder { return this; } - public ProtocolSpecBuilder evmBuilder(final Function evmBuilder) { + public ProtocolSpecBuilder evmBuilder( + final BiFunction evmBuilder) { this.evmBuilder = evmBuilder; return this; } @@ -160,6 +163,11 @@ public class ProtocolSpecBuilder { return this; } + public ProtocolSpecBuilder metricsSystem(final MetricsSystem metricsSystem) { + this.metricsSystem = metricsSystem; + return this; + } + public ProtocolSpecBuilder changeConsensusContextType( final Function, BlockHeaderValidator> blockHeaderValidatorBuilder, final Function, BlockHeaderValidator> ommerHeaderValidatorBuilder, @@ -208,9 +216,10 @@ public class ProtocolSpecBuilder { 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 = diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/vm/EVM.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/vm/EVM.java index 47eba180b1..731c249057 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/vm/EVM.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/vm/EVM.java @@ -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 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); }); } diff --git a/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java b/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java index 3d9bfa96df..d148bf9818 100644 --- a/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java +++ b/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java @@ -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) { diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/GenesisStateTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/GenesisStateTest.java index 03c08aa657..6c7e772ce2 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/GenesisStateTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/GenesisStateTest.java @@ -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())) diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/development/DevelopmentProtocolScheduleTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/development/DevelopmentProtocolScheduleTest.java index 6fcc902ca8..62538321b4 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/development/DevelopmentProtocolScheduleTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/development/DevelopmentProtocolScheduleTest.java @@ -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 schedule = - DevelopmentProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions()); + DevelopmentProtocolSchedule.create( + GenesisConfigFile.DEFAULT.getConfigOptions(), new NoOpMetricsSystem()); final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolScheduleTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolScheduleTest.java index 95355ef0df..9e55472cc3 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolScheduleTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/MainnetProtocolScheduleTest.java @@ -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 sched = MainnetProtocolSchedule.create(); + final ProtocolSchedule 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 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 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"); diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java index 768281caa1..2e7e5853c2 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java @@ -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 protocolSchedule = MainnetProtocolSchedule.create(); + final ProtocolSchedule protocolSchedule = + MainnetProtocolSchedule.create(new NoOpMetricsSystem()); return ScheduleBasedBlockHashFunction.create(protocolSchedule); } } diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/ReferenceTestProtocolSchedules.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/ReferenceTestProtocolSchedules.java index afd1f769c8..ed7dff3d47 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/ReferenceTestProtocolSchedules.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/ReferenceTestProtocolSchedules.java @@ -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 createSchedule(final GenesisConfigOptions options) { - return new ProtocolScheduleBuilder<>(options, CHAIN_ID, Function.identity()) + return new ProtocolScheduleFactory<>( + new NoOpMetricsSystem(), options, CHAIN_ID, Function.identity()) .createProtocolSchedule(); } } diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/VMReferenceTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/VMReferenceTest.java index f5c878e336..06fceee151 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/VMReferenceTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/VMReferenceTest.java @@ -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 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 = diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/operations/ConstantinopleSStoreOperationGasCostTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/operations/ConstantinopleSStoreOperationGasCostTest.java index 239ec05260..191ba1d753 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/operations/ConstantinopleSStoreOperationGasCostTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/vm/operations/ConstantinopleSStoreOperationGasCostTest.java @@ -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 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() { diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java index 815d581224..c99019e251 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java @@ -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 protocolSchdeule = MainnetProtocolSchedule.create(); + final ProtocolSchedule protocolSchdeule = + MainnetProtocolSchedule.create(new NoOpMetricsSystem()); for (final NewBlockMessage msg : messageSentCaptor.getAllValues()) { assertThat(msg.block(protocolSchdeule)).isEqualTo(minedBlock); assertThat(msg.totalDifficulty(protocolSchdeule)).isEqualTo(expectedTotalDifficulty); diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTestUtil.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTestUtil.java index eb0b8055c0..effb5cea2b 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTestUtil.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTestUtil.java @@ -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 protocolSchedule = MainnetProtocolSchedule.create(); + final ProtocolSchedule protocolSchedule = + MainnetProtocolSchedule.create(new NoOpMetricsSystem()); final GenesisConfigFile config = GenesisConfigFile.mainnet(); final GenesisState genesisState = GenesisState.fromConfig(config, protocolSchedule); final Blockchain blockchain = createInMemoryBlockchain(genesisState.getBlock()); diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/ethtaskutils/BlockchainSetupUtil.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/ethtaskutils/BlockchainSetupUtil.java index 98f8561548..d9e057d1ff 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/ethtaskutils/BlockchainSetupUtil.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/ethtaskutils/BlockchainSetupUtil.java @@ -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 { } public static BlockchainSetupUtil forTesting() { - final ProtocolSchedule protocolSchedule = MainnetProtocolSchedule.create(); + final ProtocolSchedule protocolSchedule = + MainnetProtocolSchedule.create(new NoOpMetricsSystem()); final TemporaryFolder temp = new TemporaryFolder(); try { temp.create(); diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockBodiesMessageTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockBodiesMessageTest.java index f66b0abfc4..068a882c80 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockBodiesMessageTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockBodiesMessageTest.java @@ -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 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)); diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockHeadersMessageTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockHeadersMessageTest.java index 66da8d3c61..cee7c74dfe 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockHeadersMessageTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/BlockHeadersMessageTest.java @@ -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 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)); } diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/NewBlockMessageTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/NewBlockMessageTest.java index dae24dde2c..1382b85435 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/NewBlockMessageTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/NewBlockMessageTest.java @@ -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 protocolSchedule = MainnetProtocolSchedule.create(); + private static final ProtocolSchedule protocolSchedule = + MainnetProtocolSchedule.create(new NoOpMetricsSystem()); @Test public void roundTripNewBlockMessage() { diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/ChainHeadTrackerTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/ChainHeadTrackerTest.java index 9013a8bdbf..d310658fe6 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/ChainHeadTrackerTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/ChainHeadTrackerTest.java @@ -44,7 +44,8 @@ public class ChainHeadTrackerTest { blockchain.getChainHead().getTotalDifficulty(), 0); private final ProtocolSchedule 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( diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java index b9c72639f2..f37cd624cf 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java @@ -53,7 +53,8 @@ import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class DetermineCommonAncestorTaskParameterizedTest { - private final ProtocolSchedule protocolSchedule = MainnetProtocolSchedule.create(); + private final ProtocolSchedule protocolSchedule = + MainnetProtocolSchedule.create(new NoOpMetricsSystem()); private static final BlockDataGenerator blockDataGenerator = new BlockDataGenerator(); private final LabelledMetric ethTasksTimer = NoOpMetricsSystem.NO_OP_LABELLED_TIMER; diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java index 4304092cdb..e5f25e7ef7 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java @@ -57,7 +57,8 @@ import org.junit.Test; public class DetermineCommonAncestorTaskTest { - private final ProtocolSchedule protocolSchedule = MainnetProtocolSchedule.create(); + private final ProtocolSchedule protocolSchedule = + MainnetProtocolSchedule.create(new NoOpMetricsSystem()); private final BlockDataGenerator blockDataGenerator = new BlockDataGenerator(); private final LabelledMetric ethTasksTimer = NoOpMetricsSystem.NO_OP_LABELLED_TIMER; diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java index d6efb6d837..6ddcaacee3 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java @@ -91,7 +91,8 @@ public class TestNode implements Closeable { final GenesisConfigFile genesisConfigFile = GenesisConfigFile.development(); final ProtocolSchedule protocolSchedule = - DevelopmentProtocolSchedule.create(genesisConfigFile.getConfigOptions()); + DevelopmentProtocolSchedule.create( + genesisConfigFile.getConfigOptions(), new NoOpMetricsSystem()); final GenesisState genesisState = GenesisState.fromConfig(genesisConfigFile, protocolSchedule); final BlockHashFunction blockHashFunction = ScheduleBasedBlockHashFunction.create(protocolSchedule); diff --git a/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/BlockchainImporter.java b/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/BlockchainImporter.java index 6e316a62cb..064a88203f 100644 --- a/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/BlockchainImporter.java +++ b/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/BlockchainImporter.java @@ -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 = diff --git a/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java b/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java index 1eb70a986a..770ceb1aee 100644 --- a/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java +++ b/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java @@ -88,7 +88,7 @@ public class JsonRpcTestMethodsFactory { peerDiscovery, blockchainQueries, synchronizer, - MainnetProtocolSchedule.create(), + MainnetProtocolSchedule.create(new NoOpMetricsSystem()), filterManager, transactionPool, miningCoordinator, diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java index b70106376b..bc0f7add42 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java @@ -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, diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java index 53ad439036..d54085c091 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceHostWhitelistTest.java @@ -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), diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceRpcApisTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceRpcApisTest.java index 0a6aa1a6b7..b84aa3bfd6 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceRpcApisTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceRpcApisTest.java @@ -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), diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java index 1dda1cf15e..374499fa11 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java @@ -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), diff --git a/metrics/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java b/metrics/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java index b7e0db0eb8..03adf9a595 100644 --- a/metrics/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java +++ b/metrics/src/main/java/tech/pegasys/pantheon/metrics/MetricCategory.java @@ -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; diff --git a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java index fef0ee052c..5a33f8a632 100644 --- a/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java +++ b/metrics/src/main/java/tech/pegasys/pantheon/metrics/prometheus/PrometheusMetricsSystem.java @@ -49,6 +49,10 @@ public class PrometheusMetricsSystem implements MetricsSystem { private static final String PANTHEON_PREFIX = "pantheon_"; private final Map> collectors = new ConcurrentHashMap<>(); private final CollectorRegistry registry = new CollectorRegistry(true); + private final Map> + labelledCounters = new ConcurrentHashMap<>(); + private final Map> + 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 diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonControllerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonControllerBuilder.java index 2aa74284cb..e71a17cb7d 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonControllerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonControllerBuilder.java @@ -94,7 +94,7 @@ public class PantheonControllerBuilder { return MainnetPantheonController.init( storageProvider, genesisConfig, - DevelopmentProtocolSchedule.create(genesisConfig.getConfigOptions()), + DevelopmentProtocolSchedule.create(genesisConfig.getConfigOptions(), metricsSystem), synchronizerConfiguration, miningParameters, nodeKeys, diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java index da26e1a92b..bc54a4079c 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java @@ -118,7 +118,7 @@ public class CliquePantheonController implements PantheonController 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); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftLegacyPantheonController.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftLegacyPantheonController.java index 2eab1f6b60..c6b371cc79 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftLegacyPantheonController.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftLegacyPantheonController.java @@ -109,7 +109,7 @@ public class IbftLegacyPantheonController implements PantheonController protocolSchedule = - IbftProtocolSchedule.create(genesisConfig.getConfigOptions()); + IbftProtocolSchedule.create(genesisConfig.getConfigOptions(), metricsSystem); final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule); final BlockchainStorage blockchainStorage = storageProvider.createBlockchainStorage(protocolSchedule); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java index be9178866f..6d35beb467 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java @@ -133,7 +133,7 @@ public class IbftPantheonController implements PantheonController { final KeyPair nodeKeys, final MetricsSystem metricsSystem) { final ProtocolSchedule protocolSchedule = - IbftProtocolSchedule.create(genesisConfig.getConfigOptions()); + IbftProtocolSchedule.create(genesisConfig.getConfigOptions(), metricsSystem); final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule); final BlockchainStorage blockchainStorage = storageProvider.createBlockchainStorage(protocolSchedule); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonController.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonController.java index c4d229e205..67fdd63ebc 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonController.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonController.java @@ -55,7 +55,7 @@ public interface PantheonController extends Closeable { return MainnetPantheonController.init( storageProvider, genesisConfigFile, - MainnetProtocolSchedule.fromConfig(configOptions), + MainnetProtocolSchedule.fromConfig(configOptions, metricsSystem), syncConfig, miningParameters, nodeKeys, diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java index e81c4b4637..51cbd605d3 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java @@ -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(),