-
Notifications
You must be signed in to change notification settings - Fork 721
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
Change watchEpochStateUpdate callback type #5855
base: master
Are you sure you want to change the base?
Conversation
@@ -268,21 +268,21 @@ watchEpochStateUpdate | |||
:: forall m a. (HasCallStack, MonadIO m, MonadTest m, MonadAssertion m) | |||
=> EpochStateView -- ^ The info to access the epoch state | |||
-> EpochInterval -- ^ The maximum number of epochs to wait | |||
-> ((AnyNewEpochState, SlotNo, BlockNo) -> m (Maybe a)) -- ^ The guard function (@Just@ if the condition is met, @Nothing@ otherwise) | |||
-> m (Maybe a) | |||
-> ((AnyNewEpochState, SlotNo, BlockNo) -> m (LedgerStateCondition, a)) -- ^ The guard function (@Just@ if the condition is met, @Nothing@ otherwise) |
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.
LedgerStateCondition
needs to be renamed to a more general name. ConditionCheckResult
perhaps? Will do in a follow-up PR to API.
pure $ maybeExtractGovernanceActionIndex (fromString governanceActionTxId) anyNewEpochState | ||
H.nothingFailM . fmap snd . watchEpochStateUpdate epochStateView (L.EpochInterval 1) $ \(anyNewEpochState, _, _) -> do | ||
let r = maybeExtractGovernanceActionIndex (fromString governanceActionTxId) anyNewEpochState | ||
pure (if isJust r then ConditionMet else ConditionNotMet, r) |
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.
Writing if
s by hand is error-prone. This will be simplified in a follow-up pr to API. We need Bool <-> LedgerStateCondition
conversion functions
4042040
to
a426763
Compare
a426763
to
ca8bcd8
Compare
mResult <- watchEpochStateUpdate epochStateView maxWait checkForVotes | ||
when (isNothing mResult) $ | ||
(cond, ()) <- watchEpochStateUpdate epochStateView maxWait checkForVotes | ||
when (cond == ConditionNotMet) $ |
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'm not a big fan of those ==
on a union type, for long term maintenance; but in this specific case I think it's fine. It's unlikely we'll add a third case to LedgerStateCondition
.
if isCommitteePresent == Just True | ||
then (ConditionMet, ()) | ||
else (ConditionNotMet, ()) |
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.
if isCommitteePresent == Just True | |
then (ConditionMet, ()) | |
else (ConditionNotMet, ()) | |
case isCommitteePresent of | |
Just True -> (ConditionMet, ()) | |
_ -> (ConditionNotMet, ()) |
Too bad Haskell doesn't have arm sharing here 🙃
This adds considerable complexity and opportunity for error, and I am not sure the added complexity is worth it. In any case, if we need the added flexibility, we could just have a restricted version of |
This PR is stale because it has been open 45 days with no activity. |
Description
This PR changes
watchEpochStateUpdate
callback type from a sum typeMaybe a
to a product(LedgerStateCondition, a)
, which allows to return from the function, when the condition is not satisfied, but the deadline epoch has been reached.Checklist
See Runnings tests for more details
CHANGELOG.md
for affected package.cabal
files are updatedhlint
. See.github/workflows/check-hlint.yml
to get thehlint
versionstylish-haskell
. See.github/workflows/stylish-haskell.yml
to get thestylish-haskell
versionghc-8.10.7
andghc-9.2.7
Note on CI
If your PR is from a fork, the necessary CI jobs won't trigger automatically for security reasons.
You will need to get someone with write privileges. Please contact IOG node developers to do this
for you.