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: add data cache for UTXO and RGB++ asset cells #132

Merged
merged 22 commits into from
May 17, 2024

Conversation

ahonn
Copy link
Collaborator

@ahonn ahonn commented May 9, 2024

Purpose

Implement a data cache for UTXO and RGB++ asset cells. API requests directly return cached data, which is updated using an asynchronous update mechanism (Job queue).

Changes

  • Cache the RGB++ Cells for the BTC Address and update it asynchronously
    • /rgbpp/v1/address/:address/assets with same parameters
      • no cache: 18s
      • with cache: 8s
    • also optimize /rgbpp/v1/assets routes by using batch request, speed up response time
  • Cache the UTXO data for the BTC Address and update it asynchronously
    • /bitcoin/v1/address/:address/upspent with same parameters
      • no cache: 8s
      • with cache: ~= 50ms
  • Trigger the update of the RGB++ Cells cache when the UTXO is updated
  • UTXO update interval increases exponentially
  • Update UTXO data immediately when getting a new request
  • Add UTXO sync job expiration policy (336 hours by default) and data cache expiration time
  • Add new env vars for enable/disable data cache: UTXO_SYNC_DATA_CACHE_ENABLE, RGBPP_COLLECT_DATA_CACHE_ENABLE
  • Add error handle and sentry capture
  • Add unit test cases for new services

New Envs

/**
   * UTXO sync data cache enable flag, used to cache the UTXO sync data
   * enable by default
   */
  UTXO_SYNC_DATA_CACHE_ENABLE: z
    .enum(['true', 'false'])
    .default('true')
    .transform((value) => value === 'true'),
  /**
   * UTXO sync repeat base duration, used to set the UTXO sync repeat interval
   * repeat job start interval is 10 seconds by default
   */
  UTXO_SYNC_REPEAT_BASE_DURATION: z.coerce.number().default(10 * 1000),
  /**
   * UTXO sync repeat max duration, used to maximum the UTXO sync repeat interval
   * 1 hour by default
   */
  UTXO_SYNC_REPEAT_MAX_DURATION: z.coerce.number().default(60 * 60 * 1000),
  /**
   * UTXO sync repeat expired duration, used to remove the expired UTXO sync job
   * 336 hours by default
   */
  UTXO_SYNC_REPEAT_EXPRIED_DURATION: z.coerce.number().default(336 * 60 * 60 * 1000),
  /**
   * UTXO sync data cache expire duration, used to cache the UTXO sync data
   * 30 minutes by default
   */
  UTXO_SYNC_DATA_CACHE_EXPIRE: z.coerce.number().default(30 * 60 * 1000),

  /**
   * RGB++ collect data cache enable flag, used to cache the RGB++ collect data
   * enable by default
   */
  RGBPP_COLLECT_DATA_CACHE_ENABLE: z
    .enum(['true', 'false'])
    .default('true')
    .transform((value) => value === 'true'),
  /**
   * RGB++ collect data cache expire duration, used to cache the RGB++ collect data
   */
  RGBPP_COLLECT_DATA_CACHE_EXPIRE: z.coerce.number().default(30 * 60 * 1000),

Copy link

vercel bot commented May 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
btc-assets-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2024 4:46am

@ahonn ahonn requested a review from Flouse May 9, 2024 12:48
src/services/rgbpp.ts Outdated Show resolved Hide resolved
src/routes/rgbpp/assets.ts Show resolved Hide resolved
src/plugins/cron.ts Show resolved Hide resolved
Co-authored-by: Flouse <1297478+Flouse@users.noreply.github.com>
Co-authored-by: Flouse <1297478+Flouse@users.noreply.github.com>
@ahonn ahonn merged commit ecae7c6 into develop May 17, 2024
4 checks passed
@ahonn ahonn deleted the feat/utxo-and-cell-cache branch May 17, 2024 01:47
@Dawn-githup
Copy link
Collaborator

image

@Flouse
Copy link
Contributor

Flouse commented May 20, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants