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

Add operator state cache to IndexedChainState #983

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

dmanc
Copy link
Contributor

@dmanc dmanc commented Dec 11, 2024

Why are these changes needed?

Checks

  • I've made sure the tests are passing. Note that there might be a few flaky tests, in that case, please comment that they are not relevant.
  • I've checked the new test coverage and the coverage percentage didn't drop.
  • Testing Strategy
    • Unit tests
    • Integration tests
    • This PR is not tested :(

core/indexer/state.go Outdated Show resolved Hide resolved
Copy link
Contributor

@ian-shim ian-shim left a comment

Choose a reason for hiding this comment

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

looks good to me!
waiting for tests

core/indexer/state.go Outdated Show resolved Hide resolved
@ian-shim ian-shim requested a review from jianoaix December 12, 2024 00:04
@@ -365,3 +392,13 @@ func convertIndexedOperatorInfoGqlToIndexedOperatorInfo(operator *IndexedOperato
Socket: string(operator.SocketUpdates[0].Socket),
}, nil
}

// Computes a cache key for the operator state cache. The cache key is a
// combination of the block number and the quorum IDs. Note: the order of the
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know if this is a problem but noticed that the cache key is dependent on the order you input the quorum ids.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's a unordered set, so you may eliminate the ordering effect by sorting the them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good I'll add sorting.

cli.IntFlag{
Name: OperatorStateCacheSize,
Usage: "The size of the operator state cache in elements (0 to disable)",
Value: 0,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should default be 0 or 32?

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the estimated size bytes for 32 entries and how many instances of this struct is expected to be created? If it's small enough it should be fine to enable by default

Copy link
Contributor Author

@dmanc dmanc Dec 13, 2024

Choose a reason for hiding this comment

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

Depends on the amount of operators but let's assume 200. The order of magnitude is ~1-5mb.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, it seems this cache is not really useful:

Where does the cache help?

@@ -124,6 +138,14 @@ func (ics *indexedChainState) Start(ctx context.Context) error {
}

func (ics *indexedChainState) GetIndexedOperatorState(ctx context.Context, blockNumber uint, quorums []core.QuorumID) (*core.IndexedOperatorState, error) {
// Check if the indexed operator state has been cached
cacheKey := computeCacheKey(blockNumber, quorums)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we are using cache then we need to assume that the blockNumber has been finalized already. I believe all users of this function would satisfy that assumption since they're passing in a reference block number.

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.

3 participants