Skip to content

Conversation

@Gabriel-Trintinalia
Copy link
Contributor

@Gabriel-Trintinalia Gabriel-Trintinalia commented Feb 27, 2023

PR description

This PR fixes two issues with RLP encoding:

1- BlockBody

For the BlockBody RLP serialisation, when an empty body [] is sent, a breach of protocol is triggered and Besu disconnects the peer. That causes Besu to disconnect peers with a good reputation. This PR adds an option in the readFrom method to allow an empty BlockBody whenever a [] is found. The message will be verified later and marked as invalid anyway, but besu will not disconnect the peer.

2 -NewPooledTransactionHashesMessage

NewPooledTransactionHashesMessage on Eth/68 has an issue with the array of types (byte):

[[type_0: B_1, type_1: B_1, ...], [size_0: B_4, size_1: B_4, ...], [hash_0: B_32, hash_1: B_32, ...]]

The current implementation serializes it as:

[
      ["0x01","0x02"]
      ["0x00000001","0x00000002"],
      ["0x0000000000000000000000000000000000000000000000000000000000000001",
       "0x0000000000000000000000000000000000000000000000000000000000000002"]
]

The other clients send the first array of this message as one element instead of an array:

[
      ["0x0102"]
      ["0x00000002","0x00000003"],
      ["0x0000000000000000000000000000000000000000000000000000000000000002",
       "0x0000000000000000000000000000000000000000000000000000000000000003"]
]

This PR fixes the encoding to match the other client messages.

see #5056

Documentation

  • I thought about documentation and added the doc-change-required label to this PR if
    updates are required.

Acceptance Tests (Non Mainnet)

  • I have considered running ./gradlew acceptanceTestNonMainnet locally if my PR affects non-mainnet modules.

Changelog

Signed-off-by: Gabriel-Trintinalia <[email protected]>
Signed-off-by: Gabriel-Trintinalia <[email protected]>
Signed-off-by: Gabriel-Trintinalia <[email protected]>
Signed-off-by: Gabriel-Trintinalia <[email protected]>
Signed-off-by: Gabriel-Trintinalia <[email protected]>
Signed-off-by: Gabriel-Trintinalia <[email protected]>
@Gabriel-Trintinalia Gabriel-Trintinalia changed the title WIP - Log message data when RLPException WIP - Fix issues with RLPExceptions Feb 28, 2023
Comment on lines +108 to +112
if (input.isEndOfCurrentList() && allowEmptyBody) {
// empty block [] -> Return empty body.
input.leaveList();
return empty();
}
Copy link
Contributor Author

@Gabriel-Trintinalia Gabriel-Trintinalia Feb 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle empty block body

Comment on lines +74 to +78
final List<TransactionType> types = new ArrayList<>();
final byte[] bytes = input.readBytes().toArray();
for (final byte b : bytes) {
types.add(b == 0 ? TransactionType.FRONTIER : TransactionType.of(b));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix decoding

out.startList();
out.writeList(
types, (h, w) -> w.writeByte(h == TransactionType.FRONTIER ? 0x00 : h.getSerializedType()));
out.writeBytes(Bytes.wrap((types)));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix encoding

ScheduleBasedBlockHeaderFunctions.create(protocolSchedule);
return new BytesValueRLPInput(data, false)
.readList(rlp -> BlockBody.readFrom(rlp, blockHeaderFunctions));
.readList(rlp -> BlockBody.readFrom(rlp, blockHeaderFunctions, true));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow empty block bodies here

Copy link
Contributor

@pinges pinges left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

hashes.add(transaction.getHash());
});

for (int i = 0; i < transactions.size(); i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do prefer the forEach ... But the for loop should work as well :-)

final List<TransactionType> types, final List<Integer> sizes, final List<Hash> hashes) {

final byte[] byteTypes = new byte[types.size()];
for (int i = 0; i < types.size(); i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forEach would work here as well :-)

@Gabriel-Trintinalia Gabriel-Trintinalia marked this pull request as ready for review February 28, 2023 08:10
@Gabriel-Trintinalia Gabriel-Trintinalia changed the title WIP - Fix issues with RLPExceptions Fix issues with RLPExceptions Feb 28, 2023
Copy link
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTm.
is there a related hive test for the eth/68 encoding issue?

public void shouldThrowRLPExceptionIfNotAllowedEmptyBody() {
final Bytes bytes = Bytes.fromHexString("0xc0");
final BlockHeaderFunctions blockHeaderFunctions =
ScheduleBasedBlockHeaderFunctions.create(protocolSchedule);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the blockHeaderFunctions used?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not created for the other test shouldNotThrowRLPExceptionIfAllowedEmptyBody

@Gabriel-Trintinalia Gabriel-Trintinalia enabled auto-merge (squash) March 2, 2023 23:59
@Gabriel-Trintinalia Gabriel-Trintinalia enabled auto-merge (squash) March 3, 2023 00:11
@Gabriel-Trintinalia Gabriel-Trintinalia merged commit 19eef23 into hyperledger:main Mar 3, 2023
@Gabriel-Trintinalia Gabriel-Trintinalia deleted the test-peering-log-rpc-exception-data branch March 9, 2023 01:27
elenduuche pushed a commit to elenduuche/besu that referenced this pull request Aug 16, 2023
eum602 pushed a commit to lacchain/besu that referenced this pull request Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants