-
Notifications
You must be signed in to change notification settings - Fork 2
add expensive reverse lookup #17
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,12 +10,16 @@ import ( | |
| filaddr "github.com/filecoin-project/go-address" | ||
| hamt "github.com/filecoin-project/go-hamt-ipld/v3" | ||
| filabi "github.com/filecoin-project/go-state-types/abi" | ||
| actorstypes "github.com/filecoin-project/go-state-types/actors" | ||
| filbig "github.com/filecoin-project/go-state-types/big" | ||
| filbuiltin "github.com/filecoin-project/go-state-types/builtin" | ||
| _init13 "github.com/filecoin-project/go-state-types/builtin/v13/init" | ||
| filadt "github.com/filecoin-project/go-state-types/builtin/v13/util/adt" | ||
| "github.com/filecoin-project/go-state-types/manifest" | ||
| filstore "github.com/filecoin-project/go-state-types/store" | ||
|
|
||
| "github.com/filecoin-project/lotus/chain/actors" | ||
| lbi "github.com/filecoin-project/lotus/chain/actors/builtin" | ||
| lbiinit "github.com/filecoin-project/lotus/chain/actors/builtin/init" | ||
| lbimsig "github.com/filecoin-project/lotus/chain/actors/builtin/multisig" | ||
| lchstate "github.com/filecoin-project/lotus/chain/state" | ||
| lchtypes "github.com/filecoin-project/lotus/chain/types" | ||
|
|
@@ -180,6 +184,81 @@ func enumActors(ctx context.Context, bg *blockGetter, ts *lchtypes.TipSet, actor | |
| return nil | ||
| } | ||
|
|
||
| func init() { | ||
| latestInitCode := lbiinit.AllCodes()[len(lbiinit.AllCodes())-1] | ||
| if name, av, ok := actors.GetActorMetaByCode(latestInitCode); ok { | ||
| if name != manifest.InitKey { | ||
| panic(xerrors.Errorf("actor code is not init: %s", name)) | ||
| } | ||
|
|
||
| if av != actorstypes.Version13 { | ||
| panic(xerrors.Errorf( | ||
| "the application is out of date with the network, please update to a later version," + | ||
| " or if this is the latest version file an issue to update the init actor version")) | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+187
to
+200
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ribasushi is there a better way to do this? Ideally I'd be able to just use the latest version (or map a code/actor version to the init state struct), but looking for some alternative options here. Some notes:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What you are doing here locks you into "latest upgrade interval" only: you won't be able to query stuff before a particular epoch this way. Not sure this is the right way to go about this at all.. Ideally you recreate something like this (or have filoz put it in go-state-types where it belongs)
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah, I see. So I probably still need to keep this code in place (or with a test) so as to force updating the code when a new version comes out, but I should handle the historical versions as well with some sort of large map. Not sure if this would require committing to too many abstractions from the filoz folks since I'm operating on the IPLD object so I can load it into a parallel traversing HAMT which is lower level than the abstractions they currently have.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Afaik the HAMT never changed. I have a factored out code I will push tmrw, should make it cleaner...
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@aschmahmann ☝️ it took 2 months, but here it is: #20 |
||
|
|
||
| func enumInit(ctx context.Context, bg *blockGetter, ts *lchtypes.TipSet, initFunc func(id int64, addr filaddr.Address) error) error { | ||
| ast := filstore.WrapStore(ctx, ipldcbor.NewCborStore(bg)) | ||
| getManyAst := &getManyCborStore{ | ||
| BasicIpldStore: ipldcbor.NewCborStore(bg), | ||
| } | ||
|
|
||
| var root lchtypes.StateRoot | ||
| // Try loading as a new-style state-tree (version/actors tuple). | ||
| if err := ast.Get(ctx, ts.ParentState(), &root); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| stateTree, err := lchstate.LoadStateTree(ipldcbor.NewCborStore(bg), ts.ParentState()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| initActor, err := stateTree.GetActor(filbuiltin.InitActorAddr) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| var initRoot _init13.State | ||
| // Try loading as a new-style state-tree (version/actors tuple). | ||
| if err := ast.Get(ctx, initActor.Head, &initRoot); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| initHamt, err := hamt.LoadNode(ctx, getManyAst, initRoot.AddressMap, hamtOptions...) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := initHamt.ForEachParallel(ctx, func(k string, val *cbg.Deferred) error { | ||
| var idCbg cbg.CborInt | ||
| addr, err := filaddr.NewFromBytes([]byte(k)) | ||
| if err != nil { | ||
| return xerrors.Errorf("invalid address (%x) found in state tree key: %w", []byte(k), err) | ||
| } | ||
|
|
||
| err = idCbg.UnmarshalCBOR(bytes.NewReader(val.Raw)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if ctx.Err() != nil { | ||
| return ctx.Err() | ||
| } | ||
|
|
||
| if err := initFunc(int64(idCbg), addr); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| }); err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func getBalance(_ context.Context, bg *blockGetter, ts *lchtypes.TipSet, addr filaddr.Address) error { | ||
| stateTree, err := lchstate.LoadStateTree(ipldcbor.NewCborStore(bg), ts.ParentState()) | ||
| if err != nil { | ||
|
|
||
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.
Not sure how frequently people are going to use this, my hope is if it's common enough someone will show up with a use case to determine how to handle it (e.g. if they're calling it repeatedly the type of cache that would be most useful). At the moment I don't do this more than occasionally for debugging so leaving it alone.