Skip to content

Conversation

hinto-janai
Copy link
Contributor

What

Adds a cuprate_helper::cast module and uses it throughout the codebase.

Closes #167.

@github-actions github-actions bot added A-dependency Area: Related to dependencies, or changes to a Cargo.{toml,lock} file. A-helper Area: Related to cuprate-helper. labels Sep 2, 2024
@github-actions github-actions bot added A-workspace Area: Changes to a root workspace file or general repo file. A-consensus Area: Related to consensus. A-storage Area: Related to storage. A-net Area: Related to networking. labels Sep 2, 2024
Comment on lines -117 to +119
let body_len = head
.size
.try_into()
.map_err(|_| BucketError::BucketExceededMaxSize)?;
let body_len = u64_to_usize(head.size);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know there's a max bucket size but I'm pretty sure this isn't that - it would have allowed u64::MAX before since this is u64::try_into -> usize.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah this was for 32-bit targets, size is a field sent over the network so we can't panic here

LevinCommand::GetTxPoolCompliment => 1024 * 1024 * 4, // 4 MB

LevinCommand::Unknown(_) => usize::MAX.try_into().unwrap_or(u64::MAX),
LevinCommand::Unknown(_) => u64::MAX,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a cast but if we are only supporting 64-bit this is always u64::MAX.

@hinto-janai hinto-janai marked this pull request as ready for review September 2, 2024 01:01
@hinto-janai hinto-janai requested a review from Boog900 September 2, 2024 01:01
@Boog900 Boog900 merged commit bec8cc0 into Cuprate:main Sep 2, 2024
6 checks passed
@hinto-janai hinto-janai deleted the cast branch September 2, 2024 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-consensus Area: Related to consensus. A-dependency Area: Related to dependencies, or changes to a Cargo.{toml,lock} file. A-helper Area: Related to cuprate-helper. A-net Area: Related to networking. A-storage Area: Related to storage. A-workspace Area: Changes to a root workspace file or general repo file.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Casting into/from pointer-sized integers without unwrap()
2 participants