Skip to content

Conversation

@AndreiEres
Copy link
Contributor

@AndreiEres AndreiEres commented Oct 8, 2025

Description

Limits the size of statements that are further gossiped over the network to prevent skipping oversized messages. The limit is set to match the network protocol's max statement notification size (1 MB), accounting for 1-byte vector length overhead because statements are sent as Vec<Statement>.

Integration

Affected crates:

  • sc-statement-store: Now depends on sc-network-statement for size constants
  • sc-network-statement: MAX_STATEMENT_NOTIFICATION_SIZE is now public

For downstream users:

  • Statements larger than 1 MB will now be rejected earlier before the validation pipeline

@AndreiEres AndreiEres added the T0-node This PR/Issue is related to the topic “node”. label Oct 8, 2025
@AndreiEres
Copy link
Contributor Author

/cmd prdoc --audience node_dev --bump minor


/// Maximum allowed size for a statement notification.
pub(crate) const MAX_STATEMENT_SIZE: u64 = 256 * 1024;
pub const MAX_STATEMENT_SIZE: u64 = 256 * 1024;
Copy link
Contributor

Choose a reason for hiding this comment

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

Will be 1MiB after #9912

pub const DEFAULT_MAX_TOTAL_SIZE: usize = 2 * 1024 * 1024 * 1024; // 2GiB
/// The maximum size of a single statement in bytes.
/// Accounts for the 1-byte vector length prefix when statements are gossiped as `Vec<Statement>`.
pub const MAX_STATEMENT_SIZE: usize = sc_network_statement::config::MAX_STATEMENT_SIZE as usize - 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can do it the other way around and allow this as is and increase the MAX_STATEMENT_NOTIFICATION_SIZE value to what it is +1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It creates cyclic package dependency with the other way around.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking of just moving the -1 from here to +1 there but anyway it's not that important.

