From 8bad30ca8a72534eba406eb3ebf71173d7024692 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Wed, 4 Aug 2021 10:34:46 +1000 Subject: [PATCH] Fix bug with value transfer (#2609) Signed-off-by: Sally MacFarlane --- .../besu/ethereum/core/Transaction.java | 6 +++++- .../eth/transactions/TransactionPool.java | 8 +------- .../eth/transactions/TransactionPoolTest.java | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java index a5f5b502c95..53aeb0c8db0 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java @@ -626,11 +626,15 @@ public TransactionType getType() { /** * Returns whether or not the transaction is a GoQuorum private transaction.
*
- * A GoQuorum private transaction has its v value equal to 37 or 38. + * A GoQuorum private transaction has its v value equal to 37 or 38, and does not contain a + * chainId. * * @return true if GoQuorum private transaction, false otherwise */ public boolean isGoQuorumPrivateTransaction() { + if (chainId.isPresent()) { + return false; + } return v.map( value -> GO_QUORUM_PRIVATE_TRANSACTION_V_VALUE_MIN.equals(value) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java index 53b406ef946..166e8dac485 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java @@ -47,7 +47,6 @@ import org.hyperledger.besu.plugin.services.metrics.Counter; import org.hyperledger.besu.plugin.services.metrics.LabelledMetric; -import java.math.BigInteger; import java.util.Collection; import java.util.HashSet; import java.util.Optional; @@ -236,7 +235,7 @@ private ValidationResult validateTransaction( final BlockHeader chainHeadBlockHeader = getChainHeadBlockHeader(); // Check whether it's a GoQuorum transaction - if (isGoQuorumPrivateTransaction(transaction)) { + if (transaction.isGoQuorumPrivateTransaction()) { final Optional weiValue = ofNullable(transaction.getValue()); if (weiValue.isPresent() && !weiValue.get().isZero()) { return ValidationResult.invalid(TransactionInvalidReason.ETHER_VALUE_NOT_SUPPORTED); @@ -291,11 +290,6 @@ private BlockHeader getChainHeadBlockHeader() { return blockchain.getBlockHeader(blockchain.getChainHeadHash()).get(); } - private boolean isGoQuorumPrivateTransaction(final Transaction transaction) { - return (transaction.getV().equals(BigInteger.valueOf(37)) - || (transaction.getV().equals(BigInteger.valueOf(38)))); - } - public interface TransactionBatchAddedListener { void onTransactionsAdded(Iterable transactions); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolTest.java index 26c8cc50ac6..08e0a645f8e 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolTest.java @@ -159,6 +159,22 @@ public void setUp() { blockchain.observeBlockAdded(transactionPool); } + @Test + public void mainNetValueTransferSucceeds() { + final Transaction transaction = + new TransactionTestFixture() + .value(Wei.ONE) + .chainId(Optional.of(BigInteger.ONE)) + .createTransaction(KEY_PAIR1); + + givenTransactionIsValid(transaction); + + final ValidationResult result = + transactionPool.addLocalTransaction(transaction); + + assertThat(result).isEqualTo(ValidationResult.valid()); + } + @Test public void shouldReturnExclusivelyLocalTransactionsWhenAppropriate() { final Transaction localTransaction0 = createTransaction(0);