-
Notifications
You must be signed in to change notification settings - Fork 79
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
Exported methods for iteration of verified allocations and claims #1468
base: master
Are you sure you want to change the base?
Conversation
Yes. But I wouldn't bother implementing a manual iterator like I did. Instead, I'd use iterator combinators (returning an You should be able to write this with something like |
Well...
|
Yes. |
I don't really see why we'd have to prevent calling them unless we want to prevent them from being a public API. Being "expensive" isn't really a good reason. However, if we do want to limit access, the standard way is to verify that the caller is the "system" actor. |
Is this ready for a code review? Or are you just looking for answers to those questions? |
The risk is that at some point they become impossible to call on-chain due to block/message gas limit. |
This has so far defeated me due to all handling of errors loading and iterating the inner map and type constraints on the closure. I need both ok and err branches to return an I will probably attempt a manual iterator instead. No further review needed yet. |
9b467f3
to
d41320d
Compare
d41320d
to
03eff49
Compare
@Stebalien this is ready for review now.
After making some attempts, I've decided it's not worth the effort. I'm sure it's possible, but probably requires an explicit iterator object etc to handle plumbing the errors.
I'm using ILLEGAL_ARGUMENT for the case where cursor is stale (the root CID of the structure has changed). Other issues like the keys not existing result in ILLEGAL_STATE, like every other HAMT lookup failure. Detecting this to assign a different exit code is possible, but again I deemed it not worthwhile.
I have not implemented any such mechanism. I think this falls under allowing this capability to those who can use it safely rather than preventing it for everyone just because it's possible to screw up.
I will update FIP-0076 DDO to include this method, once the signature/code is approved. The branch is against master, rather than the DDO integration branch, but I won't merge this until the FIP is accepted. |
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.
A few nits but otherwise LGTM.
runtime/src/util/mapmap.rs
Outdated
Ok(None) | ||
} | ||
|
||
// pub fn for_each_each2( |
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.
Ok, I tried to make this work but there's a fundamental problem: there's no way take ownership of the Hamt
when iterating over it. So we have a problem:
- Iterate over outer
Hamt
(outer_hamt
). - Load inner
Hamt
(inner_hamt
). - Iterate (
iter_inner_hamt
) overouter_hamt
, borrowinginner_hamt
in theiter_inner_hamt
object.
Unfortunately, we'd need to store both inner_hamt
and iter_inner_hamt
in the same structure, which we can't do because iter_inner_hamt
refers to inner_hamt
(it's a self-referential object).
There are some ways to work around this, but they're kind of painful. Manually implementing the iterator doesn't get us anywhere.
TL;DR:
It's possible to handle the errors, etc. even without an explicit iterator (although you do need to use itertools). But there's no reasonable way to deal with the lifetime issues any which way. |
Yeah, that's fine. |
Reverting this to draft and awaiting a new FIP to specify it. |
Implements exported method on the verified registry actor to iterate allocations and claims. The methods return IDs, which can then be looked up, though I could change it to return the full inflated objects too. These methods are not intended to be invoked on chain, but by off-chain parties like explorers and dashboards. Invoking methods like this can replace direct state inspection, which is a direction we should head over time.
(As a follow-up to this, we're planning to draft an FRC detailing what "deal" fields mean, and to make this backwards compatible with existing on-chain claims).
TODO
Await FIP-0076 acceptance, including spec for this methodQuestions
MapMap::for_each_each
as an external iterator, given that it's implemented in terms of them? It's probably a little more code, but more convenient to use from the outside. But there's no other callers here (yet). @Stebalien