tx limit size send peers follow up (#1308)

* Implement max message size rather then cap with fixed number of transactions

Adding transactions to the RLP until the message size exceeds the limit and then send that.

* fix final variables

* Update AbstractRLPOutput.java

add javadoc

* pr discussion

put this factory method on LimitedTransactionsMessages rather than TransactionsMessage since it returns a LimitedTransactionsMessages.

* SpotlessApply

* fix PR discussion

- simplify design
- remove useless code

* Update LimitedTransactionsMessages.java

* fix PR discussion

- simplify logic
- add tests

* Update AbstractRLPOutput.java

* Update ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/messages/LimitedTransactionsMessages.java

Co-Authored-By: abdelhamidbakhta <45264458+abdelhamidbakhta@users.noreply.github.com>

* Update Transaction.java

* fix PR discussion

* fix PR discussion

- add tests

* Update BlockDataGenerator.java

* Update LimitedTransactionsMessagesTest.java

fix PR unit test

* Update LimitedTransactionsMessagesTest.java

* Update LimitedTransactionsMessagesTest.java

Use LinkedHashSet to preserve order.

* Update LimitedTransactionsMessagesTest.java

* follow up PR

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Abdelhamid Bakhta 6 years ago committed by GitHub
parent b184320826
commit b8d97bca9a
  1. 2
      ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/messages/LimitedTransactionsMessages.java
  2. 21
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/messages/LimitedTransactionsMessagesTest.java

@ -21,7 +21,7 @@ import java.util.Set;
public final class LimitedTransactionsMessages {
private static final int LIMIT = 1048576;
static final int LIMIT = 1048576;
private final TransactionsMessage transactionsMessage;
private final Set<Transaction> includedTransactions;

@ -14,6 +14,7 @@ package tech.pegasys.pantheon.ethereum.eth.messages;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static tech.pegasys.pantheon.ethereum.eth.messages.LimitedTransactionsMessages.LIMIT;
import tech.pegasys.pantheon.ethereum.core.BlockDataGenerator;
import tech.pegasys.pantheon.ethereum.core.Transaction;
@ -27,8 +28,7 @@ import org.junit.Test;
public class LimitedTransactionsMessagesTest {
private static final int LIMIT = 1048576;
private static final int TX_PAYLOAD_LIMIT = LIMIT - 180;
private final BlockDataGenerator generator = new BlockDataGenerator();
private final Set<Transaction> sampleTxs = generator.transactions(1);
private final TransactionsMessage sampleTransactionMessages =
@ -55,11 +55,11 @@ public class LimitedTransactionsMessagesTest {
}
@Test
public void createLimitedWithFirstTransactionExceedingLimit() {
public void createLimitedWithTransactionsJustUnderTheLimit() {
final Set<Transaction> txs = new HashSet<>();
txs.add(generator.transaction(BytesValue.wrap(new byte[LIMIT - 180])));
txs.add(generator.transaction(BytesValue.wrap(new byte[LIMIT - 180])));
txs.add(generator.transaction(BytesValue.wrap(new byte[LIMIT - 180])));
txs.add(generator.transaction(BytesValue.wrap(new byte[TX_PAYLOAD_LIMIT])));
txs.add(generator.transaction(BytesValue.wrap(new byte[TX_PAYLOAD_LIMIT])));
txs.add(generator.transaction(BytesValue.wrap(new byte[TX_PAYLOAD_LIMIT])));
final LimitedTransactionsMessages firstMessage = LimitedTransactionsMessages.createLimited(txs);
assertEquals(2, firstMessage.getIncludedTransactions().size());
txs.removeAll(firstMessage.getIncludedTransactions());
@ -72,12 +72,13 @@ public class LimitedTransactionsMessagesTest {
}
@Test
public void createLimitedWithFirstTransactionExceedingLimit_2() {
public void createLimitedWithTransactionsJustUnderAndJustOverTheLimit() {
final Set<Transaction> txs = new LinkedHashSet<>();
txs.add(generator.transaction(BytesValue.wrap(new byte[LIMIT - 180])));
txs.add(generator.transaction(BytesValue.wrap(new byte[LIMIT + 100 - 180])));
txs.add(generator.transaction(BytesValue.wrap(new byte[LIMIT - 180])));
txs.add(generator.transaction(BytesValue.wrap(new byte[TX_PAYLOAD_LIMIT])));
// ensure the next transaction exceed the limit TX_PAYLOAD_LIMIT + 100
txs.add(generator.transaction(BytesValue.wrap(new byte[TX_PAYLOAD_LIMIT + 100])));
txs.add(generator.transaction(BytesValue.wrap(new byte[TX_PAYLOAD_LIMIT])));
final LimitedTransactionsMessages firstMessage = LimitedTransactionsMessages.createLimited(txs);
assertEquals(1, firstMessage.getIncludedTransactions().size());
txs.removeAll(firstMessage.getIncludedTransactions());

Loading…
Cancel
Save