-
Notifications
You must be signed in to change notification settings - Fork 1k
Limit the size of the statement for further gossiping #9965
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
Changes from 5 commits
f06dab8
eca57b4
7b8aeb1
3e69999
9a5decc
baeba9f
b0607bc
52fb0aa
f08c2a8
1e3e83b
8cdb31a
a317299
50ecef4
6b89e1c
a705c00
8703601
90c0799
bd3645e
310e05b
ed55be3
514ad77
0adf169
6daaee0
0012b9e
dad3ecd
6407d0e
46f7462
c5c15c1
90ffbe7
6cf91c4
6891b17
f52598f
5945066
b5b96eb
971fe1e
f47af22
dec3b53
894d00e
10a1fff
b8a1c2f
34ce2d4
fbaa076
a3d15d2
ac2cc30
1ce8246
633619f
7f7b1d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
||
|
|
||
| const MAINTENANCE_PERIOD: std::time::Duration = std::time::Duration::from_secs(30); | ||
|
|
||
|
|
@@ -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 | ||
| { | ||
|
||
| log::debug!( | ||
| target: LOG_TARGET, | ||
| "Ignored oversize message: {:?} ({} bytes)", | ||
|
|
@@ -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 }) | ||
|
|
@@ -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; | ||
|
|
||
There was a problem hiding this comment.
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