Skip to content
/ besu Public
forked from hyperledger/besu

Commit

Permalink
Merge branch 'main' into hyperledger#3810-qbft-no-empty-block
Browse files Browse the repository at this point in the history
Signed-off-by: amsmota <[email protected]>
  • Loading branch information
amsmota authored Apr 16, 2024
2 parents aa7e38f + 9601456 commit 46d5859
Show file tree
Hide file tree
Showing 17 changed files with 266 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2154,7 +2154,6 @@ private void initMiningParametersMetrics(final MiningParameters miningParameters
new MiningParametersMetrics(getMetricsSystem(), miningParameters);
}


private OptionalInt getGenesisBlockPeriodSeconds(
final GenesisConfigOptions genesisConfigOptions) {
if (genesisConfigOptions.isClique()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ public void throwsErrorIfHasForksWithDuplicateBlock() {

@SuppressWarnings("unchecked")
@Test
public void createsSchegit statusduleUsingSpecCreator() {
public void createsScheduleUsingSpecCreator() {
final BftConfigOptions genesisConfigOptions = JsonBftConfigOptions.DEFAULT;
final ForkSpec<BftConfigOptions> genesisForkSpec = new ForkSpec<>(0, genesisConfigOptions);
final BftFork fork1 = createFork(1, 10, 30);
final BftFork fork2 = createFork(2, 20, 60);
final BftFork fork1 = createFork(1, 10);
final BftFork fork2 = createFork(2, 20);
final SpecCreator<BftConfigOptions, BftFork> specCreator = Mockito.mock(SpecCreator.class);

final BftConfigOptions configOptions1 = createBftConfigOptions(10, 30);
final BftConfigOptions configOptions2 = createBftConfigOptions(20, 60);
final BftConfigOptions configOptions1 = createBftConfigOptions(10);
final BftConfigOptions configOptions2 = createBftConfigOptions(20);
when(specCreator.create(genesisForkSpec, fork1)).thenReturn(configOptions1);
when(specCreator.create(new ForkSpec<>(1, configOptions1), fork2)).thenReturn(configOptions2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ public void registerPluginTransactionSelectorFactory(
};
}

@Value.Derived
public long getBlockTxsSelectionMaxTime() {
final var maybeBlockPeriodSeconds = getMutableRuntimeValues().blockPeriodSeconds;
if (maybeBlockPeriodSeconds.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
@Command(
name = COMMAND_NAME,
aliases = {COMMAND_ALIAS},
description = "Execute an Ethereum State Test.",
description = "Block Builder subcommand.",
mixinStandardHelpOptions = true,
versionProvider = VersionProvider.class)
public class B11rSubCommand implements Runnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder;
import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
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;
import org.hyperledger.besu.evm.log.LogsBloomFilter;
import org.hyperledger.besu.evm.tracing.OperationTracer;
import org.hyperledger.besu.evm.tracing.StandardJsonTracer;
import org.hyperledger.besu.evm.worldstate.WorldState;
import org.hyperledger.besu.evm.worldstate.WorldUpdater;
import org.hyperledger.besu.metrics.MetricsSystemModule;
import org.hyperledger.besu.util.LogConfigurator;
Expand All @@ -58,7 +57,7 @@
import java.util.Deque;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.NavigableMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -474,8 +473,9 @@ public void run() {
lastTime = stopwatch.elapsed().toNanos();
stopwatch.reset();
if (showJsonAlloc && lastLoop) {
initialMessageFrame.getSelfDestructs().forEach(updater::deleteAccount);
updater.commit();
WorldState worldState = component.getWorldState();
MutableWorldState worldState = component.getWorldState();
dumpWorldState(worldState, out);
}
} while (remainingIters-- > 0);
Expand All @@ -486,34 +486,39 @@ public void run() {
}
}

public static void dumpWorldState(final WorldState worldState, final PrintWriter out) {
public static void dumpWorldState(final MutableWorldState worldState, final PrintWriter out) {
out.println("{");
worldState
.streamAccounts(Bytes32.ZERO, Integer.MAX_VALUE)
.sorted(Comparator.comparing(o -> o.getAddress().get().toHexString()))
.forEach(
account -> {
out.println(
" \"" + account.getAddress().map(Address::toHexString).orElse("-") + "\": {");
a -> {
var account = worldState.get(a.getAddress().get());
out.println(" \"" + account.getAddress().toHexString() + "\": {");
if (account.getCode() != null && !account.getCode().isEmpty()) {
out.println(" \"code\": \"" + account.getCode().toHexString() + "\",");
}
NavigableMap<Bytes32, AccountStorageEntry> storageEntries =
account.storageEntriesFrom(Bytes32.ZERO, Integer.MAX_VALUE);
var storageEntries =
account.storageEntriesFrom(Bytes32.ZERO, Integer.MAX_VALUE).values().stream()
.map(
e ->
Map.entry(
e.getKey().get(),
account.getStorageValue(UInt256.fromBytes(e.getKey().get()))))
.filter(e -> !e.getValue().isZero())
.sorted(Map.Entry.comparingByKey())
.toList();
if (!storageEntries.isEmpty()) {
out.println(" \"storage\": {");
out.println(
STORAGE_JOINER.join(
storageEntries.values().stream()
storageEntries.stream()
.map(
accountStorageEntry ->
e ->
" \""
+ accountStorageEntry
.getKey()
.map(UInt256::toQuantityHexString)
.orElse("-")
+ e.getKey().toQuantityHexString()
+ "\": \""
+ accountStorageEntry.getValue().toQuantityHexString()
+ e.getValue().toQuantityHexString()
+ "\"")
.toList()));
out.println(" },");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public class StateTestSubCommand implements Runnable {
description = "Force the state tests to run on a specific fork.")
private String fork = null;

@Option(
names = {"--test-name"},
description = "Limit execution to one named test.")
private String testName = null;

@Option(
names = {"--data-index"},
description = "Limit execution to one data variable.")
Expand Down Expand Up @@ -173,10 +178,12 @@ public void run() {
private void executeStateTest(final Map<String, GeneralStateTestCaseSpec> generalStateTests) {
for (final Map.Entry<String, GeneralStateTestCaseSpec> generalStateTestEntry :
generalStateTests.entrySet()) {
generalStateTestEntry
.getValue()
.finalStateSpecs()
.forEach((__, specs) -> traceTestSpecs(generalStateTestEntry.getKey(), specs));
if (testName == null || testName.equals(generalStateTestEntry.getKey())) {
generalStateTestEntry
.getValue()
.finalStateSpecs()
.forEach((__, specs) -> traceTestSpecs(generalStateTestEntry.getKey(), specs));
}
}
}

Expand Down
Loading

0 comments on commit 46d5859

Please sign in to comment.