Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

sc_network::NetworkService::write_notifications should have proper back-pressure #5481

@tomaka

Description

@tomaka

We need an answer to the question: what happens if someone runs the code below?

for _ in 0..4000000000 {
    network_service.write_notification(some_peer, some_proto, b"hello world".to_vec());
}

Right now we would buffer up 256 of these notifications and then discard the 257th and above.
While it could be a sensible option (UDP-style), GrandPa in particular isn't robust to messages being silently dropped.

I can see a couple of solutions:

  • Turn write_notification into an asynchronous function whose future is ready once the remote has accepted our message. This is the way that this problem would normally be solved, but would require changes in GrandPa.

  • write_notification returns an error if the queue is full. Note that this might be difficult to implement because the queue of messages is actually in a background task, but if that's the solution I will accommodate for it.

  • If the buffer is full, we drop all pending messages then report on the API that we have disconnected and reconnected. GrandPa (and others) need to account for random disconnections anyway, and by making a "full buffer" look like a disconnection, we use the same code for both. This might however cause an infinite loop if we immediately send messages as a response to a reconnection.

  • Make GrandPa robust to messages being silently dropped.

  • Just increase the size of the buffer if we notice that the limit gets reached.

cc @rphmeier @andresilva @mxinden

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions