Skip to content

gossipsub: refactor booleans in Handler to state machine #3655

@thomaseizinger

Description

@thomaseizinger

Description

Currently, we use a combination of booleans and enums to represent how the remote peer supports gossipsub:

/// The type of peer this handler is associated to.
peer_kind: Option<PeerKind>,
/// Keeps track on whether we have sent the peer kind to the behaviour.
//
// NOTE: Use this flag rather than checking the substream count each poll.
peer_kind_sent: bool,
/// If the peer doesn't support the gossipsub protocol we do not immediately disconnect.
/// Rather, we disable the handler and prevent any incoming or outgoing substreams from being
/// established.
///
/// This value is set to true to indicate the peer doesn't support gossipsub.
protocol_unsupported: bool,

We can simplify this by narrowing down the possible state combinations. For example, currently the type system allows peer_kind to be Some and peer_kind_sent to be true which is not possible.

Something similar can likely be done with the current outbound stream and the outbound_substream_establishing flag. It could be an enum:

enum OutboundStream {
	Establishing,
	Some(S),
	None
}

Motivation

  • Less complexity in understanding the possible states of the handler
  • Use the type system to our advantage

Current Implementation

Are you planning to do it yourself in a pull request?

No.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions