Skip to content

Discrepancy between the probabilistic expectation from a peer and the documentation #997

@vicnetto

Description

@vicnetto

According to the documentation, a node can be removed from the routing table if it has “not been useful within the time period during which they are probabilistically expected to have been utilized in a refresh”. This duration is calculated using the following equation in the documentation:

$\text{maxLastSuccessfulOutboundThreshold} = \log(1/K) \cdot \log\left(1 - \frac{\alpha}{K}\right) \cdot \text{refreshPeriod}$

However, in the implementation found in dht.go, the equation is slightly modified to:

$\text{maxLastSuccessfulOutboundThreshold} = \log(1/K) / \log\left(1 - \frac{\alpha}{K}\right) \cdot \text{refreshPeriod}$

go-libp2p-kad-dht/dht.go

Lines 319 to 335 in 18a758c

var maxLastSuccessfulOutboundThreshold time.Duration
// The threshold is calculated based on the expected amount of time that should pass before we
// query a peer as part of our refresh cycle.
// To grok the Math Wizardy that produced these exact equations, please be patient as a document explaining it will
// be published soon.
if cfg.Concurrency < cfg.BucketSize { // (alpha < K)
l1 := math.Log(float64(1) / float64(cfg.BucketSize)) // (Log(1/K))
l2 := math.Log(float64(1) - (float64(cfg.Concurrency) / float64(cfg.BucketSize))) // Log(1 - (alpha / K))
maxLastSuccessfulOutboundThreshold = time.Duration(l1 / l2 * float64(cfg.RoutingTable.RefreshInterval))
} else {
maxLastSuccessfulOutboundThreshold = cfg.RoutingTable.RefreshInterval
}
// construct routing table
// use twice the theoritical usefulness threhold to keep older peers around longer
rt, err := makeRoutingTable(dht, cfg, 2*maxLastSuccessfulOutboundThreshold)

After calculating this value, the result is multiplied by two because “IPFS defines useful as responding within 2x the time it takes any other peer from our routing table to respond to us.”

As a result, the difference between the expectation from a peer in the implementation and the documentation is:

Implementation: 1h26m26.313713864s
Documentation: 41m31.780054951s
Difference: ~45m

Is this discrepancy intended? Where can I find an explanation for this calculation? Did I miss something?

Since I was unsure whether it was a documentation or implementation issue, I decided to post directly in this repository.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions