-
Notifications
You must be signed in to change notification settings - Fork 189
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
feat(katana): added chunk size limit to events method #2644
Changes from 22 commits
0c70748
32597b7
4abd447
1afd693
86150ed
c90845d
fd4c2e7
ccb0c81
4987d1c
3d170b8
86134fc
07f2b79
66bfe44
606a544
6d82fbd
8772aa0
a8288d3
acccb45
e1103ea
099be6a
d92ce69
4761298
f2923de
7752466
56b8cb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ pub enum StarknetApiError { | |
#[error("Class hash not found")] | ||
ClassHashNotFound, | ||
#[error("Requested page size is too big")] | ||
PageSizeTooBig, | ||
PageSizeTooBig { requested: u64, max_allowed: u64 }, | ||
#[error("There are no blocks")] | ||
NoBlocks, | ||
#[error("The supplied continuation token is invalid or unknown")] | ||
|
@@ -96,7 +96,7 @@ impl StarknetApiError { | |
StarknetApiError::InvalidTxnIndex => 27, | ||
StarknetApiError::ClassHashNotFound => 28, | ||
StarknetApiError::TxnHashNotFound => 29, | ||
StarknetApiError::PageSizeTooBig => 31, | ||
StarknetApiError::PageSizeTooBig { .. } => 31, | ||
StarknetApiError::NoBlocks => 32, | ||
StarknetApiError::InvalidContinuationToken => 33, | ||
StarknetApiError::TooManyKeysInFilter => 34, | ||
|
@@ -136,6 +136,9 @@ impl StarknetApiError { | |
Some(Value::String(reason.to_string())) | ||
} | ||
|
||
StarknetApiError::PageSizeTooBig { requested: _, max_allowed: _ } => { | ||
Some(serde_json::json!(self)) | ||
} | ||
_ => None, | ||
} | ||
} | ||
|
@@ -206,7 +209,9 @@ impl From<StarknetRsError> for StarknetApiError { | |
StarknetRsError::NoBlocks => Self::NoBlocks, | ||
StarknetRsError::NonAccount => Self::NonAccount, | ||
StarknetRsError::BlockNotFound => Self::BlockNotFound, | ||
StarknetRsError::PageSizeTooBig => Self::PageSizeTooBig, | ||
StarknetRsError::PageSizeTooBig => { | ||
Self::PageSizeTooBig { requested: 0, max_allowed: 0 } | ||
} | ||
Comment on lines
+209
to
+211
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider preserving actual values in error conversion. The current implementation uses default values (0, 0) when converting from Consider modifying the - StarknetRsError::PageSizeTooBig => {
- Self::PageSizeTooBig { requested: 0, max_allowed: 0 }
- }
+ StarknetRsError::PageSizeTooBig => {
+ // TODO: Modify upstream StarknetRsError to include these fields
+ // For now, we could consider logging a warning about lost information
+ log::warn!("Converting PageSizeTooBig error with lost size information");
+ Self::PageSizeTooBig { requested: 0, max_allowed: 0 }
+ }
|
||
StarknetRsError::DuplicateTx => Self::DuplicateTransaction, | ||
StarknetRsError::ContractNotFound => Self::ContractNotFound, | ||
StarknetRsError::CompilationFailed => Self::CompilationFailed, | ||
|
@@ -278,7 +283,7 @@ mod tests { | |
#[case(StarknetApiError::TxnHashNotFound, 29, "Transaction hash not found")] | ||
#[case(StarknetApiError::ClassAlreadyDeclared, 51, "Class already declared")] | ||
#[case(StarknetApiError::InvalidContractClass, 50, "Invalid contract class")] | ||
#[case(StarknetApiError::PageSizeTooBig, 31, "Requested page size is too big")] | ||
#[case(StarknetApiError::PageSizeTooBig{requested: 1000, max_allowed: 500}, 31, "Requested page size is too big")] | ||
#[case(StarknetApiError::FailedToReceiveTxn, 1, "Failed to write transaction")] | ||
#[case(StarknetApiError::InvalidMessageSelector, 21, "Invalid message selector")] | ||
#[case(StarknetApiError::NonAccount, 58, "Sender address in not an account contract")] | ||
|
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.
💡 Codebase verification
Ohayo, sensei!
max_event_page_size
is not enforced instarknet_getEvents
The
starknet_getEvents
method does not enforce themax_event_page_size
limit, which may allow potential DoS attacks.crates/katana/rpc/rpc/src/starknet/mod.rs
🔗 Analysis chain
Verify enforcement of max_event_page_size limit
Let's ensure this limit is properly enforced in the
starknet_getEvents
method.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 247