Skip to content
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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

carbolymer
Copy link
Contributor

@carbolymer carbolymer commented May 24, 2024

Description

This PR changes watchEpochStateUpdate callback type from a sum type Maybe 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

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. These may include:
    • golden tests
    • property tests
    • roundtrip tests
    • integration tests
      See Runnings tests for more details
  • Any changes are noted in the CHANGELOG.md for affected package
  • The version bounds in .cabal files are updated
  • CI passes. See note on CI. The following CI checks are required:
    • Code is linted with hlint. See .github/workflows/check-hlint.yml to get the hlint version
    • Code is formatted with stylish-haskell. See .github/workflows/stylish-haskell.yml to get the stylish-haskell version
    • Code builds on Linux, MacOS and Windows for ghc-8.10.7 and ghc-9.2.7
  • Self-reviewed the diff

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.

@@ -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)
Copy link
Contributor Author

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)
Copy link
Contributor Author

@carbolymer carbolymer May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing ifs by hand is error-prone. This will be simplified in a follow-up pr to API. We need Bool <-> LedgerStateCondition conversion functions

@carbolymer carbolymer force-pushed the mgalazyn/test/change-watching-function-type branch from 4042040 to a426763 Compare May 28, 2024 12:53
@carbolymer carbolymer force-pushed the mgalazyn/test/change-watching-function-type branch from a426763 to ca8bcd8 Compare May 28, 2024 12:53
@carbolymer carbolymer marked this pull request as ready for review May 28, 2024 13:13
@carbolymer carbolymer requested a review from a team as a code owner May 28, 2024 13:13
mResult <- watchEpochStateUpdate epochStateView maxWait checkForVotes
when (isNothing mResult) $
(cond, ()) <- watchEpochStateUpdate epochStateView maxWait checkForVotes
when (cond == ConditionNotMet) $
Copy link
Contributor

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.

Comment on lines +270 to +272
if isCommitteePresent == Just True
then (ConditionMet, ())
else (ConditionNotMet, ())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if isCommitteePresent == Just True
then (ConditionMet, ())
else (ConditionNotMet, ())
case isCommitteePresent of
Just True -> (ConditionMet, ())
_ -> (ConditionNotMet, ())

Too bad Haskell doesn't have arm sharing here 🙃

@palas
Copy link
Contributor

palas commented Jun 4, 2024

This adds considerable complexity and opportunity for error, and I am not sure the added complexity is worth it.
Do you have a use case in mind that couldn't be done by, for example, just querying again afterwards and returning Just immediately?

In any case, if we need the added flexibility, we could just have a restricted version of watchEpochStateUpdate on top of it that doesn't have it and use that one unless we need the generic one. That would be inline with the good practice of keeping types as tight as possible. Is like using fold when you can use map, even if map is implemented on top of fold (which probably isn't).

Copy link

github-actions bot commented Aug 2, 2024

This PR is stale because it has been open 45 days with no activity.

@github-actions github-actions bot added the Stale label Aug 2, 2024
@carbolymer carbolymer removed the Stale label Aug 5, 2024
@carbolymer carbolymer marked this pull request as draft August 5, 2024 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants