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

New API for typed-protocols #52

Merged
merged 39 commits into from
Sep 16, 2024
Merged

New API for typed-protocols #52

merged 39 commits into from
Sep 16, 2024

Conversation

coot
Copy link
Collaborator

@coot coot commented Aug 20, 2024

Takes lessons learned in #3, but preserving original (parallel) pipelining design.

The original pipelining is limited to transitions which can be fulfilled by remote transitions, this could be lifted by the more general scheme of tracking pipelined transition at type level done in #3 in the future. But what's important we run the receiver for pipelined transition in parallel, which preserves performance. Below is the comparison of plain and modified cardano-node-9.1.0 syncing mainet:

block-acc-size-9 1 0

@coot
Copy link
Collaborator Author

coot commented Aug 22, 2024

I removed typed-protocols-doc from GHA for now, since it doesn't build against typed-protocols-0.2.0.0.

@coot coot self-assigned this Aug 23, 2024
@coot coot changed the title New API for typed-protocols. New API for typed-protocols Aug 23, 2024
@coot coot force-pushed the coot/typed-protocols-new-api branch from 516b253 to cdb6259 Compare August 23, 2024 14:56
Comment on lines 125 to 134
runPeer
:: forall ps (st :: ps) pr failure bytes m a .
:: forall ps (st :: ps) pr failure bytes m a.
(MonadThrow m, Exception failure)
=> Tracer m (TraceSendRecv ps)
-> Codec ps failure m bytes
-> Channel m bytes
-> Peer ps pr st m a
-> m a
-> Peer ps pr 'NonPipelined Z st m a
-> m (a, Maybe bytes)
runPeer tracer codec channel peer =
fst <$> runPeerWithDriver driver peer (startDState driver)
runPeerWithDriver driver peer Nothing
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is in typed-protocols-examples, it doesn't matter than match, does it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In typed-protocols we anyway need io-classes dependency for Monad{STM,Async} to implement runPipelinedPeerWithDriver.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looking more closely, this will require to annotate Driver with a failure type, which runPeer will return, so it will be quite substantial change.

I'd leave it for later, when we also include implementation of Driver.Simple and Driver.WithLimits in typed-protocols. This way we wouldn't pull a dependency on a logging framework - error handling will be up to the user.

@coot coot force-pushed the coot/typed-protocols-new-api branch from cdb6259 to 304b101 Compare August 27, 2024 12:39
@coot coot force-pushed the coot/typed-protocols-new-api branch 3 times, most recently from 9e162be to ea29919 Compare September 6, 2024 04:58
@coot coot force-pushed the coot/typed-protocols-new-api branch from ea29919 to f360046 Compare September 14, 2024 19:07
Copy link
Contributor

@bolt12 bolt12 left a comment

Choose a reason for hiding this comment

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

Very clean! I looked through most of it except tests which I only skimmed, the API looks much more polished! :) I just made a some comments, which don't impact the design at all.

typed-protocols/src/Network/TypedProtocol/Core.hs Outdated Show resolved Hide resolved
typed-protocols/src/Network/TypedProtocol/Lemmas.hs Outdated Show resolved Hide resolved
Comment on lines +77 to +84
-- | A proof that if one side has terminated, then the other side terminated as
-- well.
--
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here:

forall (pr :: PeerRole) (a :: Agency) (ra :: RelativeAgency).
       ra == Relative pr a ->
       NobodyHasAgency == Relative (FlipAgency pr) a ->
       Relative pr a == NobodyHasAgency && Relative (FlipAgency pr) a == NobodyHasAgency

Comment on lines 98 to 100
-> ![SomeF f] -- ^ head
-> ![SomeF f] -- ^ tail
-> SingQueueF f q
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need SomeF ? can't you "monomorphise" it to f st st' since it is what is going to be used for? This would avoid unsafeCoerce usage

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This whole module is not needed. It's an artifact of the previous approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why dont we remove it then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's what I did 😄

typed-protocols-stateful/src/Data/Type/Queue.hs Outdated Show resolved Hide resolved
@coot coot force-pushed the coot/typed-protocols-new-api branch from f360046 to c7b34a4 Compare September 16, 2024 13:10
coot and others added 10 commits September 16, 2024 15:15
The new API provides proofs for all protocols, and thus proof
obligations are not part of `Protocol` type class but instead an
internal detail of the library.
The client / server 'Peer's pattern synonyms make it easier to write
a 'Peer'.  They automatically provide the 'RelativeAgencyEq' singleton.
See "Network.TypedProtocol.PingPong.Client".
The 'IsActiveAgency' type class allows to limit cases in codecs.  We
don't need to write decoders for inactive states, ``notActiveState`
allows to reduce them.

Note that the advantage of the new approach to typed-protocols is that
we have access to protocol state singleton in the decoder, without
distinguishing which side has the agency.  This simplifies writing
codecs.
There's no need to to pass initial `dstate` it is already passed inside
`Driver` record.
* WeHaveAgencyProof
* TheyHaveAgencyProof
* NobodyHasAgencyProof
Illustrative example how to define a 'Channel' for a socket.  The
implementation is only given for posix platforms.  It is using
a non-blocking `recv` foreign call to provide `tryRecv`.
An example which demonstrates that one can pipeline two kinds of
requests, and collect all the responses.
@coot coot force-pushed the coot/typed-protocols-new-api branch from c7b34a4 to 2fa9364 Compare September 16, 2024 13:23
@coot
Copy link
Collaborator Author

coot commented Sep 16, 2024

^ I rebased the branch on top of recent main branch (which requires some rather simple conflict resultion).

@coot coot force-pushed the coot/typed-protocols-new-api branch 2 times, most recently from 3a117a2 to 9fec582 Compare September 16, 2024 14:30
coot and others added 5 commits September 16, 2024 16:50
This is because stylish-parser cannot parse the export list which starts
with
```hs
module Network.TypedProtocol.Core
  ( -- * Introduction
    -- $intro

    -- * Defining protocols
    -- $defining
    Protocol (..)
```

But this is required by haddock, to include the next section.
@coot coot force-pushed the coot/typed-protocols-new-api branch from 9fec582 to f451040 Compare September 16, 2024 14:51
@coot coot added this pull request to the merge queue Sep 16, 2024
github-merge-queue bot pushed a commit that referenced this pull request Sep 16, 2024
@coot coot removed this pull request from the merge queue due to a manual request Sep 16, 2024
@coot coot added this pull request to the merge queue Sep 16, 2024
Merged via the queue into main with commit e216a0a Sep 16, 2024
16 checks passed
@coot coot deleted the coot/typed-protocols-new-api branch September 16, 2024 15:15
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.

2 participants