if statement_len > validation.max_size as usize {
if statement_len > validation.max_size as usize ||
statement.encoded_size() > MAX_STATEMENT_SIZE
{
Copy link
Contributor

@gui1117 gui1117 Oct 16, 2025

Choose a reason for hiding this comment

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

we could also directly reject in the implementation of fn submit.
Both way are good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, we can skip expensive validation with the early return in submittion

pub const DEFAULT_MAX_TOTAL_SIZE: usize = 2 * 1024 * 1024 * 1024; // 2GiB
/// The maximum size of a single statement in bytes.
/// Accounts for the 1-byte vector length prefix when statements are gossiped as `Vec<Statement>`.
pub const MAX_STATEMENT_SIZE: usize = sc_network_statement::config::MAX_STATEMENT_SIZE as usize - 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know how to make this constraint more visible.

People should be aware that this client implementation only support such statement size.

But for now it is good and better than before.

@AndreiEres AndreiEres changed the base branch from master to AndreiEres/fix-statement-store-gossiping October 16, 2025 08:44
@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/18555597226
Failed job name: test-linux-stable

github-merge-queue bot pushed a commit that referenced this pull request Oct 16, 2025
# Description

Fixes gossiping and scalability issues in the statement-store
networking.

1. Reduced gossiping traffic by propagating only recent statements
instead of all.
2. Added an early check for statements that the node already has to skip
duplicate processing.
3. Added splitting of large statement batches to stay under
MAX_STATEMENT_NOTIFICATION_SIZE; oversized individual statements are
skipped.
4. MAX_STATEMENT_NOTIFICATION_SIZE was updated to the commonly used 1MB,
which drastically improved the gossiping speed.
5. Notifications are sent asynchronously. I don't see much difference in
performance, but according to @lexnv, it's better to do:
#9296.
6. Added a 10s timeout to handle very slow or disconnected peers.

## Integration

Internal optimizations to the gossip protocol. No downstream changes
required.

Related PR: #9965

## Things to handle in further PRs
- After this PR, nodes don't send all statements to new peers anymore,
only the recent ones.
- After restarting, the node doesn't re-gossip statements it wasn't
gossiped.
- Broadcasting notifications to all peers when the first peer is slow is
limited. We could instead use a FuturesUnordered.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Bastian Köcher <[email protected]>
Base automatically changed from AndreiEres/fix-statement-store-gossiping to master October 16, 2025 16:18
alvicsam pushed a commit that referenced this pull request Oct 17, 2025
# Description

Fixes gossiping and scalability issues in the statement-store
networking.

1. Reduced gossiping traffic by propagating only recent statements
instead of all.
2. Added an early check for statements that the node already has to skip
duplicate processing.
3. Added splitting of large statement batches to stay under
MAX_STATEMENT_NOTIFICATION_SIZE; oversized individual statements are
skipped.
4. MAX_STATEMENT_NOTIFICATION_SIZE was updated to the commonly used 1MB,
which drastically improved the gossiping speed.
5. Notifications are sent asynchronously. I don't see much difference in
performance, but according to @lexnv, it's better to do:
#9296.
6. Added a 10s timeout to handle very slow or disconnected peers.

## Integration

Internal optimizations to the gossip protocol. No downstream changes
required.

Related PR: #9965

## Things to handle in further PRs
- After this PR, nodes don't send all statements to new peers anymore,
only the recent ones.
- After restarting, the node doesn't re-gossip statements it wasn't
gossiped.
- Broadcasting notifications to all peers when the first peer is slow is
limited. We could instead use a FuturesUnordered.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Bastian Köcher <[email protected]>
@gui1117 gui1117 added this pull request to the merge queue Oct 22, 2025
Merged via the queue into master with commit de740e1 Oct 22, 2025
246 checks passed
@gui1117 gui1117 deleted the AndreiEres/max-statement-size branch October 22, 2025 02:00
@gui1117 gui1117 added A4-backport-stable2506 Pull request must be backported to the stable2506 release branch A4-backport-stable2509 Pull request must be backported to the stable2509 release branch labels Oct 22, 2025
@paritytech-release-backport-bot

Created backport PR for stable2506:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-9965-to-stable2506
git worktree add --checkout .worktree/backport-9965-to-stable2506 backport-9965-to-stable2506
cd .worktree/backport-9965-to-stable2506
git reset --hard HEAD^
git cherry-pick -x de740e1892f47e91c356858324f6e3e4b0f1be60
git push --force-with-lease

@paritytech-release-backport-bot

Created backport PR for stable2509:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-9965-to-stable2509
git worktree add --checkout .worktree/backport-9965-to-stable2509 backport-9965-to-stable2509
cd .worktree/backport-9965-to-stable2509
git reset --hard HEAD^
git cherry-pick -x de740e1892f47e91c356858324f6e3e4b0f1be60
git push --force-with-lease

gui1117 pushed a commit that referenced this pull request Oct 22, 2025
Fixes gossiping and scalability issues in the statement-store
networking.

1. Reduced gossiping traffic by propagating only recent statements
instead of all.
2. Added an early check for statements that the node already has to skip
duplicate processing.
3. Added splitting of large statement batches to stay under
MAX_STATEMENT_NOTIFICATION_SIZE; oversized individual statements are
skipped.
4. MAX_STATEMENT_NOTIFICATION_SIZE was updated to the commonly used 1MB,
which drastically improved the gossiping speed.
5. Notifications are sent asynchronously. I don't see much difference in
performance, but according to @lexnv, it's better to do:
#9296.
6. Added a 10s timeout to handle very slow or disconnected peers.

Internal optimizations to the gossip protocol. No downstream changes
required.

Related PR: #9965

- After this PR, nodes don't send all statements to new peers anymore,
only the recent ones.
- After restarting, the node doesn't re-gossip statements it wasn't
gossiped.
- Broadcasting notifications to all peers when the first peer is slow is
limited. We could instead use a FuturesUnordered.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Bastian Köcher <[email protected]>
(cherry picked from commit b21cbb5)
@gui1117 gui1117 added the A4-backport-unstable2507 Pull request must be backported to the unstable2507 release branch label Oct 22, 2025
@paritytech-release-backport-bot

Created backport PR for unstable2507:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-9965-to-unstable2507
git worktree add --checkout .worktree/backport-9965-to-unstable2507 backport-9965-to-unstable2507
cd .worktree/backport-9965-to-unstable2507
git reset --hard HEAD^
git cherry-pick -x de740e1892f47e91c356858324f6e3e4b0f1be60
git push --force-with-lease

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A4-backport-stable2506 Pull request must be backported to the stable2506 release branch A4-backport-stable2509 Pull request must be backported to the stable2509 release branch A4-backport-unstable2507 Pull request must be backported to the unstable2507 release branch T0-node This PR/Issue is related to the topic “node”.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants