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

Modify foldBlocks to recurse on ledger events #353

Merged
merged 1 commit into from Nov 6, 2023

Conversation

Jimbo4350
Copy link
Contributor

@Jimbo4350 Jimbo4350 commented Nov 3, 2023

Changelog

- description: |
    Modify foldBlocks to recurse on ledger events instead of mapping over them. This allows finer grained control over when `foldBlocks` is stopped.
# uncomment types applicable to the change:
  type:
  # - feature        # introduces a new feature
  # - breaking       # the API has changed in a breaking way
  # - compatible     # the API has changed but is non-breaking
  - optimisation   # measurable performance improvements
  # - improvement    # QoL changes e.g. refactoring
  # - bugfix         # fixes a defect
  # - test           # fixes/modifies tests
  # - maintenance    # not directly related to the code
  # - release        # related to a new release preparation
  # - documentation  # change in code docs, haddocks...

Context

Additional context for the PR goes here. If the PR fixes a particular issue please provide a link to the issue.

How to trust this PR

Highlight important bits of the PR that will make the review faster. If there are commands the reviewer can run to observe the new behavior, describe them.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff

@Jimbo4350 Jimbo4350 force-pushed the jordan/foldblocks-recurse-instead-of-map branch 2 times, most recently from 4ec545c to 613714d Compare November 3, 2023 15:32
@Jimbo4350 Jimbo4350 mentioned this pull request Nov 3, 2023
3 tasks
ledgerEvents
currBlock
accumulatorState
atomicWriteIORef stateIORef newState
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels that we should use an underlying monad in ClientStNext to store state instead of using IORef.

CSP.ClientStNext n BlockInMode ChainPoint ChainTip (StateT s IO) ()

would be cleaner I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you open a PR after this one? I'd be interested to see what you have in mind.

Copy link
Contributor

Choose a reason for hiding this comment

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

I took a closer look and it does not seem to be worth the effort. My point was to be able to use state monad in the protocol client to store the state (including an error). The problem with that is the change is quite extensive: we'd have to parameterize types used in the client e.g. LocalNodeClientProtocolsForBlock by an underlying monad additionally.
Moreover, the code in consensus we use has IO hardcoded there in the function argument e.g.:

connectTo :: forall a b.
LocalSnocket
-> NetworkConnectTracers LocalAddress NodeToClientVersion
-> Versions
     NodeToClientVersion
     NodeToClientVersionData
     (OuroborosApplicationWithMinimalCtx
        'InitiatorMode LocalAddress ByteString IO a b)
-> FilePath
-> IO ()

This would require unlifting state into IO and then lifting it again, which is cumbersome.

In the end the semantics would be pretty much the same, but with more boilerplate.

@Jimbo4350 Jimbo4350 force-pushed the jordan/foldblocks-recurse-instead-of-map branch from 613714d to e666b32 Compare November 6, 2023 15:47
@Jimbo4350 Jimbo4350 added this pull request to the merge queue Nov 6, 2023
Merged via the queue into main with commit 6d91127 Nov 6, 2023
20 checks passed
@Jimbo4350 Jimbo4350 deleted the jordan/foldblocks-recurse-instead-of-map branch November 6, 2023 16:50
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.

None yet

2 participants