-
Notifications
You must be signed in to change notification settings - Fork 443
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
Implement binary_search for collections::Vec
#836
Conversation
I think that the spellcheck failure is a false alarm, as the documentation is taken from core. |
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.
All in all LGTM so far. Will take another more detailed look into the actual implementation. We could use a bit more tests for this to cover some edge cases. Maybe pull some tests over from the core
implementation?
Co-authored-by: Robin Freyler <robbepop@web.de>
I originally was unable to find them, but now realize they resided in a different crate. I've added the core tests as well now, and removed my own tests. |
Also @Robbepop, sinc binary_search and partition are quite closely related, should I add that one too? Or perhaps create another issue and another PR? |
Another API should be done in another PR. :) |
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.
Doc comments for the functions need to be adjusted to fit ink! instead of Rust standard library. It currently contains dead links and invalid docs or docs that just does not fit. Please rework docs in this regard and we are good to go. Also we might be in need of a sort
function for storage::Vec
in the near future. Although sorting efficiently will be a major endavour and might probably be a bad idea.
For sorting it would probably be for efficient to read the storage vec into a normal vec, sort that, and write the result back? That should minimize the amount of gas fees I think. Does a wishlist exist for additions to the ink stdlib? |
Co-authored-by: Robin Freyler <robbepop@web.de>
Maybe yes, however due to caching in the |
Alright, so a PR involving adding sorting would require benchmarks of the two competing implementations? |
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.
LGTM
@cmichi please review/approve too.
We need to check the spellcheck CI so that our full pipeline is run on this PR before we merge.
Just add comparator
to the spellcheck
list for hunspell and the spellcheck CI should be fine with this PR.
Porting binary_search to the storage Vec, including the documentation found in core, led to a failure in spellcheck. Since core is considered to be correct, it is updated on spellcheck.
collections::Vec
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.
Some small nit picks, but after they're resolved we can merge
Actually now that I think about it, wasn't binary_search implementation specific behaviour the reason that polkadot had an outage? Perhaps it is not okay for this test to break, as contracts may rely on the specific behaviour? |
Umm kinda. The problem with Polkadot was that the Wasm runtime and native runtime had different sorting behaviours which caused a failure in consensus. You can read more about it here. In our case once a contract is deployed that's the only instance of it. There is no need for a network of people with potentially different versions of the contract to come to consensus on the behaviour - they only need to run what's already on chain. Whether or not we want to make any guarantees around sorting behaviour is an interesting topic. I'm not sure what the answer is here though. @cmichi @Robbepop what do you guys think? |
We should do the same as Rust and provide no sorting behavior since this could in theory severely reduce the efficiency of the algorithm. Furthermore, the API clearly says this and the problem for Polkadot existed because Polkadot did not obey the API calling guarantees and took something for granted that simply did not exist. So the problem was not caused by the Rust API or implementation but purely on the user side (Polkadot). |
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.
Please fix the doc examples to work with the respecitve ink_storage::Vec
type so that we can merge this.
This ports the binary_search implementation from
core
. I've removed the use ofget_unchecked
as that is not present inLazyIndexMap
. There's 2 tests added to verify that it works with a full vector and an empty vector.related to #834