Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing methods to transaction interface #5732

Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e3752c8
added missing methods to transaction interface, created new AccessLis…
daniellehrner Jul 30, 2023
d4cdcc3
CHANGELOG.md entry
daniellehrner Jul 30, 2023
e1e93dc
added missing javadoc entry
daniellehrner Jul 30, 2023
547133b
Update datatypes/src/main/java/org/hyperledger/besu/datatypes/Transac…
daniellehrner Aug 4, 2023
3ebafb3
Update datatypes/src/main/java/org/hyperledger/besu/datatypes/Transac…
daniellehrner Aug 4, 2023
8221324
Make smart contract permissioning features work with london fork (#5727)
siladu Jul 31, 2023
ff7c669
Correctly cache the TransactionValidator instance on creation (#5726)
fab-10 Jul 31, 2023
d7c6ef3
Reference tests 12.3 (#5733)
shemnon Jul 31, 2023
349649e
Return all not selected transactions, not only invalid ones. (#5711)
fab-10 Aug 1, 2023
bf99643
Address import performance issues (#5734)
shemnon Aug 2, 2023
4f0fe20
Add type to PendingTransactionDetail (#5729)
gtebrean Aug 2, 2023
675bd30
Migrate to blobGas in execution-spec-tests (#5745)
shemnon Aug 2, 2023
4e08e53
remove AccessListEntry interface and move its class to the datatypes …
daniellehrner Aug 4, 2023
312769b
add missing cost methods to interface, add method to get RLP of trans…
daniellehrner Aug 4, 2023
8bf7073
Merge branch 'main' into feat/issue-5731/update-transaction-interface
daniellehrner Aug 4, 2023
5f6666d
updating hash with updated reference tests
daniellehrner Aug 4, 2023
6855b76
added missing javadocs
daniellehrner Aug 4, 2023
5ca6a64
fixed compiler errors in integration tests
daniellehrner Aug 4, 2023
180135a
Merge branch 'main' into feat/issue-5731/update-transaction-interface
daniellehrner Aug 9, 2023
876c4e4
Merge branch 'main' into feat/issue-5731/update-transaction-interface
garyschulte Aug 21, 2023
3d7c991
retro blobGas name change into Transaction interface
garyschulte Aug 21, 2023
b71032f
removed methods from transaction interface which values can be derive…
daniellehrner Aug 22, 2023
12b88e1
Merge branch 'main' into feat/issue-5731/update-transaction-interface
daniellehrner Aug 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

### Bug Fixes
- Make smart contract permissioning features work with london fork [#5727](https://github.com/hyperledger/besu/pull/5727)
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) {
daniellehrner marked this conversation as resolved.
Show resolved Hide resolved
/**
* 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 @@ -14,7 +14,11 @@
*/
package org.hyperledger.besu.datatypes;

import org.hyperledger.besu.crypto.SECPSignature;
import org.hyperledger.besu.ethereum.rlp.RLPOutput;

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

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

/**
* Boolean which indicates the transaction has associated cost data, whether gas price or 1559 fee
* market parameters.
*
* @return whether cost params are present
*/
boolean hasCostParams();
daniellehrner marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns the number of blobs this transaction has, or 0 if not a blob transaction type
*
* @return return the count
*/
int getBlobCount();
daniellehrner marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns the signature used to sign the transaction.
*
* @return the signature used to sign the transaction
*/
SECPSignature getSignature();
daniellehrner marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns the public key extracted from the signature.
*
* @return the public key
*/
Optional<String> getPublicKey();
daniellehrner marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns whether the transaction is a contract creation
*
* @return {@code true} if this is a contract-creation transaction; otherwise {@code false}
*/
boolean isContractCreation();
daniellehrner marked this conversation as resolved.
Show resolved Hide resolved

/**
* Return the maximum fee per gas the sender is willing to pay for this transaction.
*
* @return max fee per gas in wei
*/
Wei getMaxGasPrice();
daniellehrner marked this conversation as resolved.
Show resolved Hide resolved

/**
* Return the effective priority fee per gas for this transaction.
*
* @param maybeBaseFee base fee in case of EIP-1559 transaction
* @return priority fee per gas in wei
*/
Wei getEffectivePriorityFeePerGas(final Optional<Wei> maybeBaseFee);
daniellehrner marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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();

/**
* Writes the transaction to RLP
*
* @param out the output to write the transaction to
*/
void writeTo(final RLPOutput out);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of my goals is to remove the RLP dependency from the datatypes module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've replaced it with a new generic method Bytes encoded();: see here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After diving into what it would take to remove it I'm thinking it should come back.

Because the CREATE operation depends on the RLP definitions to get the contract addresses the EVM module will still require the RLP, it's not just coming into EVM as a tag-along of datatypes. So removing RLP from datatypes is not really needed, as some of the RLP dependencies once it is determined they should stay are best handled where they are at design-wise.

For performance we will want to use a passed in RLPOutput object as well.


/**
* Calculates the up-front cost for the gas and data gas the transaction can use.
*
* @param gasPrice the gas price to use
* @param dataGasPrice the data gas price to use
* @param totalDataGas the gas the transaction can use
* @return the up-front cost for the gas the transaction can use.
*/
Wei getUpfrontGasCost(final Wei gasPrice, final Wei dataGasPrice, final long totalDataGas);

/**
* Calculates the up-front cost for the transaction.
*
* <p>The up-front cost is paid by the sender account before the transaction is executed. The
* sender must have the amount in its account balance to execute and some of this amount may be
* refunded after the transaction has executed.
*
* @param totalDataGas the gas the transaction can use
* @return the up-front gas cost for the transaction
*/
Wei getUpfrontCost(final long totalDataGas);

/**
* 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
* calculated as:
*
* <p>min((baseFeePerGas + maxPriorityFeePerGas), maxFeePerGas)
*
* <p>Otherwise, return gasPrice for legacy transactions.
*
* @param baseFeePerGas optional baseFee from the block header, if we are post-london
* @return the effective gas price.
*/
Wei getEffectiveGasPrice(final Optional<Wei> baseFeePerGas);
daniellehrner marked this conversation as resolved.
Show resolved Hide resolved
}
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
Loading