-
Notifications
You must be signed in to change notification settings - Fork 754
cardano-testnet | Remove old era casing functions #6551
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
Open
carbolymer
wants to merge
1
commit into
master
Choose a base branch
from
mgalazyn/refactor/testnet-remove-old-witness-conjuring
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,12 +3,14 @@ | |||||
| {-# LANGUAGE TypeFamilies #-} | ||||||
|
|
||||||
| module Testnet.EpochStateProcessing | ||||||
| ( maybeExtractGovernanceActionIndex | ||||||
| ( unsafeEraFromSbe | ||||||
| , maybeExtractGovernanceActionIndex | ||||||
| , maybeExtractGovernanceActionExpiry | ||||||
| , waitForGovActionVotes | ||||||
| ) where | ||||||
|
|
||||||
| import Cardano.Api | ||||||
| import Cardano.Api.Experimental (Era, obtainCommonConstraints, sbeToEra) | ||||||
| import Cardano.Api.Ledger (EpochInterval (..), GovActionId (..)) | ||||||
| import qualified Cardano.Api.Ledger as L | ||||||
|
|
||||||
|
|
@@ -30,21 +32,16 @@ import Testnet.Components.Query (EpochStateView, TestnetWaitPeriod (.. | |||||
|
|
||||||
| import Hedgehog | ||||||
| import Hedgehog.Extras (MonadAssertion) | ||||||
| import qualified Hedgehog.Extras as H | ||||||
|
|
||||||
| maybeExtractGovernanceActionIndex | ||||||
| :: HasCallStack | ||||||
| => TxId -- ^ transaction id searched for | ||||||
| -> AnyNewEpochState | ||||||
| -> Maybe Word16 | ||||||
| maybeExtractGovernanceActionIndex txid (AnyNewEpochState sbe newEpochState _) = | ||||||
| caseShelleyToBabbageOrConwayEraOnwards | ||||||
| (const $ error "Governance actions only available in Conway era onwards") | ||||||
| (\ceo -> conwayEraOnwardsConstraints ceo $ do | ||||||
| let proposals = newEpochState ^. L.newEpochStateGovStateL . L.proposalsGovStateL | ||||||
| Map.foldlWithKey' (compareWithTxId txid) Nothing (L.proposalsActionsMap proposals) | ||||||
| ) | ||||||
| sbe | ||||||
| obtainCommonConstraints (unsafeEraFromSbe sbe) $ do | ||||||
| let proposals = newEpochState ^. L.newEpochStateGovStateL . L.proposalsGovStateL | ||||||
| Map.foldlWithKey' (compareWithTxId txid) Nothing $ L.proposalsActionsMap proposals | ||||||
| where | ||||||
| compareWithTxId (TxId ti1) Nothing (GovActionId (L.TxId ti2) (L.GovActionIx gai)) _ | ||||||
| | ti1 == L.extractHash ti2 = Just gai | ||||||
|
|
@@ -64,16 +61,12 @@ maybeExtractGovernanceActionExpiry | |||||
| -> AnyNewEpochState | ||||||
| -> Maybe EpochNo | ||||||
| maybeExtractGovernanceActionExpiry txid (AnyNewEpochState sbe newEpochState _) = | ||||||
| caseShelleyToBabbageOrConwayEraOnwards | ||||||
| (const $ error "Governance actions only available in Conway era onwards") | ||||||
| (\ceo -> conwayEraOnwardsConstraints ceo $ do | ||||||
| let proposals = newEpochState ^. L.newEpochStateGovStateL . L.proposalsGovStateL | ||||||
| Map.foldlWithKey' (compareWithTxId txid) Nothing (L.proposalsActionsMap proposals) | ||||||
| ) | ||||||
| sbe | ||||||
| obtainCommonConstraints (unsafeEraFromSbe sbe) $ do | ||||||
| let proposals = newEpochState ^. L.newEpochStateGovStateL . L.proposalsGovStateL | ||||||
| Map.foldlWithKey' (compareWithTxId txid) Nothing $ L.proposalsActionsMap proposals | ||||||
| where | ||||||
| compareWithTxId (TxId ti1) Nothing (GovActionId (L.TxId ti2) _) govActionState | ||||||
| | ti1 == L.extractHash ti2 = Just (L.gasExpiresAfter govActionState) | ||||||
| | ti1 == L.extractHash ti2 = Just $ L.gasExpiresAfter govActionState | ||||||
| compareWithTxId _ x _ _ = x | ||||||
|
|
||||||
| -- | Wait for the last gov action proposal in the list to have DRep or SPO votes. | ||||||
|
|
@@ -93,20 +86,20 @@ waitForGovActionVotes epochStateView maxWait = withFrozenCallStack $ | |||||
| :: HasCallStack | ||||||
| => (AnyNewEpochState, SlotNo, BlockNo) | ||||||
| -> m (Maybe ()) | ||||||
| checkForVotes (AnyNewEpochState actualEra newEpochState _, _, _) = withFrozenCallStack $ do | ||||||
| caseShelleyToBabbageOrConwayEraOnwards | ||||||
| (const $ H.note_ "Only Conway era onwards is supported" >> failure) | ||||||
| (\ceo -> do | ||||||
| let govState = conwayEraOnwardsConstraints ceo $ newEpochState ^. newEpochStateGovStateL | ||||||
| proposals = govState ^. L.cgsProposalsL . L.pPropsL . to toList | ||||||
| if null proposals | ||||||
| checkForVotes (AnyNewEpochState actualEra newEpochState _, _, _) = withFrozenCallStack $ | ||||||
| obtainCommonConstraints (unsafeEraFromSbe actualEra) $ do | ||||||
| let proposals = newEpochState ^. newEpochStateGovStateL . L.cgsProposalsL . L.pPropsL . to toList | ||||||
| if null proposals | ||||||
| then pure Nothing | ||||||
| else do | ||||||
| let lastProposal = last proposals | ||||||
| gaDRepVotes = lastProposal ^. L.gasDRepVotesL . to toList | ||||||
| gaSpoVotes = lastProposal ^. L.gasStakePoolVotesL . to toList | ||||||
| if null gaDRepVotes && null gaSpoVotes | ||||||
| then pure Nothing | ||||||
| else do | ||||||
| let lastProposal = last proposals | ||||||
| gaDRepVotes = lastProposal ^. L.gasDRepVotesL . to toList | ||||||
| gaSpoVotes = lastProposal ^. L.gasStakePoolVotesL . to toList | ||||||
| if null gaDRepVotes && null gaSpoVotes | ||||||
| then pure Nothing | ||||||
| else pure $ Just () | ||||||
| ) | ||||||
| actualEra | ||||||
| else pure $ Just () | ||||||
|
|
||||||
| -- | Unsafely convert a 'ShelleyBasedEra' witness to an experimental 'Era' witness. | ||||||
| -- Throws an 'error' for deprecated (pre-Conway) eras. | ||||||
| unsafeEraFromSbe :: HasCallStack => ShelleyBasedEra era -> Era era | ||||||
| unsafeEraFromSbe = either (error . show) id . sbeToEra | ||||||
|
Contributor
Author
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.
Suggested change
Contributor
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. Claude suggested: unsafeEraFromSbe = either (error . prettyToString . prettyError) id . sbeToEra |
||||||
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
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.
unsafeEraFromSbeis partial butcardano-testnetonly ever runs Conway, so the error branch is never hit in practice.We should consider a parallel
AnyNewEpochStateLatest(parameterized on Exp.Era era) in cardano-api for consumers like cardano-testnet who are only interested in testing the latest eras. This keepsAnyNewEpochStateintact forfoldBlocksfrom genesis, eliminates the partial helper, and rules out pre-Conway at the type level.