package octez-shell-libs
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=55ea1fb8bb3273a7fc270ca8f650d45c56449665619482aad9bc12f3ea736b7e
sha512=fec850fc2d17d7490bbabd5147d62aad13b3aaed8774270f8a38ab419670ed03e0fd30cf8642a97984eca5c2446726fe590ad99c015f7ec50919dc7652f25053
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").