update json-rpc responses for 1559 (#2222)

* address assumption that if 1559 is enabled there is a london fork block config
fixes #2192

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

* omit null chainId from transaction json serialization, and fix merge regression

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

* update json-rpc responses for 1559, use current feeCap and gasPremium field names

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

* add pr number to changelog

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

* fix transaction decoder

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

* rebase and fix merge conflicts

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

* remove null chainId from json-rpc test fixtures

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

* the great 1559 rename

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

* re-remove gasTarget

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

* add serialization tests for 1559 transaction fields

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

* add json property ordering annotations to Transaction*Result and spotless

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

* rebase on master, update error message feedback from Karim

Signed-off-by: garyschulte <garyschulte@gmail.com>
pull/2290/head
garyschulte 4 years ago committed by GitHub
parent 09a49cfd2d
commit a9dcd5bb5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java
  3. 5
      config/src/test/java/org/hyperledger/besu/config/GenesisConfigFileTest.java
  4. 8
      config/src/test/java/org/hyperledger/besu/config/GenesisConfigOptionsTest.java
  5. 6
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java
  6. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java
  7. 8
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java
  8. 1
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResult.java
  9. 28
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionCompleteResult.java
  10. 24
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionPendingResult.java
  11. 7
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtils.java
  12. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java
  13. 15
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionCompleteResultTest.java
  14. 1
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockByNumber_complete.json
  15. 1
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockHashAndIndex_00.json
  16. 1
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockHashAndIndex_01.json
  17. 1
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockHashAndIndex_02.json
  18. 1
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockNumberAndIndex_00.json
  19. 1
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockNumberAndIndex_01.json
  20. 1
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockNumberAndIndex_latest.json
  21. 1
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockNumberAndIndex_pending.json
  22. 1
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByHash_addressReceiver.json
  23. 1
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByHash_contractCreation.json
  24. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java
  25. 110
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java
  26. 6
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoder.java
  27. 8
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionEncoder.java
  28. 13
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/fees/TransactionPriceCalculator.java
  29. 31
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/CallParameter.java
  30. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java
  31. 4
      ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockDataGenerator.java
  32. 16
      ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/TransactionTestFixture.java
  33. 2
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionBuilderTest.java
  34. 4
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionEIP1559Test.java
  35. 8
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoderTest.java
  36. 18
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/fees/TransactionPriceCalculatorTest.java
  37. 12
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidatorTest.java
  38. 4
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java
  39. 8
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionReplacementByPriceRuleTest.java
  40. 1
      ethereum/permissioning/build.gradle
  41. 2
      ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java
  42. 1
      ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestSetChainParams.java
  43. 2
      ethereum/retesteth/src/test/resources/org/hyperledger/besu/ethereum/retesteth/methods/1559ChainParams.json
  44. 2
      plugin-api/build.gradle
  45. 6
      plugin-api/src/main/java/org/hyperledger/besu/plugin/data/Transaction.java

@ -14,6 +14,7 @@
- Added ACCESS_LIST transactions to the list of transactions using legacy gas pricing for 1559 [\#2239](https://github.com/hyperledger/besu/pull/2239) - Added ACCESS_LIST transactions to the list of transactions using legacy gas pricing for 1559 [\#2239](https://github.com/hyperledger/besu/pull/2239)
- Reduced logging level of public key decoding failure of malformed packets. [\#2143](https://github.com/hyperledger/besu/pull/2143) - Reduced logging level of public key decoding failure of malformed packets. [\#2143](https://github.com/hyperledger/besu/pull/2143)
- Add 1559 parameters to json-rpc responses. [\#2222](https://github.com/hyperledger/besu/pull/2222)
### Early Access Features ### Early Access Features

@ -76,7 +76,7 @@ public interface GenesisConfigOptions {
OptionalLong getEIP1559BlockNumber(); OptionalLong getEIP1559BlockNumber();
default Optional<Long> getGenesisBaseFee() { default Optional<Long> getGenesisBaseFeePerGas() {
return getEIP1559BlockNumber().stream() return getEIP1559BlockNumber().stream()
.boxed() .boxed()
.filter(g -> g.equals(0L)) .filter(g -> g.equals(0L))

@ -102,11 +102,6 @@ public class GenesisConfigFileTest {
assertThat(configWithProperty("gasLimit", "1000").getGasLimit()).isEqualTo(1000); assertThat(configWithProperty("gasLimit", "1000").getGasLimit()).isEqualTo(1000);
} }
@Test
public void shouldGetGasTarget() {
assertThat(configWithProperty("gasTarget", "9999").getGasLimit()).isEqualTo(9999);
}
@Test @Test
public void shouldRequireGasLimit() { public void shouldRequireGasLimit() {
assertInvalidConfiguration(EMPTY_CONFIG::getGasLimit); assertInvalidConfiguration(EMPTY_CONFIG::getGasLimit);

@ -187,7 +187,7 @@ public class GenesisConfigOptionsTest {
final GenesisConfigOptions config = fromConfigOptions(singletonMap("londonblock", 1000)); final GenesisConfigOptions config = fromConfigOptions(singletonMap("londonblock", 1000));
assertThat(config.getEIP1559BlockNumber()).hasValue(1000); assertThat(config.getEIP1559BlockNumber()).hasValue(1000);
assertThat(config.getLondonBlockNumber()).hasValue(1000); assertThat(config.getLondonBlockNumber()).hasValue(1000);
assertThat(config.getGenesisBaseFee()).isEmpty(); assertThat(config.getGenesisBaseFeePerGas()).isEmpty();
} finally { } finally {
ExperimentalEIPs.eip1559Enabled = ExperimentalEIPs.EIP1559_ENABLED_DEFAULT_VALUE; ExperimentalEIPs.eip1559Enabled = ExperimentalEIPs.EIP1559_ENABLED_DEFAULT_VALUE;
} }
@ -200,7 +200,7 @@ public class GenesisConfigOptionsTest {
final GenesisConfigOptions config = fromConfigOptions(singletonMap("baikalblock", 1000)); final GenesisConfigOptions config = fromConfigOptions(singletonMap("baikalblock", 1000));
assertThat(config.getEIP1559BlockNumber()).hasValue(1000); assertThat(config.getEIP1559BlockNumber()).hasValue(1000);
assertThat(config.getLondonBlockNumber()).hasValue(1000); assertThat(config.getLondonBlockNumber()).hasValue(1000);
assertThat(config.getGenesisBaseFee()).isEmpty(); assertThat(config.getGenesisBaseFeePerGas()).isEmpty();
} finally { } finally {
ExperimentalEIPs.eip1559Enabled = ExperimentalEIPs.EIP1559_ENABLED_DEFAULT_VALUE; ExperimentalEIPs.eip1559Enabled = ExperimentalEIPs.EIP1559_ENABLED_DEFAULT_VALUE;
} }
@ -214,7 +214,7 @@ public class GenesisConfigOptionsTest {
final GenesisConfigOptions config = fromConfigOptions(singletonMap("aleutblock", 1000)); final GenesisConfigOptions config = fromConfigOptions(singletonMap("aleutblock", 1000));
assertThat(config.getEIP1559BlockNumber()).hasValue(1000); assertThat(config.getEIP1559BlockNumber()).hasValue(1000);
assertThat(config.getAleutBlockNumber()).hasValue(1000); assertThat(config.getAleutBlockNumber()).hasValue(1000);
assertThat(config.getGenesisBaseFee()).isEmpty(); assertThat(config.getGenesisBaseFeePerGas()).isEmpty();
} finally { } finally {
ExperimentalEIPs.eip1559Enabled = ExperimentalEIPs.EIP1559_ENABLED_DEFAULT_VALUE; ExperimentalEIPs.eip1559Enabled = ExperimentalEIPs.EIP1559_ENABLED_DEFAULT_VALUE;
} }
@ -227,7 +227,7 @@ public class GenesisConfigOptionsTest {
ExperimentalEIPs.eip1559Enabled = true; ExperimentalEIPs.eip1559Enabled = true;
final GenesisConfigOptions config = fromConfigOptions(singletonMap("londonblock", 0)); final GenesisConfigOptions config = fromConfigOptions(singletonMap("londonblock", 0));
assertThat(config.getEIP1559BlockNumber()).hasValue(0); assertThat(config.getEIP1559BlockNumber()).hasValue(0);
assertThat(config.getGenesisBaseFee()) assertThat(config.getGenesisBaseFeePerGas())
.hasValue(ExperimentalEIPs.EIP1559_BASEFEE_DEFAULT_VALUE); .hasValue(ExperimentalEIPs.EIP1559_BASEFEE_DEFAULT_VALUE);
} finally { } finally {
ExperimentalEIPs.eip1559Enabled = ExperimentalEIPs.EIP1559_ENABLED_DEFAULT_VALUE; ExperimentalEIPs.eip1559Enabled = ExperimentalEIPs.EIP1559_ENABLED_DEFAULT_VALUE;

@ -127,8 +127,10 @@ public class EthCall extends AbstractBlockParameterOrBlockHashMethod {
throw new InvalidJsonRpcParameters("Missing \"to\" field in call arguments"); throw new InvalidJsonRpcParameters("Missing \"to\" field in call arguments");
} }
if (callParams.getGasPrice() != null if (callParams.getGasPrice() != null
&& (callParams.getFeeCap().isPresent() || callParams.getGasPremium().isPresent())) { && (callParams.getMaxFeePerGas().isPresent()
throw new InvalidJsonRpcParameters("gasPrice cannot be used with baseFee or feeCap"); || callParams.getMaxPriorityFeePerGas().isPresent())) {
throw new InvalidJsonRpcParameters(
"gasPrice cannot be used with maxFeePerGas or maxPriorityFeePerGas");
} }
return callParams; return callParams;
} }

@ -102,8 +102,8 @@ public class EthEstimateGas implements JsonRpcMethod {
callParams.getTo(), callParams.getTo(),
gasLimit, gasLimit,
Optional.ofNullable(callParams.getGasPrice()).orElse(Wei.ZERO), Optional.ofNullable(callParams.getGasPrice()).orElse(Wei.ZERO),
callParams.getGasPremium(), callParams.getMaxPriorityFeePerGas(),
callParams.getFeeCap(), callParams.getMaxFeePerGas(),
callParams.getValue(), callParams.getValue(),
callParams.getPayload()); callParams.getPayload());
} }
@ -167,8 +167,9 @@ public class EthEstimateGas implements JsonRpcMethod {
private JsonCallParameter validateAndGetCallParams(final JsonRpcRequestContext request) { private JsonCallParameter validateAndGetCallParams(final JsonRpcRequestContext request) {
final JsonCallParameter callParams = request.getRequiredParameter(0, JsonCallParameter.class); final JsonCallParameter callParams = request.getRequiredParameter(0, JsonCallParameter.class);
if (callParams.getGasPrice() != null if (callParams.getGasPrice() != null
&& (callParams.getFeeCap().isPresent() || callParams.getGasPremium().isPresent())) { && (callParams.getMaxFeePerGas().isPresent()
throw new InvalidJsonRpcParameters("gasPrice cannot be used with baseFee or feeCap"); || callParams.getMaxPriorityFeePerGas().isPresent())) {
throw new InvalidJsonRpcParameters("gasPrice cannot be used with baseFee or maxFeePerGas");
} }
return callParams; return callParams;
} }

@ -42,8 +42,8 @@ public class JsonCallParameter extends CallParameter {
@JsonProperty("to") final Address to, @JsonProperty("to") final Address to,
@JsonDeserialize(using = GasDeserializer.class) @JsonProperty("gas") final Gas gasLimit, @JsonDeserialize(using = GasDeserializer.class) @JsonProperty("gas") final Gas gasLimit,
@JsonProperty("gasPrice") final Wei gasPrice, @JsonProperty("gasPrice") final Wei gasPrice,
@JsonProperty("gasPremium") final Wei gasPremium, @JsonProperty("maxPriorityFeePerGas") final Wei maxPriorityFeePerGas,
@JsonProperty("feeCap") final Wei feeCap, @JsonProperty("maxFeePerGas") final Wei maxFeePerGas,
@JsonProperty("value") final Wei value, @JsonProperty("value") final Wei value,
@JsonDeserialize(using = HexStringDeserializer.class) @JsonProperty("data") @JsonDeserialize(using = HexStringDeserializer.class) @JsonProperty("data")
final Bytes payload, final Bytes payload,
@ -53,8 +53,8 @@ public class JsonCallParameter extends CallParameter {
to, to,
gasLimit != null ? gasLimit.toLong() : -1, gasLimit != null ? gasLimit.toLong() : -1,
gasPrice, gasPrice,
Optional.ofNullable(gasPremium), Optional.ofNullable(maxPriorityFeePerGas),
Optional.ofNullable(feeCap), Optional.ofNullable(maxFeePerGas),
value, value,
payload); payload);
this.strict = Optional.ofNullable(strict).orElse(FALSE); this.strict = Optional.ofNullable(strict).orElse(FALSE);

@ -25,6 +25,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ @JsonPropertyOrder({
"number", "number",
"hash", "hash",

@ -35,6 +35,8 @@ import org.apache.tuweni.bytes.Bytes;
"from", "from",
"gas", "gas",
"gasPrice", "gasPrice",
"maxPriorityFeePerGas",
"maxFeePerGas",
"hash", "hash",
"input", "input",
"nonce", "nonce",
@ -55,10 +57,22 @@ public class TransactionCompleteResult implements TransactionResult {
private final String blockHash; private final String blockHash;
private final String blockNumber; private final String blockNumber;
@JsonInclude(JsonInclude.Include.NON_NULL)
private final String chainId; private final String chainId;
private final String from; private final String from;
private final String gas; private final String gas;
@JsonInclude(JsonInclude.Include.NON_NULL)
private final String gasPrice; private final String gasPrice;
@JsonInclude(JsonInclude.Include.NON_NULL)
private final String maxPriorityFeePerGas;
@JsonInclude(JsonInclude.Include.NON_NULL)
private final String maxFeePerGas;
private final String hash; private final String hash;
private final String input; private final String input;
private final String nonce; private final String nonce;
@ -84,6 +98,10 @@ public class TransactionCompleteResult implements TransactionResult {
this.chainId = transaction.getChainId().map(Quantity::create).orElse(null); this.chainId = transaction.getChainId().map(Quantity::create).orElse(null);
this.from = transaction.getSender().toString(); this.from = transaction.getSender().toString();
this.gas = Quantity.create(transaction.getGasLimit()); this.gas = Quantity.create(transaction.getGasLimit());
this.maxPriorityFeePerGas =
tx.getTransaction().getMaxPriorityFeePerGas().map(q -> q.toHexString()).orElse(null);
this.maxFeePerGas =
tx.getTransaction().getMaxFeePerGas().map(q -> q.toHexString()).orElse(null);
this.gasPrice = Quantity.create(transaction.getGasPrice()); this.gasPrice = Quantity.create(transaction.getGasPrice());
this.hash = transaction.getHash().toString(); this.hash = transaction.getHash().toString();
this.input = transaction.getPayload().toString(); this.input = transaction.getPayload().toString();
@ -132,6 +150,16 @@ public class TransactionCompleteResult implements TransactionResult {
return gas; return gas;
} }
@JsonGetter(value = "maxPriorityFeePerGas")
public String getMaxPriorityFeePerGas() {
return maxPriorityFeePerGas;
}
@JsonGetter(value = "maxFeePerGas")
public String getMaxFeePerGas() {
return maxFeePerGas;
}
@JsonGetter(value = "gasPrice") @JsonGetter(value = "gasPrice")
public String getGasPrice() { public String getGasPrice() {
return gasPrice; return gasPrice;

@ -32,6 +32,8 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
"from", "from",
"gas", "gas",
"gasPrice", "gasPrice",
"maxPriortyFeePerGas",
"maxFeePerGas",
"hash", "hash",
"input", "input",
"nonce", "nonce",
@ -50,7 +52,16 @@ public class TransactionPendingResult implements TransactionResult {
private final String chainId; private final String chainId;
private final String from; private final String from;
private final String gas; private final String gas;
@JsonInclude(JsonInclude.Include.NON_NULL)
private final String gasPrice; private final String gasPrice;
@JsonInclude(JsonInclude.Include.NON_NULL)
private final String maxPriorityFeePerGas;
@JsonInclude(JsonInclude.Include.NON_NULL)
private final String maxFeePerGas;
private final String hash; private final String hash;
private final String input; private final String input;
private final String nonce; private final String nonce;
@ -73,6 +84,9 @@ public class TransactionPendingResult implements TransactionResult {
this.from = transaction.getSender().toString(); this.from = transaction.getSender().toString();
this.gas = Quantity.create(transaction.getGasLimit()); this.gas = Quantity.create(transaction.getGasLimit());
this.gasPrice = Quantity.create(transaction.getGasPrice()); this.gasPrice = Quantity.create(transaction.getGasPrice());
this.maxPriorityFeePerGas =
transaction.getMaxPriorityFeePerGas().map(q -> q.toHexString()).orElse(null);
this.maxFeePerGas = transaction.getMaxFeePerGas().map(q -> q.toHexString()).orElse(null);
this.hash = transaction.getHash().toString(); this.hash = transaction.getHash().toString();
this.input = transaction.getPayload().toString(); this.input = transaction.getPayload().toString();
this.nonce = Quantity.create(transaction.getNonce()); this.nonce = Quantity.create(transaction.getNonce());
@ -116,6 +130,16 @@ public class TransactionPendingResult implements TransactionResult {
return gasPrice; return gasPrice;
} }
@JsonGetter(value = "maxPriorityFeePerGas")
public String getMaxPriorityFeePerGas() {
return maxPriorityFeePerGas;
}
@JsonGetter(value = "maxFeePerGas")
public String getMaxFeePerGas() {
return maxFeePerGas;
}
@JsonGetter(value = "hash") @JsonGetter(value = "hash")
public String getHash() { public String getHash() {
return hash; return hash;

@ -14,12 +14,9 @@
*/ */
package org.hyperledger.besu.ethereum.api.util; package org.hyperledger.besu.ethereum.api.util;
import static org.hyperledger.besu.plugin.data.TransactionType.FRONTIER;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcRequestException; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcRequestException;
import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.encoding.TransactionDecoder; import org.hyperledger.besu.ethereum.core.encoding.TransactionDecoder;
import org.hyperledger.besu.ethereum.rlp.RLP;
import org.hyperledger.besu.ethereum.rlp.RLPException; import org.hyperledger.besu.ethereum.rlp.RLPException;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -33,11 +30,7 @@ public class DomainObjectDecodeUtils {
throws InvalidJsonRpcRequestException { throws InvalidJsonRpcRequestException {
try { try {
Bytes txnBytes = Bytes.fromHexString(rawTransaction); Bytes txnBytes = Bytes.fromHexString(rawTransaction);
if (!txnBytes.isEmpty() && FRONTIER.compareTo(txnBytes.get(0)) < 0) {
return TransactionDecoder.decodeOpaqueBytes(txnBytes); return TransactionDecoder.decodeOpaqueBytes(txnBytes);
} else {
return Transaction.readFrom(RLP.input(txnBytes));
}
} catch (final IllegalArgumentException | RLPException e) { } catch (final IllegalArgumentException | RLPException e) {
LOG.debug(e); LOG.debug(e);
throw new InvalidJsonRpcRequestException("Invalid raw transaction hex", e); throw new InvalidJsonRpcRequestException("Invalid raw transaction hex", e);

@ -157,7 +157,7 @@ public class EthEstimateGasTest {
mockTransientProcessorResultGasEstimate(1L, false, false); mockTransientProcessorResultGasEstimate(1L, false, false);
Assertions.assertThatThrownBy(() -> method.response(request)) Assertions.assertThatThrownBy(() -> method.response(request))
.isInstanceOf(InvalidJsonRpcParameters.class) .isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("gasPrice cannot be used with baseFee or feeCap"); .hasMessageContaining("gasPrice cannot be used with baseFee or maxFeePerGas");
} }
@Test @Test

@ -27,6 +27,18 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test; import org.junit.Test;
public class TransactionCompleteResultTest { public class TransactionCompleteResultTest {
@Test
public void eip1559TransactionFields() {
final BlockDataGenerator gen = new BlockDataGenerator();
final Transaction transaction = gen.transaction(TransactionType.EIP1559);
TransactionCompleteResult tcr =
new TransactionCompleteResult(new TransactionWithMetadata(transaction, 0L, Hash.ZERO, 0));
assertThat(tcr.getMaxFeePerGas()).isNotEmpty();
assertThat(tcr.getMaxPriorityFeePerGas()).isNotEmpty();
assertThat(tcr.getGasPrice()).isNull();
}
@Test @Test
public void accessListTransactionFields() throws JsonProcessingException { public void accessListTransactionFields() throws JsonProcessingException {
final BlockDataGenerator gen = new BlockDataGenerator(); final BlockDataGenerator gen = new BlockDataGenerator();
@ -40,6 +52,9 @@ public class TransactionCompleteResultTest {
"0xfc84c3946cb419cbd8c2c68d5e79a3b2a03a8faff4d9e2be493f5a07eb5da95e"), "0xfc84c3946cb419cbd8c2c68d5e79a3b2a03a8faff4d9e2be493f5a07eb5da95e"),
0)); 0));
assertThat(transactionCompleteResult.getGasPrice()).isNotEmpty();
assertThat(transactionCompleteResult.getMaxFeePerGas()).isNull();
assertThat(transactionCompleteResult.getMaxPriorityFeePerGas()).isNull();
final ObjectMapper objectMapper = new ObjectMapper(); final ObjectMapper objectMapper = new ObjectMapper();
final String jsonString = final String jsonString =
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(transactionCompleteResult); objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(transactionCompleteResult);

@ -35,7 +35,6 @@
{ {
"blockHash": "0x1878c6f27178250f3d55186a2887b076936599f307d96dabcf331b2ff0a38f0c", "blockHash": "0x1878c6f27178250f3d55186a2887b076936599f307d96dabcf331b2ff0a38f0c",
"blockNumber": "0x10", "blockNumber": "0x10",
"chainId": null,
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"gas": "0x4cb2f", "gas": "0x4cb2f",
"gasPrice": "0x1", "gasPrice": "0x1",

@ -14,7 +14,6 @@
"result": { "result": {
"blockHash": "0x10aaf14a53caf27552325374429d3558398a36d3682ede6603c2c6511896e9f9", "blockHash": "0x10aaf14a53caf27552325374429d3558398a36d3682ede6603c2c6511896e9f9",
"blockNumber": "0x1", "blockNumber": "0x1",
"chainId": null,
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"gas": "0x2fefd8", "gas": "0x2fefd8",
"gasPrice": "0x1", "gasPrice": "0x1",

@ -14,7 +14,6 @@
"result": { "result": {
"blockHash": "0x0e29f455b8db7b15042efe9eabe0beb0ce2c7901919bba1107b1352191e09942", "blockHash": "0x0e29f455b8db7b15042efe9eabe0beb0ce2c7901919bba1107b1352191e09942",
"blockNumber": "0x2", "blockNumber": "0x2",
"chainId": null,
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"gas": "0x4cb2f", "gas": "0x4cb2f",
"gasPrice": "0x1", "gasPrice": "0x1",

@ -14,7 +14,6 @@
"result": { "result": {
"blockHash": "0x71d59849ddd98543bdfbe8548f5eed559b07b8aaf196369f39134500eab68e53", "blockHash": "0x71d59849ddd98543bdfbe8548f5eed559b07b8aaf196369f39134500eab68e53",
"blockNumber": "0x20", "blockNumber": "0x20",
"chainId": null,
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"gas": "0x4cb2f", "gas": "0x4cb2f",
"gasPrice": "0x1", "gasPrice": "0x1",

@ -14,7 +14,6 @@
"result": { "result": {
"blockHash": "0x0e29f455b8db7b15042efe9eabe0beb0ce2c7901919bba1107b1352191e09942", "blockHash": "0x0e29f455b8db7b15042efe9eabe0beb0ce2c7901919bba1107b1352191e09942",
"blockNumber": "0x2", "blockNumber": "0x2",
"chainId": null,
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"gas": "0x4cb2f", "gas": "0x4cb2f",
"gasPrice": "0x1", "gasPrice": "0x1",

@ -14,7 +14,6 @@
"result": { "result": {
"blockHash": "0x3d813a0ffc9cd04436e17e3e9c309f1e80df0407078e50355ce0d570b5424812", "blockHash": "0x3d813a0ffc9cd04436e17e3e9c309f1e80df0407078e50355ce0d570b5424812",
"blockNumber": "0x3", "blockNumber": "0x3",
"chainId": null,
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"gas": "0x4cb2f", "gas": "0x4cb2f",
"gasPrice": "0x1", "gasPrice": "0x1",

@ -14,7 +14,6 @@
"result": { "result": {
"blockHash": "0x71d59849ddd98543bdfbe8548f5eed559b07b8aaf196369f39134500eab68e53", "blockHash": "0x71d59849ddd98543bdfbe8548f5eed559b07b8aaf196369f39134500eab68e53",
"blockNumber": "0x20", "blockNumber": "0x20",
"chainId": null,
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"gas": "0x4cb2f", "gas": "0x4cb2f",
"gasPrice": "0x1", "gasPrice": "0x1",

@ -14,7 +14,6 @@
"result": { "result": {
"blockHash": "0x71d59849ddd98543bdfbe8548f5eed559b07b8aaf196369f39134500eab68e53", "blockHash": "0x71d59849ddd98543bdfbe8548f5eed559b07b8aaf196369f39134500eab68e53",
"blockNumber": "0x20", "blockNumber": "0x20",
"chainId": null,
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"gas": "0x4cb2f", "gas": "0x4cb2f",
"gasPrice": "0x1", "gasPrice": "0x1",

@ -13,7 +13,6 @@
"result": { "result": {
"blockHash": "0xc8df1f061abb4d0c107b2b1a794ade8780b3120e681f723fe55a7be586d95ba6", "blockHash": "0xc8df1f061abb4d0c107b2b1a794ade8780b3120e681f723fe55a7be586d95ba6",
"blockNumber": "0x1e", "blockNumber": "0x1e",
"chainId": null,
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"gas": "0x4cb2f", "gas": "0x4cb2f",
"gasPrice": "0x1", "gasPrice": "0x1",

@ -13,7 +13,6 @@
"result": { "result": {
"blockHash": "0x10aaf14a53caf27552325374429d3558398a36d3682ede6603c2c6511896e9f9", "blockHash": "0x10aaf14a53caf27552325374429d3558398a36d3682ede6603c2c6511896e9f9",
"blockNumber": "0x1", "blockNumber": "0x1",
"chainId": null,
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"gas": "0x2fefd8", "gas": "0x2fefd8",
"gasPrice": "0x1", "gasPrice": "0x1",

@ -156,7 +156,7 @@ public final class GenesisState {
.mixHash(parseMixHash(genesis)) .mixHash(parseMixHash(genesis))
.nonce(parseNonce(genesis)) .nonce(parseNonce(genesis))
.blockHeaderFunctions(ScheduleBasedBlockHeaderFunctions.create(protocolSchedule)) .blockHeaderFunctions(ScheduleBasedBlockHeaderFunctions.create(protocolSchedule))
.baseFee(genesis.getConfigOptions().getGenesisBaseFee().orElse(null)) .baseFee(genesis.getConfigOptions().getGenesisBaseFeePerGas().orElse(null))
.buildBlockHeader(); .buildBlockHeader();
} }

@ -62,9 +62,9 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
private final Wei gasPrice; private final Wei gasPrice;
private final Wei gasPremium; private final Wei maxPriorityFeePerGas;
private final Wei feeCap; private final Wei maxFeePerGas;
private final long gasLimit; private final long gasLimit;
@ -111,8 +111,8 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
* @param transactionType the transaction type * @param transactionType the transaction type
* @param nonce the nonce * @param nonce the nonce
* @param gasPrice the gas price * @param gasPrice the gas price
* @param gasPremium the gas premium * @param maxPriorityFeePerGas the max priorty fee per gas
* @param feeCap the fee cap * @param maxFeePerGas the max fee per gas
* @param gasLimit the gas limit * @param gasLimit the gas limit
* @param to the transaction recipient * @param to the transaction recipient
* @param value the value being transferred to the recipient * @param value the value being transferred to the recipient
@ -134,8 +134,8 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
final TransactionType transactionType, final TransactionType transactionType,
final long nonce, final long nonce,
final Wei gasPrice, final Wei gasPrice,
final Wei gasPremium, final Wei maxPriorityFeePerGas,
final Wei feeCap, final Wei maxFeePerGas,
final long gasLimit, final long gasLimit,
final Optional<Address> to, final Optional<Address> to,
final Wei value, final Wei value,
@ -164,8 +164,8 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
this.transactionType = transactionType; this.transactionType = transactionType;
this.nonce = nonce; this.nonce = nonce;
this.gasPrice = gasPrice; this.gasPrice = gasPrice;
this.gasPremium = gasPremium; this.maxPriorityFeePerGas = maxPriorityFeePerGas;
this.feeCap = feeCap; this.maxFeePerGas = maxFeePerGas;
this.gasLimit = gasLimit; this.gasLimit = gasLimit;
this.to = to; this.to = to;
this.value = value; this.value = value;
@ -180,8 +180,8 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
public Transaction( public Transaction(
final long nonce, final long nonce,
final Wei gasPrice, final Wei gasPrice,
final Wei gasPremium, final Wei maxPriorityFeePerGas,
final Wei feeCap, final Wei maxFeePerGas,
final long gasLimit, final long gasLimit,
final Optional<Address> to, final Optional<Address> to,
final Wei value, final Wei value,
@ -194,8 +194,8 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
TransactionType.FRONTIER, TransactionType.FRONTIER,
nonce, nonce,
gasPrice, gasPrice,
gasPremium, maxPriorityFeePerGas,
feeCap, maxFeePerGas,
gasLimit, gasLimit,
to, to,
value, value,
@ -301,23 +301,23 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
} }
/** /**
* Return the transaction gas premium. * Return the transaction max priority per gas.
* *
* @return the transaction gas premium * @return the transaction max priority per gas
*/ */
@Override @Override
public Optional<Quantity> getGasPremium() { public Optional<Quantity> getMaxPriorityFeePerGas() {
return Optional.ofNullable(gasPremium); return Optional.ofNullable(maxPriorityFeePerGas);
} }
/** /**
* Return the transaction fee cap. * Return the transaction max fee per gas.
* *
* @return the transaction fee cap * @return the transaction max fee per gas
*/ */
@Override @Override
public Optional<Quantity> getFeeCap() { public Optional<Quantity> getMaxFeePerGas() {
return Optional.ofNullable(feeCap); return Optional.ofNullable(maxFeePerGas);
} }
/** /**
@ -447,8 +447,8 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
transactionType, transactionType,
nonce, nonce,
gasPrice, gasPrice,
gasPremium, maxPriorityFeePerGas,
feeCap, maxFeePerGas,
gasLimit, gasLimit,
to, to,
value, value,
@ -573,8 +573,8 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
final TransactionType transactionType, final TransactionType transactionType,
final long nonce, final long nonce,
final Wei gasPrice, final Wei gasPrice,
final Wei gasPremium, final Wei maxPriorityFeePerGas,
final Wei feeCap, final Wei maxFeePerGas,
final long gasLimit, final long gasLimit,
final Optional<Address> to, final Optional<Address> to,
final Wei value, final Wei value,
@ -589,7 +589,15 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
case EIP1559: case EIP1559:
preimage = preimage =
eip1559Preimage( eip1559Preimage(
nonce, gasPremium, feeCap, gasLimit, to, value, payload, chainId, accessList); nonce,
maxPriorityFeePerGas,
maxFeePerGas,
gasLimit,
to,
value,
payload,
chainId,
accessList);
break; break;
case ACCESS_LIST: case ACCESS_LIST:
preimage = preimage =
@ -641,8 +649,8 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
private static Bytes eip1559Preimage( private static Bytes eip1559Preimage(
final long nonce, final long nonce,
final Wei gasPremium, final Wei maxPriorityFeePerGas,
final Wei feeCap, final Wei maxFeePerGas,
final long gasLimit, final long gasLimit,
final Optional<Address> to, final Optional<Address> to,
final Wei value, final Wei value,
@ -655,8 +663,8 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
rlpOutput.startList(); rlpOutput.startList();
rlpOutput.writeBigIntegerScalar(chainId.orElseThrow()); rlpOutput.writeBigIntegerScalar(chainId.orElseThrow());
rlpOutput.writeLongScalar(nonce); rlpOutput.writeLongScalar(nonce);
rlpOutput.writeUInt256Scalar(gasPremium); rlpOutput.writeUInt256Scalar(maxPriorityFeePerGas);
rlpOutput.writeUInt256Scalar(feeCap); rlpOutput.writeUInt256Scalar(maxFeePerGas);
rlpOutput.writeLongScalar(gasLimit); rlpOutput.writeLongScalar(gasLimit);
rlpOutput.writeBytes(to.map(Bytes::copy).orElse(Bytes.EMPTY)); rlpOutput.writeBytes(to.map(Bytes::copy).orElse(Bytes.EMPTY));
rlpOutput.writeUInt256Scalar(value); rlpOutput.writeUInt256Scalar(value);
@ -696,8 +704,8 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
return Objects.equals(this.chainId, that.chainId) return Objects.equals(this.chainId, that.chainId)
&& Objects.equals(this.gasLimit, that.gasLimit) && Objects.equals(this.gasLimit, that.gasLimit)
&& Objects.equals(this.gasPrice, that.gasPrice) && Objects.equals(this.gasPrice, that.gasPrice)
&& Objects.equals(this.gasPremium, that.gasPremium) && Objects.equals(this.maxPriorityFeePerGas, that.maxPriorityFeePerGas)
&& Objects.equals(this.feeCap, that.feeCap) && Objects.equals(this.maxFeePerGas, that.maxFeePerGas)
&& Objects.equals(this.nonce, that.nonce) && Objects.equals(this.nonce, that.nonce)
&& Objects.equals(this.payload, that.payload) && Objects.equals(this.payload, that.payload)
&& Objects.equals(this.signature, that.signature) && Objects.equals(this.signature, that.signature)
@ -709,7 +717,17 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash( return Objects.hash(
nonce, gasPrice, gasPremium, feeCap, gasLimit, to, value, payload, signature, chainId, v); nonce,
gasPrice,
maxPriorityFeePerGas,
maxFeePerGas,
gasLimit,
to,
value,
payload,
signature,
chainId,
v);
} }
@Override @Override
@ -719,9 +737,9 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
sb.append("type=").append(getType()).append(", "); sb.append("type=").append(getType()).append(", ");
sb.append("nonce=").append(getNonce()).append(", "); sb.append("nonce=").append(getNonce()).append(", ");
sb.append("gasPrice=").append(getGasPrice()).append(", "); sb.append("gasPrice=").append(getGasPrice()).append(", ");
if (getGasPremium().isPresent() && getFeeCap().isPresent()) { if (getMaxPriorityFeePerGas().isPresent() && getMaxFeePerGas().isPresent()) {
sb.append("gasPremium=").append(getGasPremium()).append(", "); sb.append("maxPriorityFeePerGas=").append(getMaxPriorityFeePerGas()).append(", ");
sb.append("feeCap=").append(getFeeCap()).append(", "); sb.append("maxFeePerGas=").append(getMaxFeePerGas()).append(", ");
} }
sb.append("gasLimit=").append(getGasLimit()).append(", "); sb.append("gasLimit=").append(getGasLimit()).append(", ");
if (getTo().isPresent()) sb.append("to=").append(getTo().get()).append(", "); if (getTo().isPresent()) sb.append("to=").append(getTo().get()).append(", ");
@ -751,9 +769,9 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
protected Wei gasPrice; protected Wei gasPrice;
protected Wei gasPremium; protected Wei maxPriorityFeePerGas;
protected Wei feeCap; protected Wei maxFeePerGas;
protected long gasLimit = -1L; protected long gasLimit = -1L;
@ -793,13 +811,13 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
return this; return this;
} }
public Builder gasPremium(final Wei gasPremium) { public Builder maxPriorityFeePerGas(final Wei maxPriorityFeePerGas) {
this.gasPremium = gasPremium; this.maxPriorityFeePerGas = maxPriorityFeePerGas;
return this; return this;
} }
public Builder feeCap(final Wei feeCap) { public Builder maxFeePerGas(final Wei maxFeePerGas) {
this.feeCap = feeCap; this.maxFeePerGas = maxFeePerGas;
return this; return this;
} }
@ -844,7 +862,7 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
} }
public Builder guessType() { public Builder guessType() {
if (gasPremium != null || feeCap != null) { if (maxPriorityFeePerGas != null || maxFeePerGas != null) {
transactionType = TransactionType.EIP1559; transactionType = TransactionType.EIP1559;
} else if (accessList.isPresent()) { } else if (accessList.isPresent()) {
transactionType = TransactionType.ACCESS_LIST; transactionType = TransactionType.ACCESS_LIST;
@ -859,8 +877,8 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
transactionType, transactionType,
nonce, nonce,
gasPrice, gasPrice,
gasPremium, maxPriorityFeePerGas,
feeCap, maxFeePerGas,
gasLimit, gasLimit,
to, to,
value, value,
@ -887,8 +905,8 @@ public class Transaction implements org.hyperledger.besu.plugin.data.Transaction
transactionType, transactionType,
nonce, nonce,
gasPrice, gasPrice,
gasPremium, maxPriorityFeePerGas,
feeCap, maxFeePerGas,
gasLimit, gasLimit,
to, to,
value, value,

@ -77,7 +77,7 @@ public class TransactionDecoder {
try { try {
transactionType = TransactionType.of(input.get(0)); transactionType = TransactionType.of(input.get(0));
} catch (final IllegalArgumentException __) { } catch (final IllegalArgumentException __) {
return decodeFrontier(RLP.input(input)); return decodeForWire(RLP.input(input));
} }
return getDecoder(transactionType).decode(RLP.input(input.slice(1))); return getDecoder(transactionType).decode(RLP.input(input.slice(1)));
} }
@ -174,8 +174,8 @@ public class TransactionDecoder {
.type(TransactionType.EIP1559) .type(TransactionType.EIP1559)
.chainId(chainId) .chainId(chainId)
.nonce(input.readLongScalar()) .nonce(input.readLongScalar())
.gasPremium(Wei.wrap(input.readBytes())) .maxPriorityFeePerGas(Wei.wrap(input.readBytes()))
.feeCap(Wei.wrap(input.readBytes())) .maxFeePerGas(Wei.wrap(input.readBytes()))
.gasLimit(input.readLongScalar()) .gasLimit(input.readLongScalar())
.to(input.readBytes(v -> v.size() == 0 ? null : Address.wrap(v))) .to(input.readBytes(v -> v.size() == 0 ? null : Address.wrap(v)))
.value(Wei.of(input.readUInt256Scalar())) .value(Wei.of(input.readUInt256Scalar()))

@ -161,9 +161,13 @@ public class TransactionEncoder {
.longValue()); .longValue());
out.writeLongScalar(transaction.getNonce()); out.writeLongScalar(transaction.getNonce());
out.writeUInt256Scalar( out.writeUInt256Scalar(
transaction.getGasPremium().map(Quantity::getValue).map(Wei::ofNumber).orElseThrow()); transaction
.getMaxPriorityFeePerGas()
.map(Quantity::getValue)
.map(Wei::ofNumber)
.orElseThrow());
out.writeUInt256Scalar( out.writeUInt256Scalar(
transaction.getFeeCap().map(Quantity::getValue).map(Wei::ofNumber).orElseThrow()); transaction.getMaxFeePerGas().map(Quantity::getValue).map(Wei::ofNumber).orElseThrow());
out.writeLongScalar(transaction.getGasLimit()); out.writeLongScalar(transaction.getGasLimit());
out.writeBytes(transaction.getTo().map(Bytes::copy).orElse(Bytes.EMPTY)); out.writeBytes(transaction.getTo().map(Bytes::copy).orElse(Bytes.EMPTY));
out.writeUInt256Scalar(transaction.getValue()); out.writeUInt256Scalar(transaction.getValue());

@ -34,12 +34,13 @@ public interface TransactionPriceCalculator {
if (!transaction.getType().supports1559FeeMarket()) { if (!transaction.getType().supports1559FeeMarket()) {
return transaction.getGasPrice(); return transaction.getGasPrice();
} }
final Wei gasPremium = final Wei maxPriorityFeePerGas =
Wei.of((BigInteger) transaction.getGasPremium().orElseThrow().getValue()); Wei.of((BigInteger) transaction.getMaxPriorityFeePerGas().orElseThrow().getValue());
final Wei feeCap = Wei.of((BigInteger) transaction.getFeeCap().orElseThrow().getValue()); final Wei maxFeePerGas =
Wei price = gasPremium.add(baseFee); Wei.of((BigInteger) transaction.getMaxFeePerGas().orElseThrow().getValue());
if (price.compareTo(feeCap) > 0) { Wei price = maxPriorityFeePerGas.add(baseFee);
price = feeCap; if (price.compareTo(maxFeePerGas) > 0) {
price = maxFeePerGas;
} }
return price; return price;
}; };

@ -31,9 +31,9 @@ public class CallParameter {
private final long gasLimit; private final long gasLimit;
private final Optional<Wei> gasPremium; private final Optional<Wei> maxPriorityFeePerGas;
private final Optional<Wei> feeCap; private final Optional<Wei> maxFeePerGas;
private final Wei gasPrice; private final Wei gasPrice;
@ -51,8 +51,8 @@ public class CallParameter {
this.from = from; this.from = from;
this.to = to; this.to = to;
this.gasLimit = gasLimit; this.gasLimit = gasLimit;
this.gasPremium = Optional.empty(); this.maxPriorityFeePerGas = Optional.empty();
this.feeCap = Optional.empty(); this.maxFeePerGas = Optional.empty();
this.gasPrice = gasPrice; this.gasPrice = gasPrice;
this.value = value; this.value = value;
this.payload = payload; this.payload = payload;
@ -63,15 +63,15 @@ public class CallParameter {
final Address to, final Address to,
final long gasLimit, final long gasLimit,
final Wei gasPrice, final Wei gasPrice,
final Optional<Wei> gasPremium, final Optional<Wei> maxPriorityFeePerGas,
final Optional<Wei> feeCap, final Optional<Wei> maxFeePerGas,
final Wei value, final Wei value,
final Bytes payload) { final Bytes payload) {
this.from = from; this.from = from;
this.to = to; this.to = to;
this.gasLimit = gasLimit; this.gasLimit = gasLimit;
this.gasPremium = gasPremium; this.maxPriorityFeePerGas = maxPriorityFeePerGas;
this.feeCap = feeCap; this.maxFeePerGas = maxFeePerGas;
this.gasPrice = gasPrice; this.gasPrice = gasPrice;
this.value = value; this.value = value;
this.payload = payload; this.payload = payload;
@ -93,12 +93,12 @@ public class CallParameter {
return gasPrice; return gasPrice;
} }
public Optional<Wei> getGasPremium() { public Optional<Wei> getMaxPriorityFeePerGas() {
return gasPremium; return maxPriorityFeePerGas;
} }
public Optional<Wei> getFeeCap() { public Optional<Wei> getMaxFeePerGas() {
return feeCap; return maxFeePerGas;
} }
public Wei getValue() { public Wei getValue() {
@ -122,14 +122,15 @@ public class CallParameter {
&& Objects.equals(from, that.from) && Objects.equals(from, that.from)
&& Objects.equals(to, that.to) && Objects.equals(to, that.to)
&& Objects.equals(gasPrice, that.gasPrice) && Objects.equals(gasPrice, that.gasPrice)
&& Objects.equals(gasPremium, that.gasPremium) && Objects.equals(maxPriorityFeePerGas, that.maxPriorityFeePerGas)
&& Objects.equals(feeCap, that.feeCap) && Objects.equals(maxFeePerGas, that.maxFeePerGas)
&& Objects.equals(value, that.value) && Objects.equals(value, that.value)
&& Objects.equals(payload, that.payload); && Objects.equals(payload, that.payload);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(from, to, gasLimit, gasPrice, gasPremium, feeCap, value, payload); return Objects.hash(
from, to, gasLimit, gasPrice, maxPriorityFeePerGas, maxFeePerGas, value, payload);
} }
} }

@ -174,8 +174,8 @@ public class TransactionSimulator {
.value(value) .value(value)
.payload(payload) .payload(payload)
.signature(FAKE_SIGNATURE); .signature(FAKE_SIGNATURE);
callParams.getGasPremium().ifPresent(transactionBuilder::gasPremium); callParams.getMaxPriorityFeePerGas().ifPresent(transactionBuilder::maxPriorityFeePerGas);
callParams.getFeeCap().ifPresent(transactionBuilder::feeCap); callParams.getMaxFeePerGas().ifPresent(transactionBuilder::maxFeePerGas);
final Transaction transaction = transactionBuilder.build(); final Transaction transaction = transactionBuilder.build();

@ -399,8 +399,8 @@ public class BlockDataGenerator {
return Transaction.builder() return Transaction.builder()
.type(TransactionType.EIP1559) .type(TransactionType.EIP1559)
.nonce(positiveLong()) .nonce(positiveLong())
.gasPremium(Wei.wrap(bytes32())) .maxPriorityFeePerGas(Wei.wrap(bytes32()))
.feeCap(Wei.wrap(bytes32())) .maxFeePerGas(Wei.wrap(bytes32()))
.gasLimit(positiveLong()) .gasLimit(positiveLong())
.to(to) .to(to)
.value(Wei.of(positiveLong())) .value(Wei.of(positiveLong()))

@ -41,8 +41,8 @@ public class TransactionTestFixture {
private Optional<BigInteger> chainId = Optional.of(BigInteger.valueOf(1337)); private Optional<BigInteger> chainId = Optional.of(BigInteger.valueOf(1337));
private Optional<Wei> gasPremium = Optional.empty(); private Optional<Wei> maxPriorityFeePerGas = Optional.empty();
private Optional<Wei> feeCap = Optional.empty(); private Optional<Wei> maxFeePerGas = Optional.empty();
public Transaction createTransaction(final KeyPair keys) { public Transaction createTransaction(final KeyPair keys) {
final Transaction.Builder builder = Transaction.builder(); final Transaction.Builder builder = Transaction.builder();
@ -58,8 +58,8 @@ public class TransactionTestFixture {
to.ifPresent(builder::to); to.ifPresent(builder::to);
chainId.ifPresent(builder::chainId); chainId.ifPresent(builder::chainId);
gasPremium.ifPresent(builder::gasPremium); maxPriorityFeePerGas.ifPresent(builder::maxPriorityFeePerGas);
feeCap.ifPresent(builder::feeCap); maxFeePerGas.ifPresent(builder::maxFeePerGas);
return builder.signAndBuild(keys); return builder.signAndBuild(keys);
} }
@ -109,13 +109,13 @@ public class TransactionTestFixture {
return this; return this;
} }
public TransactionTestFixture gasPremium(final Optional<Wei> gasPremium) { public TransactionTestFixture maxPriorityFeePerGas(final Optional<Wei> maxPriorityFeePerGas) {
this.gasPremium = gasPremium; this.maxPriorityFeePerGas = maxPriorityFeePerGas;
return this; return this;
} }
public TransactionTestFixture feeCap(final Optional<Wei> feeCap) { public TransactionTestFixture maxFeePerGas(final Optional<Wei> maxFeePerGas) {
this.feeCap = feeCap; this.maxFeePerGas = maxFeePerGas;
return this; return this;
} }
} }

@ -32,7 +32,7 @@ public class TransactionBuilderTest {
public void guessTypeCanGuessAllTypes() { public void guessTypeCanGuessAllTypes() {
final BlockDataGenerator gen = new BlockDataGenerator(); final BlockDataGenerator gen = new BlockDataGenerator();
final Transaction.Builder frontierBuilder = Transaction.builder(); final Transaction.Builder frontierBuilder = Transaction.builder();
final Transaction.Builder eip1559Builder = Transaction.builder().feeCap(Wei.of(5)); final Transaction.Builder eip1559Builder = Transaction.builder().maxFeePerGas(Wei.of(5));
final Transaction.Builder accessListBuilder = final Transaction.Builder accessListBuilder =
Transaction.builder() Transaction.builder()
.accessList(List.of(new AccessListEntry(gen.address(), List.of(gen.bytes32())))); .accessList(List.of(new AccessListEntry(gen.address(), List.of(gen.bytes32()))));

@ -53,9 +53,9 @@ public class TransactionEIP1559Test {
.nonce(0) .nonce(0)
.value(Wei.ZERO) .value(Wei.ZERO)
.gasLimit(30000) .gasLimit(30000)
.gasPremium(Wei.of(2)) .maxPriorityFeePerGas(Wei.of(2))
.payload(Bytes.EMPTY.trimLeadingZeros()) .payload(Bytes.EMPTY.trimLeadingZeros())
.feeCap(Wei.of(new BigInteger("5000000000", 10))) .maxFeePerGas(Wei.of(new BigInteger("5000000000", 10)))
.gasPrice(null) .gasPrice(null)
.to(Address.fromHexString("0x000000000000000000000000000000000000aaaa")) .to(Address.fromHexString("0x000000000000000000000000000000000000aaaa"))
.accessList(accessListEntries) .accessList(accessListEntries)

@ -58,8 +58,8 @@ public class TransactionDecoderTest {
TransactionDecoder.decodeForWire(RLP.input(Bytes.fromHexString(FRONTIER_TX_RLP))); TransactionDecoder.decodeForWire(RLP.input(Bytes.fromHexString(FRONTIER_TX_RLP)));
assertThat(transaction).isNotNull(); assertThat(transaction).isNotNull();
assertThat(transaction.getGasPrice()).isEqualByComparingTo(Wei.of(50L)); assertThat(transaction.getGasPrice()).isEqualByComparingTo(Wei.of(50L));
assertThat(transaction.getGasPremium()).isEmpty(); assertThat(transaction.getMaxPriorityFeePerGas()).isEmpty();
assertThat(transaction.getFeeCap()).isEmpty(); assertThat(transaction.getMaxFeePerGas()).isEmpty();
} }
@Test @Test
@ -67,8 +67,8 @@ public class TransactionDecoderTest {
final Transaction transaction = final Transaction transaction =
TransactionDecoder.decodeForWire(RLP.input(Bytes.fromHexString(EIP1559_TX_RLP))); TransactionDecoder.decodeForWire(RLP.input(Bytes.fromHexString(EIP1559_TX_RLP)));
assertThat(transaction).isNotNull(); assertThat(transaction).isNotNull();
assertThat(transaction.getGasPremium()).hasValue(Wei.of(2L)); assertThat(transaction.getMaxPriorityFeePerGas()).hasValue(Wei.of(2L));
assertThat(transaction.getFeeCap()).hasValue(Wei.of(new BigInteger("5000000000", 10))); assertThat(transaction.getMaxFeePerGas()).hasValue(Wei.of(new BigInteger("5000000000", 10)));
ExperimentalEIPs.eip1559Enabled = ExperimentalEIPs.EIP1559_ENABLED_DEFAULT_VALUE; ExperimentalEIPs.eip1559Enabled = ExperimentalEIPs.EIP1559_ENABLED_DEFAULT_VALUE;
} }
} }

@ -46,8 +46,8 @@ public class TransactionPriceCalculatorTest {
private final TransactionPriceCalculator transactionPriceCalculator; private final TransactionPriceCalculator transactionPriceCalculator;
private final TransactionType transactionType; private final TransactionType transactionType;
private final Wei gasPrice; private final Wei gasPrice;
private final Wei gasPremium; private final Wei maxPriorityFeePerGas;
private final Wei feeCap; private final Wei maxFeePerGas;
private final Optional<Long> baseFee; private final Optional<Long> baseFee;
private final Wei expectedPrice; private final Wei expectedPrice;
@ -55,15 +55,15 @@ public class TransactionPriceCalculatorTest {
final TransactionPriceCalculator transactionPriceCalculator, final TransactionPriceCalculator transactionPriceCalculator,
final TransactionType transactionType, final TransactionType transactionType,
final Wei gasPrice, final Wei gasPrice,
final Wei gasPremium, final Wei maxPriorityFeePerGas,
final Wei feeCap, final Wei maxFeePerGas,
final Optional<Long> baseFee, final Optional<Long> baseFee,
final Wei expectedPrice) { final Wei expectedPrice) {
this.transactionPriceCalculator = transactionPriceCalculator; this.transactionPriceCalculator = transactionPriceCalculator;
this.transactionType = transactionType; this.transactionType = transactionType;
this.gasPrice = gasPrice; this.gasPrice = gasPrice;
this.gasPremium = gasPremium; this.maxPriorityFeePerGas = maxPriorityFeePerGas;
this.feeCap = feeCap; this.maxFeePerGas = maxFeePerGas;
this.baseFee = baseFee; this.baseFee = baseFee;
this.expectedPrice = expectedPrice; this.expectedPrice = expectedPrice;
} }
@ -98,7 +98,7 @@ public class TransactionPriceCalculatorTest {
Optional.of(150L), Optional.of(150L),
Wei.of(578L) Wei.of(578L)
}, },
// EIP-1559 must return gas premium + base fee // EIP-1559 must return maxPriorityFeePerGas + base fee
{ {
EIP_1559_CALCULATOR, EIP_1559_CALCULATOR,
EIP1559, EIP1559,
@ -129,8 +129,8 @@ public class TransactionPriceCalculatorTest {
.type(transactionType) .type(transactionType)
.accessList(transactionType == ACCESS_LIST ? Collections.emptyList() : null) .accessList(transactionType == ACCESS_LIST ? Collections.emptyList() : null)
.gasPrice(gasPrice) .gasPrice(gasPrice)
.gasPremium(gasPremium) .maxPriorityFeePerGas(maxPriorityFeePerGas)
.feeCap(feeCap) .maxFeePerGas(maxFeePerGas)
.build(), .build(),
baseFee)) baseFee))
.isEqualByComparingTo(expectedPrice); .isEqualByComparingTo(expectedPrice);

@ -287,8 +287,8 @@ public class MainnetTransactionValidatorTest {
final Transaction transaction = final Transaction transaction =
new TransactionTestFixture() new TransactionTestFixture()
.type(TransactionType.EIP1559) .type(TransactionType.EIP1559)
.gasPremium(Optional.of(Wei.of(3))) .maxPriorityFeePerGas(Optional.of(Wei.of(3)))
.feeCap(Optional.of(Wei.of(6))) .maxFeePerGas(Optional.of(Wei.of(6)))
.gasLimit(21000) .gasLimit(21000)
.chainId(Optional.of(BigInteger.ONE)) .chainId(Optional.of(BigInteger.ONE))
.createTransaction(senderKeys); .createTransaction(senderKeys);
@ -321,8 +321,8 @@ public class MainnetTransactionValidatorTest {
final Transaction transaction = final Transaction transaction =
new TransactionTestFixture() new TransactionTestFixture()
.type(TransactionType.EIP1559) .type(TransactionType.EIP1559)
.gasPremium(Optional.of(Wei.of(1))) .maxPriorityFeePerGas(Optional.of(Wei.of(1)))
.feeCap(Optional.of(Wei.of(1))) .maxFeePerGas(Optional.of(Wei.of(1)))
.chainId(Optional.of(BigInteger.ONE)) .chainId(Optional.of(BigInteger.ONE))
.createTransaction(senderKeys); .createTransaction(senderKeys);
final Optional<Long> basefee = Optional.of(150000L); final Optional<Long> basefee = Optional.of(150000L);
@ -345,8 +345,8 @@ public class MainnetTransactionValidatorTest {
defaultGoQuorumCompatibilityMode); defaultGoQuorumCompatibilityMode);
final Transaction transaction = final Transaction transaction =
new TransactionTestFixture() new TransactionTestFixture()
.gasPremium(Optional.of(Wei.of(1))) .maxPriorityFeePerGas(Optional.of(Wei.of(1)))
.feeCap(Optional.of(Wei.of(1))) .maxFeePerGas(Optional.of(Wei.of(1)))
.chainId(Optional.empty()) .chainId(Optional.empty())
.createTransaction(senderKeys); .createTransaction(senderKeys);
final Optional<Long> basefee = Optional.of(150000L); final Optional<Long> basefee = Optional.of(150000L);

@ -397,8 +397,8 @@ public class TransactionSimulatorTest {
.nonce(1L) .nonce(1L)
.gasPrice(callParameter.getGasPrice()) .gasPrice(callParameter.getGasPrice())
.gasLimit(callParameter.getGasLimit()) .gasLimit(callParameter.getGasLimit())
.feeCap(callParameter.getFeeCap().orElseThrow()) .maxFeePerGas(callParameter.getMaxFeePerGas().orElseThrow())
.gasPremium(callParameter.getGasPremium().orElseThrow()) .maxPriorityFeePerGas(callParameter.getMaxPriorityFeePerGas().orElseThrow())
.to(callParameter.getTo()) .to(callParameter.getTo())
.sender(callParameter.getFrom()) .sender(callParameter.getFrom())
.value(callParameter.getValue()) .value(callParameter.getValue())

@ -109,12 +109,14 @@ public class TransactionReplacementByPriceRuleTest {
return transactionInfo; return transactionInfo;
} }
private static TransactionInfo eip1559Tx(final long gasPremium, final long feeCap) { private static TransactionInfo eip1559Tx(
final long maxPriorityFeePerGas, final long maxFeePerGas) {
final TransactionInfo transactionInfo = mock(TransactionInfo.class); final TransactionInfo transactionInfo = mock(TransactionInfo.class);
final Transaction transaction = mock(Transaction.class); final Transaction transaction = mock(Transaction.class);
when(transaction.getType()).thenReturn(TransactionType.EIP1559); when(transaction.getType()).thenReturn(TransactionType.EIP1559);
when(transaction.getGasPremium()).thenReturn(Optional.of(Wei.of(gasPremium))); when(transaction.getMaxPriorityFeePerGas())
when(transaction.getFeeCap()).thenReturn(Optional.of(Wei.of(feeCap))); .thenReturn(Optional.of(Wei.of(maxPriorityFeePerGas)));
when(transaction.getMaxFeePerGas()).thenReturn(Optional.of(Wei.of(maxFeePerGas)));
when(transactionInfo.getTransaction()).thenReturn(transaction); when(transactionInfo.getTransaction()).thenReturn(transaction);
return transactionInfo; return transactionInfo;
} }

@ -34,6 +34,7 @@ dependencies {
implementation project(':metrics:core') implementation project(':metrics:core')
implementation project(':util') implementation project(':util')
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.google.guava:guava' implementation 'com.google.guava:guava'
implementation 'org.apache.logging.log4j:log4j-api' implementation 'org.apache.logging.log4j:log4j-api'
implementation 'org.apache.tuweni:bytes' implementation 'org.apache.tuweni:bytes'

@ -77,7 +77,7 @@ public class RetestethService {
new EthGetTransactionCount( new EthGetTransactionCount(
retestethContext::getBlockchainQueries, retestethContext::getBlockchainQueries,
retestethContext::getPendingTransactions, retestethContext::getPendingTransactions,
true), false),
new DebugStorageRangeAt( new DebugStorageRangeAt(
retestethContext::getBlockchainQueries, retestethContext::getBlockReplay, true), retestethContext::getBlockchainQueries, retestethContext::getBlockReplay, true),
new TestModifyTimestamp(retestethContext), new TestModifyTimestamp(retestethContext),

@ -146,7 +146,6 @@ public class TestSetChainParams implements JsonRpcMethod {
.getString("baseFeePerGas")) .getString("baseFeePerGas"))
.map(Long::decode) .map(Long::decode)
.orElse(ExperimentalEIPs.EIP1559_BASEFEE_DEFAULT_VALUE); .orElse(ExperimentalEIPs.EIP1559_BASEFEE_DEFAULT_VALUE);
maybeMove(genesis, "gasTarget", chainParamsJson, "gasLimit");
} }
// strip out precompiles with zero balance // strip out precompiles with zero balance

@ -2,7 +2,7 @@
"genesis" : { "genesis" : {
"author" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", "author" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"difficulty" : "0x020000", "difficulty" : "0x020000",
"gasTarget" : "0x04d2", "gasLimit" : "0x04d2",
"baseFeePerGas" : "0x3039", "baseFeePerGas" : "0x3039",
"extraData" : "0x00", "extraData" : "0x00",
"timestamp" : "0x00", "timestamp" : "0x00",

@ -64,7 +64,7 @@ Calculated : ${currentHash}
tasks.register('checkAPIChanges', FileStateChecker) { tasks.register('checkAPIChanges', FileStateChecker) {
description = "Checks that the API for the Plugin-API project does not change without deliberate thought" description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
files = sourceSets.main.allJava.files files = sourceSets.main.allJava.files
knownHash = 'Zgu1UsdzijNYhkIN4ryqMlAU292gWh6661GWdf5bi14=' knownHash = 'VhijQ2/y9GqGlgxreOf6nIXZB6eSNb2m7uhibCPPJvI='
} }
check.dependsOn('checkAPIChanges') check.dependsOn('checkAPIChanges')

@ -59,10 +59,10 @@ public interface Transaction {
* A scalar value equal to the number of Wei to be paid on top of base fee, as specified in * A scalar value equal to the number of Wei to be paid on top of base fee, as specified in
* EIP-1559. * EIP-1559.
* *
* @return the quantity of Wei for gas premium. * @return the quantity of Wei for max fee per gas
*/ */
@Unstable @Unstable
default Optional<Quantity> getGasPremium() { default Optional<Quantity> getMaxPriorityFeePerGas() {
return Optional.empty(); return Optional.empty();
} }
@ -72,7 +72,7 @@ public interface Transaction {
* @return the quantity of Wei for fee cap. * @return the quantity of Wei for fee cap.
*/ */
@Unstable @Unstable
default Optional<Quantity> getFeeCap() { default Optional<Quantity> getMaxFeePerGas() {
return Optional.empty(); return Optional.empty();
} }

Loading…
Cancel
Save