Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
f06dab8
Gossip only recent statements
AndreiEres Oct 2, 2025
eca57b4
Check if the store already has a statement before processing
AndreiEres Oct 2, 2025
7b8aeb1
Reduce notification size if too large
AndreiEres Oct 2, 2025
3e69999
Update metrics
AndreiEres Oct 2, 2025
9a5decc
Update from github-actions[bot] running command 'prdoc --audience nod…
github-actions[bot] Oct 2, 2025
baeba9f
Update PRDOC
AndreiEres Oct 2, 2025
b0607bc
Update semver
AndreiEres Oct 2, 2025
52fb0aa
Address review comments
AndreiEres Oct 3, 2025
f08c2a8
Fix types
AndreiEres Oct 3, 2025
1e3e83b
Fix up
AndreiEres Oct 3, 2025
8cdb31a
Fix up
AndreiEres Oct 6, 2025
a317299
Fix typo
AndreiEres Oct 7, 2025
50ecef4
Remove unused var
AndreiEres Oct 7, 2025
6b89e1c
Update validation queue size
AndreiEres Oct 7, 2025
a705c00
Add mocked handler for tests
AndreiEres Oct 7, 2025
8703601
Add dirty test
AndreiEres Oct 7, 2025
90c0799
Add more tests
AndreiEres Oct 7, 2025
bd3645e
Fix duplicate processing
AndreiEres Oct 7, 2025
310e05b
Add more tests
AndreiEres Oct 7, 2025
ed55be3
Add metrics for ignored statements
AndreiEres Oct 7, 2025
514ad77
Remove unused tokio
AndreiEres Oct 7, 2025
0adf169
Fix tests
AndreiEres Oct 7, 2025
6daaee0
Fix style
AndreiEres Oct 8, 2025
0012b9e
Fix skipping very large statements
AndreiEres Oct 8, 2025
dad3ecd
Limit the size of the statement for further gossiping
AndreiEres Oct 8, 2025
6407d0e
Update from github-actions[bot] running command 'prdoc --audience nod…
github-actions[bot] Oct 8, 2025
46f7462
Update pr_doc
AndreiEres Oct 8, 2025
c5c15c1
Fix docs
AndreiEres Oct 8, 2025
90ffbe7
Update the logic
AndreiEres Oct 8, 2025
6cf91c4
Update logging and metrics
AndreiEres Oct 8, 2025
6891b17
Increase notification size
AndreiEres Oct 9, 2025
f52598f
Send async notifications
AndreiEres Oct 9, 2025
5945066
Fix tests
AndreiEres Oct 9, 2025
b5b96eb
Add more logs
AndreiEres Oct 14, 2025
971fe1e
Modify metrics setting
AndreiEres Oct 14, 2025
f47af22
Handle very slow or disconnected peers
AndreiEres Oct 14, 2025
dec3b53
Merge branch 'master' into AndreiEres/fix-statement-store-gossiping
AndreiEres Oct 15, 2025
894d00e
Update substrate/client/network/statement/src/lib.rs
AndreiEres Oct 15, 2025
10a1fff
Update
AndreiEres Oct 15, 2025
b8a1c2f
Merge branch 'master' into AndreiEres/fix-statement-store-gossiping
AndreiEres Oct 16, 2025
34ce2d4
Merge branch 'AndreiEres/fix-statement-store-gossiping' into AndreiEr…
AndreiEres Oct 16, 2025
fbaa076
Fix name
AndreiEres Oct 16, 2025
a3d15d2
Fix flaky test
AndreiEres Oct 16, 2025
ac2cc30
Merge branch 'AndreiEres/fix-statement-store-gossiping' into AndreiEr…
AndreiEres Oct 16, 2025
1ce8246
Add early return
AndreiEres Oct 16, 2025
633619f
Update prdoc
AndreiEres Oct 16, 2025
7f7b1d5
Merge remote-tracking branch 'origin/master' into AndreiEres/max-stat…
AndreiEres Oct 17, 2025
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions prdoc/pr_9965.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: Limit the size of the statement for further gossiping
doc:
- audience: Node Dev
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_SIZE` (256 KB), accounting for 1-byte vector length overhead because statements are sent as `Vec<Statement>`."
crates:
- name: sc-network-statement
bump: minor
- name: sc-statement-store
bump: minor
2 changes: 1 addition & 1 deletion substrate/client/network/statement/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(crate) const PROPAGATE_TIMEOUT: time::Duration = time::Duration::from_millis
pub(crate) const MAX_KNOWN_STATEMENTS: usize = 4 * 1024 * 1024;

/// 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


/// Maximum number of statement validation request we keep at any moment.
pub(crate) const MAX_PENDING_STATEMENTS: usize = 2 * 1024 * 1024;
1 change: 1 addition & 0 deletions substrate/client/statement-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ parking_lot = { workspace = true, default-features = true }
prometheus-endpoint = { workspace = true, default-features = true }
sc-client-api = { workspace = true, default-features = true }
sc-keystore = { workspace = true, default-features = true }
sc-network-statement = { workspace = true, default-features = true }
sp-api = { workspace = true, default-features = true }
sp-blockchain = { workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }
Expand Down
30 changes: 29 additions & 1 deletion substrate/client/statement-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ pub const DEFAULT_MAX_TOTAL_STATEMENTS: usize = 4 * 1024 * 1024; // ~4 million
/// The maximum amount of data the statement store can hold, regardless of the number of
/// statements from which the data originates.
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.

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.


const MAINTENANCE_PERIOD: std::time::Duration = std::time::Duration::from_secs(30);

Expand Down Expand Up @@ -378,7 +381,9 @@ impl Index {
current_time: u64,
) -> MaybeInserted {
let statement_len = statement.data_len();
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

log::debug!(
target: LOG_TARGET,
"Ignored oversize message: {:?} ({} bytes)",
Expand Down Expand Up @@ -1049,6 +1054,7 @@ mod tests {
Some(a) if a == account(2) => (2, 1000),
Some(a) if a == account(3) => (3, 1000),
Some(a) if a == account(4) => (4, 1000),
Some(a) if a == account(42) => (42, 42 * crate::MAX_STATEMENT_SIZE as u32),
_ => (2, 2000),
};
Ok(ValidStatement{ max_count, max_size })
Expand Down Expand Up @@ -1321,6 +1327,28 @@ mod tests {
assert_eq!(expected_statements, statements);
}

#[test]
fn max_statement_size_for_gossiping() {
let (store, _temp) = test_store();
store.index.write().options.max_total_size = 42 * crate::MAX_STATEMENT_SIZE;

assert_eq!(
store.submit(
statement(42, 1, Some(1), crate::MAX_STATEMENT_SIZE - 500),
StatementSource::Local
),
SubmitResult::New(NetworkPriority::High)
);

assert_eq!(
store.submit(
statement(42, 2, Some(1), 2 * crate::MAX_STATEMENT_SIZE),
StatementSource::Local
),
SubmitResult::Ignored
);
}

#[test]
fn expired_statements_are_purged() {
use super::DEFAULT_PURGE_AFTER_SEC;
Expand Down
Loading