From d842966484ff2dc5d5c56ccd93476ebf1a85f9ad Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Tue, 2 Jan 2024 11:46:49 +0100 Subject: [PATCH] Implement only sending one notification at a time as per RFC 56 (#2813) cc https://github.com/paritytech/polkadot-sdk/issues/2812 cc https://github.com/polkadot-fellows/RFCs/pull/56 Since this is a one line of code change, and for the sake of this not taking six months to be done, I've opted to open a PR myself. --------- Co-authored-by: Aaro Altonen <48052676+altonen@users.noreply.github.com> --- prdoc/pr_2813.prdoc | 11 +++++++++++ substrate/client/network/transactions/src/lib.rs | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 prdoc/pr_2813.prdoc diff --git a/prdoc/pr_2813.prdoc b/prdoc/pr_2813.prdoc new file mode 100644 index 000000000000..ff6e5cf5cf6b --- /dev/null +++ b/prdoc/pr_2813.prdoc @@ -0,0 +1,11 @@ +title: "Implement only sending one notification at a time as per RFC 56" + +doc: + - audience: Node Dev + description: | + Transactions are now gossiped one at a time instead of as batches, as per RFC 56. This + allows decoding notifications without knowing how to decode individual transactions, and + allows for a more fine grained backpressure. + +crates: + - name: "sc-network-transactions" diff --git a/substrate/client/network/transactions/src/lib.rs b/substrate/client/network/transactions/src/lib.rs index 9758ea4c4fcb..b2299667448c 100644 --- a/substrate/client/network/transactions/src/lib.rs +++ b/substrate/client/network/transactions/src/lib.rs @@ -475,7 +475,20 @@ where propagated_to.entry(hash).or_default().push(who.to_base58()); } trace!(target: "sync", "Sending {} transactions to {}", to_send.len(), who); - let _ = self.notification_service.send_sync_notification(who, to_send.encode()); + // Historically, the format of a notification of the transactions protocol + // consisted in a (SCALE-encoded) `Vec`. + // After RFC 56, the format was modified in a backwards-compatible way to be + // a (SCALE-encoded) tuple `(Compact(1), Transaction)`, which is the same encoding + // as a `Vec` of length one. This is no coincidence, as the change was + // intentionally done in a backwards-compatible way. + // In other words, the `Vec` that is sent below **must** always have only a single + // element in it. + // See + for to_send in to_send { + let _ = self + .notification_service + .send_sync_notification(who, vec![to_send].encode()); + } } }