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

Đang mở
#307 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
typescript
Lĩnh vực
networking

Hướng nghiên cứu

Bắt đầu với packages/discv5/src/kademlia/kademlia.ts tại KademliaRoutingTable.getValue và bucketForId, sau đó lần theo lời gọi từ packages/discv5/src/service/service.ts trong Discv5.getKadValue. Tái hiện việc tra cứu own-ENR từ test/e2e/connect.test.ts và quyết định liệu completion nên trả về undefined hay một lỗi rõ ràng hơn; test không còn được để lộ TypeError hiện tại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
31
Fork
22
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ChainSafe/discv5

Tất cả issue của ChainSafe/discv5

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.