reth
reth copied to clipboard
fix(net): fix update_root ENR/LINK handling
trafficstars
update_root handled partial root changes inverted: when only link_root changed it set SyncState::Enr, and when only enr_root changed it set SyncState::Link. Additionally, the case where both roots changed was treated as “unchanged”, and the case where neither changed triggered a full resync (Pending). This contradicted EIP-1459 semantics (enr-root -> ENR subtree, link-root -> link subtree), caused incorrect query sequences, potential missed updates, and unnecessary DNS lookups, and led to “unexpected entry” logs during resolution.
Fixes:
- Renamed local flags to enr_unchanged/link_unchanged for clarity.
Corrected the state mapping:
- (true, true): early return (no resync).
- (false, true): clear unresolved_nodes, set SyncState::Enr (ENR changed).
- (true, false): clear unresolved_links, set SyncState::Link (LINK changed).
- (false, false): clear both, set SyncState::Pending (both changed).
Added unit tests covering all four scenarios and verifying emitted SyncAction ordering (Link then Enr when both changed).