-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Use string in extensions Block Height to be consistent #3187
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
base: master
Are you sure you want to change the base?
Changes from all commits
d3b2990
a0043c0
e2260ea
765f693
3612ec7
6ca4a2d
8e62650
b669b67
228516c
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Use `String` for block type in GraphQL response extensions |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,11 +118,8 @@ fn set_current_state<E>( | |
| Value::Number(current_stf_version.into()), | ||
| ); | ||
|
|
||
| let current_block_height: u32 = *current_block_height; | ||
| extensions.set( | ||
| CURRENT_FUEL_BLOCK_HEIGHT, | ||
| Value::Number(current_block_height.into()), | ||
| ); | ||
| let block_height_str = block_to_trimmed_string(current_block_height); | ||
| extensions.set(CURRENT_FUEL_BLOCK_HEIGHT, Value::String(block_height_str)); | ||
| } | ||
|
|
||
| trait SetExtensionsResponse { | ||
|
|
@@ -141,6 +138,21 @@ impl SetExtensionsResponse for BTreeMap<String, Value> { | |
| } | ||
| } | ||
|
|
||
| fn block_to_trimmed_string(block_height: BlockHeight) -> String { | ||
| let mut block_height_str = block_height.to_string(); | ||
|
|
||
| // trim leading zeros | ||
| let cut = block_height_str | ||
| .as_bytes() | ||
| .iter() | ||
| .position(|&b| b != b'0') | ||
| // if it's all zeros, keep a single "0" | ||
| .unwrap_or(block_height_str.len().saturating_sub(1)); | ||
|
|
||
| block_height_str.drain(..cut); | ||
| block_height_str | ||
| } | ||
|
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. Trimmed hex string breaks BlockHeight deserialization roundtripHigh Severity
Additional Locations (1) |
||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||


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.
Unnecessary leading zero trimming is dead code
Low Severity
The
block_to_trimmed_stringfunction contains logic to trim leading zeros from a string (lines 144-152), but this code path can never execute meaningfully. In Rust,u32::to_string()never produces leading zeros - it always outputs the minimal decimal representation. The entire trimming logic is dead code that adds unnecessary complexity. The function could be simplified to justu32::from(block_height).to_string().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.
... that's not what I was getting. I was getting leading zeros and that's why I added it.