Skip to content

Conversation

michaelkaplan13
Copy link
Contributor

Why this should be merged

Optimizes look ups of the subnet ID for a given blockchain ID, particularly for chains with validatorState instances that would otherwise require going over grpc for the look up each time (i.e. subnet-evm instances).

See discussion here.

How this works

Uses an LRU cache for subnet IDs for given blockchain IDs.

How this was tested

Unit tests

Need to be documented in RELEASES.md?

No

@Copilot Copilot AI review requested due to automatic review settings October 7, 2025 20:54
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds an LRU cache for subnet IDs keyed by blockchain ID to avoid repeated underlying (potentially gRPC) lookups and renames the existing validator set cache field for clarity. Also introduces unit tests validating cache population, hits, and error handling paths.

  • Introduces subnetIDsCache (LRU) with configurable size.
  • Renames internal validator set cache field and adds GetSubnetID caching logic.
  • Adds comprehensive test for subnet ID caching behavior including error path.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
snow/validators/state.go Adds subnet ID cache, renames validator set cache field, implements cached GetSubnetID.
snow/validators/state_test.go Adds unit test covering subnet ID cache miss/hit and error handling behavior.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Michael Kaplan <55204436+michaelkaplan13@users.noreply.github.com>
@michaelkaplan13
Copy link
Contributor Author

@StephenButtolph called out that this does not actually improve the worst case verification times/cost for flows dependent on GetSubnetID, since bogus blockchain ID parameters could be provided, which will never be cached.

It's strictly a best case performance optimization, but should not be relied upon for gas price calculations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant