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

feat: bitmap #119

Merged
merged 26 commits into from
Jun 17, 2024
Merged

feat: bitmap #119

merged 26 commits into from
Jun 17, 2024

Conversation

qalisander
Copy link
Member

@qalisander qalisander commented Jun 13, 2024

Resolves #77

  • Tests
  • Documentation

Copy link

netlify bot commented Jun 13, 2024

Deploy Preview for contracts-stylus canceled.

Name Link
🔨 Latest commit ab7f3c7
🔍 Latest deploy log https://app.netlify.com/sites/contracts-stylus/deploys/66708a00ac6d7a0008726b3e

Copy link

codecov bot commented Jun 13, 2024

Codecov Report

Attention: Patch coverage is 86.27451% with 7 lines in your changes missing coverage. Please review.

Project coverage is 84.3%. Comparing base (9b1c54d) to head (ab7f3c7).

Additional details and impacted files
Files Coverage Δ
lib/motsu-proc/src/test.rs 97.6% <100.0%> (+0.2%) ⬆️
lib/motsu/src/context.rs 100.0% <100.0%> (ø)
contracts/src/utils/structs/bitmap.rs 84.0% <84.0%> (ø)

... and 1 file with indirect coverage changes

Copy link
Contributor

@alexfertel alexfertel left a comment

Choose a reason for hiding this comment

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

Looks good at a first glance, will do a proper review when I get some time.

One question I have is that I think this is a good candidate for implementing StorageType, right? What do you think?

@bidzyyys bidzyyys self-requested a review June 14, 2024 14:08
Copy link
Collaborator

@bidzyyys bidzyyys left a comment

Choose a reason for hiding this comment

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

Looks good ✅

contracts/src/utils/structs/bitmap.rs Outdated Show resolved Hide resolved
contracts/src/utils/structs/bitmap.rs Outdated Show resolved Hide resolved
contracts/src/utils/structs/bitmap.rs Outdated Show resolved Hide resolved
contracts/src/utils/structs/bitmap.rs Show resolved Hide resolved
@qalisander
Copy link
Member Author

qalisander commented Jun 15, 2024

One question I have is that I think this is a good candidate for implementing StorageType, right? What do you think?

I think yes. I can reuse this contract to build consecutive on top. We don't need to use stylus inheritance just aggregation

#[motsu::test]
fn set_value() {
proptest!(|(value: U256)| {
let mut bit_map = BitMap::default();
Copy link
Member Author

Choose a reason for hiding this comment

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

This one seems a bit debatable decision, but now #[motsu::test] macro locks storage for a test execution even if there is no contract argument.
Assuming that rust contract struct can be created during test.
And the state of this contract will be single per test.
What do you think @alexfertel ? Or may be use with_context function?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think with_context is slightly cleaner because we are instantiating the contract twice this way (with default), right?

In any case, I'm fine either way, I'll leave it to your judgment!

@qalisander qalisander marked this pull request as ready for review June 17, 2024 15:46
Cargo.toml Outdated Show resolved Hide resolved
contracts/Cargo.toml Show resolved Hide resolved
contracts/src/utils/structs/bitmap.rs Outdated Show resolved Hide resolved
contracts/src/utils/structs/bitmap.rs Outdated Show resolved Hide resolved
contracts/src/utils/structs/bitmap.rs Outdated Show resolved Hide resolved
contracts/src/utils/structs/bitmap.rs Show resolved Hide resolved
@qalisander qalisander requested a review from bidzyyys June 17, 2024 17:19
Copy link
Contributor

@alexfertel alexfertel left a comment

Choose a reason for hiding this comment

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

Looks great! 🚀

Besides the question about StorageType I left a few small changes. In any case, I think it's fine to merge as is, and later update it if we need to.

.gitignore Outdated Show resolved Hide resolved
contracts/src/utils/structs/bitmap.rs Outdated Show resolved Hide resolved
contracts/src/utils/structs/bitmap.rs Outdated Show resolved Hide resolved
contracts/src/utils/structs/bitmap.rs Outdated Show resolved Hide resolved
contracts/src/utils/structs/bitmap.rs Outdated Show resolved Hide resolved
}

/// Get bucket index.
fn get_bucket(index: U256) -> U256 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we #[inline] these? They are private & small.

Copy link
Member Author

@qalisander qalisander Jun 17, 2024

Choose a reason for hiding this comment

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

I used to think that those small and private functions should be unlined by default by rust compiler

#[motsu::test]
fn set_value() {
proptest!(|(value: U256)| {
let mut bit_map = BitMap::default();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think with_context is slightly cleaner because we are instantiating the contract twice this way (with default), right?

In any case, I'm fine either way, I'll leave it to your judgment!

contracts/src/lib.rs Outdated Show resolved Hide resolved
@qalisander qalisander merged commit d0994ee into main Jun 17, 2024
20 checks passed
@alexfertel alexfertel deleted the bitmap branch June 21, 2024 16:49
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.

[Feature]: BitMaps
3 participants