Skip to content

Commit

Permalink
add missing cost methods to interface, add method to get RLP of trans…
Browse files Browse the repository at this point in the history
…action

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
  • Loading branch information
daniellehrner committed Aug 4, 2023
1 parent ba8f425 commit e4094b8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand Down Expand Up @@ -265,4 +266,45 @@ default Optional<? extends Quantity> getMaxFeePerDataGas() {
* @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);

/**
* 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
* @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.
*
* @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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ private Bytes32 getOrComputeSenderRecoveryHash() {
*
* @param out the output to write the transaction to
*/
@Override
public void writeTo(final RLPOutput out) {
TransactionEncoder.encodeForWire(this, out);
}
Expand Down Expand Up @@ -734,6 +735,7 @@ private boolean isUpfrontGasCostTooHigh() {
* @param dataGasPrice the data gas price to use
* @return the up-front cost for the gas the transaction can use.
*/
@Override
public Wei getUpfrontGasCost(
final Wei gasPrice, final Wei dataGasPrice, final long totalDataGas) {
if (gasPrice == null || gasPrice.isZero()) {
Expand Down Expand Up @@ -770,6 +772,7 @@ private BigInteger calculateUpfrontGasCost(
*
* @return the up-front gas cost for the transaction
*/
@Override
public Wei getUpfrontCost(final long totalDataGas) {
return getMaxUpfrontGasCost(totalDataGas).addExact(getValue());
}
Expand All @@ -788,6 +791,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 @@ -800,6 +804,7 @@ public Wei getMaxGasPrice() {
* @param baseFeePerGas optional baseFee from the block header, if we are post-london
* @return the effective gas price.
*/
@Override
public final Wei getEffectiveGasPrice(final Optional<Wei> baseFeePerGas) {
return getEffectivePriorityFeePerGas(baseFeePerGas).addExact(baseFeePerGas.orElse(Wei.ZERO));
}
Expand Down

0 comments on commit e4094b8

Please sign in to comment.