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

PeerSharingServer refactorisation #4782

Closed
coot opened this issue Jan 18, 2024 · 3 comments · Fixed by #4795
Closed

PeerSharingServer refactorisation #4782

coot opened this issue Jan 18, 2024 · 3 comments · Fixed by #4795
Labels
peer-sharing Issues / PRs related to peer sharing technical debt

Comments

@coot
Copy link
Contributor

coot commented Jan 18, 2024

computePeerSharing should be defined in Ouroboros.Network.PeerSharing. We don't need to export it, it should be used directly by peerSharingServer. This will simplify the interface we expose to consensus, e.g. no callback in the daApplicationInitiatorResponderMode, but instead requires access to PublicPeerSelectionState which is fine, we do that for other mini-protocols as well. Ideally daApplicationIntiatorResponderMode wouldn't it as an argument, other protocols don't need to pass similar information if I recall correctly.

@coot coot added technical debt peer-sharing Issues / PRs related to peer sharing labels Jan 18, 2024
@bolt12
Copy link
Contributor

bolt12 commented Jan 18, 2024

IIRC it is only how it is now because polymorphism shenanigans and because we need access to the PeerSelectionState. Since peerSharingServer is used in consensus code when setting up the miniprotocols and since we need access to PeerSelectionState, we have to partially apply computePeerSharingServer which is defined in ouroboros-network Diffusion.P2P (module that has access to PeerSelectionState) to daApplicationInitiatorResponderMode.

If we want to move computePeerSharing to Ouroboros.Network.PeerSharing and call it directly in peerSharingServer we still need a way to pass an STM action to read the PeerSelectionState to consensus. So maybe the cleanest way to do this is to define a PeerSharing consensus API dictionary and use that

@coot
Copy link
Contributor Author

coot commented Jan 18, 2024

We can pass TVar PublicPeerSelectionState to Diffusion through DiffusionArguments (even better just pass atomically . writeTVar publicPeerSelectionStateVar :: PublickPeerSelectionState -> m () - this requires some changes, but it's possible). Then we will have access to the TVar outside of Diffusion and thus allow us to create peerSharingServer outside of the diffusion context, it will be responsibility of consensus to create the TVar and pass it to the right places. This is already true for other mini-protocols, that they create some context outside of diffusion, e.g. the bracketSyncWithFetchClient requires FetchClientRegistry which is part of NodeKernel, maybe that's the right place for the TVar too.

@coot
Copy link
Contributor Author

coot commented Jan 19, 2024

NodeKernel contains other pieces of diffusion state. We can also make this more explicit by providing State (diffusion stuff is supposed to be imported qualified so it will be Diffusion.State), e.g.

data State peeraddr = State {
  dsFetchClientRegistry      :: FetchClientRegistry (ConnectionId peeraddr) hdr blk m,
  
  dfPeerSharingRegistry      :: PeerSharingRegistry peeraddr m,
  
  dfPublicPeerSelectionState :: TVar m PublicPeerSelectionState
  -- ^ the new thing which we add to `NodeKernel`
}

newState :: m (State peeraddr)
newState = ...

And then consolidate it in NodeKernel in a single field getDiffusionState :: NodeKernel -> Diffusion.State

I would define provide it in Ouroboros.Network.Diffusion.State module and re-export from Ouroboros.Network.Diffusion.

This way in the future we can extend NodeKernel in in a simple way without much changes to ouroboros-consensus.

We could also define our own initState function, similar to initiNodeKernel. It would fork blockFetchLogic, such function will need to take arguments which are constructed by consensus, so I am not sure if this is worth it. If we do so then Diffusion.State can also contain getFetchMode.

bolt12 added a commit that referenced this issue Feb 1, 2024
bolt12 added a commit that referenced this issue Feb 8, 2024
bolt12 added a commit that referenced this issue Feb 12, 2024
crocodile-dentist pushed a commit that referenced this issue Feb 21, 2024
Merging commits from master (should be an empty commit or trivial to
resolve conflicts when this branch is merged into master)

Squashed commit of the following:

commit e48175f
Merge: 8ab4448 7d49003
Author: Armando Santos <armandoifsantos@gmail.com>
Date:   Wed Feb 21 13:42:17 2024 +0000

    Merge pull request #4810 from IntersectMBO/bolt12/bootstrapPeers-forget

    Forget non-established bootstrap peers

commit 7d49003
Author: Armando Santos <armando@well-typed.com>
Date:   Wed Feb 21 10:32:52 2024 +0000

    Added FetchMode script to Testnet tests

commit 05ab38b
Author: Armando Santos <armando@well-typed.com>
Date:   Mon Feb 19 15:38:02 2024 +0000

    Churn BootstrapPeers

commit 58a4f3b
Author: Armando Santos <armando@well-typed.com>
Date:   Tue Feb 20 15:53:55 2024 +0000

    Forget about non established bootstrap peers

commit 8ab4448
Merge: b118f38 b4f086a
Author: Marcin Wójtowicz <158484752+crocodile-dentist@users.noreply.github.com>
Date:   Tue Feb 20 12:48:42 2024 +0000

    Merge pull request #4803 from IntersectMBO/refactor/withpeerselectionaction

    refactor withPeerSelectionAction argument list

commit b4f086a
Author: Marcin Wójtowicz <158484752+crocodile-dentist@users.noreply.github.com>
Date:   Tue Feb 20 11:55:49 2024 +0100

    Update ouroboros-network/src/Ouroboros/Network/PeerSelection/PeerSelectionActions.hs

    Co-authored-by: Marcin Szamotulski <coot@coot.me>

commit 5cf418c
Author: Marcin Wójtowicz <marcin.wojtowicz@iohk.io>
Date:   Sun Feb 11 18:53:32 2024 +0100

    refactor withPeerSelectionAction argument list

commit b118f38
Merge: f83f71a 2b44951
Author: Armando Santos <armandoifsantos@gmail.com>
Date:   Wed Feb 14 18:06:56 2024 +0000

    Merge pull request #4799 from IntersectMBO/bolt12/bootstrap-peers-fix

    Fix local roots clamp to trustable & changed LedgerPeersConsensusInterface function type signature

commit 2b44951
Author: Armando Santos <armando@well-typed.com>
Date:   Wed Feb 7 14:14:10 2024 +0000

    Fix local roots clamp to trustable and changed API

commit f83f71a
Merge: 436d902 2193d67
Author: Marcin Szamotulski <coot@coot.me>
Date:   Mon Feb 12 12:07:48 2024 +0000

    Merge pull request #4796 from AndrewWestberg/amw/comment_fix

    Fix comment: Duplex started in NodeToNodeV_10

commit 2193d67
Author: Andrew Westberg <andrewwestberg@gmail.com>
Date:   Fri Feb 2 19:30:59 2024 +0000

    Fix comment: Duplex started in NodeToNodeV_10
bolt12 added a commit that referenced this issue Mar 6, 2024
bolt12 added a commit that referenced this issue Mar 6, 2024
@coot coot linked a pull request Mar 6, 2024 that will close this issue
github-merge-queue bot pushed a commit that referenced this issue Mar 6, 2024
crocodile-dentist pushed a commit that referenced this issue Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
peer-sharing Issues / PRs related to peer sharing technical debt
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants