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

eth/filters: add global block logs cache #25459

Merged
merged 13 commits into from
Aug 19, 2022
Merged

Conversation

s1na
Copy link
Contributor

@s1na s1na commented Aug 1, 2022

This adds a cache for block logs which is shared by all filters. In order to share the cache reference, filters now need to be created through a 'filter system' object. Cache size is user-configurable via --cache.blocklogs.

This PR is an alternative to #25425.
cc @ryanschneider

Fixes #25421
Includes #25468, which should be merged first.

@ryanschneider
Copy link
Contributor

lgtm! Thanks!

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -266,6 +267,9 @@ func (f *Filter) checkMatches(ctx context.Context, header *types.Header) (logs [
if err != nil {
return nil, err
}
if logsList == nil {
Copy link
Member

@rjl493456442 rjl493456442 Aug 2, 2022

Choose a reason for hiding this comment

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

It's weird to add this "duplicated" check here, usually a nil error means the returned result is not empty.

I would vote to add the check here https://github.com/ethereum/go-ethereum/pull/25459/files#diff-9886da3412b43831145f62cec6e895eb3613a175b945e5b026543b7463454603R204

func (b *EthAPIBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error) {
       result := b.eth.blockchain.GetLogsByHash(hash)
       if result == nil {
             return nil, errors.New("xxx")
       }
       return b.eth.blockchain.GetLogsByHash(hash), nil
}

Also in les_apiBackend.GetLogs, we should also return the error if logs is not found.

func (b *LesApiBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error) {
	if number := rawdb.ReadHeaderNumber(b.eth.chainDb, hash); number != nil {
		return light.GetBlockLogs(ctx, b.eth.odr, hash, *number)
	}
	return nil, fmt.Errorf("failed to get logs for block %x", hash)
}

internal/ethapi/backend.go Outdated Show resolved Hide resolved
@fjl
Copy link
Contributor

fjl commented Aug 2, 2022

This is ready for testing now. The cache size is configurable via --cache.logcache or in TOML with Eth.FilterLogCacheSize = 128, for example.

@holiman Please re-check this, the PR has changed significantly after your initial review.

@fjl fjl changed the title core,eth: cache logs in blockchain eth/filters: add global block logs cache Aug 3, 2022
cmd/utils/flags.go Outdated Show resolved Hide resolved
@s1na s1na force-pushed the filter/cache-logs branch from 359a19a to dfb6bd7 Compare August 4, 2022 09:40
cmd/utils/flags.go Outdated Show resolved Hide resolved
JukLee0ira added a commit to JukLee0ira/XDPoSChain that referenced this pull request Jul 23, 2024
JukLee0ira added a commit to JukLee0ira/XDPoSChain that referenced this pull request Aug 3, 2024
gzliudan pushed a commit to XinFinOrg/XDPoSChain that referenced this pull request Aug 3, 2024
wanwiset25 pushed a commit to XinFinOrg/XDPoSChain that referenced this pull request Aug 23, 2024
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.

Apparent Performance regression in eth_getLogs
6 participants