`discv5.getKadValue` returns incomprehensible error when looking up own ENR

Aperta
#307 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
typescript
Ambito
networking

Direzione di ricerca

Inizia da packages/discv5/src/kademlia/kademlia.ts, in KademliaRoutingTable.getValue e bucketForId, poi segui la chiamata da packages/discv5/src/service/service.ts in Discv5.getKadValue. Riproduci la ricerca del proprio ENR da test/e2e/connect.test.ts e decidi se il completamento debba restituire undefined o un errore più chiaro; il test non dovrebbe più esporre il TypeError attuale.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

After having seen this sort of issue on and off when in various edge case scenarios in Ultralight where a node mistakenly queries its own routing table for its nodeId, I've finally figured out the source of this error and want to ask if there's a "best practice" solution for it. The issue is:

    discv5.getKadValue(discv5.enr.nodeId)

produces this very hard to understand error

     TypeError: Cannot read properties of undefined (reading 'getValue')
      at KademliaRoutingTable.getValue (file:///home/jim/development/discv5/packages/discv5/src/kademlia/kademlia.ts:156:23)
      at Discv5.getKadValue (file:///home/jim/development/discv5/packages/discv5/src/service/service.ts:214:30)
      at Context.<anonymous> (file:///home/jim/development/discv5/packages/discv5/test/e2e/connect.test.ts:69:21)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

The reason this error is produced is because when you compute the log2Distance for your own nodeId, the distance is 0 and so RoutingTable.bucketForId computes a bucketId of -1 and there is no bucket at that index.

It would be nice if we could either return undefined (since the ENR isn't in the routing table) or else throw an error that makes more sense like "Don't look for your own ENR in your routing table" (which might be cleaner since it really doesn't make sense to look for your own ENR in your own routing table).

Let me know if there's a preference and I'll raise a PR accordingly.

Lingua principale
TypeScript
Stelle
31
Fork
22
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ChainSafe/discv5

Tutte le issue di ChainSafe/discv5

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.