Skip to content

Commit

Permalink
Retesteth compatibility (#845)
Browse files Browse the repository at this point in the history
* When in retesteth return the coinbase in the eth_getBlockByHash, as
required by the retesteth tool.
* use genesis extraData when mining
* storage keys should be 0x00 instead of 0x when zero.

Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
  • Loading branch information
shemnon authored May 6, 2020
1 parent d096d9a commit b738ca6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@ public class EthGetBlockByHash implements JsonRpcMethod {

private final BlockResultFactory blockResult;
private final Supplier<BlockchainQueries> blockchain;
private final boolean includeCoinbase;

public EthGetBlockByHash(
final BlockchainQueries blockchain, final BlockResultFactory blockResult) {
this(Suppliers.ofInstance(blockchain), blockResult);
this(Suppliers.ofInstance(blockchain), blockResult, false);
}

public EthGetBlockByHash(
final Supplier<BlockchainQueries> blockchain, final BlockResultFactory blockResult) {
final Supplier<BlockchainQueries> blockchain,
final BlockResultFactory blockResult,
final boolean includeCoinbase) {
this.blockchain = blockchain;
this.blockResult = blockResult;
this.includeCoinbase = includeCoinbase;
}

@Override
Expand All @@ -65,7 +69,11 @@ private BlockResult blockResult(final JsonRpcRequestContext request) {
}

private BlockResult transactionComplete(final Hash hash) {
return blockchain.get().blockByHash(hash).map(blockResult::transactionComplete).orElse(null);
return blockchain
.get()
.blockByHash(hash)
.map(tx -> blockResult.transactionComplete(tx, includeCoinbase))
.orElse(null);
}

private BlockResult transactionHash(final Hash hash) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ public static class StorageEntry {
public StorageEntry(final AccountStorageEntry entry, final boolean shortValues) {
if (shortValues) {
this.value = entry.getValue().toShortHexString();
this.key = entry.getKey().map(UInt256::toShortHexString).orElse(null);
this.key =
entry
.getKey()
.map(UInt256::toShortHexString)
.map(s -> "0x".equals(s) ? "0x00" : s)
.orElse(null);
} else {
this.value = entry.getValue().toHexString();
this.key = entry.getKey().map(UInt256::toHexString).orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tuweni.bytes.Bytes;

public class RetestethContext {

Expand All @@ -72,6 +73,7 @@ public class RetestethContext {

private final ReentrantLock contextLock = new ReentrantLock();
private Address coinbase;
private Bytes extraData;
private MutableBlockchain blockchain;
private ProtocolContext<Void> protocolContext;
private BlockchainQueries blockchainQueries;
Expand Down Expand Up @@ -128,6 +130,7 @@ private boolean buildContext(

final GenesisState genesisState = GenesisState.fromJson(genesisConfigString, protocolSchedule);
coinbase = genesisState.getBlock().getHeader().getCoinbase();
extraData = genesisState.getBlock().getHeader().getExtraData();

final WorldStateArchive worldStateArchive =
new WorldStateArchive(
Expand Down Expand Up @@ -248,6 +251,10 @@ public Address getCoinbase() {
return coinbase;
}

public Bytes getExtraData() {
return extraData;
}

public MutableBlockchain getBlockchain() {
return blockchain;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public RetestethService(
new EthGetBlockByNumber(retestethContext::getBlockchainQueries, blockResult, true),
new DebugAccountRange(retestethContext::getBlockchainQueries),
new EthGetBalance(retestethContext::getBlockchainQueries),
new EthGetBlockByHash(retestethContext::getBlockchainQueries, blockResult),
new EthGetBlockByHash(retestethContext::getBlockchainQueries, blockResult, true),
new EthGetCode(retestethContext::getBlockchainQueries),
new EthGetTransactionCount(
retestethContext::getBlockchainQueries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.hyperledger.besu.ethereum.retesteth.RetestethContext;

import com.google.common.base.Functions;
import org.apache.tuweni.bytes.Bytes;

public class TestMineBlocks implements JsonRpcMethod {
private final RetestethContext context;
Expand Down Expand Up @@ -65,7 +64,7 @@ private boolean mineNewBlock() {
final EthHashBlockCreator blockCreator =
new EthHashBlockCreator(
context.getCoinbase(),
header -> Bytes.of(),
header -> context.getExtraData(),
context.getTransactionPool().getPendingTransactions(),
protocolContext,
protocolSchedule,
Expand Down

0 comments on commit b738ca6

Please sign in to comment.