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

Speed up StateListMessages in some cases #6007

Merged
merged 1 commit into from
Apr 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions node/impl/full/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,31 @@ func (a *StateAPI) StateListMessages(ctx context.Context, match *api.MessageMatc

if match.To == address.Undef && match.From == address.Undef {
return nil, xerrors.Errorf("must specify at least To or From in message filter")
} else if match.To != address.Undef {
_, err := a.StateLookupID(ctx, match.To, tsk)

// if the recipient doesn't exist at the start point, we're not gonna find any matches
if xerrors.Is(err, types.ErrActorNotFound) {
return nil, nil
}

if err != nil {
return nil, xerrors.Errorf("looking up match.To: %w", err)
}
} else if match.From != address.Undef {
_, err := a.StateLookupID(ctx, match.From, tsk)

// if the sender doesn't exist at the start point, we're not gonna find any matches
if xerrors.Is(err, types.ErrActorNotFound) {
return nil, nil
}

if err != nil {
return nil, xerrors.Errorf("looking up match.From: %w", err)
}
}

// TODO: This should probably match on both ID and robust address, no?
matchFunc := func(msg *types.Message) bool {
if match.From != address.Undef && match.From != msg.From {
return false
Expand Down