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

[Off-chain] feat: in-memory query cache(s) #994

Merged
merged 47 commits into from
Feb 25, 2025

Conversation

bryanchriswhite
Copy link
Contributor

@bryanchriswhite bryanchriswhite commented Dec 11, 2024

Summary

Adds the QueryCache[T any] and HistoricalQueryCache[T any] interfaces, InMemoryCache[T any] implementation, configurations, and options functions.

---
title: Legend
---

classDiagram-v2

class GenericInterface__T__any {
    <<interface>>
    GenericMethod() T
}

class Implemenetation {
    ExportedField FieldType
    unexportedField FieldType
}

Implemenetation --|> GenericInterface__T__any: implements

%% class Embedder__T__any {
%%     <<interface>>
%%     GenericInterface[T]
%% }

%% Embedder__T__any ..|> GenericInterface__T__any: embeds
Loading
---
title: Caches
---

classDiagram-v2


class KeyValueCache__T__any {
    <<interface>>
    Get(key string) (value T, isCached bool)
    Set(key string, value T) (err error)
    Delete(key string)
    Clear()
}

class HistoricalKeyValueCache__T__any {
    <<interface>>
    GetLatestVersion(key string) (value T, isCached bool)
    GetVersion(key string, version int64) (value T, isCached bool)
    SetVersion(key string, value T, version int64) (err error)
}

class keyValueCache__T__any:::cacheImpl
keyValueCache__T__any --|> KeyValueCache__T__any

class historicalKeyValueCache__T__any
historicalKeyValueCache__T__any --|> HistoricalKeyValueCache__T__any
Loading

Issue

Type of change

Select one or more from the following:

Testing

  • Documentation: make docusaurus_start; only needed if you make doc changes
  • Unit Tests: make go_develop_and_test
  • LocalNet E2E Tests: make test_e2e
  • DevNet E2E Tests: Add the devnet-test-e2e label to the PR.

Sanity Checklist

  • I have tested my changes using the available tooling
  • I have commented my code
  • I have performed a self-review of my own code; both comments & source code
  • I create and reference any new tickets, if applicable
  • I have left TODOs throughout the codebase, if applicable

@bryanchriswhite bryanchriswhite added the off-chain Off-chain business logic label Dec 11, 2024
@bryanchriswhite bryanchriswhite self-assigned this Dec 11, 2024
@bryanchriswhite bryanchriswhite linked an issue Dec 11, 2024 that may be closed by this pull request
4 tasks
@bryanchriswhite bryanchriswhite marked this pull request as ready for review December 12, 2024 11:20
* pokt/main:
  [Relayminer, Bug] fix: sessiontree logger never initialized (#993)
  fix: E2E tests - RPC URL path (#1008)
  Updated cheat sheat docs with an example after installation (#1004)
  fix: Nil session tree logger (#1007)
@bryanchriswhite bryanchriswhite changed the base branch from fix/sessiontree to main December 13, 2024 14:24
Copy link
Member

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

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

@bryanchriswhite I did a superficial review but did not dive into the validation of the business logic line-by-line.

Is there any section where you'd want another pair of 👀 ?

Copy link
Member

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

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

Love the iteration. Thanks @bryanchriswhite!

Left a few new comments, a few replies to older threads, but it should be g2g after the next round 🙌

Copy link
Contributor

@red-0ne red-0ne left a comment

Choose a reason for hiding this comment

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

Great caching design.

Left some comments but did not tend to pkg/client/query/cache/memory_test.go yet. Which I'll do right after this one.

Copy link
Contributor

@red-0ne red-0ne left a comment

Choose a reason for hiding this comment

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

This shape is easier to read and reason about 👍

I left some comments but should be trivial to address.

Copy link
Member

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

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

Just realized I never published my review from yesterday :(

bryanchriswhite and others added 2 commits February 21, 2025 10:16
Co-authored-by: red-0ne <[email protected]>
Co-authored-by: Daniel Olshansky <[email protected]>
* pokt/main:
  [RelayMiner] Introduce new relay authenticator for relay signing and verification (#1077)
  Update links to Soothe's Explorer and GraphQL Playground (#1087)
  [Docs] Followup on making homebrew troubleshooting easier to identify (#1084)
Copy link
Member

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

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

@bryanchriswhite I did a "show changes since your last review" and it seems like all the files have changed?

Either way, lmk when this is ready for a re-review.

@bryanchriswhite
Copy link
Contributor Author

bryanchriswhite commented Feb 24, 2025

@bryanchriswhite I did a "show changes since your last review" and it seems like all the files have changed?

Either way, lmk when this is ready for a re-review.

Sorry about that, this is likely the result of file renaming/reorganization. The cache now lives at pkg/cache, rather than pkg/client/query/cache. While its initial usage may be in the query clients, the cache pkg itself doesn't have any dependency or coupling to the query client pkg.

@bryanchriswhite
Copy link
Contributor Author

bryanchriswhite commented Feb 24, 2025

Additionally, based on prior feedback and the continued iteration here, I've refactored GetVersion() to ONLY return the specific version requested, and added a new GetVersionLTE() method which implements the previous behavior:

	// GetVersionLTE retrieves the value at the nearest version <= maxVersion.
	// It returns true if a value meeting the version criteria for the given
	// key is cached, false otherwise.
	GetVersionLTE(key string, maxVersion int64) (T, bool)

Copy link
Contributor

@red-0ne red-0ne left a comment

Choose a reason for hiding this comment

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

Love the shape it took 🔥

Thanks for your patience iterating over it.

Copy link
Member

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

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

Love the final shape of this!

@bryanchriswhite bryanchriswhite merged commit 0ef80a3 into main Feb 25, 2025
13 checks passed
@bryanchriswhite
Copy link
Contributor Author

bryanchriswhite commented Feb 26, 2025

PLEASE DO NOT DELETE THIS BRANCH UNTIL DOWNSTREAM PRS HAVE BEEN REBASED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
off-chain Off-chain business logic
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[Off-Chain] ModuleParamsClient & Historical Params
3 participants