mirror of
https://github.com/vacp2p/status-linea-besu.git
synced 2026-01-09 13:58:02 -05:00
evmtool was not respecting the --genesis option (#7518)
* EVMTool should respect --genesis option Update the code so that the genesis file option will be respected when set. Also, default --fork options should set a rational base fee. Signed-off-by: Danno Ferrin <danno@numisight.com> --------- Signed-off-by: Danno Ferrin <danno@numisight.com>
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
- **DebugMetrics**: Fixed a `ClassCastException` occurring in `DebugMetrics` when handling nested metric structures. Previously, `Double` values within these structures were incorrectly cast to `Map` objects, leading to errors. This update allows for proper handling of both direct values and nested structures at the same level. Issue# [#7383]
|
||||
- **DebugMetrics**: Fixed a `ClassCastException` occurring in `DebugMetrics` when handling nested metric structures. Previously, `Double` values within these structures were incorrectly cast to `Map` objects, leading to errors. This update allows for proper handling of both direct values and nested structures at the same level. Issue# [#7383](https://github.com/hyperledger/besu/pull/7383)
|
||||
- `evmtool` was not respecting the `--genesis` setting, resulting in unexpected trace results. [#7433](https://github.com/hyperledger/besu/pull/7433)
|
||||
|
||||
### Tests
|
||||
- Added a comprehensive test case to reproduce the bug and verify the fix for the `ClassCastException` in `DebugMetrics`. This ensures that complex, dynamically nested metric structures can be handled without errors.
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
*/
|
||||
package org.hyperledger.besu.datatypes;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/** Description and metadata for a hard fork */
|
||||
public interface HardforkId {
|
||||
|
||||
@@ -112,6 +115,19 @@ public interface HardforkId {
|
||||
public String description() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* The most recent finalized mainnet hardfork Besu supports. This will change across versions
|
||||
* and will be updated after mainnet activations.
|
||||
*
|
||||
* @return the most recently activated mainnet spec.
|
||||
*/
|
||||
public static MainnetHardforkId mostRecent() {
|
||||
return Stream.of(MainnetHardforkId.values())
|
||||
.filter(MainnetHardforkId::finalized)
|
||||
.max(Comparator.naturalOrder())
|
||||
.orElseThrow();
|
||||
}
|
||||
}
|
||||
|
||||
/** List of all Ethereum Classic hard forks. */
|
||||
|
||||
@@ -158,22 +158,23 @@ public class BlockHeader extends SealableBlockHeader
|
||||
out.writeBytes(extraData);
|
||||
out.writeBytes(mixHashOrPrevRandao);
|
||||
out.writeLong(nonce);
|
||||
if (baseFee != null) {
|
||||
do {
|
||||
if (baseFee == null) break;
|
||||
out.writeUInt256Scalar(baseFee);
|
||||
}
|
||||
if (withdrawalsRoot != null) {
|
||||
|
||||
if (withdrawalsRoot == null) break;
|
||||
out.writeBytes(withdrawalsRoot);
|
||||
}
|
||||
if (excessBlobGas != null && blobGasUsed != null) {
|
||||
|
||||
if (excessBlobGas == null || blobGasUsed == null) break;
|
||||
out.writeLongScalar(blobGasUsed);
|
||||
out.writeUInt64Scalar(excessBlobGas);
|
||||
}
|
||||
if (parentBeaconBlockRoot != null) {
|
||||
|
||||
if (parentBeaconBlockRoot == null) break;
|
||||
out.writeBytes(parentBeaconBlockRoot);
|
||||
}
|
||||
if (requestsRoot != null) {
|
||||
|
||||
if (requestsRoot == null) break;
|
||||
out.writeBytes(requestsRoot);
|
||||
}
|
||||
} while (false);
|
||||
out.endList();
|
||||
}
|
||||
|
||||
|
||||
@@ -478,7 +478,14 @@ public class EvmToolCommand implements Runnable {
|
||||
.mixHash(Hash.ZERO)
|
||||
.nonce(0)
|
||||
.blockHeaderFunctions(new MainnetBlockHeaderFunctions())
|
||||
.baseFee(component.getBlockchain().getChainHeadHeader().getBaseFee().orElse(null))
|
||||
.baseFee(
|
||||
component
|
||||
.getBlockchain()
|
||||
.getChainHeadHeader()
|
||||
.getBaseFee()
|
||||
.or(() -> genesisFileModule.providesGenesisConfigFile().getBaseFeePerGas())
|
||||
.orElse(
|
||||
protocolSpec.getFeeMarket().implementsBaseFee() ? Wei.of(0xa) : null))
|
||||
.buildBlockHeader();
|
||||
|
||||
Address contractAddress =
|
||||
@@ -519,13 +526,12 @@ public class EvmToolCommand implements Runnable {
|
||||
lastTime = stopwatch.elapsed().toNanos();
|
||||
}
|
||||
if (lastLoop) {
|
||||
if (messageFrame.getExceptionalHaltReason().isPresent()) {
|
||||
out.println(messageFrame.getExceptionalHaltReason().get());
|
||||
}
|
||||
if (messageFrame.getRevertReason().isPresent()) {
|
||||
out.println(
|
||||
new String(messageFrame.getRevertReason().get().toArrayUnsafe(), UTF_8));
|
||||
}
|
||||
messageFrame
|
||||
.getExceptionalHaltReason()
|
||||
.ifPresent(haltReason -> out.println(haltReason));
|
||||
messageFrame
|
||||
.getRevertReason()
|
||||
.ifPresent(bytes -> out.println(new String(bytes.toArrayUnsafe(), UTF_8)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -572,7 +578,7 @@ public class EvmToolCommand implements Runnable {
|
||||
out.println("{");
|
||||
worldState
|
||||
.streamAccounts(Bytes32.ZERO, Integer.MAX_VALUE)
|
||||
.sorted(Comparator.comparing(o -> o.getAddress().get().toHexString()))
|
||||
.sorted(Comparator.comparing(o -> o.getAddress().orElse(Address.ZERO).toHexString()))
|
||||
.forEach(
|
||||
a -> {
|
||||
var account = worldState.get(a.getAddress().get());
|
||||
@@ -585,7 +591,7 @@ public class EvmToolCommand implements Runnable {
|
||||
.map(
|
||||
e ->
|
||||
Map.entry(
|
||||
e.getKey().get(),
|
||||
e.getKey().orElse(UInt256.ZERO),
|
||||
account.getStorageValue(UInt256.fromBytes(e.getKey().get()))))
|
||||
.filter(e -> !e.getValue().isZero())
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.hyperledger.besu.cli.config.EthNetworkConfig;
|
||||
import org.hyperledger.besu.cli.config.NetworkName;
|
||||
import org.hyperledger.besu.config.GenesisConfigFile;
|
||||
import org.hyperledger.besu.config.GenesisConfigOptions;
|
||||
import org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId;
|
||||
import org.hyperledger.besu.ethereum.chain.GenesisState;
|
||||
import org.hyperledger.besu.ethereum.core.Block;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions;
|
||||
@@ -28,6 +29,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
@@ -116,7 +118,7 @@ public class GenesisFileModule {
|
||||
final JsonObject config = new JsonObject();
|
||||
genesis.put("config", config);
|
||||
config.put("chainId", 1337);
|
||||
config.put("londonBlock", 0);
|
||||
config.put(MainnetHardforkId.mostRecent().toString().toLowerCase(Locale.ROOT) + "Time", 0);
|
||||
genesis.put("baseFeePerGas", "0x3b9aca00");
|
||||
genesis.put("gasLimit", "0x2540be400");
|
||||
genesis.put("difficulty", "0x0");
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule;
|
||||
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
|
||||
import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder;
|
||||
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters;
|
||||
import org.hyperledger.besu.evm.EvmSpecVersion;
|
||||
import org.hyperledger.besu.evm.internal.EvmConfiguration;
|
||||
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
|
||||
|
||||
@@ -71,14 +70,13 @@ class MainnetGenesisFileModule extends GenesisFileModule {
|
||||
}
|
||||
}
|
||||
|
||||
if (fork.isPresent()) {
|
||||
var schedules = createSchedules(configOptions.getChainId().orElse(BigInteger.valueOf(1337)));
|
||||
var schedule =
|
||||
schedules.get(
|
||||
fork.orElse(EvmSpecVersion.defaultVersion().getName())
|
||||
.toLowerCase(Locale.getDefault()));
|
||||
var schedule = schedules.get(fork.get().toLowerCase(Locale.getDefault()));
|
||||
if (schedule != null) {
|
||||
return schedule.get();
|
||||
}
|
||||
}
|
||||
|
||||
return MainnetProtocolSchedule.fromConfig(
|
||||
configOptions,
|
||||
|
||||
Reference in New Issue
Block a user