Skip to content
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

Implement only sending one notification at a time as per RFC 56 #2813

Merged
merged 5 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions prdoc/pr_2813.prdoc
Original file line number Diff line number Diff line change
@@ -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"
15 changes: 14 additions & 1 deletion substrate/client/network/transactions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transaction>`.
// 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 <https://github.com/polkadot-fellows/RFCs/blob/main/text/0056-one-transaction-per-notification.md>
for to_send in to_send {
let _ = self
.notification_service
.send_sync_notification(who, vec![to_send].encode());
Comment on lines +488 to +490
Copy link
Member

Choose a reason for hiding this comment

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

Please at least leave a comment that this is done on purpose.

}
}
}

Expand Down