mirror of
https://github.com/vacp2p/status-linea-besu.git
synced 2026-01-09 22:07:59 -05:00
Transaction.gasPrice Optional (#2396)
Signed-off-by: garyschulte <garyschulte@gmail.com>
This commit is contained in:
@@ -138,7 +138,7 @@ public abstract class JsonBlockImporterTest {
|
||||
assertThat(tx.getTo())
|
||||
.hasValue(Address.fromHexString("627306090abaB3A6e1400e9345bC60c78a8BEf57"));
|
||||
assertThat(tx.getGasLimit()).isEqualTo(0xFFFFF1L);
|
||||
assertThat(tx.getGasPrice()).isEqualTo(Wei.fromHexString("0xFF"));
|
||||
assertThat(tx.getGasPrice().get()).isEqualTo(Wei.fromHexString("0xFF"));
|
||||
assertThat(tx.getValue()).isEqualTo(Wei.of(1L));
|
||||
assertThat(tx.getNonce()).isEqualTo(0L);
|
||||
// Check second tx
|
||||
@@ -148,7 +148,7 @@ public abstract class JsonBlockImporterTest {
|
||||
assertThat(tx.getTo())
|
||||
.hasValue(Address.fromHexString("f17f52151EbEF6C7334FAD080c5704D77216b732"));
|
||||
assertThat(tx.getGasLimit()).isEqualTo(0xFFFFF2L);
|
||||
assertThat(tx.getGasPrice()).isEqualTo(Wei.fromHexString("0xEF"));
|
||||
assertThat(tx.getGasPrice().get()).isEqualTo(Wei.fromHexString("0xEF"));
|
||||
assertThat(tx.getValue()).isEqualTo(Wei.of(0L));
|
||||
assertThat(tx.getNonce()).isEqualTo(1L);
|
||||
|
||||
@@ -166,7 +166,7 @@ public abstract class JsonBlockImporterTest {
|
||||
assertThat(tx.getTo())
|
||||
.hasValue(Address.fromHexString("f17f52151EbEF6C7334FAD080c5704D77216b732"));
|
||||
assertThat(tx.getGasLimit()).isEqualTo(0xFFFFFFL);
|
||||
assertThat(tx.getGasPrice()).isEqualTo(Wei.fromHexString("0xFF"));
|
||||
assertThat(tx.getGasPrice().get()).isEqualTo(Wei.fromHexString("0xFF"));
|
||||
assertThat(tx.getValue()).isEqualTo(Wei.of(0L));
|
||||
assertThat(tx.getNonce()).isEqualTo(0L);
|
||||
|
||||
@@ -192,7 +192,7 @@ public abstract class JsonBlockImporterTest {
|
||||
.isEqualTo(Address.fromHexString("627306090abaB3A6e1400e9345bC60c78a8BEf57"));
|
||||
assertThat(tx.getTo()).isEmpty();
|
||||
assertThat(tx.getGasLimit()).isEqualTo(0xFFFFFFL);
|
||||
assertThat(tx.getGasPrice()).isEqualTo(Wei.fromHexString("0xFF"));
|
||||
assertThat(tx.getGasPrice().get()).isEqualTo(Wei.fromHexString("0xFF"));
|
||||
assertThat(tx.getValue()).isEqualTo(Wei.of(0L));
|
||||
assertThat(tx.getNonce()).isEqualTo(1L);
|
||||
}
|
||||
@@ -229,7 +229,7 @@ public abstract class JsonBlockImporterTest {
|
||||
assertThat(tx.getTo())
|
||||
.hasValue(Address.fromHexString("627306090abaB3A6e1400e9345bC60c78a8BEf57"));
|
||||
assertThat(tx.getGasLimit()).isEqualTo(0xFFFFF1L);
|
||||
assertThat(tx.getGasPrice()).isEqualTo(Wei.fromHexString("0xFF"));
|
||||
assertThat(tx.getGasPrice().get()).isEqualTo(Wei.fromHexString("0xFF"));
|
||||
assertThat(tx.getValue()).isEqualTo(Wei.of(1L));
|
||||
assertThat(tx.getNonce()).isEqualTo(0L);
|
||||
// Check second tx
|
||||
@@ -239,7 +239,7 @@ public abstract class JsonBlockImporterTest {
|
||||
assertThat(tx.getTo())
|
||||
.hasValue(Address.fromHexString("f17f52151EbEF6C7334FAD080c5704D77216b732"));
|
||||
assertThat(tx.getGasLimit()).isEqualTo(0xFFFFF2L);
|
||||
assertThat(tx.getGasPrice()).isEqualTo(Wei.fromHexString("0xEF"));
|
||||
assertThat(tx.getGasPrice().get()).isEqualTo(Wei.fromHexString("0xEF"));
|
||||
assertThat(tx.getValue()).isEqualTo(Wei.of(0L));
|
||||
assertThat(tx.getNonce()).isEqualTo(1L);
|
||||
|
||||
@@ -257,7 +257,7 @@ public abstract class JsonBlockImporterTest {
|
||||
assertThat(tx.getTo())
|
||||
.hasValue(Address.fromHexString("f17f52151EbEF6C7334FAD080c5704D77216b732"));
|
||||
assertThat(tx.getGasLimit()).isEqualTo(0xFFFFFFL);
|
||||
assertThat(tx.getGasPrice()).isEqualTo(Wei.fromHexString("0xFF"));
|
||||
assertThat(tx.getGasPrice().get()).isEqualTo(Wei.fromHexString("0xFF"));
|
||||
assertThat(tx.getValue()).isEqualTo(Wei.of(0L));
|
||||
assertThat(tx.getNonce()).isEqualTo(0L);
|
||||
|
||||
@@ -283,7 +283,7 @@ public abstract class JsonBlockImporterTest {
|
||||
.isEqualTo(Address.fromHexString("627306090abaB3A6e1400e9345bC60c78a8BEf57"));
|
||||
assertThat(tx.getTo()).isEmpty();
|
||||
assertThat(tx.getGasLimit()).isEqualTo(0xFFFFFFL);
|
||||
assertThat(tx.getGasPrice()).isEqualTo(Wei.fromHexString("0xFF"));
|
||||
assertThat(tx.getGasPrice().get()).isEqualTo(Wei.fromHexString("0xFF"));
|
||||
assertThat(tx.getValue()).isEqualTo(Wei.of(0L));
|
||||
assertThat(tx.getNonce()).isEqualTo(1L);
|
||||
}
|
||||
@@ -334,7 +334,7 @@ public abstract class JsonBlockImporterTest {
|
||||
assertThat(tx.getTo())
|
||||
.hasValue(Address.fromHexString("627306090abaB3A6e1400e9345bC60c78a8BEf57"));
|
||||
assertThat(tx.getGasLimit()).isEqualTo(0xFFFFF1L);
|
||||
assertThat(tx.getGasPrice()).isEqualTo(Wei.fromHexString("0xFF"));
|
||||
assertThat(tx.getGasPrice().get()).isEqualTo(Wei.fromHexString("0xFF"));
|
||||
assertThat(tx.getValue()).isEqualTo(Wei.of(1L));
|
||||
assertThat(tx.getNonce()).isEqualTo(2L);
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ public class JsonRpcResponseUtils {
|
||||
|
||||
final Transaction transaction = mock(Transaction.class);
|
||||
when(transaction.getType()).thenReturn(TransactionType.FRONTIER);
|
||||
when(transaction.getGasPrice()).thenReturn(Wei.fromHexString(gasPrice));
|
||||
when(transaction.getGasPrice()).thenReturn(Optional.of(Wei.fromHexString(gasPrice)));
|
||||
when(transaction.getNonce()).thenReturn(unsignedLong(nonce));
|
||||
when(transaction.getV()).thenReturn(bigInteger(v));
|
||||
when(transaction.getR()).thenReturn(bigInteger(r));
|
||||
|
||||
@@ -91,7 +91,7 @@ public class TransactionAdapter extends AdapterBase {
|
||||
}
|
||||
|
||||
public Optional<Wei> getGasPrice() {
|
||||
return Optional.of(transactionWithMetadata.getTransaction().getGasPrice());
|
||||
return transactionWithMetadata.getTransaction().getGasPrice();
|
||||
}
|
||||
|
||||
public Optional<Long> getGas() {
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.MinerDataResul
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.MinerDataResult.UncleRewardResult;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockWithMetadata;
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
import org.hyperledger.besu.ethereum.api.query.TransactionReceiptWithMetadata;
|
||||
import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.Hash;
|
||||
@@ -35,7 +34,6 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
@@ -86,17 +84,16 @@ public class EthGetMinerDataByBlockHash implements JsonRpcMethod {
|
||||
final Wei transactionFee =
|
||||
block.getTransactions().stream()
|
||||
.map(
|
||||
t -> {
|
||||
Optional<TransactionReceiptWithMetadata> transactionReceiptWithMetadata =
|
||||
blockchainQueries.transactionReceiptByTransactionHash(
|
||||
t.getTransaction().getHash());
|
||||
return t.getTransaction()
|
||||
.getGasPrice()
|
||||
.multiply(
|
||||
transactionReceiptWithMetadata
|
||||
.map(TransactionReceiptWithMetadata::getGasUsed)
|
||||
.orElse(0L));
|
||||
})
|
||||
t ->
|
||||
blockchainQueries
|
||||
.transactionReceiptByTransactionHash(t.getTransaction().getHash())
|
||||
.map(
|
||||
receipt ->
|
||||
receipt
|
||||
.getTransaction()
|
||||
.calcEffectiveGas(receipt.getBaseFee())
|
||||
.multiply(receipt.getGasUsed()))
|
||||
.orElse(Wei.ZERO))
|
||||
.reduce(Wei.ZERO, BaseUInt256Value::add);
|
||||
final Wei uncleInclusionReward =
|
||||
staticBlockReward.multiply(block.getOmmers().size()).divide(32);
|
||||
|
||||
@@ -102,7 +102,7 @@ public class TransactionCompleteResult implements TransactionResult {
|
||||
tx.getTransaction().getMaxPriorityFeePerGas().map(q -> q.toShortHexString()).orElse(null);
|
||||
this.maxFeePerGas =
|
||||
tx.getTransaction().getMaxFeePerGas().map(q -> q.toShortHexString()).orElse(null);
|
||||
this.gasPrice = Quantity.create(transaction.getGasPrice());
|
||||
this.gasPrice = transaction.getGasPrice().map(Quantity::create).orElse(null);
|
||||
this.hash = transaction.getHash().toString();
|
||||
this.input = transaction.getPayload().toString();
|
||||
this.nonce = Quantity.create(transaction.getNonce());
|
||||
|
||||
@@ -83,7 +83,7 @@ public class TransactionPendingResult implements TransactionResult {
|
||||
this.chainId = transaction.getChainId().map(Quantity::create).orElse(null);
|
||||
this.from = transaction.getSender().toString();
|
||||
this.gas = Quantity.create(transaction.getGasLimit());
|
||||
this.gasPrice = Quantity.create(transaction.getGasPrice());
|
||||
this.gasPrice = transaction.getGasPrice().map(Quantity::create).orElse(null);
|
||||
this.maxPriorityFeePerGas =
|
||||
transaction.getMaxPriorityFeePerGas().map(q -> q.toHexString()).orElse(null);
|
||||
this.maxFeePerGas = transaction.getMaxFeePerGas().map(q -> q.toHexString()).orElse(null);
|
||||
|
||||
@@ -67,7 +67,8 @@ public class PendingTransactionFilter {
|
||||
isValid = validateTo(transactionInfo, predicate, value);
|
||||
break;
|
||||
case GAS_PRICE_FIELD:
|
||||
isValid = validateWei(transactionInfo.getTransaction().getGasPrice(), predicate, value);
|
||||
isValid =
|
||||
validateWei(transactionInfo.getTransaction().getGasPrice().get(), predicate, value);
|
||||
break;
|
||||
case GAS_FIELD:
|
||||
isValid =
|
||||
|
||||
@@ -51,7 +51,7 @@ public class PendingTransactionDetailResult implements JsonRpcResult {
|
||||
public PendingTransactionDetailResult(final Transaction tx) {
|
||||
this.from = tx.getSender().toString();
|
||||
this.gas = Quantity.create(tx.getGasLimit());
|
||||
this.gasPrice = Quantity.create(tx.getGasPrice());
|
||||
this.gasPrice = tx.getGasPrice().map(Quantity::create).orElse(null);
|
||||
this.hash = tx.getHash().toString();
|
||||
this.input = tx.getPayload().toString();
|
||||
this.nonce = Quantity.create(tx.getNonce());
|
||||
|
||||
@@ -820,7 +820,8 @@ public class BlockchainQueries {
|
||||
.orElseThrow(
|
||||
() -> new IllegalStateException("Could not retrieve block #" + l)))
|
||||
.flatMap(Collection::stream)
|
||||
.mapToLong(t -> t.getGasPrice().toLong())
|
||||
.filter(t -> t.getGasPrice().isPresent())
|
||||
.mapToLong(t -> t.getGasPrice().get().toLong())
|
||||
.sorted()
|
||||
.toArray();
|
||||
return (gasCollection == null || gasCollection.length == 0)
|
||||
|
||||
@@ -1700,7 +1700,7 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
|
||||
}
|
||||
assertThat(Wei.fromHexString(result.getString("value"))).isEqualTo(transaction.getValue());
|
||||
assertThat(Wei.fromHexString(result.getString("gasPrice")))
|
||||
.isEqualTo(transaction.getGasPrice());
|
||||
.isEqualTo(transaction.getGasPrice().get());
|
||||
assertThat(Long.decode(result.getString("gas"))).isEqualTo(transaction.getGasLimit());
|
||||
assertThat(Bytes.fromHexString(result.getString("input"))).isEqualTo(transaction.getPayload());
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class SimpleTestTransactionBuilder {
|
||||
|
||||
final Transaction transaction = mock(Transaction.class);
|
||||
when(transaction.getHash()).thenReturn(blockHash);
|
||||
when(transaction.getGasPrice()).thenReturn(Wei.fromHexString(gasPrice));
|
||||
when(transaction.getGasPrice()).thenReturn(Optional.of(Wei.fromHexString(gasPrice)));
|
||||
when(transaction.getNonce()).thenReturn(unsignedLong(nonce));
|
||||
when(transaction.getV()).thenReturn(bigInteger(v));
|
||||
when(transaction.getR()).thenReturn(bigInteger(r));
|
||||
|
||||
@@ -128,7 +128,7 @@ public class PendingTransactionFilterTest {
|
||||
final int numberTrx = 5;
|
||||
for (int i = 1; i < numberTrx; i++) {
|
||||
Transaction transaction = mock(Transaction.class);
|
||||
when(transaction.getGasPrice()).thenReturn(Wei.of(i));
|
||||
when(transaction.getGasPrice()).thenReturn(Optional.of(Wei.of(i)));
|
||||
when(transaction.getValue()).thenReturn(Wei.of(i));
|
||||
when(transaction.getGasLimit()).thenReturn((long) i);
|
||||
when(transaction.getNonce()).thenReturn((long) i);
|
||||
|
||||
@@ -32,9 +32,11 @@ import org.hyperledger.besu.plugin.data.Quantity;
|
||||
import org.hyperledger.besu.plugin.data.TransactionType;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
@@ -61,11 +63,11 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
|
||||
|
||||
private final long nonce;
|
||||
|
||||
private final Wei gasPrice;
|
||||
private final Optional<Wei> gasPrice;
|
||||
|
||||
private final Wei maxPriorityFeePerGas;
|
||||
private final Optional<Wei> maxPriorityFeePerGas;
|
||||
|
||||
private final Wei maxFeePerGas;
|
||||
private final Optional<Wei> maxFeePerGas;
|
||||
|
||||
private final long gasLimit;
|
||||
|
||||
@@ -134,9 +136,9 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
|
||||
public Transaction(
|
||||
final TransactionType transactionType,
|
||||
final long nonce,
|
||||
final Wei gasPrice,
|
||||
final Wei maxPriorityFeePerGas,
|
||||
final Wei maxFeePerGas,
|
||||
final Optional<Wei> gasPrice,
|
||||
final Optional<Wei> maxPriorityFeePerGas,
|
||||
final Optional<Wei> maxFeePerGas,
|
||||
final long gasLimit,
|
||||
final Optional<Address> to,
|
||||
final Wei value,
|
||||
@@ -185,9 +187,9 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
|
||||
|
||||
public Transaction(
|
||||
final long nonce,
|
||||
final Wei gasPrice,
|
||||
final Wei maxPriorityFeePerGas,
|
||||
final Wei maxFeePerGas,
|
||||
final Optional<Wei> gasPrice,
|
||||
final Optional<Wei> maxPriorityFeePerGas,
|
||||
final Optional<Wei> maxFeePerGas,
|
||||
final long gasLimit,
|
||||
final Optional<Address> to,
|
||||
final Wei value,
|
||||
@@ -242,9 +244,9 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
|
||||
final Optional<BigInteger> chainId) {
|
||||
this(
|
||||
nonce,
|
||||
gasPrice,
|
||||
null,
|
||||
null,
|
||||
Optional.of(gasPrice),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
gasLimit,
|
||||
to,
|
||||
value,
|
||||
@@ -284,7 +286,19 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
|
||||
final Address sender,
|
||||
final Optional<BigInteger> chainId,
|
||||
final Optional<BigInteger> v) {
|
||||
this(nonce, gasPrice, null, null, gasLimit, to, value, signature, payload, sender, chainId, v);
|
||||
this(
|
||||
nonce,
|
||||
Optional.of(gasPrice),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
gasLimit,
|
||||
to,
|
||||
value,
|
||||
signature,
|
||||
payload,
|
||||
sender,
|
||||
chainId,
|
||||
v);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,7 +317,7 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
|
||||
* @return the transaction gas price
|
||||
*/
|
||||
@Override
|
||||
public Wei getGasPrice() {
|
||||
public Optional<Wei> getGasPrice() {
|
||||
return gasPrice;
|
||||
}
|
||||
|
||||
@@ -313,8 +327,8 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
|
||||
* @return the transaction max priority per gas
|
||||
*/
|
||||
@Override
|
||||
public Optional<Quantity> getMaxPriorityFeePerGas() {
|
||||
return Optional.ofNullable(maxPriorityFeePerGas);
|
||||
public Optional<Wei> getMaxPriorityFeePerGas() {
|
||||
return maxPriorityFeePerGas;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -323,8 +337,23 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
|
||||
* @return the transaction max fee per gas
|
||||
*/
|
||||
@Override
|
||||
public Optional<Quantity> getMaxFeePerGas() {
|
||||
return Optional.ofNullable(maxFeePerGas);
|
||||
public Optional<Wei> getMaxFeePerGas() {
|
||||
return maxFeePerGas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Boolean which indicates the transaction has associated cost data, whether gas price or 1559 fee
|
||||
* market parameters.
|
||||
*
|
||||
* @return whether cost params are presetn
|
||||
*/
|
||||
public boolean hasCostParams() {
|
||||
return Arrays.asList(getGasPrice(), getMaxFeePerGas(), getMaxPriorityFeePerGas()).stream()
|
||||
.flatMap(Optional::stream)
|
||||
.map(Quantity::getAsBigInteger)
|
||||
.filter(q -> q.longValue() > 0L)
|
||||
.findAny()
|
||||
.isPresent();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -453,9 +482,9 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
|
||||
computeSenderRecoveryHash(
|
||||
transactionType,
|
||||
nonce,
|
||||
gasPrice,
|
||||
maxPriorityFeePerGas,
|
||||
maxFeePerGas,
|
||||
gasPrice.orElse(null),
|
||||
maxPriorityFeePerGas.orElse(null),
|
||||
maxFeePerGas.orElse(null),
|
||||
gasLimit,
|
||||
to,
|
||||
value,
|
||||
@@ -533,7 +562,13 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
|
||||
* @return the up-front cost for the gas the transaction can use.
|
||||
*/
|
||||
public Wei getUpfrontGasCost() {
|
||||
return getUpfrontGasCost((Wei.of(getMaxFeePerGas().orElse(getGasPrice()).getAsBigInteger())));
|
||||
return getUpfrontGasCost(
|
||||
Stream.concat(maxFeePerGas.stream(), gasPrice.stream())
|
||||
.findFirst()
|
||||
.orElseThrow(
|
||||
() ->
|
||||
new IllegalStateException(
|
||||
String.format("Transaction requires either gasPrice or maxFeePerGas"))));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -752,10 +787,16 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
|
||||
sb.append(isContractCreation() ? "ContractCreation" : "MessageCall").append("{");
|
||||
sb.append("type=").append(getType()).append(", ");
|
||||
sb.append("nonce=").append(getNonce()).append(", ");
|
||||
sb.append("gasPrice=").append(getGasPrice()).append(", ");
|
||||
getGasPrice()
|
||||
.ifPresent(
|
||||
gasPrice -> sb.append("gasPrice=").append(gasPrice.toShortHexString()).append(", "));
|
||||
if (getMaxPriorityFeePerGas().isPresent() && getMaxFeePerGas().isPresent()) {
|
||||
sb.append("maxPriorityFeePerGas=").append(getMaxPriorityFeePerGas()).append(", ");
|
||||
sb.append("maxFeePerGas=").append(getMaxFeePerGas()).append(", ");
|
||||
sb.append("maxPriorityFeePerGas=")
|
||||
.append(getMaxPriorityFeePerGas().map(Wei::toShortHexString).get())
|
||||
.append(", ");
|
||||
sb.append("maxFeePerGas=")
|
||||
.append(getMaxFeePerGas().map(Wei::toShortHexString).get())
|
||||
.append(", ");
|
||||
}
|
||||
sb.append("gasLimit=").append(getGasLimit()).append(", ");
|
||||
if (getTo().isPresent()) sb.append("to=").append(getTo().get()).append(", ");
|
||||
@@ -897,9 +938,9 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
|
||||
return new Transaction(
|
||||
transactionType,
|
||||
nonce,
|
||||
gasPrice,
|
||||
maxPriorityFeePerGas,
|
||||
maxFeePerGas,
|
||||
Optional.ofNullable(gasPrice),
|
||||
Optional.ofNullable(maxPriorityFeePerGas),
|
||||
Optional.ofNullable(maxFeePerGas),
|
||||
gasLimit,
|
||||
to,
|
||||
value,
|
||||
@@ -950,7 +991,7 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
|
||||
* @param baseFeePerGas optional baseFee from the block header, if we are post-london
|
||||
* @return the effective gas price.
|
||||
*/
|
||||
public final BigInteger calcEffectiveGas(final Optional<Long> baseFeePerGas) {
|
||||
public final Wei calcEffectiveGas(final Optional<Long> baseFeePerGas) {
|
||||
return baseFeePerGas
|
||||
.filter(fee -> getType().supports1559FeeMarket())
|
||||
.map(BigInteger::valueOf)
|
||||
@@ -965,6 +1006,7 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
|
||||
.map(
|
||||
maxPriorityFeePerGas ->
|
||||
baseFee.add(maxPriorityFeePerGas).min(maxFeePerGas))))
|
||||
.orElse(getGasPrice().getAsBigInteger());
|
||||
.map(Wei::ofNumber)
|
||||
.orElse(getGasPrice().get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.hyperledger.besu.ethereum.core.Transaction;
|
||||
import org.hyperledger.besu.ethereum.core.Wei;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLP;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLPOutput;
|
||||
import org.hyperledger.besu.plugin.data.Quantity;
|
||||
import org.hyperledger.besu.plugin.data.TransactionType;
|
||||
|
||||
import java.math.BigInteger;
|
||||
@@ -78,7 +77,7 @@ public class TransactionEncoder {
|
||||
static void encodeFrontier(final Transaction transaction, final RLPOutput out) {
|
||||
out.startList();
|
||||
out.writeLongScalar(transaction.getNonce());
|
||||
out.writeUInt256Scalar(transaction.getGasPrice());
|
||||
out.writeUInt256Scalar(transaction.getGasPrice().orElseThrow());
|
||||
out.writeLongScalar(transaction.getGasLimit());
|
||||
out.writeBytes(transaction.getTo().map(Bytes::copy).orElse(Bytes.EMPTY));
|
||||
out.writeUInt256Scalar(transaction.getValue());
|
||||
@@ -92,7 +91,7 @@ public class TransactionEncoder {
|
||||
encodeAccessListInner(
|
||||
transaction.getChainId(),
|
||||
transaction.getNonce(),
|
||||
transaction.getGasPrice(),
|
||||
transaction.getGasPrice().orElseThrow(),
|
||||
transaction.getGasLimit(),
|
||||
transaction.getTo(),
|
||||
transaction.getValue(),
|
||||
@@ -149,14 +148,8 @@ public class TransactionEncoder {
|
||||
out.startList();
|
||||
out.writeLongScalar(transaction.getChainId().orElseThrow().longValue());
|
||||
out.writeLongScalar(transaction.getNonce());
|
||||
out.writeUInt256Scalar(
|
||||
transaction
|
||||
.getMaxPriorityFeePerGas()
|
||||
.map(Quantity::getValue)
|
||||
.map(Wei::ofNumber)
|
||||
.orElseThrow());
|
||||
out.writeUInt256Scalar(
|
||||
transaction.getMaxFeePerGas().map(Quantity::getValue).map(Wei::ofNumber).orElseThrow());
|
||||
out.writeUInt256Scalar(transaction.getMaxPriorityFeePerGas().orElseThrow());
|
||||
out.writeUInt256Scalar(transaction.getMaxFeePerGas().orElseThrow());
|
||||
out.writeLongScalar(transaction.getGasLimit());
|
||||
out.writeBytes(transaction.getTo().map(Bytes::copy).orElse(Bytes.EMPTY));
|
||||
out.writeUInt256Scalar(transaction.getValue());
|
||||
|
||||
@@ -17,7 +17,6 @@ package org.hyperledger.besu.ethereum.core.fees;
|
||||
import org.hyperledger.besu.ethereum.core.Transaction;
|
||||
import org.hyperledger.besu.ethereum.core.Wei;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Optional;
|
||||
|
||||
@FunctionalInterface
|
||||
@@ -25,19 +24,17 @@ public interface TransactionPriceCalculator {
|
||||
Wei price(Transaction transaction, Optional<Long> baseFee);
|
||||
|
||||
static TransactionPriceCalculator frontier() {
|
||||
return (transaction, baseFee) -> transaction.getGasPrice();
|
||||
return (transaction, baseFee) -> transaction.getGasPrice().get();
|
||||
}
|
||||
|
||||
static TransactionPriceCalculator eip1559() {
|
||||
return (transaction, maybeBaseFee) -> {
|
||||
final Wei baseFee = Wei.of(maybeBaseFee.orElseThrow());
|
||||
if (!transaction.getType().supports1559FeeMarket()) {
|
||||
return transaction.getGasPrice();
|
||||
return transaction.getGasPrice().get();
|
||||
}
|
||||
final Wei maxPriorityFeePerGas =
|
||||
Wei.of((BigInteger) transaction.getMaxPriorityFeePerGas().orElseThrow().getValue());
|
||||
final Wei maxFeePerGas =
|
||||
Wei.of((BigInteger) transaction.getMaxFeePerGas().orElseThrow().getValue());
|
||||
final Wei maxPriorityFeePerGas = transaction.getMaxPriorityFeePerGas().orElseThrow();
|
||||
final Wei maxFeePerGas = transaction.getMaxFeePerGas().orElseThrow();
|
||||
Wei price = maxPriorityFeePerGas.add(baseFee);
|
||||
if (price.compareTo(maxFeePerGas) > 0) {
|
||||
price = maxFeePerGas;
|
||||
|
||||
@@ -269,7 +269,7 @@ public class GoQuorumBlockProcessor extends MainnetBlockProcessor {
|
||||
|
||||
return new Transaction(
|
||||
transaction.getNonce(),
|
||||
transaction.getGasPrice(),
|
||||
transaction.getGasPrice().get(),
|
||||
transaction.getGasLimit(),
|
||||
transaction.getTo(),
|
||||
transaction.getValue(),
|
||||
|
||||
@@ -112,7 +112,7 @@ public class MainnetTransactionValidator {
|
||||
return signatureResult;
|
||||
}
|
||||
|
||||
if (goQuorumCompatibilityMode && !transaction.getGasPrice().isZero()) {
|
||||
if (goQuorumCompatibilityMode && transaction.hasCostParams()) {
|
||||
return ValidationResult.invalid(
|
||||
TransactionInvalidReason.GAS_PRICE_MUST_BE_ZERO,
|
||||
"gasPrice must be set to zero on a GoQuorum compatible network");
|
||||
|
||||
@@ -79,7 +79,7 @@ public class TestCodeExecutor {
|
||||
.originator(SENDER_ADDRESS)
|
||||
.contract(SENDER_ADDRESS)
|
||||
.contractAccountVersion(accountVersion)
|
||||
.gasPrice(transaction.getGasPrice())
|
||||
.gasPrice(transaction.getGasPrice().get())
|
||||
.inputData(transaction.getPayload())
|
||||
.sender(SENDER_ADDRESS)
|
||||
.value(transaction.getValue())
|
||||
|
||||
@@ -52,6 +52,7 @@ public class TransactionGoQuorumTest {
|
||||
public void givenPublicTransaction_assertThatIsGoQuorumFlagIsFalse() {
|
||||
final Transaction transaction = Transaction.readFrom(ETHEREUM_PUBLIC_TX_RLP);
|
||||
assertThat(transaction.isGoQuorumPrivateTransaction()).isFalse();
|
||||
assertThat(transaction.hasCostParams()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,6 +61,7 @@ public class TransactionGoQuorumTest {
|
||||
|
||||
assertThat(transaction.getV()).isEqualTo(37);
|
||||
assertThat(transaction.isGoQuorumPrivateTransaction()).isTrue();
|
||||
assertThat(transaction.hasCostParams()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,6 +70,7 @@ public class TransactionGoQuorumTest {
|
||||
|
||||
assertThat(transaction.getV()).isEqualTo(38);
|
||||
assertThat(transaction.isGoQuorumPrivateTransaction()).isTrue();
|
||||
assertThat(transaction.hasCostParams()).isFalse();
|
||||
}
|
||||
|
||||
private static RLPInput toRLP(final String bytes) {
|
||||
|
||||
@@ -58,7 +58,7 @@ public class TransactionDecoderTest {
|
||||
final Transaction transaction =
|
||||
TransactionDecoder.decodeForWire(RLP.input(Bytes.fromHexString(FRONTIER_TX_RLP)));
|
||||
assertThat(transaction).isNotNull();
|
||||
assertThat(transaction.getGasPrice()).isEqualByComparingTo(Wei.of(50L));
|
||||
assertThat(transaction.getGasPrice().get()).isEqualByComparingTo(Wei.of(50L));
|
||||
assertThat(transaction.getMaxPriorityFeePerGas()).isEmpty();
|
||||
assertThat(transaction.getMaxFeePerGas()).isEmpty();
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class FixedKeySigningPrivateMarkerTransactionFactoryTest {
|
||||
|
||||
assertThat(transaction.getNonce()).isEqualTo(providedNonce);
|
||||
assertThat(transaction.getGasLimit()).isEqualTo(privTransaction.getGasLimit());
|
||||
assertThat(transaction.getGasPrice()).isEqualTo(privTransaction.getGasPrice());
|
||||
assertThat(transaction.getGasPrice().get()).isEqualTo(privTransaction.getGasPrice());
|
||||
assertThat(transaction.getValue()).isEqualTo(privTransaction.getValue());
|
||||
assertThat(transaction.getSender())
|
||||
.isEqualTo(Util.publicKeyToAddress(signingKeys.getPublicKey()));
|
||||
|
||||
@@ -57,7 +57,7 @@ public class RandomSigningPrivateMarkerTransactionFactoryTest {
|
||||
|
||||
assertThat(transaction.getNonce()).isEqualTo(0);
|
||||
assertThat(transaction.getGasLimit()).isEqualTo(privTransaction.getGasLimit());
|
||||
assertThat(transaction.getGasPrice()).isEqualTo(privTransaction.getGasPrice());
|
||||
assertThat(transaction.getGasPrice().get()).isEqualTo(privTransaction.getGasPrice());
|
||||
assertThat(transaction.getValue()).isEqualTo(privTransaction.getValue());
|
||||
assertThat(transaction.getTo()).isEqualTo(Optional.of(precompiledAddress));
|
||||
assertThat(transaction.getPayload())
|
||||
|
||||
@@ -429,7 +429,7 @@ public class PendingTransactions {
|
||||
transaction.getMaxFeePerGas().get().getValue().longValue() - curBaseFee.orElse(0L));
|
||||
} else {
|
||||
maybeNegativePriorityFeePerGas =
|
||||
transaction.getGasPrice().getValue().longValue() - curBaseFee.orElse(0L);
|
||||
transaction.getGasPrice().get().getValue().longValue() - curBaseFee.orElse(0L);
|
||||
}
|
||||
return maybeNegativePriorityFeePerGas;
|
||||
}
|
||||
@@ -602,10 +602,7 @@ public class PendingTransactions {
|
||||
}
|
||||
|
||||
public Wei getGasPrice() {
|
||||
if (transaction.getGasPrice() == null) {
|
||||
return Wei.ZERO;
|
||||
}
|
||||
return transaction.getGasPrice();
|
||||
return transaction.getGasPrice().orElse(Wei.ZERO);
|
||||
}
|
||||
|
||||
public long getSequence() {
|
||||
|
||||
@@ -91,7 +91,7 @@ public class TransactionReplacementByPriceRuleTest {
|
||||
final TransactionInfo transactionInfo = mock(TransactionInfo.class);
|
||||
final Transaction transaction = mock(Transaction.class);
|
||||
when(transaction.getType()).thenReturn(TransactionType.FRONTIER);
|
||||
when(transaction.getGasPrice()).thenReturn(Wei.of(price));
|
||||
when(transaction.getGasPrice()).thenReturn(Optional.of(Wei.of(price)));
|
||||
when(transactionInfo.getTransaction()).thenReturn(transaction);
|
||||
return transactionInfo;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFac
|
||||
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
|
||||
import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator;
|
||||
import org.hyperledger.besu.ethereum.core.Block;
|
||||
import org.hyperledger.besu.ethereum.core.Transaction;
|
||||
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
|
||||
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState;
|
||||
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
|
||||
@@ -439,8 +438,8 @@ public class EthStatsService {
|
||||
// retrieves transactions from the last blocks and takes the lowest gas price. If no transaction
|
||||
// is present we return the minTransactionGasPrice of the mining coordinator
|
||||
return block.getBody().getTransactions().stream()
|
||||
.min(Comparator.comparing(Transaction::getGasPrice))
|
||||
.map(Transaction::getGasPrice)
|
||||
.min(Comparator.comparing(t -> t.calcEffectiveGas(block.getHeader().getBaseFee())))
|
||||
.map(t -> t.calcEffectiveGas(block.getHeader().getBaseFee()))
|
||||
.filter(wei -> wei.getValue().longValue() > 0)
|
||||
.orElse(miningCoordinator.getMinTransactionGasPrice())
|
||||
.getValue()
|
||||
|
||||
@@ -33,6 +33,8 @@ import java.util.Optional;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
import org.apache.tuweni.units.bigints.BaseUInt256Value;
|
||||
|
||||
/**
|
||||
* Controller that can read from a smart contract that exposes the permissioning call
|
||||
@@ -194,7 +196,7 @@ public class TransactionSmartContractPermissioningController
|
||||
encodeAddress(transaction.getSender()),
|
||||
encodeAddress(transaction.getTo()),
|
||||
transaction.getValue().toBytes(),
|
||||
transaction.getGasPrice().toBytes(),
|
||||
transaction.getGasPrice().map(BaseUInt256Value::toBytes).orElse(Bytes32.ZERO),
|
||||
encodeLong(transaction.getGasLimit()),
|
||||
encodeBytes(transaction.getPayload()));
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ Calculated : ${currentHash}
|
||||
tasks.register('checkAPIChanges', FileStateChecker) {
|
||||
description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
|
||||
files = sourceSets.main.allJava.files
|
||||
knownHash = 'U0V/Yrf6sGuSSgCu/T8GwhiEkABioLF+hb311yeSH9I='
|
||||
knownHash = 'ZkGZQLEzSBKfKu/imY+u5pYWAtWGXzlXSWlUAsvjZ9g='
|
||||
}
|
||||
check.dependsOn('checkAPIChanges')
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public interface Transaction {
|
||||
*
|
||||
* @return the quantity of Wei per gas unit paid.
|
||||
*/
|
||||
Quantity getGasPrice();
|
||||
Optional<? extends Quantity> getGasPrice();
|
||||
|
||||
/**
|
||||
* A scalar value equal to the number of Wei to be paid on top of base fee, as specified in
|
||||
@@ -62,7 +62,7 @@ public interface Transaction {
|
||||
* @return the quantity of Wei for max fee per gas
|
||||
*/
|
||||
@Unstable
|
||||
default Optional<Quantity> getMaxPriorityFeePerGas() {
|
||||
default Optional<? extends Quantity> getMaxPriorityFeePerGas() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public interface Transaction {
|
||||
* @return the quantity of Wei for fee cap.
|
||||
*/
|
||||
@Unstable
|
||||
default Optional<Quantity> getMaxFeePerGas() {
|
||||
default Optional<? extends Quantity> getMaxFeePerGas() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user