-
Notifications
You must be signed in to change notification settings - Fork 33
[Peras 3] Make ChainDB aware of PerasCertDB, and switch to weighted chain selection
#1678
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
Changes from all commits
d88e87d
0ee8c3e
b9144df
5fdd8b3
52ba886
5250576
c6032cb
39dea5f
b9c74f0
673f11f
6c7ee08
458d50a
1844901
1018f6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ### Breaking | ||
|
|
||
| - In module `Ouroboros.Consensus.Node.GSM`, `GSMView` now has a monadic `getCandidateOverSelection :: STM m (selection -> chainSyncState -> CandidateVersusSelection)` instead of the previous pure `candidateOverSelection`. This is due to the fact that chain comparisons now depend on the set of Peras certificates (if Peras is enabled). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ### Breaking | ||
|
|
||
| - Make the `ChainDB` aware of the `PerasCertDB`, and modify the chain selection function accordingly. In practice, it means that the candidate fragment is now selected based on its Peras weight, instead of its length. | ||
|
|
||
| Note that if Peras is disabled (which is the default), there is no observable difference. | ||
|
|
||
| - Add module `Ouroboros.Consensus.Peras.SelectView`, which introduces a `WeightedSelectView` to correctly measure the length of a chain fragment. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,24 +3,42 @@ | |
| {-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
| {-# OPTIONS_GHC -Wno-orphans #-} | ||
|
|
||
| module Ouroboros.Consensus.Config.SecurityParam (SecurityParam (..)) where | ||
| module Ouroboros.Consensus.Config.SecurityParam | ||
| ( SecurityParam (..) | ||
| , maxRollbackWeight | ||
| ) where | ||
|
|
||
| import Cardano.Binary | ||
| import Cardano.Ledger.BaseTypes.NonZero | ||
| import Data.Word | ||
| import GHC.Generics (Generic) | ||
| import NoThunks.Class (NoThunks) | ||
| import Ouroboros.Consensus.Block.SupportsPeras (PerasWeight (..)) | ||
| import Quiet | ||
|
|
||
| -- | Protocol security parameter | ||
| -- | ||
| -- We interpret this as the number of rollbacks we support. | ||
| -- In longest-chain protocols, we interpret this as the number of rollbacks we | ||
| -- support. | ||
| -- | ||
| -- i.e., k == 1: we can roll back at most one block | ||
| -- k == 2: we can roll back at most two blocks, etc | ||
| -- | ||
| -- NOTE: This talks about the number of /blocks/ we can roll back, not | ||
| -- the number of /slots/. | ||
| -- | ||
| -- In weightiest-chain protocols (such as Ouroboros Peras), we interpret this as | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somehow overloading the meaning of a SecurityParameter implicitly makes me feel a bit uncomfortable. We collate the measure of "meters" with that of "grams" so to speak.
Do you see a way to perhaps be more explicit about this? Separating into Praos and Peras sub modules etc. |
||
| -- the maximum amount of weight we can roll back. Here, the total weight of a | ||
| -- chain (fragment) is defined to be its length plus the sum of all weight | ||
| -- boosts given to some of its blocks on the chain (fragment). | ||
| -- | ||
| -- i.e. k == 30: we can roll back at most 30 unweighted blocks, or two blocks | ||
dnadales marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| -- each having additional weight 14. In the latter case, the chain fragment has | ||
| -- total weight @2 + 2 * 14 = 30@. | ||
| newtype SecurityParam = SecurityParam {maxRollbacks :: NonZero Word64} | ||
| deriving (Eq, Generic, NoThunks, ToCBOR, FromCBOR) | ||
| deriving Show via Quiet SecurityParam | ||
|
|
||
| -- | The maximum amount of weight we can roll back. | ||
| maxRollbackWeight :: SecurityParam -> PerasWeight | ||
| maxRollbackWeight = PerasWeight . unNonZero . maxRollbacks | ||
|
Comment on lines
+43
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just seen it used in |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ module Ouroboros.Consensus.Fragment.Diff | |
| import Data.Word (Word64) | ||
| import GHC.Stack (HasCallStack) | ||
| import Ouroboros.Consensus.Block | ||
| import Ouroboros.Consensus.Peras.Weight | ||
| import Ouroboros.Network.AnchoredFragment | ||
| ( AnchoredFragment | ||
| , AnchoredSeq (..) | ||
|
|
@@ -73,12 +74,31 @@ getTip = castPoint . AF.headPoint . getSuffix | |
| getAnchorPoint :: ChainDiff b -> Point b | ||
| getAnchorPoint = castPoint . AF.anchorPoint . getSuffix | ||
|
|
||
| -- | Return 'True' iff applying the 'ChainDiff' to a chain @C@ will result in | ||
| -- a chain shorter than @C@, i.e., the number of blocks to roll back is | ||
| -- greater than the length of the new elements in the suffix to add. | ||
| rollbackExceedsSuffix :: HasHeader b => ChainDiff b -> Bool | ||
| rollbackExceedsSuffix (ChainDiff nbRollback suffix) = | ||
| nbRollback > fromIntegral (AF.length suffix) | ||
| -- | Return 'True' iff applying the 'ChainDiff' to the given chain @C@ will | ||
| -- result in a chain with less weight than @C@, i.e., the suffix of @C@ to roll | ||
| -- back has more weight than suffix is adding. | ||
| rollbackExceedsSuffix :: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In terms keeping Peras/Praos line explicit, wdyt about having forall b1 b2.
( HasHeader b1
, HasHeader b2
) =>
(AnchoredFragment b1 -> s) ->
AnchoredFragment b1 ->
ChainDiff b2 ->
Bool
rollbackExceedsSuffix summarize curChain (ChainDiff nbRollback suffix) =
summarize suffixToRollBack > summarize suffix
where
suffixToRollBack = AF.anchorNewest nbRollback curChainJust thinking how to move direct mentions of Peras closer to the call sites. |
||
| forall b0 b1 b2. | ||
| ( HasHeader b0 | ||
| , HasHeader b1 | ||
| , HasHeader b2 | ||
| , HeaderHash b0 ~ HeaderHash b1 | ||
| , HeaderHash b0 ~ HeaderHash b2 | ||
| ) => | ||
| PerasWeightSnapshot b0 -> | ||
| -- | The chain @C@ the diff is applied to. | ||
| AnchoredFragment b1 -> | ||
| ChainDiff b2 -> | ||
| Bool | ||
| rollbackExceedsSuffix weights curChain (ChainDiff nbRollback suffix) = | ||
| weightOf suffixToRollBack > weightOf suffix | ||
| where | ||
| suffixToRollBack = AF.anchorNewest nbRollback curChain | ||
|
|
||
| weightOf :: | ||
| (HasHeader b, HeaderHash b ~ HeaderHash b0) => | ||
| AnchoredFragment b -> PerasWeight | ||
| weightOf = totalWeightOfFragment weights | ||
|
|
||
| {------------------------------------------------------------------------------- | ||
| Constructors | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.