Skip to content

Commit

Permalink
Updates for execution-spec-tests (hyperledger#5638)
Browse files Browse the repository at this point in the history
Updates needed to keep executing execution-spec-tests
* add withdrawals support
* add access lists to transactions
* accept t8n and b11r CLI args that are zero length or all whitespace
* Enumerate forks in t8n and b11r help
* remove JSON wrapping from t8n transaction RLP

Signed-off-by: Danno Ferrin <danno.ferrin@swirldslabs.com>
  • Loading branch information
shemnon authored and eum602 committed Nov 3, 2023
1 parent f7d1913 commit 0cee232
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

import com.fasterxml.jackson.core.JsonParser.Feature;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand All @@ -47,7 +50,12 @@
import org.slf4j.LoggerFactory;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.IParameterConsumer;
import picocli.CommandLine.Model.ArgSpec;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
import picocli.CommandLine.ParentCommand;

@Command(
name = COMMAND_NAME,
Expand Down Expand Up @@ -81,6 +89,12 @@ public class B11rSubCommand implements Runnable {
description = "The ommers for the block")
private final Path ommers = stdinPath;

@Option(
names = {"--input.withdrawals"},
paramLabel = "full path",
description = "The withdrawals for the block")
private final Path withdrawals = stdinPath;

@Option(
names = {"--seal.clique"},
paramLabel = "full path",
Expand Down Expand Up @@ -114,7 +128,25 @@ public class B11rSubCommand implements Runnable {

private static final ObjectMapper objectMapper = new ObjectMapper();

@CommandLine.ParentCommand private final EvmToolCommand parentCommand;
@ParentCommand private final EvmToolCommand parentCommand;

@Parameters(parameterConsumer = OnlyEmptyParams.class)
@SuppressWarnings("UnusedVariable")
private final List<String> parameters = new ArrayList<>();

static class OnlyEmptyParams implements IParameterConsumer {
@Override
public void consumeParameters(
final Stack<String> args, final ArgSpec argSpec, final CommandSpec commandSpec) {
while (!args.isEmpty()) {
if (!args.pop().isEmpty()) {
throw new CommandLine.ParameterException(
argSpec.command().commandLine(),
"The block-builder command does not accept any non-empty parameters");
}
}
}
}

@SuppressWarnings("unused")
public B11rSubCommand() {
Expand All @@ -136,40 +168,47 @@ public void run() {
.withSpacesInObjectEntries()
.withObjectIndenter(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE.withIndent(" "))
.withArrayIndenter(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE.withIndent(" ")));
final ObjectReader t8nReader = objectMapper.reader();
final ObjectReader b11rReader = objectMapper.reader();
objectMapper.disable(Feature.AUTO_CLOSE_SOURCE);

ObjectNode config;
try {
if (header.equals(stdinPath)
|| txs.equals(stdinPath)
|| ommers.equals(stdinPath)
|| sealClique.equals(stdinPath)) {
|| sealClique.equals(stdinPath)
|| withdrawals.equals(stdinPath)) {
config =
(ObjectNode)
t8nReader.readTree(new InputStreamReader(parentCommand.in, StandardCharsets.UTF_8));
b11rReader.readTree(
new InputStreamReader(parentCommand.in, StandardCharsets.UTF_8));
} else {
config = objectMapper.createObjectNode();
}

if (!header.equals(stdinPath)) {
try (FileReader reader = new FileReader(header.toFile(), StandardCharsets.UTF_8)) {
config.set("header", t8nReader.readTree(reader));
config.set("header", b11rReader.readTree(reader));
}
}
if (!txs.equals(stdinPath)) {
try (FileReader reader = new FileReader(txs.toFile(), StandardCharsets.UTF_8)) {
config.set("txs", t8nReader.readTree(reader));
config.set("txs", b11rReader.readTree(reader));
}
}
if (!withdrawals.equals(stdinPath)) {
try (FileReader reader = new FileReader(withdrawals.toFile(), StandardCharsets.UTF_8)) {
config.set("withdrawals", b11rReader.readTree(reader));
}
}
if (!ommers.equals(stdinPath)) {
try (FileReader reader = new FileReader(ommers.toFile(), StandardCharsets.UTF_8)) {
config.set("ommers", t8nReader.readTree(reader));
config.set("ommers", b11rReader.readTree(reader));
}
}
if (!sealClique.equals(stdinPath)) {
try (FileReader reader = new FileReader(sealClique.toFile(), StandardCharsets.UTF_8)) {
config.set("clique", t8nReader.readTree(reader));
config.set("clique", b11rReader.readTree(reader));
}
}
} catch (final JsonProcessingException jpe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.hyperledger.besu.ethereum.vm.CachingBlockHashLookup;
import org.hyperledger.besu.evm.Code;
import org.hyperledger.besu.evm.EVM;
import org.hyperledger.besu.evm.EvmSpecVersion;
import org.hyperledger.besu.evm.account.AccountStorageEntry;
import org.hyperledger.besu.evm.code.CodeInvalid;
import org.hyperledger.besu.evm.frame.MessageFrame;
Expand All @@ -53,10 +54,15 @@
import java.io.PrintWriter;
import java.time.Instant;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.NavigableMap;
import java.util.Optional;
import java.util.stream.Collectors;

import com.google.common.base.Joiner;
import com.google.common.base.Stopwatch;
Expand Down Expand Up @@ -246,10 +252,40 @@ void execute(final InputStream input, final PrintWriter output, final String[] a
.addPattern("^--trace.(\\w(-|\\w)*)$", "--trace.no$1", "--trace.[no]$1")
.build());

// Enumerate forks to support execution-spec-tests
addForkHelp(commandLine.getSubcommands().get("t8n"));
addForkHelp(commandLine.getSubcommands().get("t8n-server"));

commandLine.setExecutionStrategy(new CommandLine.RunLast());
commandLine.execute(args);
}

private static void addForkHelp(final CommandLine subCommandLine) {
subCommandLine
.getHelpSectionMap()
.put("forks_header", help -> help.createHeading("%nKnown Forks:%n"));
subCommandLine
.getHelpSectionMap()
.put(
"forks",
help ->
help.createTextTable(
Arrays.stream(EvmSpecVersion.values())
.collect(
Collectors.toMap(
EvmSpecVersion::getName,
EvmSpecVersion::getDescription,
(a, b) -> b,
LinkedHashMap::new)))
.toString());
List<String> keys = new ArrayList<>(subCommandLine.getHelpSectionKeys());
int index = keys.indexOf(CommandLine.Model.UsageMessageSpec.SECTION_KEY_FOOTER_HEADING);
keys.add(index, "forks_header");
keys.add(index + 1, "forks");

subCommandLine.setHelpSectionKeys(keys);
}

@Override
public void run() {
LogConfigurator.setLevel("", "OFF");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.hyperledger.besu.ethereum.referencetests.ReferenceTestEnv;
import org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState;
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput;
import org.hyperledger.besu.evm.AccessListEntry;
import org.hyperledger.besu.evm.tracing.OperationTracer;
import org.hyperledger.besu.evm.tracing.StandardJsonTracer;
import org.hyperledger.besu.plugin.data.TransactionType;
Expand All @@ -49,6 +50,10 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.Stack;
import java.util.stream.StreamSupport;

import com.fasterxml.jackson.core.JsonParser.Feature;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand All @@ -64,7 +69,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Command;
import picocli.CommandLine.IParameterConsumer;
import picocli.CommandLine.Model.ArgSpec;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Option;
import picocli.CommandLine.ParameterException;
import picocli.CommandLine.Parameters;
import picocli.CommandLine.ParentCommand;

@Command(
Expand Down Expand Up @@ -147,6 +157,24 @@ record RejectedTransaction(int index, String error) {}

@ParentCommand private final EvmToolCommand parentCommand;

@Parameters(parameterConsumer = OnlyEmptyParams.class)
@SuppressWarnings("UnusedVariable")
private final List<String> parameters = new ArrayList<>();

static class OnlyEmptyParams implements IParameterConsumer {
@Override
public void consumeParameters(
final Stack<String> args, final ArgSpec argSpec, final CommandSpec commandSpec) {
while (!args.isEmpty()) {
if (!args.pop().isEmpty()) {
throw new ParameterException(
argSpec.command().commandLine(),
"The transition command does not accept any non-empty parameters");
}
}
}
}

@SuppressWarnings("unused")
public T8nSubCommand() {
// PicoCLI requires this
Expand Down Expand Up @@ -270,7 +298,9 @@ public OperationTracer getManagedTracer(final int txIndex, final Hash txHash) {
}

@Override
public void disposeTracer(final OperationTracer tracer) {}
public void disposeTracer(final OperationTracer tracer) {
// single-test mode doesn't need to track tracers
}
};
}
final T8nExecutor.T8nResult result =
Expand Down Expand Up @@ -302,7 +332,7 @@ public void disposeTracer(final OperationTracer tracer) {}
} else {
try (PrintStream fileOut =
new PrintStream(new FileOutputStream(outDir.resolve(outBody).toFile()))) {
fileOut.println(result.bodyBytes());
fileOut.print(result.bodyBytes().textValue());
}
}

Expand Down Expand Up @@ -364,6 +394,29 @@ private List<Transaction> extractTransactions(final Iterator<JsonNode> it) {
Bytes.fromHexStringLenient(txNode.get("chainId").textValue()).toArrayUnsafe()));
}

if (txNode.has("accessList")) {
JsonNode accessList = txNode.get("accessList");
if (!accessList.isArray()) {
parentCommand.out.printf(
"TX json node unparseable: expected accessList to be an array - %s%n", txNode);
continue;
}
List<AccessListEntry> entries = new ArrayList<>(accessList.size());
for (JsonNode entryAsJson : accessList) {
Address address = Address.fromHexString(entryAsJson.get("address").textValue());
List<String> storageKeys =
StreamSupport.stream(
Spliterators.spliteratorUnknownSize(
entryAsJson.get("storageKeys").elements(), Spliterator.ORDERED),
false)
.map(JsonNode::textValue)
.toList();
var accessListEntry = AccessListEntry.createAccessListEntry(address, storageKeys);
entries.add(accessListEntry);
}
builder.accessList(entries);
}

if (txNode.has("secretKey")) {
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithmFactory.getInstance();
KeyPair keys =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public static ReferenceTestProtocolSchedules create(final StubGenesisConfigOptio
builder.put("Merge", createSchedule(genesisStub.clone().mergeNetSplitBlock(0)));
builder.put("Shanghai", createSchedule(genesisStub.clone().shanghaiTime(0)));
builder.put("Cancun", createSchedule(genesisStub.clone().cancunTime(0)));
builder.put("Future_EIPs", createSchedule(genesisStub.clone().futureEipsTime(0)));
builder.put("Experimental_EIPs", createSchedule(genesisStub.clone().experimentalEipsTime(0)));
return new ReferenceTestProtocolSchedules(builder.build());
}

Expand Down
Loading

0 comments on commit 0cee232

Please sign in to comment.