Skip to content

Add contract ID cache and DB table #192

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

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open

Add contract ID cache and DB table #192

wants to merge 32 commits into from

Conversation

aditya1702
Copy link
Contributor

@aditya1702 aditya1702 commented Jun 11, 2025

What

  • Add a contracts DB table which stores the name and symbol of custom tokens.
  • Add an in-memory cache that maintains the contracts in local memory to speed up lookups.
contractID : {
     name
     symbol
}

This mapping is stored as a hash map structure in memory. We use the go-cache library for setting up the cache.

  • Add relevant unit tests

For pod restarts, the cache will be initialized from the DB which acts a persistent data store.

Why

We dont need to call the simulation function each time to get the relevant name and symbol values for custom tokens. We can simply store the information in the cache when processing token transfer events for these tokens and use the info by querying against the cache.

Known limitations

N/A

Issue that this PR addresses

Closes #190 #206 #207

Checklist

PR Structure

  • It is not possible to break this PR down into smaller PRs.
  • This PR does not mix refactoring changes with feature changes.
  • This PR's title starts with name of package that is most changed in the PR, or all if the changes are broad or impact many packages.

Thoroughness

  • This PR adds tests for the new functionality or fixes.
  • All updated queries have been tested (refer to this check if the data set returned by the updated query is expected to be same as the original one).

Release

  • This is not a breaking change.
  • This is ready to be tested in development.
  • The new functionality is gated with a feature flag if this is not ready for production.

@aditya1702 aditya1702 marked this pull request as ready for review June 11, 2025 16:59
@JakeUrban
Copy link
Contributor

JakeUrban commented Jun 11, 2025

I'm not convinced the benefits we're getting by caching name and symbol is worth adding an additional component to the architecture. We want this project to be as easy to run for other organizations as possible. If we want this indexed, can we store it in postgres?

@aditya1702
Copy link
Contributor Author

I'm not convinced the benefits we're getting by caching name and symbol is worth adding an additional component to the architecture. We want this project to be as easy to run for other organizations as possible. If we want this indexed, can we store it in postgres?

@JakeUrban @marcelosalloum My bad, in my mind I was thinking of how freighter backend would use this and since it already uses redis this was very straightforward. However, I agree with making it easy for the ecosystem to use. We can just store it in-memory instead.

I will update the code to use it

@aditya1702 aditya1702 changed the title Add contract ID cache Add contract ID cache and DB tables Jun 16, 2025
@aditya1702 aditya1702 changed the title Add contract ID cache and DB tables Add contract ID cache and DB table Jun 16, 2025
Copy link
Collaborator

@marcelosalloum marcelosalloum left a comment

Choose a reason for hiding this comment

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

Looking great!

I left a few comments about code completeness and a question regarding database expiration. We can sync by DM if you want.

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.

State Change Indexer: Add Contract Cache Store and DB Tables
3 participants