sigp / enr

Ethereum Node Record
MIT License
61 stars 29 forks source link

fix: decode rlp header on Enr::build #72

Closed mattsse closed 6 months ago

mattsse commented 6 months ago

closes #71

https://github.com/sigp/enr/issues/71#issuecomment-2033297989

Unless the .build() fails on normal types, it should be the case that all rlp-bytes can be decoded as bytes right?

This changes the sanitize check from Bytes::decode to Header::decode, this is required for list types that are added via Builder::add_value because Bytes::decode fails on lists: https://github.com/alloy-rs/rlp/blob/2ccf23f7b6a363c844443a13f9496391ee6892ac/crates/rlp/src/decode.rs#L83

added new test that fails on main:

test tests::test_add_content_value ... FAILED

failures:

---- tests::test_add_content_value stdout ----
thread 'tests::test_add_content_value' panicked at src/lib.rs:1519:14:
called `Result::unwrap()` on an `Err` value: InvalidRlpData(UnexpectedList)

also update Enr::get to restore the previous behaviour of rlp::data which returns the payload data

https://docs.rs/rlp/latest/src/rlp/rlpin.rs.html#159

we could add a Bytes::decode_unchecked to alloy-rlp that does not care about list

cc @DaniPopes