Skip to content

Commit

Permalink
Fix bug with value transfer (hyperledger#2609)
Browse files Browse the repository at this point in the history
Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
  • Loading branch information
macfarla authored Aug 4, 2021
1 parent 481832e commit 8bad30c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,15 @@ public TransactionType getType() {
/**
* Returns whether or not the transaction is a GoQuorum private transaction. <br>
* <br>
* A GoQuorum private transaction has its <i>v</i> value equal to 37 or 38.
* A GoQuorum private transaction has its <i>v</i> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -236,7 +235,7 @@ private ValidationResult<TransactionInvalidReason> validateTransaction(
final BlockHeader chainHeadBlockHeader = getChainHeadBlockHeader();

// Check whether it's a GoQuorum transaction
if (isGoQuorumPrivateTransaction(transaction)) {
if (transaction.isGoQuorumPrivateTransaction()) {
final Optional<Wei> weiValue = ofNullable(transaction.getValue());
if (weiValue.isPresent() && !weiValue.get().isZero()) {
return ValidationResult.invalid(TransactionInvalidReason.ETHER_VALUE_NOT_SUPPORTED);
Expand Down Expand Up @@ -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<Transaction> transactions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransactionInvalidReason> result =
transactionPool.addLocalTransaction(transaction);

assertThat(result).isEqualTo(ValidationResult.valid());
}

@Test
public void shouldReturnExclusivelyLocalTransactionsWhenAppropriate() {
final Transaction localTransaction0 = createTransaction(0);
Expand Down

0 comments on commit 8bad30c

Please sign in to comment.