-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
82 additions
and
82 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Fork Deltas | ||
|
||
This design describes a way to checkpoint the bank state such that it can track multiple forks without duplicating data. It addresses the following challenges: | ||
|
||
* Forks are potentially created at every slot boundary. | ||
* Forks can be based on any previously produced block. | ||
* Forks are eventually finalized such that rollback is impossible. | ||
* Unreachable forks need to be pruned. | ||
|
||
## Architecture | ||
|
||
The basic design idea is to maintain a DAG of forks. Each fork points back to a single ancestor. The DAG is initialized with a root. Each subsequent fork must descend from the root. | ||
|
||
## Active Forks | ||
|
||
An *active fork* is a direct list of connected forks that descend from the current root to a specific fork without any descendants. | ||
|
||
For example: | ||
``` | ||
1 | ||
/ \ | ||
2 \ | ||
/| | | ||
/ | | | ||
4 | | | ||
5 /\ | ||
6 \ | ||
7 | ||
``` | ||
|
||
The following *active forks* are in the deltas DAG | ||
|
||
* 4,2,1 | ||
* 5,2,1 | ||
* 6,1 | ||
* 7,1 | ||
|
||
## Merging into root | ||
|
||
A validator votes for a finalized fork. The *active fork* connecting the fork to the root is merged. If the *active fork* is longer than `Forks::ROLLBACK_DEPTH` the oldest two forks are merged. The oldest fork in the *active fork* is the current root, so the second oldest is a direct descendant of the root fork. Once merged, the current root is updated to the root descendant. Any forks that are not descendants from the new root are pruned since they are no longer reachable. | ||
|
||
For example: | ||
|
||
``` | ||
1 | ||
/ \ | ||
2 \ | ||
/| | | ||
/ | | | ||
4 | | | ||
5 /\ | ||
6 \ | ||
7 | ||
``` | ||
|
||
* ROLLBACK\_DEPTH=2, vote=5, *active fork*={5,2,1} | ||
|
||
``` | ||
2 | ||
/| | ||
/ | | ||
4 | | ||
5 | ||
``` | ||
|
||
The new root is 2, and any active forks that are not descendants from 2 are pruned. | ||
|
||
* ROLLBACK\_DEPTH=2, vote=6, *active fork*={6,1} | ||
|
||
``` | ||
1 | ||
/ \ | ||
2 \ | ||
/| | | ||
/ | | | ||
4 | | | ||
5 /\ | ||
6 \ | ||
7 | ||
``` | ||
|
||
The tree remains with `root=1`, since the *active fork* starting at 6 is only 2 forks long. |