Skip to content

Commit 77568f7

Browse files
authored
Update discv5-theory.md
1 parent 7111aa5 commit 77568f7

1 file changed

Lines changed: 31 additions & 66 deletions

File tree

discv5/discv5-theory.md

Lines changed: 31 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ Implementations may maintain additional indices for efficient retrieval by servi
472472
IP prefix.
473473

474474
Expired advertisements are removed automatically. Once an advertisement expires, it is no longer returned in
475-
lookup responses and no longer contributes to waiting-time calculations.
475+
lookup responses.
476476

477477
If a registrar receives a registration request for an advertisement that is already present in its ad cache, the
478478
registrar may treat the request as a renewal or ignore it, depending on the renewal semantics specified by the
@@ -484,7 +484,7 @@ service.
484484
Registrars use admission control to decide whether and when an incoming registration request for an advertisement may be admitted to the
485485
ad cache.
486486

487-
Admission is based on a waiting-time mechanism. If an advertisement is not admitted immediately, the registrar
487+
Admission is based on a **waiting-time mechanism**. If an advertisement is not admitted immediately, the registrar
488488
returns a ticket and a waiting time. This mechanism promotes diversity in the ad cache and avoids requiring
489489
registrars to keep unbounded per-request state for pending registrations.
490490

@@ -506,27 +506,25 @@ registrar treats the request as a new registration attempt or rejects it, depend
506506

507507
A ticket is a registrar-issued object that allows an advertiser to retry a registration attempt after waiting.
508508

509-
A ticket is bound to the advertisement, the registrar, and timing information. The advertiser uses the latest
510-
ticket issued by the registrar when retrying the registration. The exact ticket encoding, signature format, and
511-
signature domain are specified in the wire-format document.
509+
A ticket is bound to the advertisement, the registrar, and timing information. The advertiser uses the latest ticket issued by the registrar when retrying the registration. The exact ticket encoding, signature format, and signature domain are specified in the wire-format document.
512510

513511
Algorithmically, a ticket contains enough information for the registrar to verify:
514512

515513
- the advertisement to which the ticket applies;
516-
- the time at which the ticket was first issued;
517-
- the time at which the ticket was last updated;
518-
- the remaining waiting time reported to the advertiser;
514+
- the registrar time at which the ticket was first issued;
515+
- the registrar time at which the ticket was last updated;
516+
- the remaining waiting duration reported to the advertiser;
519517
- that the ticket was issued by the registrar.
520518

519+
The timestamps in the ticket are generated and interpreted by the registrar. The advertiser does not need to compare those timestamps with its own local clock. The advertiser only needs to wait for the relative waiting duration reported by the registrar before retrying.
520+
521521
A retry is valid only during the registration window associated with the ticket:
522522

523523
tmod + twait ≤ now ≤ tmod + twait + δ
524524

525-
where `tmod` is the ticket modification time, `twait` is the remaining wait time reported in the ticket, and `δ`
526-
is the registration window duration.
525+
where `tmod` is the ticket modification time according to the registrar's clock, `twait` is the remaining waiting duration reported to the advertiser, `δ` is the registration window duration, and `now` is the registrar's current time when processing the retry.
527526

528-
If the advertiser retries before the scheduled time, the registrar may ignore the request. If the advertiser
529-
retries after the registration window, the advertiser loses the accumulated waiting time and must start over.
527+
The advertiser does not use `tmod` to schedule the retry and does not need its clock to be synchronised with the registrar's clock. The advertiser waits for the relative duration `twait` using its own local timer, then retries with the ticket. The registrar validates the retry window using its own clock when the ticket is presented again.
530528

531529
### Waiting-Time Function
532530

@@ -588,7 +586,7 @@ The tree is updated when advertisements are admitted or expire. When an advertis
588586
the path corresponding to the advertiser's IP address are incremented. When the advertisement expires or is removed,
589587
those counters are decremented.
590588

591-
The same principle can be applied to IPv6 by using the IPv6 address length.
589+
TODO: IPv6
592590

593591
### Waiting-Time Lower Bound
594592

@@ -646,17 +644,13 @@ An advertiser registers an advertisement by sending a registration request to a
646644
The first registration request for an advertisement is sent without a ticket. The registrar either admits the
647645
advertisement immediately or returns a ticket and a waiting time.
648646

649-
If the registrar returns a ticket, the advertiser waits for the indicated duration and retries with the latest
650-
ticket. If the registrar recomputes the waiting time and determines that more waiting is required, it returns an
651-
updated ticket and waiting time. The advertiser repeats this process until the advertisement is admitted or the
652-
attempt fails.
647+
If the registrar returns a ticket, the advertiser waits before retrying with the latest ticket. A single waiting interval SHOULD NOT exceed `E`, the advertisement expiry duration. If the registrar still cannot admit the advertisement after the retry, it may return an updated ticket and a new waiting time.
648+
649+
The protocol does not define a fixed maximum total duration for a registration attempt. An implementation MAY abandon an attempt after a local timeout, after a configured maximum number of retries, or if the registrar is considered unusable according to local DISC-NG liveness policy.
653650

654-
A registration attempt fails if the registrar is unreachable, rejects the request, returns malformed responses, or
655-
is otherwise considered unusable according to local DISC-NG liveness policy. On failure, the advertiser removes
656-
the registrar from the pending state for that bucket and may select another registrar.
651+
A registration attempt fails if the registrar is unreachable, rejects the request, returns malformed responses, the registration window is missed, a local retry or timeout limit is reached, or the registrar is otherwise considered unusable according to local DISC-NG liveness policy. On failure, the advertiser removes the registrar from the pending state for that bucket and may select another registrar.
657652

658-
When registration succeeds, the advertisement remains stored by the registrar until it expires, unless it is removed
659-
earlier by registrar policy.
653+
When registration succeeds, the advertisement remains stored by the registrar until it expires, unless it is removed earlier by registrar policy.
660654

661655
Registration responses may include additional ENRs selected from the registrar's view of the service table. The
662656
advertiser may use these ENRs to update its advertise table `B(s)` after validating the ENRs and checking DISC-NG
@@ -683,49 +677,31 @@ set of registrars, but to maintain sufficient active or pending placements acros
683677

684678
A discoverer looking for service `s` queries registrars selected from its search table `B(s)`.
685679

686-
Lookup starts from the furthest bucket from `s` and progresses towards the closest bucket. The discoverer queries
687-
up to `Klookup` registrars per bucket and stops when it has collected at least `Flookup` distinct advertisers or
688-
when no unqueried registrars remain.
689-
690-
For each bucket `bᵢ(s)`, the discoverer selects candidate registrars from the bucket. The same registrar should not
691-
be queried repeatedly during a single lookup unless the implementation has exhausted other candidates and chooses
692-
to retry according to local policy.
680+
Lookup proceeds bucket by bucket, starting from the bucket furthest from `s` and progressing towards buckets closer to `s`. For each bucket `bᵢ(s)`, the discoverer selects candidate registrars from that bucket and queries up to `Klookup` of them.
693681

694-
If a queried registrar is unreachable, times out, or returns a malformed response, the discoverer treats that query
695-
as failed and continues with another candidate. Repeated failures may cause the registrar to be temporarily excluded
696-
from DISC-NG operations.
682+
A registrar may return advertisements for service `s`. The discoverer validates the returned advertisements, extracts the advertised ENRs, and de-duplicates them by advertiser identity. Advertisements are candidate results for the target service.
697683

698-
Lookup responses may include advertisements and additional ENRs. Advertisements are candidate results for the target
699-
service. Additional ENRs are used to improve the discoverer's search table `B(s)`.
684+
The lookup terminates when the discoverer has collected enough distinct advertisers for its local or service-specific purpose, or when no unqueried registrars remain. The required number of advertisers is determined by the application or service using DISC-NG, rather than by the DISC-NG lookup procedure itself.
700685

701-
The discoverer validates returned ENRs before using them. Invalid ENRs are ignored.
686+
The same registrar should not be queried repeatedly during a single lookup unless the implementation has exhausted other candidates and chooses to retry according to local policy.
702687

703-
### Lookup Responses
688+
If a queried registrar is unreachable, times out, or returns a malformed response, the discoverer treats that query as failed and continues with another candidate. Repeated failures may cause the registrar to be temporarily excluded from DISC-NG operations.
704689

705-
A registrar receiving a lookup request for service `s` returns up to `Freturn` advertisements for that service from
706-
its ad cache.
690+
Lookup responses may also include additional ENRs. These ENRs are not lookup results; they are auxiliary routing information used to improve the discoverer's search table `B(s)`.
707691

708-
A registrar may also return additional ENRs selected from its view of the service table. The requester uses these
709-
ENRs to update its local service table `B(s)`. The exact encoding of returned advertisements and neighbour ENRs is
710-
specified in the wire-format document.
692+
The discoverer validates returned ENRs before using them. Invalid ENRs are ignored.
711693

712-
The registrar should return only non-expired advertisements. It may choose which advertisements to return when more
713-
than `Freturn` advertisements for the service are present in its ad cache.
694+
### Lookup Responses
714695

715-
Additional neighbour ENRs are not themselves lookup results. They are auxiliary routing information used to improve
716-
future registration and lookup operations.
696+
A registrar receiving a lookup request for service `s` returns up to `Freturn` advertisements for that service from its ad cache.
717697

718-
### Distinct Advertisers
698+
The registrar MUST NOT return expired advertisements. If more than `Freturn` advertisements for the service are present in its ad cache, the registrar SHOULD return a pseudo-random subset of at most `Freturn` advertisements. The selection procedure SHOULD avoid deterministic bias towards the same advertisers across repeated lookup requests.
719699

720-
Lookup termination is based on the number of distinct advertisers, not the number of raw advertisements or ENRs
721-
received.
700+
A registrar can also return additional ENRs selected from its view of the service table for `s`. These ENRs are not lookup results; they are auxiliary routing information used to improve future registration and lookup operations.
722701

723-
A discoverer may receive the same advertiser from multiple registrars and de-duplicates results before deciding
724-
whether `Flookup` has been reached.
702+
The registrar SHOULD select additional ENRs across buckets of its service table, for example by returning at most one randomly selected node from each bucket. This helps the requester improve its local service table `B(s)` across the service-centred key space, rather than only learning nodes closest to `s`.
725703

726-
Two advertisements identify the same advertiser if they resolve to the same advertised node identity according to
727-
the ENR identity scheme. Implementations should use the ENR node ID, rather than response source or registrar
728-
identity, for de-duplication.
704+
The requester uses returned neighbour ENRs to update its local service table `B(s)` after validating the ENRs, checking DISC-NG capability, and applying local DISC-NG usability policy. The exact encoding of returned advertisements and neighbour ENRs is specified in the wire-format document.
729705

730706
### Updating the Search Table During Lookup
731707

@@ -738,9 +714,7 @@ An ENR learned through lookup is eligible for insertion into `B(s)` only if:
738714
3. the node is not temporarily excluded by local DISC-NG usability policy;
739715
4. the node satisfies ordinary Discovery v5 liveness requirements, or is scheduled for ordinary liveness verification.
740716

741-
Implementations may insert learned ENRs immediately with an unverified flag and verify liveness asynchronously, or
742-
may require liveness verification before insertion. However, implementations should avoid selecting unverified nodes
743-
for DISC-NG operations if doing so would conflict with ordinary Discovery v5 table-maintenance rules.
717+
Implementations may insert learned ENRs immediately with an unverified flag and verify liveness asynchronously.
744718

745719
## Parameters
746720

@@ -754,12 +728,10 @@ The DISC-NG algorithms use the following parameters:
754728
| `Flookup` | Target number of distinct advertisers collected by lookup | `30` |
755729
| `E` | Advertisement expiry duration | `15 min` |
756730
| `C` | Registrar ad cache capacity | `1000` |
757-
| `δ` | Registration retry window duration | `TBD` |
731+
| `δ` | Registration retry window duration | **`TBD`** |
758732
| `Pocc` | Occupancy exponent in the waiting-time function | `10` |
759733
| `G` | Safety constant in the waiting-time function | `10^-7` |
760734

761-
Parameters that are not yet standardised should remain marked as `TBD` until agreed in the protocol specification.
762-
763735
## Implementation Considerations
764736

765737
### ENR Freshness
@@ -769,12 +741,6 @@ Advertisers should send their current ENR when registering an advertisement.
769741
Registrars should store the ENR that was admitted and return that ENR in lookup responses until the advertisement
770742
expires or is renewed.
771743

772-
### ENR Validation
773-
774-
Registrars and discoverers must validate ENRs according to the ENR rules before storing or using them.
775-
776-
Invalid ENRs are ignored.
777-
778744
### Clocks
779745

780746
DISC-NG does not require clock synchronisation between advertisers and registrars.
@@ -796,4 +762,3 @@ This document describes algorithms and data structures.
796762
The exact encoding of DISC-NG messages, ticket signatures, request identifiers, response splitting, returned
797763
advertisements, neighbour ENRs, and any application-specific advertisement payload is specified in the wire-format
798764
document.
799-

0 commit comments

Comments
 (0)