Skip to content

Commit c03008b

Browse files
committed
add mainnet vs minimal protocol schedule implementations for comparison
Signed-off-by: garyschulte <[email protected]>
1 parent ed54725 commit c03008b

File tree

1 file changed

+49
-23
lines changed

1 file changed

+49
-23
lines changed

src/main/java/org/hyperledger/besu/riscv/poc/block/execution/BlockRunner.java

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
import org.hyperledger.besu.ethereum.core.Block;
3030
import org.hyperledger.besu.ethereum.core.BlockHeader;
3131
import org.hyperledger.besu.ethereum.core.Difficulty;
32+
import org.hyperledger.besu.ethereum.core.MiningConfiguration;
3233
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
3334
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions;
35+
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule;
3436
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
3537
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
3638
import org.hyperledger.besu.ethereum.rlp.RLP;
@@ -82,11 +84,21 @@ private record CommandLineArgs(
8284
Optional<String> blockRlpPath,
8385
Optional<String> genesisConfigPath) {}
8486

85-
/**
86-
* Factory method that builds a complete in-memory Besu execution environment. It imports previous
87-
* headers, reconstructs the world state from a witness, and returns a {@link BlockRunner} ready
88-
* to process a block.
89-
*/
87+
private static final NoOpMetricsSystem noOpMetricsSystem = new NoOpMetricsSystem();
88+
89+
// Configure the EVM with in-memory (stacked) world updater mode.
90+
private static final EvmConfiguration evmConfiguration =
91+
new EvmConfiguration(
92+
EvmConfiguration.DEFAULT.jumpDestCacheWeightKB(),
93+
EvmConfiguration.WorldUpdaterMode.STACKED,
94+
true);
95+
/*
96+
97+
/**
98+
* Factory method that builds a complete in-memory Besu execution environment. It imports previous
99+
* headers, reconstructs the world state from a witness, and returns a {@link BlockRunner} ready
100+
* to process a block.
101+
*/
90102
public static BlockRunner create(
91103
final BlockHeader targetBlockHeader,
92104
final List<BlockHeader> prevHeaders,
@@ -96,25 +108,12 @@ public static BlockRunner create(
96108

97109
final GenesisConfig genesisConfig = GenesisConfig.fromConfig(genesisConfigJson);
98110

99-
final NoOpMetricsSystem noOpMetricsSystem = new NoOpMetricsSystem();
111+
// use a minimal protocol schedule:
112+
final ProtocolSchedule protocolSchedule = constructMinimalConfig(genesisConfig, targetBlockHeader);
100113

101-
// Configure the EVM with in-memory (stacked) world updater mode.
102-
final EvmConfiguration evmConfiguration =
103-
new EvmConfiguration(
104-
EvmConfiguration.DEFAULT.jumpDestCacheWeightKB(),
105-
EvmConfiguration.WorldUpdaterMode.STACKED,
106-
true);
107-
108-
// Build a minimal protocol schedule with only the necessary fork spec and Graal precompiles.
109-
// This avoids the overhead of building all fork specs from Frontier through the latest,
110-
// and prevents loading JNA-based native libraries that will be replaced.
111-
final ProtocolSchedule protocolSchedule =
112-
MinimalProtocolSchedule.create(
113-
targetBlockHeader,
114-
genesisConfig,
115-
evmConfiguration,
116-
new BadBlockManager(),
117-
noOpMetricsSystem);
114+
//TODO: possibly make minimal vs mainnet protocol schedule configurable
115+
// // or use the mainnet-derived protocol schedule
116+
// final ProtocolSchedule protocolSchedule = constructFromGenesisConfig(genesisConfig);
118117

119118
// Construct the genesis state and world state root.
120119
final GenesisState genesisState =
@@ -342,6 +341,33 @@ public void processBlock(final Block block) {
342341
System.out.println(" Stateroot: " + result.getYield().get().getWorldState().rootHash());
343342
}
344343

344+
private static ProtocolSchedule constructMinimalConfig(
345+
GenesisConfig genesisConfig,
346+
BlockHeader targetBlockHeader) {
347+
return MinimalProtocolSchedule.create(
348+
targetBlockHeader,
349+
genesisConfig,
350+
evmConfiguration,
351+
new BadBlockManager(),
352+
noOpMetricsSystem);
353+
354+
}
355+
356+
private static ProtocolSchedule constructFromGenesisConfig(
357+
final GenesisConfig genesisConfig) {
358+
// Build the mainnet protocol schedule based on the genesis config.
359+
return
360+
MainnetProtocolSchedule.fromConfig(
361+
genesisConfig.getConfigOptions(),
362+
evmConfiguration,
363+
MiningConfiguration.MINING_DISABLED,
364+
new BadBlockManager(),
365+
false,
366+
false,
367+
noOpMetricsSystem);
368+
369+
370+
}
345371
/** Print usage information and exit. */
346372
private static void printUsageAndExit() {
347373
System.out.println("Usage: BlockRunner [OPTIONS]");

0 commit comments

Comments
 (0)