-
Notifications
You must be signed in to change notification settings - Fork 722
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
Initial ledger events integration into cardano-testnet #5523
Merged
Merged
Changes from all commits
Commits
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
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
98 changes: 98 additions & 0 deletions
98
cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Node/LedgerEvents.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,98 @@ | ||
{-# LANGUAGE BangPatterns #-} | ||
{-# LANGUAGE DisambiguateRecordFields #-} | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module Cardano.Testnet.Test.Node.LedgerEvents | ||
( hprop_ledger_events_sanity_check | ||
) where | ||
|
||
import Cardano.Api | ||
|
||
import Cardano.Testnet | ||
|
||
import Prelude | ||
|
||
import Control.Monad.Trans.Except | ||
import Control.Monad.Trans.Except.Extra | ||
import qualified Data.Text as Text | ||
import GHC.IO.Exception (IOException) | ||
import GHC.Stack (callStack) | ||
import System.FilePath ((</>)) | ||
|
||
import Hedgehog | ||
import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO | ||
import qualified Hedgehog.Extras.Test.Base as H | ||
|
||
import qualified Testnet.Property.Utils as H | ||
import Testnet.Runtime | ||
|
||
newtype AdditionalCatcher | ||
= IOE IOException | ||
deriving Show | ||
|
||
-- Ledger events can be emitted upon the application of the various ledger rules. | ||
-- Event definition example: https://github.com/input-output-hk/cardano-ledger/blob/afedb7d519761ccdd9c013444aa4b3e0bf0e68ef/eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Gov.hs#L198 | ||
-- Event emission: https://github.com/input-output-hk/cardano-ledger/blob/afedb7d519761ccdd9c013444aa4b3e0bf0e68ef/eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Gov.hs#L389 | ||
-- We can directly access these events via `foldBlocks` exposed by cardano-api. In the normal operation of a node, these events are ignored | ||
-- (see: https://github.com/input-output-hk/ouroboros-consensus/commit/c1abf51948a673a2bbd540e5b7929ce1f07c108e#diff-4274b4c9494fc060b0980695df1b5de3412eccd31cd10c77836ef5bc66e40dd8R123) however a node's client | ||
-- that is requesting blocks can reconstruct the ledger state and access the ledger events via `tickThenApplyLedgerResult`. This is what | ||
-- `foldBlocks` does. Below is a simple test that illustrates `foldBlocks` pattern matching on the RetiredPools event (https://github.com/input-output-hk/cardano-ledger/blob/afedb7d519761ccdd9c013444aa4b3e0bf0e68ef/eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/PoolReap.hs#L177). | ||
-- This sets the stage for more direct testing of clusters allowing us to avoid querying the node, dealing with serialization to and from disk, | ||
-- setting timeouts for expected results etc. | ||
hprop_ledger_events_sanity_check :: Property | ||
hprop_ledger_events_sanity_check = H.integrationRetryWorkspace 2 "ledger-events-sanity-check" $ \tempAbsBasePath' -> do | ||
-- Start a local test net | ||
conf <- H.noteShowM $ mkConf tempAbsBasePath' | ||
|
||
let fastTestnetOptions = cardanoDefaultTestnetOptions | ||
{ cardanoEpochLength = 100 | ||
, cardanoSlotLength = 0.1 | ||
} | ||
|
||
!testnetRuntime | ||
<- cardanoTestnet fastTestnetOptions conf | ||
NodeRuntime{nodeSprocket} <- H.headM $ poolRuntime <$> poolNodes testnetRuntime | ||
let socketName' = IO.sprocketName nodeSprocket | ||
socketBase = IO.sprocketBase nodeSprocket -- /tmp | ||
socketPath = socketBase </> socketName' | ||
|
||
H.note_ $ "Sprocket: " <> show nodeSprocket | ||
H.note_ $ "Abs path: " <> tempAbsBasePath' | ||
H.note_ $ "Socketpath: " <> socketPath | ||
|
||
|
||
!ret <- runExceptT $ handleIOExceptT IOE | ||
$ runExceptT $ foldBlocks | ||
(File $ configurationFile testnetRuntime) | ||
(File socketPath) | ||
FullValidation | ||
[] -- Initial accumulator state | ||
foldBlocksAccumulator | ||
case ret of | ||
Left (IOE e) -> | ||
H.failMessage callStack $ "foldBlocks failed with: " <> show e | ||
Right (Left e) -> | ||
H.failMessage callStack $ "foldBlocks failed with: " <> Text.unpack (renderFoldBlocksError e) | ||
Right (Right _v) -> success | ||
|
||
|
||
foldBlocksAccumulator | ||
:: Env | ||
-> LedgerState | ||
-> [LedgerEvent] | ||
-> BlockInMode -- Block i | ||
-> [LedgerEvent] -- ^ Accumulator at block i - 1 | ||
-> IO ([LedgerEvent], FoldStatus) -- ^ Accumulator at block i and fold status | ||
foldBlocksAccumulator _ _ allEvents _ _ = | ||
if any filterPoolReap allEvents | ||
then return (allEvents , StopFold) | ||
else return ([], ContinueFold) | ||
where | ||
-- We end the fold on PoolReap ledger event | ||
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. that's not 100% true, because 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. |
||
filterPoolReap :: LedgerEvent -> Bool | ||
filterPoolReap (PoolReap _) = True | ||
filterPoolReap _ = False | ||
|
||
|
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you still need the
/tmp
comment?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do to remind myself that the base is
tmp