Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update RPCs for yParity #6119

Merged
merged 11 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Implement new `miner_setMinPriorityFee` and `miner_getMinPriorityFee` RPC methods [#6080](https://github.com/hyperledger/besu/pull/6080)
- Clique config option `createemptyblocks` to not create empty blocks [#6082](https://github.com/hyperledger/besu/pull/6082)
- Upgrade EVM Reference Tests to v13 (Cancun) [#6114](https://github.com/hyperledger/besu/pull/6114)
- Add `yParity` to GraphQL and JSON-RPC for relevant querise. [6119](https://github.com/hyperledger/besu/pull/6119)

### Bug fixes

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,15 @@ default Optional<? extends Quantity> getMaxFeePerBlobGas() {
Quantity getValue();

/**
* Value corresponding to the 'V' component of the signature of the transaction.
* Value corresponding to the 'yParity' component of non-legacy signatures.
*
* @return the 'yParity' component of the signature
*/
BigInteger getYParity();

/**
* Value corresponding to the 'v' component of legacy signatures, which encodes chainId and
* yParity.
*
* @return the 'V' component of the signature
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity;

import java.math.BigInteger;
import java.util.Locale;

import graphql.GraphQLContext;
Expand Down Expand Up @@ -118,6 +119,8 @@ String convertImpl(final Object input) {
return convertImpl(stringValue.getValue());
} else if (input instanceof IntValue intValue) {
return UInt256.valueOf(intValue.getValue()).toShortHexString();
} else if (input instanceof BigInteger bigInteger) {
return "0x" + bigInteger.toString(16);
} else {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -235,6 +236,22 @@ public List<LogAdapter> getLogs(final DataFetchingEnvironment environment) {
return results;
}

public BigInteger getR() {
return transactionWithMetadata.getTransaction().getR();
}

public BigInteger getS() {
return transactionWithMetadata.getTransaction().getS();
}

public Optional<BigInteger> getV() {
return Optional.ofNullable(transactionWithMetadata.getTransaction().getV());
}

public Optional<BigInteger> getYParity() {
return Optional.ofNullable(transactionWithMetadata.getTransaction().getYParity());
}

public List<AccessListEntryAdapter> getAccessList() {
return transactionWithMetadata
.getTransaction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"transactionIndex",
"type",
"value",
"yParity",
"v",
"r",
"s",
Expand Down Expand Up @@ -82,6 +83,7 @@ public class TransactionCompleteResult implements TransactionResult {
private final String transactionIndex;
private final String type;
private final String value;
private final String yParity;
private final String v;
private final String r;
private final String s;
Expand Down Expand Up @@ -114,12 +116,17 @@ public TransactionCompleteResult(final TransactionWithMetadata tx) {
this.nonce = Quantity.create(transaction.getNonce());
this.to = transaction.getTo().map(Bytes::toHexString).orElse(null);
this.transactionIndex = Quantity.create(tx.getTransactionIndex().get());
this.type =
transactionType.equals(TransactionType.FRONTIER)
? Quantity.create(0)
: Quantity.create(transactionType.getSerializedType());
if (transactionType.equals(TransactionType.FRONTIER)) {
this.type = Quantity.create(0);
this.yParity = null;
this.v = Quantity.create(transaction.getV());

} else {
this.type = Quantity.create(transactionType.getSerializedType());
this.yParity = Quantity.create(transaction.getYParity());
this.v = null;
}
this.value = Quantity.create(transaction.getValue());
this.v = Quantity.create(transaction.getV());
this.r = Quantity.create(transaction.getR());
this.s = Quantity.create(transaction.getS());
this.versionedHashes = transaction.getVersionedHashes().orElse(null);
Expand Down Expand Up @@ -210,6 +217,13 @@ public String getValue() {
return value;
}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonGetter(value = "yParity")
public String getYParity() {
return yParity;
}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonGetter(value = "v")
public String getV() {
return v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"to",
"transactionIndex",
"value",
"yParity",
"v",
"r",
"s",
Expand Down Expand Up @@ -77,6 +78,7 @@ public class TransactionPendingResult implements TransactionResult {
private final String to;
private final String type;
private final String value;
private final String yParity;
private final String v;
private final String r;
private final String s;
Expand Down Expand Up @@ -104,12 +106,17 @@ public TransactionPendingResult(final Transaction transaction) {
TransactionEncoder.encodeOpaqueBytes(transaction, EncodingContext.POOLED_TRANSACTION)
.toString();
this.to = transaction.getTo().map(Address::toHexString).orElse(null);
this.type =
transactionType.equals(TransactionType.FRONTIER)
? Quantity.create(0)
: Quantity.create(transactionType.getSerializedType());
if (transactionType.equals(TransactionType.FRONTIER)) {
this.type = Quantity.create(0);
this.yParity = null;
this.v = Quantity.create(transaction.getV());

} else {
this.type = Quantity.create(transactionType.getSerializedType());
this.yParity = Quantity.create(transaction.getYParity());
this.v = null;
}
this.value = Quantity.create(transaction.getValue());
this.v = Quantity.create(transaction.getV());
this.r = Quantity.create(transaction.getR());
this.s = Quantity.create(transaction.getS());
this.versionedHashes = transaction.getVersionedHashes().orElse(null);
Expand Down Expand Up @@ -195,6 +202,13 @@ public String getValue() {
return value;
}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonGetter(value = "yParity")
public String getYParity() {
return yParity;
}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonGetter(value = "v")
public String getV() {
return v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.hyperledger.besu.ethereum.core.Transaction;

import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.apache.tuweni.bytes.Bytes;

Expand All @@ -33,6 +34,7 @@
"to",
"type",
"value",
"yParity",
"v",
"r",
"s"
Expand All @@ -47,24 +49,31 @@ public class PendingTransactionDetailResult implements JsonRpcResult {
private final String to;
private final String type;
private final String value;
private final String yParity;
private final String v;
private final String r;
private final String s;

public PendingTransactionDetailResult(final Transaction tx) {
TransactionType transactionType = tx.getType();
this.from = tx.getSender().toString();
this.gas = Quantity.create(tx.getGasLimit());
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());
this.to = tx.getTo().map(Bytes::toHexString).orElse(null);
this.type =
tx.getType().equals(TransactionType.FRONTIER)
? Quantity.create(0)
: Quantity.create(tx.getType().getSerializedType());
if (transactionType.equals(TransactionType.FRONTIER)) {
this.type = Quantity.create(0);
this.yParity = null;
this.v = Quantity.create(tx.getV());

} else {
this.type = Quantity.create(transactionType.getSerializedType());
this.yParity = Quantity.create(tx.getYParity());
this.v = null;
}
this.value = Quantity.create(tx.getValue());
this.v = Quantity.create(tx.getV());
this.r = Quantity.create(tx.getR());
this.s = Quantity.create(tx.getS());
}
Expand Down Expand Up @@ -114,6 +123,13 @@ public String getValue() {
return value;
}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonGetter(value = "yParity")
public String getyParity() {
return yParity;
}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonGetter(value = "v")
public String getV() {
return v;
Expand Down
5 changes: 3 additions & 2 deletions ethereum/api/src/main/resources/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,8 @@ type Transaction {
logs: [Log!]
r: BigInt!
s: BigInt!
v: BigInt!
v: BigInt
yParity: BigInt

"""Envelope transaction support"""
type: Long
Expand Down Expand Up @@ -595,4 +596,4 @@ type Withdrawal {

"""Amount is the withdrawal value in Gwei."""
amount: Long!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.plugin.data.SyncStatus;
import org.hyperledger.besu.testutil.BlockTestUtil;

import java.nio.file.Path;
import java.util.Collections;
Expand Down Expand Up @@ -74,9 +73,7 @@ public abstract class AbstractEthGraphQLHttpServiceTest {

@BeforeAll
public static void setupConstants() {
blockchainSetupUtil =
BlockchainSetupUtil.createForEthashChain(
BlockTestUtil.getHiveTestChainResources(), DataStorageFormat.BONSAI);
blockchainSetupUtil = BlockchainSetupUtil.forHiveTesting(DataStorageFormat.BONSAI);
blockchainSetupUtil.importAllBlocks();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected void setupBonsaiBlockchain() {
}

protected BlockchainSetupUtil getBlockchainSetupUtil(final DataStorageFormat storageFormat) {
return BlockchainSetupUtil.forTesting(storageFormat);
return BlockchainSetupUtil.forHiveTesting(storageFormat);
}

protected BlockchainSetupUtil createBlockchainSetupUtil(
Expand All @@ -121,8 +121,7 @@ public void setup() throws Exception {
setupBlockchain();
}

protected BlockchainSetupUtil startServiceWithEmptyChain(final DataStorageFormat storageFormat)
throws Exception {
protected BlockchainSetupUtil startServiceWithEmptyChain(final DataStorageFormat storageFormat) {
final BlockchainSetupUtil emptySetupUtil = getBlockchainSetupUtil(storageFormat);
startService(emptySetupUtil);
return emptySetupUtil;
Expand Down Expand Up @@ -199,7 +198,7 @@ protected void startService() throws Exception {
startService(blockchainSetupUtil);
}

private void startService(final BlockchainSetupUtil blockchainSetupUtil) throws Exception {
private void startService(final BlockchainSetupUtil blockchainSetupUtil) {

final JsonRpcConfiguration config = JsonRpcConfiguration.createDefault();
final Map<String, JsonRpcMethod> methods = getRpcMethods(config, blockchainSetupUtil);
Expand Down
Loading
Loading