ChainSafe / ChainSafe/gossamer
Design `NotificationService` Implementation
- Dominant language
- Go
- Stars
- 454
- Forks
- 144
- PR merge metrics
- No merged PRs in 30d
Description
## Scope
The current `NotificationService` interface is used as a dependency by the recently introduced `GossipEngine`. We will need to create an implementation of `NotificationService` that utilizes existing `dot/network` stack code but then translates params and returned types to the primitives expected by `NotificationService` interface.
## Functional Requirements
The interface is as follows:
```go
type NotificationService interface {
// Instruct NotificationService to open a new substream for peer.
OpenSubstream(peer peerid.PeerID) <-chan error
// Instruct NotificationService to close substream for "peer".
CloseSubstream(peer peerid.PeerID) <-chan error
// Send synchronous notification to peer.
SendSyncNotification(peer peerid.PeerID, notification []byte)
// Send asynchronous notification to peer, allowing sender to exercise backpressure.
// Returns an error if the peer doesn't exist.
SendAsyncNotification(peer peerid.PeerID, notification []byte) <-chan error
// Set handshake for the notification protocol replacing the old handshake.
SetHandshake(handshake []byte) <-chan error
// Non-blocking variant of SetHandshake that attempts to update the handshake and returns an error if the channel
// is blocked.
//
// Technically the function can return an error if the channel to NotificationService is closed but that doesn't
// happen under normal operation.
TrySetHandshake(handshake []byte) error
// Get next event from the NotificationService event stream.
NextEvent() <-chan NotificationEvent
// Get protocol name of the NotificationService.
Protocol() network.ProtocolName
// Get message sink of the peer.
MessageSink(peer peerid.PeerID) MessageSink
}
```
Much of the functionality described the `NotificationService` interface is already implemented in existing Gossamer code. A description for each method should be described as a possible implementation path.
## Related resources
- https://github.com/ChainSafe/gossamer/blob/f32d39c27d464d524955d1bf21c5e1d4dcff3491/internal/client/network/service/service.go#L233
## Acceptance criteria
[] Summary, design paper or meta knowledge written and merged to main repo
[] Artifacts produced
[] Tech lead sign off
[] Team member sign off (mention who)
[] Workshop or knowledge session conducted
[] Issues created and estimated (if necessary)
Contributor guide
Assessment
This issue has not been assessed yet.