Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

[PAN-2879] Support multiple private marker transactions in a block #1646

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.Transaction;
import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions;
import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPool;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcMethod;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
Expand All @@ -35,6 +36,8 @@
import tech.pegasys.pantheon.ethereum.rlp.RLPException;
import tech.pegasys.pantheon.util.bytes.BytesValue;

import java.util.OptionalLong;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -46,6 +49,7 @@ public class EeaSendRawTransaction implements JsonRpcMethod {
private final PrivateTransactionHandler privateTransactionHandler;
private final TransactionPool transactionPool;
private final JsonRpcParameter parameters;
private final PendingTransactions pendingTransactions;

public EeaSendRawTransaction(
final BlockchainQueries blockchain,
Expand All @@ -56,6 +60,7 @@ public EeaSendRawTransaction(
this.privateTransactionHandler = privateTransactionHandler;
this.transactionPool = transactionPool;
this.parameters = parameters;
this.pendingTransactions = transactionPool.getPendingTransactions();
}

@Override
Expand Down Expand Up @@ -136,6 +141,8 @@ private PrivateTransaction decodeRawTransaction(final String hash)
}

protected long getNonce(final Address address) {
return blockchain.getTransactionCount(address, blockchain.headBlockNumber());
final OptionalLong pendingNonce = pendingTransactions.getNextNonceForSender(address);
return pendingNonce.orElseGet(
() -> blockchain.getTransactionCount(address, blockchain.headBlockNumber()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.Transaction;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions;
import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPool;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter;
Expand All @@ -39,6 +40,7 @@
import java.io.IOException;
import java.math.BigInteger;
import java.util.Optional;
import java.util.OptionalLong;

import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -108,8 +110,12 @@ public class EeaSendRawTransactionTest {

@Mock private BlockchainQueries blockchainQueries;

@Mock private PendingTransactions pendingTransactions;

@Before
public void before() {
when(transactionPool.getPendingTransactions()).thenReturn(pendingTransactions);

method =
new EeaSendRawTransaction(blockchainQueries, privateTxHandler, transactionPool, parameter);
}
Expand Down Expand Up @@ -200,7 +206,6 @@ public void validTransactionIsSentToTransactionPool() throws Exception {
.thenReturn(PUBLIC_TRANSACTION);
when(transactionPool.addLocalTransaction(any(Transaction.class)))
.thenReturn(ValidationResult.valid());

final JsonRpcRequest request =
new JsonRpcRequest(
"2.0", "eea_sendRawTransaction", new String[] {VALID_PRIVATE_TRANSACTION_RLP});
Expand Down Expand Up @@ -340,7 +345,6 @@ private void verifyErrorForInvalidTransaction(
.thenReturn(PUBLIC_TRANSACTION);
when(transactionPool.addLocalTransaction(any(Transaction.class)))
.thenReturn(ValidationResult.invalid(transactionInvalidReason));

final JsonRpcRequest request =
new JsonRpcRequest(
"2.0", "eea_sendRawTransaction", new String[] {VALID_PRIVATE_TRANSACTION_RLP});
Expand All @@ -361,6 +365,13 @@ private void verifyErrorForInvalidTransaction(
verify(transactionPool).addLocalTransaction(any(Transaction.class));
}

@Test
public void nextNonceUsesTxPool() {
Address address = PUBLIC_TRANSACTION.getSender();
when(pendingTransactions.getNextNonceForSender(address)).thenReturn(OptionalLong.of(123));
assertThat(method.getNonce(address)).isEqualTo(123);
}

@Test
public void getMethodReturnsExpectedName() {
assertThat(method.getName()).matches("eea_sendRawTransaction");
Expand Down