Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADR] Light Client Architecture #185

Merged
merged 10 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions docs/architecture/adr-006-light-client-refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# ADR 006: Light Client Refactor

## Changelog
- 2020-03-15: Initial draft
- 2020-03-23: New decomposition

## Context

The light client protocol provides a method for verifying application
state without the execution of all preceding transactions. The
protocol for the light client is described in
[English](https://github.com/tendermint/spec/tree/bucky/light-reorg/spec/consensus/light)
while the rust implementation is described in
[ADR-002](adr-002-light-client-adr-index.md). This ADR outlines the
next iteration of the light client implementation in rust in which
multiple modules (Peer Exchange, Requester, Verifier, etc.) operate
concurrently.

The basis for this work comes from the learnings of the [Reactor
Experiments](https://github.com/informalsystems/reactor-experiments) as
well as the [Blockchain Reactor
Refactor](https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-043-blockchain-riri-org.md). The key take aways from that work are:

1. Separate concerns into independently verifiable (by humans as well as
computers) components.
2. Deterministic functions wherever possible
3. Use events to index parameters of component function executions to
maintain alignment between specs and implementations.

## Decision

Model the Scheduler ,Verifier, Detector and IO as separate
independently verifiable components. Communication between components is
done by a demuxer component which ownes state and dispatches events
between business logic executing components. Business logic is executed
as a synchronous deterministic function. The composition of components
can also be executed as a deterministic function.

![Decomposition Diagram](assets/light-client-decomposition.png)

### State
The light client maintains state about commit/header/validators abbreviated as LightBlocks. It also has state pertaining to peers and evidence.
Copy link
Member

@josef-widder josef-widder Apr 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LightBlocks will need to maintain ValidatorSet and NextValidatorSet. NextValidatorSet is used for bisection using the trustingperiod, where we check the NextValidatorSet of an old block agains the commit/validatorSet of the new block,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity: is there something wrong with using ValidatorSet (not NextValidatorSet)? (other than validator set might have changed between ValidatorSet and NextValidatorSet)


![State Diagram](assets/light-client-state.png)

### Verification Flow
The flow of events and mutations on state necessary for verification.

![State Diagram](assets/light-client-verification-flow.png)

### Detection Flow
The flow of events and mutations on state necessary for fork detection.

![State Diagram](assets/light-client-detection-flow.png)

### Events & State
There has been a notable change in thinking here. The previous version
of this ADR was built on the tenet of `communicate through events and
not through state`. The motivation being to serialize mutations
to state using event loops for deterministic simulation. The problem
with this approach is that it required components to replicate state.
For instance if the detector and the verifier both needed a store of
light blocks, we would need to:

* Replicate that state in memory
* Produce flows of events to populate both representations
* Deal with inconsistencies between representations.

The new approach shares state by `lending` read only access to state
for duration of the synchronous and deterministic execution of the sub
component (ie. verifier, detector). The result of the execution is an
event which then the owner can use to mutate the state accordingly.
This way state mutation are serialized (deterministic) even if they are
temporarily shared by separate components.

### Concurrency

No concurrency for now. We have some ideas of how to handle concurrency
within this architecture that will be handled a separate ADR.

## Status

Proposed

## Consequences

### Positive
- Better Isolation of Concerns
- Deterministic Testing of the composition of components.
- No async functions

### Negative

### Neutral

## References

* [Light Client Spec](https://github.com/tendermint/spec/tree/bucky/light-reorg/spec/consensus/light)
* [Blockchain Reactor Refactor](https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-043-blockchain-riri-org.md)
* [Reactor Experiments](https://github.com/informalsystems/reactor-experiments)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/architecture/assets/light-client-state.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.