-
Notifications
You must be signed in to change notification settings - Fork 978
Fix issues with RLPExceptions #5140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issues with RLPExceptions #5140
Conversation
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]>
Signed-off-by: Gabriel-Trintinalia <[email protected]>
Signed-off-by: Gabriel-Trintinalia <[email protected]>
Signed-off-by: Gabriel-Trintinalia <[email protected]>
| if (input.isEndOfCurrentList() && allowEmptyBody) { | ||
| // empty block [] -> Return empty body. | ||
| input.leaveList(); | ||
| return empty(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle empty block body
| 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)); | ||
| } |
There was a problem hiding this comment.
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))); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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
pinges
left a comment
There was a problem hiding this 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++) { |
There was a problem hiding this comment.
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++) { |
There was a problem hiding this comment.
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 :-)
...perledger/besu/ethereum/eth/transactions/NewPooledTransactionHashesMessageProcessorTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Gabriel-Trintinalia <[email protected]>
macfarla
left a comment
There was a problem hiding this 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the blockHeaderFunctions used?
There was a problem hiding this comment.
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
Signed-off-by: Gabriel-Trintinalia <[email protected]>
Signed-off-by: Gabriel-Trintinalia <[email protected]>
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
NewPooledTransactionHashesMessageon 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:
The other clients send the first array of this message as one element instead of an array:
This PR fixes the encoding to match the other client messages.
see #5056
Documentation
doc-change-requiredlabel to this PR ifupdates are required.
Acceptance Tests (Non Mainnet)
./gradlew acceptanceTestNonMainnetlocally if my PR affects non-mainnet modules.Changelog