Skip to content
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

Replace unvalidatebitfield to bitfield to avoid validating when state… #617

Merged
merged 9 commits into from
Sep 11, 2022

Conversation

lyswifter
Copy link
Contributor

@lyswifter lyswifter commented Sep 8, 2022

replace unvalidatebitfield to bitfield

@lyswifter lyswifter linked an issue Sep 8, 2022 that may be closed by this pull request
@lyswifter lyswifter changed the title replace unvalidatebitfield to bitfield to avoid validating when state… Replace unvalidatebitfield to bitfield to avoid validating when state… Sep 8, 2022
@lyswifter
Copy link
Contributor Author

@Stebalien please give a check for those commits

@codecov-commenter
Copy link

codecov-commenter commented Sep 8, 2022

Codecov Report

Merging #617 (63883ff) into master (f385f23) will increase coverage by 0.02%.
The diff coverage is 96.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #617      +/-   ##
==========================================
+ Coverage   84.42%   84.45%   +0.02%     
==========================================
  Files          88       88              
  Lines       18083    18051      -32     
==========================================
- Hits        15267    15245      -22     
+ Misses       2816     2806      -10     
Impacted Files Coverage Δ
actors/miner/src/types.rs 88.88% <ø> (ø)
actors/miner/src/partition_state.rs 92.22% <66.66%> (+0.49%) ⬆️
actors/miner/src/deadline_state.rs 84.71% <100.00%> (ø)
actors/miner/src/lib.rs 80.55% <100.00%> (+0.13%) ⬆️
actors/miner/src/sector_map.rs 94.50% <100.00%> (-0.45%) ⬇️
actors/miner/src/sectors.rs 92.70% <100.00%> (+0.78%) ⬆️
test_vm/src/util.rs 100.00% <100.00%> (ø)
actors/miner/src/deadline_info.rs 79.77% <0.00%> (-16.86%) ⬇️
... and 6 more

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

Couple of small changes, but this mostly looks good.

@@ -80,7 +80,7 @@ impl DeadlineSectorMap {
policy,
deadline_idx,
partition_idx,
BitField::try_from_bits(sector_numbers.iter().copied())?.into(),
&BitField::try_from_bits(sector_numbers.iter().copied()).unwrap(), // sector_numbers may be nil to unwrap
Copy link
Member

Choose a reason for hiding this comment

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

Why use unwrap instead of ??

@@ -106,26 +106,18 @@ impl PartitionSectorMap {
partition_idx: u64,
sector_numbers: Vec<u64>,
) -> anyhow::Result<()> {
self.add(partition_idx, BitField::try_from_bits(sector_numbers)?.into())
self.add(partition_idx, &BitField::try_from_bits(sector_numbers).unwrap())
Copy link
Member

Choose a reason for hiding this comment

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

This can panic if passed a sector number that's out of the bitfield range (u64::MAX). Let's use ?.

@lyswifter
Copy link
Contributor Author

@Stebalien I fixed them and you can have a look...

}
None => {
let sector_numbers = sector_numbers.clone();
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I missed this. Any reason to clone here instead of taking by-value in add?

Copy link
Contributor Author

@lyswifter lyswifter Sep 9, 2022

Choose a reason for hiding this comment

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

&BitField because maybe better to receive a reference of bitfield instead of a value can help to reduce the size of parameters. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

In the expected case, we'll have one bitfield per partition. So, if we take it by reference, we'll have to clone it. Cloning is significantly more expensive than copying 36 bytes (the size of a BitField object in wasm).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All right, I will fix it to pass a value directly.

@Stebalien
Copy link
Member

Sorry, one thing I missed. Otherwise LGTM.

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

LGTM!

@Stebalien
Copy link
Member

@anorth I'll leave this for you to merge in case it conflicts with something else you're working on.

@anorth anorth merged commit 42b2add into master Sep 11, 2022
@anorth anorth deleted the no-using-unvalidateBitField branch September 11, 2022 23:42
@anorth anorth mentioned this pull request Sep 20, 2022
5 tasks
shamb0 pushed a commit to shamb0/builtin-actors that referenced this pull request Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Eager bitfield validation in parameters
4 participants