rlp: precursor changes for trie, p2p#1778
Conversation
Updated: Thu Sep 10 17:26:32 UTC 2015 |
059abe4 to
50c424f
Compare
|
👍 |
There was a problem hiding this comment.
Wouldn't this switch be simpler with? (Haven't run the code, just a pseudo-code suggestion)
binary.Read(bytes.NewBuffer(b[:int(slen)]), binary.BigEndian, &s)
There was a problem hiding this comment.
package binary assumes that the input contains enough bytes to hold a uint64. b isn't always 8 bytes long. Furthermore, the Split* functions should not allocate or use reflection.
|
Could you also add a test which verifies the encoder EOF issue and its resolution? IMHO the bug and fix is very subtle, so I'd like to see a test to avoid an accidental regression. |
2b546ab to
11f1bc7
Compare
|
@karalabe PTAL |
11f1bc7 to
1ad1af7
Compare
|
Please don't merge directly after review, I still need to squash these. |
There was a problem hiding this comment.
The tagsize in this condition took me a while to verify that it cannot screw up. Maybe we could simply write buf[1] there? If it's a string, it means the tag == 1 if length <= 55, or tag == [2-9] if length > 55. Since the content check already made sure we're in the first case, tag must be == 1. It would seem cleaner to write that there, instead of the variable. But this is really nitpicking, I can live without it :D
|
LGTM 👍 |
The bug can cause crashes if Read is called after EOF has been returned. No code performs such calls right now, but hitting the bug gets more likely as rlp.EncodeToReader gets used in more places.
1ad1af7 to
f73fd95
Compare
|
@karalabe I've moved the check into the case where it applies. |
These functions allow destructuring of raw rlp-encoded bytes without the overhead of reflection or copying.
f73fd95 to
fc8b246
Compare
rlp: precursor changes for trie, p2p
* check error from getting statedb for a block to avoid panic * add a warning log statement * 🤦 * Update ethstats/ethstats.go Co-authored-by: piersy <pierspowlesland@gmail.com> * remove unessasary change Co-authored-by: piersy <pierspowlesland@gmail.com> Co-authored-by: Gaston Ponti <pontigaston@gmail.com>
These changes are required both for the new trie code and the full rlpx protocol implementation.