nim-eth icon indicating copy to clipboard operation
nim-eth copied to clipboard

Rework ENR code to solve several shortcomings

Open kdeme opened this issue 1 year ago • 1 comments

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 extraFields in 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.init versus initRecord. The latter is not even used anywhere except for testing.
  • the extraFields parameters and initRecord API 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.

kdeme avatar Jun 20 '24 09:06 kdeme

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

kdeme avatar Jun 21 '24 18:06 kdeme