nim-eth
nim-eth copied to clipboard
Rework ENR code to solve several shortcomings
There are several issues in the current ENR code, to name some:
- Currently it is possible to have FieldPairs with duplicate keys or even full duplicate FieldPairs in the ENR due to the custom
extraFieldsin the API - Currently we cannot remove FIeldPairs in some update ENR function (see also https://github.com/status-im/nim-eth/issues/639)
- Currently when using the API with Opt IpAddres or Port, providing an Opt.none will not actually remove the field
- Some API that is more restrictive than the other:
Record.initversusinitRecord. The latter is not even used anywhere except for testing. - the
extraFieldsparameters andinitRecordAPI allows for reserved keys with invalid types to get into the ENR.
Additionally, there is currently no easy API to set the ip6, tcp6 and udp6 reserved fields. It is only possible through the custom extraFields, which doesn't limit these reserved keys to the correct value type.
Part 1: https://github.com/status-im/nim-eth/pull/707
More parts to do:
- Rework also the decoding of an ENR (need to move id key check and possibly others?) and then make toTypedRecord no longer allowed to fail.
- Add dual stack support in ENR
- Cleaner kv access
- Adding an EnrBuilder is something that fits well for ENR's I think
- Removal of fields + better API for update and/or just set individual parts