Skip to content

Commit

Permalink
Add missing methods to transaction interface (hyperledger#5732)
Browse files Browse the repository at this point in the history
* added missing methods to transaction interface, created new AccessListEntry interface to add it to the transaction interface

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* CHANGELOG.md entry

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* added missing javadoc entry

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* Update datatypes/src/main/java/org/hyperledger/besu/datatypes/Transaction.java

Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* Update datatypes/src/main/java/org/hyperledger/besu/datatypes/Transaction.java

Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* Make smart contract permissioning features work with london fork (hyperledger#5727)

* Make smart contract permissioning features work with london fork

Override the transactionSimulator's default TransactionValidationParams with one that allows for exceeding the account balance (which effectively zeros the baseFee).
This mimics the way that eth_estimateGas and eth_call are implemented.
Similar change to hyperledger#5277

Update ATs to use londonBlock (existing genesis allocs necessitate zeroBaseFee as well)

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>

* changelog
Signed-off-by: Simon Dudley <simon.dudley@consensys.net>

---------

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* Correctly cache the TransactionValidator instance on creation (hyperledger#5726)

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* Reference tests 12.3 (hyperledger#5733)

Update Reference Tests to 12.3
* fix decoding error
* add ignored field
* update module

Signed-off-by: Danno Ferrin <danno.ferrin@swirldslabs.com>
Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* Return all not selected transactions, not only invalid ones. (hyperledger#5711)

This way it is possible for the caller to have more data about the selection
process.

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* Address import performance issues (hyperledger#5734)

* ensure we are on a single tuweni version
* factor out an unneeded concatenate

Signed-off-by: Danno Ferrin <danno.ferrin@swirldslabs.com>
Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* Add type to PendingTransactionDetail (hyperledger#5729)

* add type

* update changelog

---------

Signed-off-by: George Tebrean <george@web3labs.com>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* Migrate to blobGas in execution-spec-tests (hyperledger#5745)

Execution-spec-tests migrated from DataGas to BlobGas and checks for its
inclusion in tests now. Add needed support.

Signed-off-by: Danno Ferrin <danno.ferrin@swirldslabs.com>
Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* remove AccessListEntry interface and move its class to the datatypes module

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* add missing cost methods to interface, add method to get RLP of transaction

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* updating hash with updated reference tests

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* added missing javadocs

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* fixed compiler errors in integration tests

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

* retro blobGas name change into Transaction interface

Signed-off-by: garyschulte <garyschulte@gmail.com>

* removed methods from transaction interface which values can be derived through other means. Added new method encoded to return the encoded tx in Bytes instead of RLPOutput

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>

---------

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Danno Ferrin <danno.ferrin@swirldslabs.com>
Signed-off-by: George Tebrean <george@web3labs.com>
Signed-off-by: garyschulte <garyschulte@gmail.com>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Co-authored-by: Simon Dudley <simon.dudley@consensys.net>
Co-authored-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Co-authored-by: Danno Ferrin <danno.ferrin@swirldslabs.com>
Co-authored-by: George Tebrean <99179176+gtebrean@users.noreply.github.com>
Co-authored-by: garyschulte <garyschulte@gmail.com>
Signed-off-by: garyschulte <garyschulte@gmail.com>
  • Loading branch information
7 people committed Aug 28, 2023
1 parent 8ce6b66 commit 74f1bda
Show file tree
Hide file tree
Showing 30 changed files with 100 additions and 90 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Add ABI-decoded revert reason to `eth_call` and `eth_estimateGas` responses [#5705](https://github.com/hyperledger/besu/issues/5705)

### Additions and Improvements
- Add missing methods to the `Transaction` interface [#5732](https://github.com/hyperledger/besu/pull/5732)
- Added `benchmark` subcommand to `evmtool` [#5754](https://github.com/hyperledger/besu/issues/5754)
- JSON output is now compact by default. This can be overridden by the new `--json-pretty-print-enabled` CLI option. [#5766](https://github.com/hyperledger/besu/pull/5766)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright ConsenSys AG.
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand All @@ -12,35 +12,18 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.evm;

import org.hyperledger.besu.datatypes.Address;
package org.hyperledger.besu.datatypes;

import java.util.List;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;

/** The Access list entry. */
public class AccessListEntry {
private final Address address;
private final List<Bytes32> storageKeys;

/**
* Instantiates a new Access list entry.
*
* @param address the address
* @param storageKeys the storage keys
*/
public AccessListEntry(final Address address, final List<Bytes32> storageKeys) {
this.address = address;
this.storageKeys = storageKeys;
}

/** An access list entry as defined in EIP-2930 */
public record AccessListEntry(Address address, List<Bytes32> storageKeys) {
/**
* Create access list entry.
*
Expand All @@ -56,26 +39,6 @@ public static AccessListEntry createAccessListEntry(
address, storageKeys.stream().map(Bytes32::fromHexString).collect(Collectors.toList()));
}

/**
* Gets address.
*
* @return the address
*/
@JsonIgnore
public Address getAddress() {
return address;
}

/**
* Gets storage keys.
*
* @return the storage keys
*/
@JsonIgnore
public List<Bytes32> getStorageKeys() {
return storageKeys;
}

/**
* Gets address string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.hyperledger.besu.datatypes;

import java.math.BigInteger;
import java.util.List;
import java.util.Optional;

import org.apache.tuweni.bytes.Bytes;
Expand Down Expand Up @@ -183,4 +184,39 @@ default Optional<? extends Quantity> getMaxFeePerBlobGas() {
* @return the type of the transaction
*/
TransactionType getType();

/**
* Return the versioned hashes for this transaction.
*
* @return optional list of versioned hashes
*/
Optional<List<VersionedHash>> getVersionedHashes();

/**
* Return the blobs with commitments for this transaction.
*
* @return optional blobs with commitments
*/
Optional<BlobsWithCommitments> getBlobsWithCommitments();

/**
* Return the address of the contract, if the transaction creates one
*
* @return address of new contract or empty otherwise
*/
Optional<Address> contractAddress();

/**
* Return the access list in case of EIP-2930 transaction
*
* @return optional access list
*/
Optional<List<AccessListEntry>> getAccessList();

/**
* Returns the transaction with the proper encoding
*
* @return the encoded transaction as Bytes
*/
Bytes encoded();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import org.hyperledger.besu.datatypes.AccessListEntry;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.api.jsonrpc.BlockchainImporter;
Expand All @@ -27,7 +28,6 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.CreateAccessListResult;
import org.hyperledger.besu.evm.AccessListEntry;
import org.hyperledger.besu.testutil.BlockTestUtil;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import org.hyperledger.besu.datatypes.AccessListEntry;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.api.jsonrpc.BlockchainImporter;
Expand All @@ -26,7 +27,6 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.evm.AccessListEntry;
import org.hyperledger.besu.testutil.BlockTestUtil;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/
package org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter;

import org.hyperledger.besu.datatypes.AccessListEntry;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.evm.AccessListEntry;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -32,11 +32,11 @@ public AccessListEntryAdapter(final AccessListEntry accessListEntry) {
}

public List<Bytes32> getStorageKeys() {
final var storage = accessListEntry.getStorageKeys();
final var storage = accessListEntry.storageKeys();
return new ArrayList<>(storage);
}

public Optional<Address> getAddress() {
return Optional.of(accessListEntry.getAddress());
return Optional.of(accessListEntry.address());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;

import org.hyperledger.besu.datatypes.AccessListEntry;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
Expand All @@ -29,7 +30,6 @@
import org.hyperledger.besu.ethereum.transaction.CallParameter;
import org.hyperledger.besu.ethereum.transaction.TransactionSimulator;
import org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult;
import org.hyperledger.besu.evm.AccessListEntry;
import org.hyperledger.besu.evm.tracing.AccessListOperationTracer;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters;

import org.hyperledger.besu.datatypes.AccessListEntry;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.json.HexLongDeserializer;
import org.hyperledger.besu.ethereum.core.json.HexStringDeserializer;
import org.hyperledger.besu.ethereum.transaction.CallParameter;
import org.hyperledger.besu.evm.AccessListEntry;

import java.util.List;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results;

import org.hyperledger.besu.evm.AccessListEntry;
import org.hyperledger.besu.datatypes.AccessListEntry;

import java.util.Collection;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results;

import org.hyperledger.besu.datatypes.AccessListEntry;
import org.hyperledger.besu.datatypes.TransactionType;
import org.hyperledger.besu.datatypes.VersionedHash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.evm.AccessListEntry;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results;

import org.hyperledger.besu.datatypes.AccessListEntry;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.TransactionType;
import org.hyperledger.besu.datatypes.VersionedHash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.encoding.TransactionEncoder;
import org.hyperledger.besu.evm.AccessListEntry;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.hyperledger.besu.datatypes.AccessListEntry;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest;
Expand All @@ -43,7 +44,6 @@
import org.hyperledger.besu.ethereum.transaction.TransactionSimulator;
import org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.evm.AccessListEntry;
import org.hyperledger.besu.evm.tracing.AccessListOperationTracer;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

import org.hyperledger.besu.crypto.SECPSignature;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.datatypes.AccessListEntry;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.BlockDataGenerator;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.encoding.TransactionEncoder;
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
import org.hyperledger.besu.evm.AccessListEntry;

import java.math.BigInteger;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
import org.hyperledger.besu.crypto.SECPSignature;
import org.hyperledger.besu.crypto.SignatureAlgorithm;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.datatypes.AccessListEntry;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Blob;
import org.hyperledger.besu.datatypes.BlobsWithCommitments;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.KZGCommitment;
import org.hyperledger.besu.datatypes.KZGProof;
import org.hyperledger.besu.datatypes.Quantity;
import org.hyperledger.besu.datatypes.Sha256Hash;
import org.hyperledger.besu.datatypes.TransactionType;
import org.hyperledger.besu.datatypes.VersionedHash;
Expand All @@ -42,10 +42,8 @@
import org.hyperledger.besu.ethereum.rlp.RLP;
import org.hyperledger.besu.ethereum.rlp.RLPInput;
import org.hyperledger.besu.ethereum.rlp.RLPOutput;
import org.hyperledger.besu.evm.AccessListEntry;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -432,20 +430,11 @@ public Optional<Wei> getMaxFeePerBlobGas() {
}

/**
* Boolean which indicates the transaction has associated cost data, whether gas price or 1559 fee
* market parameters.
* Return the effective priority fee per gas for this transaction.
*
* @return whether cost params are present
* @param maybeBaseFee base fee in case of EIP-1559 transaction
* @return priority fee per gas in wei
*/
public boolean hasCostParams() {
return Arrays.asList(
getGasPrice(), getMaxFeePerGas(), getMaxPriorityFeePerGas(), getMaxFeePerBlobGas())
.stream()
.flatMap(Optional::stream)
.map(Quantity::getAsBigInteger)
.anyMatch(q -> q.longValue() > 0L);
}

public Wei getEffectivePriorityFeePerGas(final Optional<Wei> maybeBaseFee) {
return maybeBaseFee
.map(
Expand Down Expand Up @@ -547,6 +536,7 @@ public Optional<Bytes> getData() {
return getTo().isPresent() ? Optional.of(payload) : Optional.empty();
}

@Override
public Optional<List<AccessListEntry>> getAccessList() {
return maybeAccessList;
}
Expand Down Expand Up @@ -625,6 +615,13 @@ public void writeTo(final RLPOutput out) {
TransactionEncoder.encodeForWire(this, out);
}

@Override
public Bytes encoded() {
final BytesValueRLPOutput rplOutput = new BytesValueRLPOutput();
writeTo(rplOutput);
return rplOutput.encoded();
}

@Override
public BigInteger getR() {
return signature.getR();
Expand Down Expand Up @@ -780,6 +777,7 @@ public Wei getMaxGasPrice() {
new IllegalStateException(
"Transaction requires either gasPrice or maxFeePerGas")));
}

/**
* Calculates the effectiveGasPrice of a transaction on the basis of an {@code Optional<Long>}
* baseFee and handles unwrapping Optional fee parameters. If baseFee is present, effective gas is
Expand All @@ -801,10 +799,12 @@ public TransactionType getType() {
return this.transactionType;
}

@Override
public Optional<List<VersionedHash>> getVersionedHashes() {
return versionedHashes;
}

@Override
public Optional<BlobsWithCommitments> getBlobsWithCommitments() {
return blobsWithCommitments;
}
Expand Down Expand Up @@ -1127,6 +1127,7 @@ public String toTraceLog() {
return sb.append("}").toString();
}

@Override
public Optional<Address> contractAddress() {
if (isContractCreation()) {
return Optional.of(Address.contractAddress(getSender(), getNonce()));
Expand Down
Loading

0 comments on commit 74f1bda

Please sign in to comment.