Skip to main content

explain_away

Function explain_away 

Source
fn explain_away(
    suspects: Vec<Suspect>,
    known_dead: impl Fn(&OffchainPublicKey) -> bool,
) -> HashSet<OffchainPublicKey>
Expand description

Of the relayers whose overdue replies would make them black holes, those whose lateness no other one explains.

A reply out late counts against every relayer on its leg that its partner’s leg does not share, since a race cannot tell which of them held it. With a leg’s relayers drawn from many, the relayers on legs through a dead one collected its overdue replies too, and were judged dead with it: on a cluster, an innocent relayer was judged dead in two of every three runs that killed one (48 of 72) once the paths were spread over every first relayer, against one in four before.

A dead relayer is on all the legs that failed through it, an innocent one only on those it shares with it, so the dead one explains the most: the most replies, unanswered for any suspect, that are out on a leg through it. They are taken in that order: one is a black hole if at least MIN_RACES of its unanswered replies (MIN_RACES_OVER_ONE_HOP for one that delivers over its other hop) are on legs through no relayer already taken, and every reply out on a leg through it is then explained. Two relayers dead at once are both taken while each has replies the other does not explain; one that only ever sat on legs through the other cannot be told from an innocent one, and waits until those legs are gone.

What a suspect explains, and not how many replies it has unanswered itself: each relayer counts those by its own bar, so of two relayers on the same legs the one with the shorter bar has more of them, whichever of the two lost them. Measured with the replier’s link to a relayer cut: the relayer behind it on those legs, with a bar of 0.22 s against 0.38 s, had 4 unanswered replies to its 2 and then 12 to its 11, was taken first and confirmed, which cost two wipes of the stock and kept a healthy relayer out for the rest of the session.

The fewest relayers that explain the overdue replies are taken, so the reverse also holds: a live relayer whose every leg ran through relayers that died collects all their overdue replies, more than any of them has, and is taken in their place, one dead relayer explaining the lateness as well as two. That takes a live relayer with nothing delivered through it since: one that also sits on a leg that delivers has its overdue replies answered (see RaceHistory::unanswered) and is no suspect.

A suspect explains a reply by being on its leg, whether or not it holds a race on it itself. A relayer on both legs of a pair over the same hop holds none (see RelayerHealth::open_race), and one that stalls is exactly that: it passes one reply and holds the other. Measured on a cluster, counting only the races held: the relayer behind a stalling one had 20 replies unanswered, at least three of them on legs where the stalling one held no race, so the stalling one did not explain them and the healthy one was judged, wiped for and kept out for 80 s, with the stalling one on every one of those legs.

Relayers that explain equally many are taken from the one further up the legs of those replies: a dead relayer and one that only ever follows it explain the same replies, and what the upstream one loses never reaches the other.

Two that explain the same replies with neither ahead of the other on all their legs are a tie the evidence does not decide, and neither is taken at this flush: their replies count as explained, so that nobody else is judged for them, and the next reply out on a leg through one alone decides. Taking one of them is a guess. Measured on a cluster, with the tie going to the smaller summed position: 5 such ties in 64 runs, the dead relayer taken in 2 and a healthy one in 3, each of those costing a wipe of the stock for nothing and a second one two to four seconds later. A relayer known_dead already is never set aside this way: its verdict stands, and explains the other’s.