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(parachain/availability-distribution): implement cache for runtime info #4494

Open
1 task
Tracked by #3598
haikoschol opened this issue Jan 22, 2025 · 0 comments
Open
1 task
Tracked by #3598
Labels
C-simple Minor changes changes, no additional research needed. Good first issue/review. S-subsystems-availability issues related to polkadot host availability subsystem functionality. T-implementation this issue/pr is a new feature or functionality.

Comments

@haikoschol
Copy link
Contributor

haikoschol commented Jan 22, 2025

Issue summary

The availability distribution subsystem needs information obtain from the runtime to perform its tasks. To avoid the performance impact of redundant calls, it makes sense to cache this information in the subsystems state.

Implementation details

This issue should be done last when implementing the availability distribution subsystem.

The Parity implementation uses multiple types to implement caching such as RuntimeInfo and SessionCache. There is some overlap in the data they store because some of these types are used in other contexts as well. Instead of anticipating this in our implementation, it probably makes sense to only cover the needs of availability distribution for now and focus on caching the data returned by the runtime functions it uses:

Since this data needs to be accessed by the subsystem itself, as well as the chunk fetching tasks, the cache should probably be implemented in a separate type.

type BlockState interface {
	GetHeader(hash common.Hash) (*types.Header, error)
	GetRuntime(blockHash common.Hash) (instance runtime.Instance, err error)
}

type runtimeCache struct {
        blockState BlockState
        // LRU data structures for cached data
        // maybe a cache for runtime instances as well
}

func (rc *runtimeCache) sessionIndexForChild(blockHash common.Hash) (parachaintypes.SessionIndex, error) {
        // ...
}

func (rc *runtimeCache) sessionInfo(blockHash common.Hash, sessionIndex parachaintypes.SessionIndex) (*parachaintypes.SessionInfo, error) {
        // ...
}

func (rc *runtimeCache) availabilityCores(blockHash common.Hash) ([]parachaintypes.CoreState, error) {
        // ...
}

Acceptance criteria

  • New code is 60% covered with unit tests
@haikoschol haikoschol added C-simple Minor changes changes, no additional research needed. Good first issue/review. S-subsystems-availability issues related to polkadot host availability subsystem functionality. T-implementation this issue/pr is a new feature or functionality. labels Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-simple Minor changes changes, no additional research needed. Good first issue/review. S-subsystems-availability issues related to polkadot host availability subsystem functionality. T-implementation this issue/pr is a new feature or functionality.
Projects
None yet
Development

No branches or pull requests

1 participant