Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
[PAN-2946] Retesteth support (#1818)
Browse files Browse the repository at this point in the history
Add support for retesteth, a JSON-RPC based reference testing API.
  • Loading branch information
Danno Ferrin authored Aug 7, 2019
1 parent b93f0fe commit 2d478de
Show file tree
Hide file tree
Showing 23 changed files with 1,372 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void stop() {
}
}

void awaitStop() throws InterruptedException {
public void awaitStop() throws InterruptedException {
shutdown.await();
serviceFutures.forEach(future -> future.cancel(true));
if (!syncWorkerExecutor.awaitTermination(30, TimeUnit.SECONDS)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public DebugAccountRange(
public String getName() {
// TODO(shemnon) 5229b899 is the last stable commit of retesteth, after this they rename the
// method to just "debug_accountRange". Once the tool is stable we will support the new name.
return "debug_accountRangeAt";
return "debug_accountRange";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"request": {
"id": 415,
"jsonrpc": "2.0",
"method": "debug_accountRangeAt",
"method": "debug_accountRange",
"params": [
"0xc8df1f061abb4d0c107b2b1a794ade8780b3120e681f723fe55a7be586d95ba6",
"0x1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"request": {
"id": 414,
"jsonrpc": "2.0",
"method": "debug_accountRangeAt",
"method": "debug_accountRange",
"params": [
"0x10",
"0x1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"request": {
"id": 415,
"jsonrpc": "2.0",
"method": "debug_accountRangeAt",
"method": "debug_accountRange",
"params": [
"0x10",
"0x1",
Expand Down
53 changes: 53 additions & 0 deletions ethereum/retesteth/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2019 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

apply plugin: 'java-library'

jar {
baseName 'pantheon-retesteth'
manifest {
attributes(
'Specification-Title': baseName,
'Specification-Version': project.version,
'Implementation-Title': baseName,
'Implementation-Version': calculateVersion()
)
}
}

dependencies {
implementation(project(':config'))
implementation(project(':ethereum:blockcreation'))
implementation(project(':ethereum:core'))
implementation(project(':ethereum:eth'))
implementation(project(':ethereum:graphql'))
implementation(project(':ethereum:jsonrpc'))
implementation(project(':ethereum:rlp'))
implementation(project(':ethereum:p2p'))
// implementation(project(':pantheon'))
implementation(project(':metrics:core'))
implementation(project(':nat'))
implementation(project(':services:kvstore'))
implementation(project(':util'))

implementation 'com.google.guava:guava'
implementation 'io.vertx:vertx-core'
implementation 'io.vertx:vertx-web'
implementation 'org.apache.logging.log4j:log4j-api'

testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.mockito:mockito-core'

runtime 'org.apache.logging.log4j:log4j-core'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright 2019 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.pantheon.ethereum.retesteth;

import tech.pegasys.pantheon.ethereum.BlockValidator;
import tech.pegasys.pantheon.ethereum.MainnetBlockValidator;
import tech.pegasys.pantheon.ethereum.core.BlockImporter;
import tech.pegasys.pantheon.ethereum.core.TransactionFilter;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.BlockProcessor;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockImporter;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockProcessor;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpec;

import java.math.BigInteger;
import java.util.Optional;

public class NoRewardProtocolScheduleWrapper<C> implements ProtocolSchedule<C> {

private final ProtocolSchedule<C> delegate;

NoRewardProtocolScheduleWrapper(final ProtocolSchedule<C> delegate) {
this.delegate = delegate;
}

@Override
public ProtocolSpec<C> getByBlockNumber(final long number) {
final ProtocolSpec<C> original = delegate.getByBlockNumber(number);
final BlockProcessor noRewardBlockProcessor =
new MainnetBlockProcessor(
original.getTransactionProcessor(),
original.getTransactionReceiptFactory(),
Wei.ZERO,
original.getMiningBeneficiaryCalculator(),
original.isSkipZeroBlockRewards());
final BlockValidator<C> noRewardBlockValidator =
new MainnetBlockValidator<>(
original.getBlockHeaderValidator(),
original.getBlockBodyValidator(),
noRewardBlockProcessor);
final BlockImporter<C> noRewardBlockImporter =
new MainnetBlockImporter<>(noRewardBlockValidator);
return new ProtocolSpec<>(
original.getName(),
original.getEvm(),
original.getTransactionValidator(),
original.getTransactionProcessor(),
original.getBlockHeaderValidator(),
original.getOmmerHeaderValidator(),
original.getBlockBodyValidator(),
noRewardBlockProcessor,
noRewardBlockImporter,
noRewardBlockValidator,
original.getBlockHeaderFunctions(),
original.getTransactionReceiptFactory(),
original.getDifficultyCalculator(),
Wei.ZERO, // block reward
original.getMiningBeneficiaryCalculator(),
original.getPrecompileContractRegistry(),
original.isSkipZeroBlockRewards());
}

@Override
public Optional<BigInteger> getChainId() {
return delegate.getChainId();
}

@Override
public void setTransactionFilter(final TransactionFilter transactionFilter) {
delegate.setTransactionFilter(transactionFilter);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2019 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.pantheon.ethereum.retesteth;

import java.time.Clock;
import java.time.Instant;
import java.time.ZoneId;
import java.util.Optional;

public class RetestethClock extends Clock {

private Optional<Instant> fixedInstant;
private final Clock delegateClock;

RetestethClock() {
this(Clock.systemUTC());
}

private RetestethClock(final Clock delegateClock) {
fixedInstant = Optional.empty();
this.delegateClock = delegateClock;
}

@Override
public ZoneId getZone() {
return delegateClock.getZone();
}

@Override
public Clock withZone(final ZoneId zone) {
final RetestethClock zonedClock = new RetestethClock(delegateClock.withZone(zone));
zonedClock.fixedInstant = fixedInstant;
return zonedClock;
}

@Override
public Instant instant() {
return fixedInstant.orElseGet(delegateClock::instant);
}

public void resetTime(final long time) {
fixedInstant = Optional.of(Instant.ofEpochSecond(time));
}

public void advanceSeconds(final long seconds) {
fixedInstant = Optional.of(Instant.ofEpochSecond(instant().getEpochSecond() + seconds));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2019 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.pantheon.ethereum.retesteth;

import java.nio.file.Path;

public class RetestethConfiguration {

private final Path dataPath;

public RetestethConfiguration(final Path dataPath) {
this.dataPath = dataPath;
}

Path getDataPath() {
return dataPath;
}
}
Loading

0 comments on commit 2d478de

Please sign in to comment.