-
Notifications
You must be signed in to change notification settings - Fork 32
Remove cdbFutureBlocks
#1269
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
Merged
Merged
Remove cdbFutureBlocks
#1269
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b593b9c
Add changelog fragments
dnadales 949f6b2
Remove `cdbFutureBlocks`
dnadales 232f607
Remove obsolete module `Ouroboros.Consensus.Fragment.InFuture`
dnadales 78343cb
Add a section in our documentation describing how blocks from the fut…
dnadales 28dde8d
Change `chainSelectionForBlock` so that it returns `()`
dnadales 5d01e90
Add a precondition to `addBlock` and `addBlockAsync`
dnadales 4220761
Remove the `AddFutureBlock` command
dnadales 8c05749
Correct a comment stating that the `ImmutableDB` truncates blocks fro…
dnadales 40ac1b9
Remove `InFutureExceedsClockSkew`
dnadales 3f88dc0
Correct the comment stating under which conditions ...
dnadales 21ab657
Remove the `InvalidBlockReason` data type
dnadales File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
docs/website/contents/for-developers/HandlingBlocksFromTheFuture.md
This file contains hidden or 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,44 @@ | ||
# Blocks from the future | ||
|
||
A node can receive a block whose slot is ahead of the current slot. We call such **blocks from the future**. | ||
|
||
The Praos protocol ignores chains with blocks from the future during chain selection. | ||
It assumes nodes have perfectly synchronized clocks, which is not realistic due to imperfections in protocols like NTP and leap seconds. | ||
In practice, a clock skew of up to 2 seconds is considered acceptable. | ||
Our implementation differentiates between blocks from the near future and those from the far future: | ||
|
||
- A block is from the near future if the onset of its slot is ahead of the wall clock, but only by at most the admissible clock skew. Despite being from the future, these blocks are assumed to potentially have been minted by honest nodes. | ||
- A block is from the far future if the onset of its slot is ahead of the wall clock by more than the admissible clock skew. By assumption, these blocks cannot have been minted by an honest node. | ||
|
||
# Handling blocks from the future | ||
|
||
As of [#525](https://github.com/IntersectMBO/ouroboros-consensus/pull/525): | ||
|
||
- When receiving a header from the **near** future in `ChainSync`, an artificial delay is introduced until the header is no longer from the future. | ||
Only then it is validated and the corresponding block body is downloaded and added to the `ChainDB` for chain selection, where it is not considered to be from the future due to the previous artificial delay. | ||
- When receiving a header from the far future, we immediately disconnect from the corresponding peer. | ||
|
||
In addition, we never forge atop a block from the future (which was the case even before [#525](https://github.com/IntersectMBO/ouroboros-consensus/pull/525). | ||
|
||
### During initialization | ||
|
||
Since we now delay the headers until they are no longer from the **near future**, a caught up node will never contain blocks from the future in the `VolatileDB`, according to its own clock. | ||
However, there are two caveats: | ||
- Clock rewinds can violate this property. In particular the node [will error](https://github.com/IntersectMBO/ouroboros-consensus/blob/4488656439e78c572c3dce0f7ed2cf98f61c65bb/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/BlockchainTime/WallClock/HardFork.hs#L138-L146) when we rewind the clock by more than [20 seconds](https://github.com/IntersectMBO/ouroboros-consensus/blob/4488656439e78c572c3dce0f7ed2cf98f61c65bb/ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/Node.hs#L485). | ||
- The node clock might be set in the future relative to the rest of the nodes in the network. | ||
Thus, it is possible that after restarting a node with a clock set in the future, and setting the clock back so that the clock is now synchronized with the rest of the network, the blocks in the `VolatileDB` are regarded as blocks from the future. | ||
|
||
When initializing the `ChainDB` we do not check if blocks in the `VolatileDB` are from the future. This presents two inconveniences: | ||
amesgen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- When the node diffuses these blocks from the **far** future, it will be disconnected from other peers. | ||
- The node [will not forge](https://github.com/IntersectMBO/ouroboros-consensus/blob/16fa8754be24f26eddef006c03ba945ea00e3566/ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/NodeKernel.hs#L708) a block on top of a block from the future, thus missing its chance to lead in the slot. | ||
|
||
These problems can be solved by wiping out the `VolatileDB` in this situation. | ||
However, note this is an extremely rare situation: the clock of the node would have to have been set quite far in the future, as shutting down a node and restarting it already takes a significant amount of time. | ||
|
||
In the future we might delete blocks from the future from the `VolatileDB` to improve the user experience and robustness of the initialization logic. For now it does not seem worthwhile to handle that rare case. (Downstream/bidirectional peers will disconnect from such a node, but only until enough time has passed that its `VolatileDB` does not contain blocks from the future anymore.) | ||
|
||
# References | ||
|
||
- [Original issue that prompted the fix](https://github.com/IntersectMBO/ouroboros-network/issues/4251) | ||
- [Blocks from the future (Incident report)](https://updates.cardano.intersectmbo.org/2024-09-07-incident) |
This file contains hidden or 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
8 changes: 8 additions & 0 deletions
8
...rdano/changelog.d/20240927_125151_damian.nadales_1260_remove_cdbFutureBlocks.md
This file contains hidden or 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,8 @@ | ||
### Breaking | ||
|
||
- Remove `CheckInFuture m blk` from `openChainDB`. | ||
|
||
### Non-Breaking | ||
|
||
- Remove references to `Ouroboros.Consensus.Fragment.InFuture`. | ||
- Adapt the code to account for the removed `cdbFutureBlocks` and related fields. |
This file contains hidden or 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
This file contains hidden or 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
7 changes: 7 additions & 0 deletions
7
...usion/changelog.d/20240927_131047_damian.nadales_1260_remove_cdbFutureBlocks.md
This file contains hidden or 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,7 @@ | ||
### Breaking | ||
|
||
- Remove `CheckInFuture m blk` argument from `openChainDB`. | ||
|
||
### Patch | ||
|
||
- Remove references to `Ouroboros.Consensus.Fragment.InFuture`. |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
11 changes: 11 additions & 0 deletions
11
...ensus/changelog.d/20240927_125606_damian.nadales_1260_remove_cdbFutureBlocks.md
This file contains hidden or 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,11 @@ | ||
### Breaking | ||
|
||
- Remove `cdbFutureBlocks` from `ChainDbEnv`. | ||
- Remove `BlockInTheFuture`, `ChainSelectionForFutureBlock`, `CandidateContainsFutureBlocks`, and `CandidateContainsFutureBlocksExceedingClockSkew` from `TraceAddBlockEvent`. | ||
- Remove `cdbCheckInFuture` from `CBD`. | ||
- Remove `cdbsCheckInFuture` from `ChainDbSpecificArgs`. | ||
- Remove `CheckInFuture m blk` argument from `completeChainDbArgs`. | ||
- Remove `CheckInFuture m blk` argument from `initialChainSelection`. | ||
- Remove `cdbsCheckInFuture` from `ChainDbSpecificArgs`. | ||
- Delete module `Ouroboros.Consensus.Fragment.InFuture`. `ClockSkew` functions live now in `Ouroboros.Consensus.MiniProtocol.ChainSync.Client.InFutureCheck`. | ||
* Remove ``InvalidBlockReason`, since it was now simply wrapping up `ExtValidationError`. |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.