This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PAN-2946] Retesteth support (#1818)
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
Showing
23 changed files
with
1,372 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
83 changes: 83 additions & 0 deletions
83
...c/main/java/tech/pegasys/pantheon/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...reum/retesteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/RetestethClock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...esteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/RetestethConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.