update RPC methods : fill gasPrice for post london 1559 transaction (#2535)

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
pull/2686/head
matkt 3 years ago committed by GitHub
parent 82aabdef81
commit 9b3c734c6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 1
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseKey.java
  3. 7
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseUtils.java
  4. 3
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetBlockByHashIntegrationTest.java
  5. 5
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthGetBlockByNumberIntegrationTest.java
  6. 1
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResultFactory.java
  7. 11
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionCompleteResult.java
  8. 8
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionPendingResult.java
  9. 20
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java
  10. 8
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/TransactionWithMetadata.java
  11. 16
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java
  12. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAtTest.java
  13. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceTransactionTest.java
  14. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockHashAndIndexTest.java
  15. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetUncleByBlockNumberAndIndexTest.java
  16. 37
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionCompleteResultTest.java

@ -14,6 +14,8 @@
- The command line option --Xsecp-native-enabled was added as an alias for --Xsecp256k1-native-enabled [#2630](https://github.com/hyperledger/besu/pull/2630)
- Added Labelled gauges for metrics [#2646](https://github.com/hyperledger/besu/pull/2646)
- support for `eth/66` networking protocol [#2365](https://github.com/hyperledger/besu/pull/2365)
- update RPC methods for post london 1559 transaction [#2535](https://github.com/hyperledger/besu/pull/2535)
### Bug Fixes
- Consider effective price and effective priority fee in transaction replacement rules [\#2529](https://github.com/hyperledger/besu/issues/2529)

@ -20,6 +20,7 @@ public enum JsonRpcResponseKey {
DIFFICULTY,
EXTRA_DATA,
GAS_LIMIT,
GAS_PRICE,
GAS_USED,
LOGS_BLOOM,
MIX_HASH,

@ -145,9 +145,10 @@ public class JsonRpcResponseUtils {
}
public TransactionResult transaction(
final TransactionType transactionType,
final String blockHash,
final String blockNumber,
final String chainId,
final Long baseFee,
final String fromAddress,
final String gas,
final String gasPrice,
@ -164,7 +165,7 @@ public class JsonRpcResponseUtils {
final String s) {
final Transaction transaction = mock(Transaction.class);
when(transaction.getType()).thenReturn(TransactionType.FRONTIER);
when(transaction.getType()).thenReturn(transactionType);
when(transaction.getGasPrice()).thenReturn(Optional.of(Wei.fromHexString(gasPrice)));
when(transaction.getNonce()).thenReturn(unsignedLong(nonce));
when(transaction.getV()).thenReturn(bigInteger(v));
@ -176,7 +177,6 @@ public class JsonRpcResponseUtils {
when(transaction.getPayload()).thenReturn(bytes(input));
when(transaction.getValue()).thenReturn(wei(value));
when(transaction.getGasLimit()).thenReturn(unsignedLong(gas));
when(transaction.getChainId()).thenReturn(Optional.ofNullable(bigInteger(chainId)));
when(transaction.getPublicKey()).thenReturn(Optional.ofNullable(publicKey));
when(transaction.getSignature())
.thenReturn(
@ -193,6 +193,7 @@ public class JsonRpcResponseUtils {
new TransactionWithMetadata(
transaction,
unsignedLong(blockNumber),
Optional.ofNullable(baseFee),
Hash.fromHexString(blockHash),
unsignedInt(transactionIndex)));
}

@ -27,6 +27,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcRespon
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionResult;
import org.hyperledger.besu.ethereum.core.Hash;
import org.hyperledger.besu.plugin.data.TransactionType;
import org.hyperledger.besu.testutil.BlockTestUtil;
import java.util.EnumMap;
@ -110,6 +111,7 @@ public class EthGetBlockByHashIntegrationTest {
expectedResult.put(JsonRpcResponseKey.EXTRA_DATA, "0x");
expectedResult.put(JsonRpcResponseKey.SIZE, "0x96a");
expectedResult.put(JsonRpcResponseKey.GAS_LIMIT, "0x2fefd8");
expectedResult.put(JsonRpcResponseKey.GAS_PRICE, "0x1");
expectedResult.put(JsonRpcResponseKey.GAS_USED, "0x78674");
expectedResult.put(JsonRpcResponseKey.TIMESTAMP, "0x561bc2e0");
expectedResult.put(
@ -121,6 +123,7 @@ public class EthGetBlockByHashIntegrationTest {
final List<TransactionResult> transactions =
responseUtils.transactions(
responseUtils.transaction(
TransactionType.FRONTIER,
"0x10aaf14a53caf27552325374429d3558398a36d3682ede6603c2c6511896e9f9",
"0x1",
null,

@ -27,6 +27,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonR
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionResult;
import org.hyperledger.besu.plugin.data.TransactionType;
import org.hyperledger.besu.testutil.BlockTestUtil;
import java.util.EnumMap;
@ -213,6 +214,7 @@ public class EthGetBlockByNumberIntegrationTest {
out.put(JsonRpcResponseKey.EXTRA_DATA, "0x");
out.put(JsonRpcResponseKey.GAS_LIMIT, "0x2fefd8");
out.put(JsonRpcResponseKey.GAS_USED, "0x5c99");
out.put(JsonRpcResponseKey.GAS_PRICE, "0x1");
out.put(
JsonRpcResponseKey.LOGS_BLOOM,
"0x00000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000080000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000400000000000000000200000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000800000000040000000000000000000000000000000000000000010000000000000000000000000");
@ -242,6 +244,7 @@ public class EthGetBlockByNumberIntegrationTest {
final List<TransactionResult> transactions =
responseUtils.transactions(
responseUtils.transaction(
TransactionType.FRONTIER,
"0x71d59849ddd98543bdfbe8548f5eed559b07b8aaf196369f39134500eab68e53",
"0x20",
null,
@ -345,6 +348,7 @@ public class EthGetBlockByNumberIntegrationTest {
out.put(JsonRpcResponseKey.EXTRA_DATA, "0x");
out.put(JsonRpcResponseKey.GAS_LIMIT, "0x2fefd8");
out.put(JsonRpcResponseKey.GAS_USED, "0x559f");
out.put(JsonRpcResponseKey.GAS_PRICE, "0x1");
out.put(
JsonRpcResponseKey.LOGS_BLOOM,
"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
@ -374,6 +378,7 @@ public class EthGetBlockByNumberIntegrationTest {
final List<TransactionResult> transactions =
responseUtils.transactions(
responseUtils.transaction(
TransactionType.FRONTIER,
"0x609427ccfeae6d2a930927c9a29a0a3077cac7e4b5826159586b10e25770eef9",
"0x5",
null,

@ -64,6 +64,7 @@ public class BlockResultFactory {
new TransactionWithMetadata(
block.getBody().getTransactions().get(i),
block.getHeader().getNumber(),
block.getHeader().getBaseFee(),
block.getHash(),
i));
}

@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results;
import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata;
import org.hyperledger.besu.ethereum.core.AccessListEntry;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.core.encoding.TransactionEncoder;
import org.hyperledger.besu.plugin.data.TransactionType;
@ -63,8 +64,6 @@ public class TransactionCompleteResult implements TransactionResult {
private final String from;
private final String gas;
@JsonInclude(JsonInclude.Include.NON_NULL)
private final String gasPrice;
@JsonInclude(JsonInclude.Include.NON_NULL)
@ -99,10 +98,12 @@ public class TransactionCompleteResult implements TransactionResult {
this.from = transaction.getSender().toString();
this.gas = Quantity.create(transaction.getGasLimit());
this.maxPriorityFeePerGas =
tx.getTransaction().getMaxPriorityFeePerGas().map(q -> q.toShortHexString()).orElse(null);
tx.getTransaction().getMaxPriorityFeePerGas().map(Wei::toShortHexString).orElse(null);
this.maxFeePerGas =
tx.getTransaction().getMaxFeePerGas().map(q -> q.toShortHexString()).orElse(null);
this.gasPrice = transaction.getGasPrice().map(Quantity::create).orElse(null);
tx.getTransaction().getMaxFeePerGas().map(Wei::toShortHexString).orElse(null);
this.gasPrice =
Quantity.create(
transaction.getGasPrice().orElse(transaction.getEffectiveGasPrice(tx.getBaseFee())));
this.hash = transaction.getHash().toString();
this.input = transaction.getPayload().toString();
this.nonce = Quantity.create(transaction.getNonce());

@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results;
import org.hyperledger.besu.ethereum.core.AccessListEntry;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
import org.hyperledger.besu.plugin.data.TransactionType;
@ -53,7 +54,6 @@ public class TransactionPendingResult implements TransactionResult {
private final String from;
private final String gas;
@JsonInclude(JsonInclude.Include.NON_NULL)
private final String gasPrice;
@JsonInclude(JsonInclude.Include.NON_NULL)
@ -83,10 +83,10 @@ 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 = 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);
transaction.getMaxPriorityFeePerGas().map(Wei::toHexString).orElse(null);
this.maxFeePerGas = transaction.getMaxFeePerGas().map(Wei::toHexString).orElse(null);
this.gasPrice = transaction.getGasPrice().map(Quantity::create).orElse(maxFeePerGas);
this.hash = transaction.getHash().toString();
this.input = transaction.getPayload().toString();
this.nonce = Quantity.create(transaction.getNonce());

@ -386,7 +386,10 @@ public class BlockchainQueries {
final List<Transaction> txs = body.getTransactions();
final List<TransactionWithMetadata> formattedTxs =
formatTransactions(
txs, header.getNumber(), blockHeaderHash);
txs,
header.getNumber(),
header.getBaseFee(),
blockHeaderHash);
final List<Hash> ommers =
body.getOmmers().stream()
.map(BlockHeader::getHash)
@ -504,7 +507,11 @@ public class BlockchainQueries {
final Transaction transaction = blockchain.getTransactionByHash(transactionHash).orElseThrow();
return Optional.of(
new TransactionWithMetadata(
transaction, header.getNumber(), blockHash, loc.getTransactionIndex()));
transaction,
header.getNumber(),
header.getBaseFee(),
blockHash,
loc.getTransactionIndex()));
}
/**
@ -555,7 +562,7 @@ public class BlockchainQueries {
return null;
}
return new TransactionWithMetadata(
txs.get(txIndex), header.getNumber(), blockHeaderHash, txIndex);
txs.get(txIndex), header.getNumber(), header.getBaseFee(), blockHeaderHash, txIndex);
}
public Optional<TransactionLocation> transactionLocationByHash(final Hash transactionHash) {
@ -854,11 +861,14 @@ public class BlockchainQueries {
}
private List<TransactionWithMetadata> formatTransactions(
final List<Transaction> txs, final long blockNumber, final Hash blockHash) {
final List<Transaction> txs,
final long blockNumber,
final Optional<Long> baseFee,
final Hash blockHash) {
final int count = txs.size();
final List<TransactionWithMetadata> result = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
result.add(new TransactionWithMetadata(txs.get(i), blockNumber, blockHash, i));
result.add(new TransactionWithMetadata(txs.get(i), blockNumber, baseFee, blockHash, i));
}
return result;
}

@ -25,12 +25,14 @@ public class TransactionWithMetadata {
private final Transaction transaction;
private final Optional<Long> blockNumber;
private final Optional<Long> baseFee;
private final Optional<Hash> blockHash;
private final Optional<Integer> transactionIndex;
public TransactionWithMetadata(final Transaction transaction) {
this.transaction = transaction;
this.blockNumber = Optional.empty();
this.baseFee = Optional.empty();
this.blockHash = Optional.empty();
this.transactionIndex = Optional.empty();
}
@ -38,10 +40,12 @@ public class TransactionWithMetadata {
public TransactionWithMetadata(
final Transaction transaction,
final long blockNumber,
final Optional<Long> baseFee,
final Hash blockHash,
final int transactionIndex) {
this.transaction = transaction;
this.blockNumber = Optional.of(blockNumber);
this.baseFee = baseFee;
this.blockHash = Optional.of(blockHash);
this.transactionIndex = Optional.of(transactionIndex);
}
@ -54,6 +58,10 @@ public class TransactionWithMetadata {
return blockNumber;
}
public Optional<Long> getBaseFee() {
return baseFee;
}
public Optional<Hash> getBlockHash() {
return blockHash;
}

@ -1682,7 +1682,12 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
final Hash expectedBlockHash = block.getHeader().getHash();
final long expectedBlockNumber = block.getHeader().getNumber();
assertTransactionResultMatchesTransaction(
transactionResult, transaction, expectedIndex, expectedBlockHash, expectedBlockNumber);
transactionResult,
transaction,
expectedIndex,
expectedBlockHash,
block.getHeader().getBaseFee(),
expectedBlockNumber);
}
}
}
@ -1692,6 +1697,7 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
final Transaction transaction,
final Integer index,
final Hash blockHash,
final Optional<Long> baseFee,
final Long blockNumber) {
assertThat(Hash.fromHexString(result.getString("hash"))).isEqualTo(transaction.getHash());
assertThat(Long.decode(result.getString("nonce"))).isEqualByComparingTo(transaction.getNonce());
@ -1720,7 +1726,7 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
}
assertThat(Wei.fromHexString(result.getString("value"))).isEqualTo(transaction.getValue());
assertThat(Optional.ofNullable(result.getString("gasPrice")).map(Wei::fromHexString))
.isEqualTo(transaction.getGasPrice());
.isEqualTo(Optional.of(transaction.getEffectiveGasPrice(baseFee)));
assertThat(Optional.ofNullable(result.getString("maxFeePerGas")).map(Wei::fromHexString))
.isEqualTo(transaction.getMaxFeePerGas());
assertThat(
@ -1843,7 +1849,11 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
for (int i = 0; i < txs.size(); i++) {
formattedTxs.add(
new TransactionWithMetadata(
txs.get(i), block.getHeader().getNumber(), block.getHash(), i));
txs.get(i),
block.getHeader().getNumber(),
block.getHeader().getBaseFee(),
block.getHash(),
i));
}
final List<Hash> ommers =
block.getBody().getOmmers().stream().map(BlockHeader::getHash).collect(Collectors.toList());

@ -89,7 +89,8 @@ public class DebugStorageRangeAtTest {
@Test
public void shouldRetrieveStorageRange_fullValues() {
final TransactionWithMetadata transactionWithMetadata =
new TransactionWithMetadata(transaction, 12L, blockHash, TRANSACTION_INDEX);
new TransactionWithMetadata(
transaction, 12L, Optional.empty(), blockHash, TRANSACTION_INDEX);
final BlockWithMetadata<TransactionWithMetadata, Hash> blockWithMetadata =
new BlockWithMetadata<>(
blockHeader,

@ -70,7 +70,7 @@ public class DebugTraceTransactionTest {
@Test
public void shouldTraceTheTransactionUsingTheTransactionTracer() {
final TransactionWithMetadata transactionWithMetadata =
new TransactionWithMetadata(transaction, 12L, blockHash, 2);
new TransactionWithMetadata(transaction, 12L, Optional.empty(), blockHash, 2);
final Map<String, Boolean> map = new HashMap<>();
map.put("disableStorage", true);
final Object[] params = new Object[] {transactionHash, map};

@ -167,7 +167,8 @@ public class EthGetUncleByBlockHashAndIndexTest {
for (int i = 0; i < 3; i++) {
final Transaction transaction = transactionTestFixture.createTransaction(keyPair);
transactions.add(
new TransactionWithMetadata(transaction, header.getNumber(), header.getHash(), 0));
new TransactionWithMetadata(
transaction, header.getNumber(), header.getBaseFee(), header.getHash(), 0));
}
final List<Hash> ommers = new ArrayList<>();

@ -143,7 +143,8 @@ public class EthGetUncleByBlockNumberAndIndexTest {
for (int i = 0; i < 3; i++) {
final Transaction transaction = transactionTestFixture.createTransaction(keyPair);
transactions.add(
new TransactionWithMetadata(transaction, header.getNumber(), header.getHash(), 0));
new TransactionWithMetadata(
transaction, header.getNumber(), Optional.empty(), header.getHash(), 0));
}
final List<Hash> ommers = new ArrayList<>();

@ -45,6 +45,7 @@ public class TransactionCompleteResultTest {
.maxPriorityFeePerGas(Optional.of(Wei.ZERO))
.createTransaction(gen.generateKeyPair()),
0L,
Optional.of(7L),
Hash.ZERO,
0));
@ -57,10 +58,41 @@ public class TransactionCompleteResultTest {
final BlockDataGenerator gen = new BlockDataGenerator();
final Transaction transaction = gen.transaction(TransactionType.EIP1559);
TransactionCompleteResult tcr =
new TransactionCompleteResult(new TransactionWithMetadata(transaction, 0L, Hash.ZERO, 0));
new TransactionCompleteResult(
new TransactionWithMetadata(transaction, 0L, Optional.of(7L), Hash.ZERO, 0));
assertThat(tcr.getMaxFeePerGas()).isNotEmpty();
assertThat(tcr.getMaxPriorityFeePerGas()).isNotEmpty();
assertThat(tcr.getGasPrice()).isNull();
assertThat(tcr.getGasPrice()).isNotEmpty();
assertThat(tcr.getGasPrice())
.isEqualTo(Quantity.create(transaction.getEffectiveGasPrice(Optional.of(7L))));
}
@Test
public void legacyTransactionPostLondonFields() {
final BlockDataGenerator gen = new BlockDataGenerator();
final Transaction transaction = gen.transaction(TransactionType.FRONTIER);
TransactionCompleteResult tcr =
new TransactionCompleteResult(
new TransactionWithMetadata(transaction, 0L, Optional.of(7L), Hash.ZERO, 0));
assertThat(tcr.getMaxFeePerGas()).isNull();
assertThat(tcr.getMaxPriorityFeePerGas()).isNull();
assertThat(tcr.getGasPrice()).isNotEmpty();
assertThat(tcr.getGasPrice())
.isEqualTo(Quantity.create(transaction.getGasPrice().orElseThrow()));
}
@Test
public void legacyTransactionPreLondonFields() {
final BlockDataGenerator gen = new BlockDataGenerator();
final Transaction transaction = gen.transaction(TransactionType.FRONTIER);
TransactionCompleteResult tcr =
new TransactionCompleteResult(
new TransactionWithMetadata(transaction, 0L, Optional.empty(), Hash.ZERO, 0));
assertThat(tcr.getMaxFeePerGas()).isNull();
assertThat(tcr.getMaxPriorityFeePerGas()).isNull();
assertThat(tcr.getGasPrice()).isNotEmpty();
assertThat(tcr.getGasPrice())
.isEqualTo(Quantity.create(transaction.getGasPrice().orElseThrow()));
}
@Test
@ -72,6 +104,7 @@ public class TransactionCompleteResultTest {
new TransactionWithMetadata(
transaction,
136,
Optional.empty(),
Hash.fromHexString(
"0xfc84c3946cb419cbd8c2c68d5e79a3b2a03a8faff4d9e2be493f5a07eb5da95e"),
0));

Loading…
Cancel
Save