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

docs: inter-block cache specification #14370

Merged
merged 9 commits into from
Jan 16, 2023
Merged

Conversation

angbrav
Copy link
Contributor

@angbrav angbrav commented Dec 20, 2022

Description

Contributes to: #12986

Proposes a specification for the inter-block cache feature following the spec template.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the documentation writing guidelines
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@angbrav angbrav requested a review from a team as a code owner December 20, 2022 15:17
docs/spec/store/interblock-cache.md Outdated Show resolved Hide resolved
docs/spec/store/interblock-cache.md Outdated Show resolved Hide resolved
docs/spec/store/interblock-cache.md Outdated Show resolved Hide resolved
Copy link

@thpani thpani left a comment

Choose a reason for hiding this comment

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

Just a note on iteration, rest LGTM! 🙌


#### Iteration

Iteration is not supported.
Copy link

Choose a reason for hiding this comment

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

In the implementation, since CommitKVStoreCache embeds a CommitKVStore, it does expose the CommitKVStore iteration API.

Since this is just a system model, I guess it's sound to underspecify here, but probably surprising to the reader?

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've added a sentence. Please check.

Copy link

Choose a reason for hiding this comment

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

Looks good, thx!

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>

## Synopsis

The inter-block cache is an in-memory cache storing (in-most-cases) immutable state that modules need to read in between blocks. When enabled, all sub-stores of a multi store, e.g., `rootmulti`, are wrapped.
Copy link
Member

Choose a reason for hiding this comment

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

can we drop (in-most-cases)?

Suggested change
The inter-block cache is an in-memory cache storing (in-most-cases) immutable state that modules need to read in between blocks. When enabled, all sub-stores of a multi store, e.g., `rootmulti`, are wrapped.
The inter-block cache is an in-memory cache storing immutable state that modules need to read in between blocks. When enabled, all sub-stores of a multi store, e.g., `rootmulti`, are wrapped.

Copy link
Contributor Author

@angbrav angbrav Jan 3, 2023

Choose a reason for hiding this comment

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

Actually, I wonder if there is any guarantee that the inter-block cache stores the immutable state. Thoughts on what enables this? Is it the ARC? If so, I will highlight this.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not immutable. If a key is updated, the cache will be updated.

Copy link
Contributor Author

@angbrav angbrav Jan 6, 2023

Choose a reason for hiding this comment

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

I know it is not immutable. My point is whether there is anything in place that in case of reaching the max capacity of the cache, it is likely that immutable state remains cache. My guess is that the fact that the cache is an ARC may help with that: it tracks both frequency and recency of use. Thus, under the assumption that immutable state is more frequently queried, the ARC may help guaranteeing that this is almost always cached, even when max capacity is reached.

If we agree that the above is correct, I will highlight that it is important that the cache implementation is an ARC (or something similar that enables the above), instead of just discussing it as an implementation detail.

Also, I want to get rid of the word immutable, it is confusing: nothing is immutable per se, we only mean keys that a rarely updated.

Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

LGTM, left one question then we can merge

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

Globally curious about the usage of typescript instead of go in the code blocks and general notation.


The inter-block cache requires that the cache implementation to provide methods to create a cache, add a key/value pair, remove a key/value pair and retrieve the value associated to a key. In this specification, we assume that a `Cache` feature offers this functionality through the following methods:

* `NewCache(size: int)` creates a new cache with `size` capacity and returns it.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* `NewCache(size: int)` creates a new cache with `size` capacity and returns it.
* `NewCache(size int)` creates a new cache with `size` capacity and returns it.

nit: Cannot we use Go syntax everywhere?

* `Add(key: string, value: []byte)` inserts a key/value pair into the `Cache`.
* `Remove(key: string)` removes the key/value pair identified by `key` from `Cache`.

The specification also assumes that `CommitKVStore` offers the following API:
Copy link
Member

Choose a reason for hiding this comment

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

Like here, why not simply display a Go interface?


`CommitKVCacheManager` implements the cache manager. It maintains a mapping from a store key to a `KVStore`.

```typescript
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@angbrav
Copy link
Contributor Author

angbrav commented Jan 6, 2023

Globally curious about the usage of typescript instead of go in the code blocks and general notation.

The main reason is here. In any case, if everyone feels more comfortable with just using go, it is fine with me, it was just a recommendation. If we decide to go for go, we should update the template accordingly.

@julienrbrt
Copy link
Member

Globally curious about the usage of typescript instead of go in the code blocks and general notation.

The main reason is here. In any case, if everyone feels more comfortable with just using go, it is fine with me, it was just a recommendation. If we decide to go for go, we should update the template accordingly.

It does not need to be valid syntax (so it solve your point, like #14020 (comment)), but as it lives in the docs, and the SDK is mainly Go, it feels weird to have another language.

@tac0turtle tac0turtle enabled auto-merge (squash) January 16, 2023 11:32
@tac0turtle
Copy link
Member

merging this, we can do follow ups

@tac0turtle tac0turtle merged commit b17f65d into main Jan 16, 2023
@tac0turtle tac0turtle deleted the manuel/interblock-cache-spec branch January 16, 2023 11:34
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.

6 participants