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(lens): Optimize StateGetActor calls. #214

Merged
merged 5 commits into from
Jan 12, 2021

Conversation

hsanjuan
Copy link
Contributor

Add a utility function called "OptimizedStateGetActorWithFallback()" which
gets the current tipset's state by trying to load the child's state and using
ParentState() on that, so that we avoid recomputing the state for the current
tipset by applying messages.

If anything goes wrong, the function falls back to the original, more
expensive StateGetActor, and logs a warning.

Add a utility function called "OptimizedStateGetActorWithFallback()" which
gets the current tipset's state by trying to load the child's state and using
ParentState() on that, so that we avoid recomputing the state for the current
tipset by applying messages.

If anything goes wrong, the function falls back to the original, more
expensive StateGetActor, and logs a warning.
@hsanjuan hsanjuan requested a review from frrist November 10, 2020 14:53
Copy link
Member

@frrist frrist left a comment

Choose a reason for hiding this comment

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

LGTM. I'd recommend giving this a read for more context on the nuance of the lotus API methods: https://protocollabs.slack.com/archives/CKT1X7YFN/p1603386966321800

lens/util.go Outdated
return nil, xerrors.Errorf("Failed to load tipset: %w", err)
}

child, err := api.ChainGetTipSetByHeight(ctx, ts.Height()+1, types.NewTipSetKey())
Copy link
Member

Choose a reason for hiding this comment

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

why pass types.NewTipSetKey() here? Is this intended to be types.EmptyTSK?

lens/util.go Outdated Show resolved Hide resolved
lens/util.go Outdated Show resolved Hide resolved
lens/util.go Outdated Show resolved Hide resolved
@frrist
Copy link
Member

frrist commented Nov 18, 2020

@hsanjuan I have cherry-picked and tweaked these changes to handle null rounds in #238 -- see defb12a#diff-a771f3c826cfe5ebe05c1a003873af47456ee3e16188c1e5d0a1162c0b3e27acR41.

In the same PR I have fixed what I believe to be an off by one error (see #238 (comment)) I discovered while reviewing this. Without the off-by-one fix many of the calls to StateGetActor will continue to fail which is why I (sloppy) did this all in a single PR.

Feel free to merge the changes in defb12a here and I will land the bug fix as a follow on, or just land #238 directly in your AM.

@hsanjuan
Copy link
Contributor Author

@frrist I have imported your changes and added some smaller fixes.

@frrist
Copy link
Member

frrist commented Nov 18, 2020

My approval is sticky, this LGTM.

@frrist
Copy link
Member

frrist commented Jan 11, 2021

Hey @hsanjuan is there anything preventing you from merging this?

@hsanjuan
Copy link
Contributor Author

I don't remember. Either I forgot or there were discussions about not calling these methods at all and this felt like more crust. Should we merge (I can rebase), or close?

@frrist
Copy link
Member

frrist commented Jan 11, 2021

StateGetActor is still used through out Visor during actor extraction, and as far as I am aware Lotus will still recompute state when the method is called -- meaning this is still worth merging since it will alleviate the performance hit of state computation for some cases.

Copy link
Contributor Author

@hsanjuan hsanjuan left a comment

Choose a reason for hiding this comment

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

@frrist ok, this should be good to go.

Please review again. The problem was that there was a TODO because I did not manage to enable the optimization for the lotus-api lens as I did not find how to access a store. I somehow managed now.

// pre-computed ParentState().
//
// TODO: Remove. See: https://github.com/filecoin-project/sentinel-visor/issues/196
func OptimizedStateGetActorWithFallback(ctx context.Context, store cbor.IpldStore, chainAPI full.ChainModuleAPI, fallback full.StateModuleAPI, actor address.Address, tsk types.TipSetKey) (*types.Actor, error) {
Copy link
Contributor Author

@hsanjuan hsanjuan Jan 12, 2021

Choose a reason for hiding this comment

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

This could be simpler if FullNodeAPI actually implemented FullNode but it doesn't:

lens/util/repo.go:109:74: cannot use ra.FullNodeAPI (type impl.FullNodeAPI) as type api.FullNode in argument to lens.OptimizedStateGetActorWithFallback:
	impl.FullNodeAPI does not implement api.FullNode (AuthNew method has pointer receiver)

@hsanjuan hsanjuan requested a review from frrist January 12, 2021 17:27
@hsanjuan hsanjuan merged commit d368cd1 into master Jan 12, 2021
@hsanjuan hsanjuan deleted the fix/196-state-get-actor-perf branch January 12, 2021 18:08
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.

2 participants