package octez-shell-libs
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=ddfb5076eeb0b32ac21c1eed44e8fc86a6743ef18ab23fff02d36e365bb73d61
sha512=d22a827df5146e0aa274df48bc2150b098177ff7e5eab52c6109e867eb0a1f0ec63e6bfbb0e3645a6c2112de3877c91a17df32ccbff301891ce4ba630c997a65
doc/octez-shell-libs.shell/Tezos_shell/Consensus_heuristic/index.html
Module Tezos_shell.Consensus_heuristic
Source
Consensus heuristic
A consensus heuristic is a mechanism by which a node attempts to find a data that its network of peers generally agrees upon. Typically, the node attempts to find out what the p2p network as a whole agrees is the head of the chain.
Note that, by nature, this problem does not necessarily have one exact solution. This is a heuristic, it makes a "best guess" based on information available locally.
The consensus heuristic is given candidates: tuples of the form p,d
where d
is the data and p
is a peer id indicating the provenance of the data. Typically, a candidate indicates what a peer considers to be the head of the chain.
The consensus heuristic is parametrized by two values:
- expected is the number of candidates that the heuristic keeps internally,
- threshold is the number of candidates that need to agree on their data for a consensus to be reached.
A precondition for the heuristic is that 0 <= threshold <= expected < 2 * threshold
to ensure a unique consensus value.
'a t
is the abstract internal state for the consensus heuristic mechanism. 'a
is the type of the data that needs to be agreed upon.
Note that these values are intended to be short-lived, one shot. Specifically, these values are not meant to be used over a long period of time during which there is churn in the set of p2p neighbors.
The three different states that the heuristic can be in.
- If the heuristic received less than expected candidates and no candidates' data has threshold occurrences, then its state is
Need_more_candidates
.
- If the heuristic received expected (or more) candidates but no candidates' data has threshold occurrences, its state is
No_consensus
. The payload for the constructor lists all the candidates' data with the number of their occurrences.
- Otherwise there is some candidates' data that has threshold occurrences or more and the state is
Consensus
.
create ~compare ~expected ~threshold ()
is a fresh heuristic state.
compare
is used internally to instantiate a map of candidates. It must be a total order over the type of data, but the specific of the order has no effect on the consensus.
get_state heuristic
returns the current state
of the heuristic according to the semantics given above.
update heuristic (peer, data)
updates the heuristic with the candidate (peer, data)
. If a data was already registered for peer
, then it is replaced by the update. It is the responsibility of the caller given a peer to update better and better data (for the caller's notion of "better").