Skip to content

Commit

Permalink
cleanup and expose to evmtool
Browse files Browse the repository at this point in the history
Signed-off-by: Danno Ferrin <[email protected]>
  • Loading branch information
shemnon committed Oct 13, 2023
1 parent 01b793f commit 00defce
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,83 +129,60 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides

/** The Sync config. */
protected SynchronizerConfiguration syncConfig;

/** The Ethereum wire protocol configuration. */
protected EthProtocolConfiguration ethereumWireProtocolConfiguration;

/** The Transaction pool configuration. */
protected TransactionPoolConfiguration transactionPoolConfiguration;

/** The Network id. */
protected BigInteger networkId;

/** The Mining parameters. */
protected MiningParameters miningParameters;

/** The Metrics system. */
protected ObservableMetricsSystem metricsSystem;

/** The Privacy parameters. */
protected PrivacyParameters privacyParameters;

/** The Pki block creation configuration. */
protected Optional<PkiBlockCreationConfiguration> pkiBlockCreationConfiguration =
Optional.empty();

/** The Data directory. */
protected Path dataDirectory;

/** The Clock. */
protected Clock clock;

/** The Node key. */
protected NodeKey nodeKey;

/** The Is revert reason enabled. */
protected boolean isRevertReasonEnabled;

/** The Gas limit calculator. */
GasLimitCalculator gasLimitCalculator;

/** The Storage provider. */
protected StorageProvider storageProvider;

/** The Is pruning enabled. */
protected boolean isPruningEnabled;

/** The Pruner configuration. */
protected PrunerConfiguration prunerConfiguration;

/** The Required blocks. */
protected Map<Long, Hash> requiredBlocks = Collections.emptyMap();

/** The Reorg logging threshold. */
protected long reorgLoggingThreshold;

/** The Data storage configuration. */
protected DataStorageConfiguration dataStorageConfiguration =
DataStorageConfiguration.DEFAULT_CONFIG;

/** The Message permissioning providers. */
protected List<NodeMessagePermissioningProvider> messagePermissioningProviders =
Collections.emptyList();

/** The Evm configuration. */
protected EvmConfiguration evmConfiguration;

/** The Max peers. */
protected int maxPeers;

private int peerLowerBound;
private int maxRemotelyInitiatedPeers;

/** The Chain pruner configuration. */
protected ChainPrunerConfiguration chainPrunerConfiguration = ChainPrunerConfiguration.DEFAULT;

private NetworkingConfiguration networkingConfiguration;
private Boolean randomPeerPriority;
private Optional<TransactionSelectorFactory> transactionSelectorFactory = Optional.empty();

/** the Dagger configured context that can provide dependencies */
protected Optional<BesuComponent> besuComponent = Optional.empty();

Expand Down Expand Up @@ -1081,7 +1058,7 @@ WorldStateArchive createWorldStateArchive(
metricsSystem,
besuComponent.map(BesuComponent::getBesuPluginContext).orElse(null),
evmConfiguration);
default -> {
case FOREST -> {
final WorldStatePreimageStorage preimageStorage =
storageProvider.createWorldStatePreimageStorage();
yield new DefaultWorldStateArchive(worldStateStorage, preimageStorage, evmConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Stream<Trace> generateStateDiff(final TransactionTrace transactionTrace)
// calculate storage diff
final Map<String, DiffNode> storageDiff = new TreeMap<>();
for (final Map.Entry<UInt256, UInt256> entry :
((MutableAccount) updatedAccount).getUpdatedStorage().entrySet()) { // FIXME cast
((MutableAccount) updatedAccount).getUpdatedStorage().entrySet()) {
final UInt256 newValue = entry.getValue();
if (rootAccount == null) {
if (!UInt256.ZERO.equals(newValue)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,24 +315,14 @@ public NavigableMap<Bytes32, AccountStorageEntry> storageEntriesFrom(

@Override
public String toString() {
return "AccountState"
+ "{"
+ "address="
+ getAddress()
+ ", "
+ "nonce="
+ getNonce()
+ ", "
+ "balance="
+ getBalance()
+ ", "
+ "storageRoot="
+ getStorageRoot()
+ ", "
+ "codeHash="
+ getCodeHash()
+ ", "
+ "}";
final StringBuilder builder = new StringBuilder();
builder.append("AccountState").append("{");
builder.append("address=").append(getAddress()).append(", ");
builder.append("nonce=").append(getNonce()).append(", ");
builder.append("balance=").append(getBalance()).append(", ");
builder.append("storageRoot=").append(getStorageRoot()).append(", ");
builder.append("codeHash=").append(getCodeHash()).append(", ");
return builder.append("}").toString();
}

private Optional<UInt256> getStorageTrieKeyPreimage(final Bytes32 trieKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public static DefaultWorldStateArchive createInMemoryWorldStateArchive() {

public static BonsaiWorldStateProvider createBonsaiInMemoryWorldStateArchive(
final Blockchain blockchain) {
return createBonsaiInMemoryWorldStateArchive(blockchain, EvmConfiguration.DEFAULT);
}

public static BonsaiWorldStateProvider createBonsaiInMemoryWorldStateArchive(
final Blockchain blockchain, final EvmConfiguration evmConfiguration) {
final InMemoryKeyValueStorageProvider inMemoryKeyValueStorageProvider =
new InMemoryKeyValueStorageProvider();
final CachedMerkleTrieLoader cachedMerkleTrieLoader =
Expand All @@ -93,7 +98,7 @@ public static BonsaiWorldStateProvider createBonsaiInMemoryWorldStateArchive(
cachedMerkleTrieLoader,
new NoOpMetricsSystem(),
null,
EvmConfiguration.DEFAULT);
evmConfiguration);
}

public static MutableWorldState createInMemoryWorldState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,25 @@ void setBytes(final String optionValue) {
names = {"--sender"},
paramLabel = "<address>",
description = "Calling address for this invocation.")
private final Address sender = Address.fromHexString("0x00");
private final Address sender = Address.ZERO;

@Option(
names = {"--receiver"},
paramLabel = "<address>",
description = "Receiving address for this invocation.")
private final Address receiver = Address.fromHexString("0x00");
private final Address receiver = Address.ZERO;

@Option(
names = {"--contract"},
paramLabel = "<address>",
description = "The address holding the contract code.")
private final Address contract = Address.ZERO;

@Option(
names = {"--coinbase"},
paramLabel = "<address>",
description = "Coinbase for this invocation.")
private final Address coinbase = Address.fromHexString("0x00");
private final Address coinbase = Address.ZERO;

@Option(
names = {"--input"},
Expand Down Expand Up @@ -383,11 +389,13 @@ public void run() {
WorldUpdater updater = component.getWorldUpdater();
updater.getOrCreate(sender);
updater.getOrCreate(receiver);
var contractAccount = updater.getOrCreate(contract);
contractAccount.setCode(codeBytes);

MessageFrame initialMessageFrame =
MessageFrame.builder()
.type(MessageFrame.Type.MESSAGE_CALL)
.worldUpdater(updater)
.worldUpdater(updater.updater())
.initialGas(txGas)
.contract(Address.ZERO)
.address(receiver)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,6 @@ void handleT8nRequest(

ReferenceTestEnv referenceTestEnv =
objectMapper.convertValue(input.get("env"), ReferenceTestEnv.class);
// Map<String, ReferenceTestWorldState.AccountMock> accounts =
// objectMapper.convertValue(
// input.get("alloc"),
// objectMapper
// .getTypeFactory()
// .constructMapType(TreeMap.class, String.class,
// ReferenceTestWorldState.AccountMock.class));
Map<String, ReferenceTestWorldState.AccountMock> accounts =
objectMapper.convertValue(input.get("alloc"), new TypeReference<>() {});

Expand Down
19 changes: 0 additions & 19 deletions evm/src/main/java/org/hyperledger/besu/evm/internal/Words.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,6 @@ static long clampedMultiply(final long a, final long b) {
}
}

/**
* Multiplies a and b, but if an underflow/overflow occurs return the Integer max/min value
*
* @param a first value
* @param b second value
* @return value of a times b if no over/underflows or Integer.MAX_VALUE/Integer.MIN_VALUE
* otherwise
*/
static int clampedMultiply(final int a, final int b) {
long r = (long) a * (long) b;
int ri = (int) r;
if (ri == r) {
return ri;
} else {
// out of bounds, clamp it!
return ((a ^ b) < 0) ? Integer.MIN_VALUE : Integer.MAX_VALUE;
}
}

/**
* Returns the lesser of the two values, when compared as an unsigned value
*
Expand Down

0 comments on commit 00defce

Please sign in to comment.