-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sanity checks for the current node configuration on node startup
Currently the only supported sanity check is that k (the security parameter) is consistent between eras, and traces a SanityCheckIssue exception if it isn't
- Loading branch information
1 parent
0f4c374
commit d9fdb4c
Showing
22 changed files
with
357 additions
and
5 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...nsus-cardano/changelog.d/20240214_182440_fraser.murray_startup_sanity_checks.md
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,27 @@ | ||
<!-- | ||
A new scriv changelog fragment. | ||
Uncomment the section that is right (remove the HTML comment wrapper). | ||
--> | ||
|
||
<!-- | ||
### Patch | ||
- A bullet item for the Patch category. | ||
--> | ||
|
||
<!-- | ||
### Non-Breaking | ||
- A bullet item for the Non-Breaking category | ||
--> | ||
|
||
<!-- | ||
### Breaking | ||
- A bullet item for the Breaking category. | ||
--> |
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
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
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
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
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
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
81 changes: 81 additions & 0 deletions
81
ouroboros-consensus-cardano/test/cardano-test/Test/Consensus/Cardano/SupportsSanityCheck.hs
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,81 @@ | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
module Test.Consensus.Cardano.SupportsSanityCheck (tests) where | ||
|
||
import Ouroboros.Consensus.Cardano.Block | ||
import Ouroboros.Consensus.Config | ||
import Ouroboros.Consensus.HardFork.Combinator.Basics | ||
import Ouroboros.Consensus.Node.ProtocolInfo | ||
import Ouroboros.Consensus.Shelley.Ledger.SupportsProtocol () | ||
import Test.Consensus.Cardano.ProtocolInfo | ||
import qualified Test.QuickCheck as QC | ||
import qualified Test.QuickCheck.Gen as Gen | ||
import Test.Tasty | ||
import Test.Tasty.QuickCheck | ||
import qualified Test.ThreadNet.Infra.Shelley as Shelley | ||
import Test.Util.SanityCheck | ||
|
||
tests :: TestTree | ||
tests = testGroup "SupportsSanityCheck" | ||
[ testProperty "cardano block top level config passes a sanity check" prop_cardanoBlockSanityChecks | ||
, testProperty "intentionally-misconfigured top level config fails a sanity check" prop_intentionallyBrokenConfigDoesNotSanityCheck | ||
] | ||
|
||
prop_cardanoBlockSanityChecks :: QC.Property | ||
prop_cardanoBlockSanityChecks = | ||
forAllBlind genSimpleTestProtocolInfo (prop_sanityChecks . pInfoConfig) | ||
|
||
prop_intentionallyBrokenConfigDoesNotSanityCheck :: QC.Property | ||
prop_intentionallyBrokenConfigDoesNotSanityCheck = | ||
forAllBlind genSimpleTestProtocolInfo $ \pinfo -> | ||
let saneTopLevelConfig = | ||
pInfoConfig pinfo | ||
brokenConfig = breakTopLevelConfig saneTopLevelConfig | ||
in expectFailure $ prop_sanityChecks brokenConfig | ||
|
||
breakTopLevelConfig :: TopLevelConfig (CardanoBlock StandardCrypto) -> TopLevelConfig (CardanoBlock StandardCrypto) | ||
breakTopLevelConfig tlc = | ||
let TopLevelConfig{topLevelConfigProtocol} = tlc | ||
HardForkConsensusConfig{hardForkConsensusConfigK} = topLevelConfigProtocol | ||
SecurityParam k = hardForkConsensusConfigK | ||
in tlc | ||
{ topLevelConfigProtocol = topLevelConfigProtocol | ||
{ hardForkConsensusConfigK = SecurityParam (succ k) | ||
} | ||
} | ||
|
||
genSimpleTestProtocolInfo :: Gen (ProtocolInfo (CardanoBlock StandardCrypto)) | ||
genSimpleTestProtocolInfo = do | ||
setup <- arbitrary | ||
pure $ | ||
mkSimpleTestProtocolInfo | ||
(decentralizationParam setup) | ||
(securityParam setup) | ||
(byronSlotLength setup) | ||
(shelleySlotLength setup) | ||
(hardForkSpec setup) | ||
|
||
data SimpleTestProtocolInfoSetup = SimpleTestProtocolInfoSetup | ||
{ decentralizationParam :: Shelley.DecentralizationParam | ||
, securityParam :: SecurityParam | ||
, byronSlotLength :: ByronSlotLengthInSeconds | ||
, shelleySlotLength :: ShelleySlotLengthInSeconds | ||
, hardForkSpec :: HardForkSpec | ||
} | ||
|
||
instance Arbitrary SimpleTestProtocolInfoSetup where | ||
arbitrary = do | ||
SimpleTestProtocolInfoSetup | ||
<$> arbitrary | ||
<*> genSecurityParam | ||
<*> genByronSlotLength | ||
<*> genShelleySlotLength | ||
<*> genHardForkSpec | ||
where | ||
genSecurityParam = | ||
SecurityParam <$> Gen.choose (8, 12) | ||
genByronSlotLength = | ||
ByronSlotLengthInSeconds <$> Gen.choose (1, 4) | ||
genShelleySlotLength = | ||
ShelleySlotLengthInSeconds <$> Gen.choose (1, 4) | ||
genHardForkSpec = | ||
hardForkInto <$> Gen.chooseEnum (Byron, Conway) |
24 changes: 24 additions & 0 deletions
24
...us-diffusion/changelog.d/20240207_130158_fraser.murray_startup_sanity_checks.md
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,24 @@ | ||
<!-- | ||
A new scriv changelog fragment. | ||
Uncomment the section that is right (remove the HTML comment wrapper). | ||
--> | ||
|
||
<!-- | ||
### Patch | ||
- A bullet item for the Patch category. | ||
--> | ||
|
||
### Non-Breaking | ||
|
||
- Adds a Tracer for startup sanity check warnings in Ouroboros.Consensus.Node.Tracers (see BlockSupportsSanityCheck in ouroboros-consensus) | ||
|
||
|
||
<!-- | ||
### Breaking | ||
- A bullet item for the Breaking category. | ||
--> |
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
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
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
24 changes: 24 additions & 0 deletions
24
...sus-protocol/changelog.d/20240207_130614_fraser.murray_startup_sanity_checks.md
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,24 @@ | ||
<!-- | ||
A new scriv changelog fragment. | ||
Uncomment the section that is right (remove the HTML comment wrapper). | ||
--> | ||
|
||
<!-- | ||
### Patch | ||
- A bullet item for the Patch category. | ||
--> | ||
|
||
### Non-Breaking | ||
|
||
- ProtocolConfigHasSecurityParam instances for Praos and TPraos | ||
|
||
|
||
<!-- | ||
### Breaking | ||
- A bullet item for the Breaking category. | ||
--> |
22 changes: 22 additions & 0 deletions
22
...os-consensus/changelog.d/20240207_130158_fraser.murray_startup_sanity_checks.md
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,22 @@ | ||
<!-- | ||
A new scriv changelog fragment. | ||
Uncomment the section that is right (remove the HTML comment wrapper). | ||
--> | ||
|
||
<!-- | ||
### Patch | ||
- A bullet item for the Patch category. | ||
--> | ||
### Non-Breaking | ||
|
||
- Add BlockSupportsSanityCheck to check for common configuration issues which may manifest themselves in unusual but not necessarily immediately obvious ways. For now it only checks that `k` is the same across all eras. | ||
|
||
<!-- | ||
### Breaking | ||
- A bullet item for the Breaking category. | ||
--> |
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
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
Oops, something went wrong.