Skip to content

[WIP] Add ObjectDiffusion miniprotocol for Peras cert and vote diffusion #5181

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

Draft
wants to merge 10 commits into
base: peras-staging
Choose a base branch
from

Conversation

tbagrel1
Copy link

@tbagrel1 tbagrel1 commented Aug 7, 2025

Closes tweag/cardano-peras#57. IntersectMBO/ouroboros-consensus#1615 depends on this PR.

Defines a new miniprotocol, ObjectDiffusion, highly inspired from TxSubmission.

It supports two modes (initAgency type parameter), one where the inbound peer initiates the communication, and the other where the outbound peer does.

For that, it relies on the InboundAgency and OutboundAgency types (see ouroboros-network-protocols/src/Ouroboros/Network/Protocol/ObjectDiffusion/Type.hs). So far, they are aliases for hardcoded ServerAgency and ClientAgency. It doesn't bother us too much for now, as client/server roles are purely arbitrary and symmetrical from a typed-protocols PoV, but apparently for production they carry a particular meaning, so we should find a way to fix that.

On a side note, this PR also adds a new miniprotocol parameter (and a corresponding default value) for the number of certs to ack for PerasCert diffusion (based on ObjectDiffusion).

Comment on lines +75 to +81
pattern ReflOutboundAgency :: ReflRelativeAgency ClientAgency (r :: RelativeAgency) (r :: RelativeAgency)
pattern ReflOutboundAgency = ReflClientAgency
type ReflOutboundAgency = 'ReflClientAgency

pattern ReflInboundAgency :: ReflRelativeAgency ServerAgency (r :: RelativeAgency) (r :: RelativeAgency)
pattern ReflInboundAgency = ReflServerAgency
type ReflInboundAgency = 'ReflServerAgency
Copy link
Contributor

Choose a reason for hiding this comment

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

One should not need these patterns at all so I wouldn't include them.

Comment on lines +153 to +157
data StBlockingStyle where
-- | In this sub-state the reply need not be prompt. There is no timeout.
StBlocking :: StBlockingStyle
-- | In this state the peer must reply. There is a timeout.
StNonBlocking :: StBlockingStyle
Copy link
Contributor

@coot coot Aug 7, 2025

Choose a reason for hiding this comment

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

Why not import this type from Ouroboros.Network.Protocol.TxSubmission2.Type? It can also be exported here.

Comment on lines +125 to +127
type SingObjectDiffusion ::
ObjectDiffusion initAgency objectId object ->
Type
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check our style guide in ./docs/StyleGuide.md

Suggested change
type SingObjectDiffusion ::
ObjectDiffusion initAgency objectId object ->
Type
type SingObjectDiffusion
:: ObjectDiffusion initAgency objectId object
-> Type

Comment on lines +88 to +89
type ObjectDiffusion :: Agency -> Type -> Type -> Type
data ObjectDiffusion initAgency objectId object where
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
type ObjectDiffusion :: Agency -> Type -> Type -> Type
data ObjectDiffusion initAgency objectId object where
type ObjectDiffusion :: Type -> Type -> Type
data ObjectDiffusion objectId object where

The initAgency doesn't seem to be used anywhere in the protocol definitions, can it be dropped?

-- of these constraints is also a protocol error. The constraints are intended
-- to ensure that implementations are able to work in bounded space.
instance Protocol (ObjectDiffusion initAgency objectId object) where
-- \| The messages in the object diffusion protocol.
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
-- \| The messages in the object diffusion protocol.
-- | The messages in the object diffusion protocol.

I know haddock doesn't support it yet, but it also doesn't complain about it, doesn't it?

Comment on lines +322 to +324
deriving instance Eq (SingBlockingStyle b)

deriving instance Show (SingBlockingStyle b)
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
deriving instance Eq (SingBlockingStyle b)
deriving instance Show (SingBlockingStyle b)
deriving instance Eq (SingBlockingStyle b)
deriving instance Show (SingBlockingStyle b)

Comment on lines +326 to +330
type instance Sing = SingBlockingStyle

instance SingI StBlocking where sing = SingBlocking

instance SingI StNonBlocking where sing = SingNonBlocking
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
type instance Sing = SingBlockingStyle
instance SingI StBlocking where sing = SingBlocking
instance SingI StNonBlocking where sing = SingNonBlocking
type instance Sing = SingBlockingStyle
instance SingI StBlocking where sing = SingBlocking
instance SingI StNonBlocking where sing = SingNonBlocking

Comment on lines +343 to +349
deriving instance (Eq a) => Eq (BlockingReplyList blocking a)

deriving instance (Show a) => Show (BlockingReplyList blocking a)

deriving instance Foldable (BlockingReplyList blocking)

instance (NFData a) => NFData (BlockingReplyList blocking a) where
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
deriving instance (Eq a) => Eq (BlockingReplyList blocking a)
deriving instance (Show a) => Show (BlockingReplyList blocking a)
deriving instance Foldable (BlockingReplyList blocking)
instance (NFData a) => NFData (BlockingReplyList blocking a) where
deriving instance (Eq a) => Eq (BlockingReplyList blocking a)
deriving instance (Show a) => Show (BlockingReplyList blocking a)
deriving instance Foldable (BlockingReplyList blocking)
instance (NFData a) => NFData (BlockingReplyList blocking a) where

-- object identifiers.
data Message (ObjectDiffusion initAgency objectId object) from to where
MsgInit ::
Message (ObjectDiffusion initAgency objectId object) StInit StIdle
Copy link
Contributor

Choose a reason for hiding this comment

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

Or did you mean:

MsgInit :: Message (ObjectDiffusion initAgency objectId object) initAgency StIdle

@amesgen
Copy link
Member

amesgen commented Aug 7, 2025

@coot Thanks for the comments! Note though that this is early stage code (ie this is a draft PR), not yet intended for review by the Network team 😅

@amesgen amesgen force-pushed the peras/object-diffusion branch from 5f76136 to bca44ca Compare August 13, 2025 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

4 participants