Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Conversation

@kianenigma
Copy link
Contributor

Currently this rpc endpoint only works for state values.

Now, if no data exists in the given storage key, we check it is a (double) map and any other key-pairs are stored with that prefix. If so, we return the sum of all values.

@kianenigma kianenigma added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. labels Aug 7, 2020
@kianenigma kianenigma requested a review from tomusdrw August 7, 2020 14:19
Copy link
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

lgtm if doing both queries in parallel is expected

Box::new(self.storage(block, key)
.map(|x| x.map(|x| x.0.len() as u64)))
let value_len = self.storage(block, key.clone()).map(|x| x.map(|x| x.0.len() as u64));
let pairs_len = self.storage_pairs(block, key.clone())
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't that query be done conditionally only if value_len results into None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that makes more sense and I initially started with that, but failed to get it to work. Ideally I want: only if the first one is Ok(None), then try the second one.

But I am not sure if this is even possible? I am but new to futures.

Copy link
Contributor

@tomusdrw tomusdrw Aug 7, 2020

Choose a reason for hiding this comment

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

Depends on the futures version we have here, but it seems it's 0.1 and I think it should be something like this:

value_len.and_then(|result| match result {
  None => Either::A(self.storage_pairs(...)...),
  Some(v) => Either:B(future::done(Ok(Some(v))),
})

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'm pretty sure I tried something like that and failed once, but let me try again and get back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay so this was the first time I was working with futures and the main point of confusion was the versioning going on (which makes me appreciate more and more the standardised async/await). I wasn't aware that the rpc us using and re-exporting 0.1 and the current crate is using 0.3, and I was getting strange errors all over the place.

Copy link
Member

Choose a reason for hiding this comment

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

The storage_pairs function will return the results directly. You need to do this differently here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can you explain more? I don't see the difference in what you suggested.

Copy link
Member

Choose a reason for hiding this comment

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

When you call a function that returns a future, you can also directly return the result. This means the first time the future is polled the result is ready. However this also means that the operation is always executed, in this case the scanning of the storage. I propose that you put the scanning call into a closure and only call this closure if the first storage call returned a none. This means you will only scan the storage when the value does not exists vs query it always.

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 exactly wanted to do as you explain: only query the second if the first one is None. This is how I thought: calling self.storage_pairs and storing it in pairs_len executes nothing, because it is not yet polled. I thought that also afterwards when I pass it to and_then, it is would be only polled in the None arm, but apparently not.

@kianenigma kianenigma added A6-mustntgrumble and removed A0-please_review Pull request needs code review. labels Aug 7, 2020
@kianenigma kianenigma added A0-please_review Pull request needs code review. and removed A6-mustntgrumble labels Aug 10, 2020
@kianenigma kianenigma requested review from NikVolf and cecton August 10, 2020 19:03
Box::new(self.storage(block, key)
.map(|x| x.map(|x| x.0.len() as u64)))
let value_len = self.storage(block, key.clone()).map(|x| x.map(|x| x.0.len() as u64));
let pairs_len = self.storage_pairs(block, key.clone())
Copy link
Member

Choose a reason for hiding this comment

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

The storage_pairs function will return the results directly. You need to do this differently here.

@kianenigma
Copy link
Contributor Author

with a gratitude to @bkchr:

@kianenigma
Copy link
Contributor Author

bot merge

@ghost
Copy link

ghost commented Aug 11, 2020

Waiting for commit status.

@ghost
Copy link

ghost commented Aug 11, 2020

Checks failed; merge aborted.

@kianenigma
Copy link
Contributor Author

bot merge

@ghost
Copy link

ghost commented Aug 11, 2020

Trying merge.

@ghost ghost merged commit 865321f into master Aug 11, 2020
@ghost ghost deleted the kiz-rpc-for-map-len branch August 11, 2020 12:09
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants