Skip to content

Commit

Permalink
Expose v field in JSON-RPC in some transaction types (hyperledger#6819
Browse files Browse the repository at this point in the history
)

* Expose `v` field in JSON-RPC in some transaction types

The execution API marks the `v` field as optional for EIP-2930 and
EIP-1559 transactions, preferring the `yParity` feld.  However, some
tooling still depends on the presence of the `v` field. For those two
transaction types both `v` and `yParity` will be returned now.

Signed-off-by: Danno Ferrin <[email protected]>
  • Loading branch information
shemnon authored and matthew1001 committed Jun 7, 2024
1 parent 5525f39 commit 77014d9
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- Fix txpool dump/restore race condition [#6665](https://github.com/hyperledger/besu/pull/6665)
- Make block transaction selection max time aware of PoA transitions [#6676](https://github.com/hyperledger/besu/pull/6676)
- Don't enable the BFT mining coordinator when running sub commands such as `blocks export` [#6675](https://github.com/hyperledger/besu/pull/6675)
- In JSON-RPC return optional `v` fields for type 1 and type 2 transactions [#6762](https://github.com/hyperledger/besu/pull/6762)

### Download Links

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public TransactionCompleteResult(final TransactionWithMetadata tx) {
this.v =
(transactionType == TransactionType.ACCESS_LIST
|| transactionType == TransactionType.EIP1559)
? this.yParity
? Quantity.create(transaction.getV())
: null;
}
this.value = Quantity.create(transaction.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public TransactionPendingResult(final Transaction transaction) {
this.v =
(transactionType == TransactionType.ACCESS_LIST
|| transactionType == TransactionType.EIP1559)
? this.yParity
? Quantity.create(transaction.getV())
: null;
}
this.value = Quantity.create(transaction.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public PendingTransactionDetailResult(final Transaction tx) {
this.v =
(transactionType == TransactionType.ACCESS_LIST
|| transactionType == TransactionType.EIP1559)
? this.yParity
? Quantity.create(tx.getV())
: null;
}
this.value = Quantity.create(tx.getValue());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"request": "{transaction (hash : \"0x3ecd2ca6cf26c864d0ea5f038a58d4cd4a46a3e242fe92f446f392fdc232dd98\") { accessList { address storageKeys } maxFeePerGas maxPriorityFeePerGas nonce type status } } ",
"request": "{transaction (hash : \"0x3ecd2ca6cf26c864d0ea5f038a58d4cd4a46a3e242fe92f446f392fdc232dd98\") { accessList { address storageKeys } maxFeePerGas maxPriorityFeePerGas nonce type status yParity v} } ",
"response": {
"data": {
"transaction": {
Expand All @@ -15,7 +15,9 @@
"maxPriorityFeePerGas": "0x3b9aca00",
"nonce": "0x20",
"type": "0x2",
"status": "0x1"
"status": "0x1",
"yParity": "0x0",
"v": "0x25"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"type": "0x2",
"value": "0x0",
"yParity": "0x0",
"v" : "0x0",
"v" : "0x25",
"r": "0x8abbfbd4c5f2a13a8d5ed394ac50bac7d678f83a23f645818492f76e8ee17ab3",
"s": "0x7bd38c6929235f775d68b45bd7dea7981264f9a265b6bea97b070e15be88389c"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,14 @@ public BigInteger getS() {

@Override
public BigInteger getV() {
if (transactionType != null && transactionType != TransactionType.FRONTIER) {
// EIP-2718 typed transaction, use yParity:
if (transactionType != null
&& transactionType != TransactionType.FRONTIER
&& transactionType != TransactionType.ACCESS_LIST
&& transactionType != TransactionType.EIP1559) {
// Newer transaction type lacks V, so return null
return null;
} else {
// Mandatory for legacy, optional for EIP-2930 and EIP-1559 TXes, prohibited for all others.
final BigInteger recId = BigInteger.valueOf(signature.getRecId());
return chainId
.map(bigInteger -> recId.add(REPLAY_PROTECTED_V_BASE).add(TWO.multiply(bigInteger)))
Expand Down

0 comments on commit 77014d9

Please sign in to comment.