From def39f26caff583b40d3d32698bfd13cc94c28e0 Mon Sep 17 00:00:00 2001 From: KONFeature Date: Fri, 3 Jan 2025 15:56:52 +0100 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Reput=20realtime=20caching?= =?UTF-8?q?=20+=20upgrade=20to=20erpc:0.0.35?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- infra/erpc.ts | 7 ++- packages/erpc/Dockerfile | 12 ++--- packages/erpc/src/storage.ts | 97 +++++++++++++++++++----------------- 3 files changed, 61 insertions(+), 55 deletions(-) diff --git a/infra/erpc.ts b/infra/erpc.ts index df7fd5c..4c200eb 100644 --- a/infra/erpc.ts +++ b/infra/erpc.ts @@ -69,8 +69,11 @@ export const erpcService = new SstService("Erpc", { }, // Container health check health: { - command: ["CMD-SHELL", "curl -f http://localhost:8080/healthcheck || exit 1"], - startPeriod: "15 seconds" + command: [ + "CMD-SHELL", + "curl -f http://localhost:8080/healthcheck || exit 1", + ], + startPeriod: "15 seconds", }, // Logging options logging: { diff --git a/packages/erpc/Dockerfile b/packages/erpc/Dockerfile index eaee2f5..512bf1b 100644 --- a/packages/erpc/Dockerfile +++ b/packages/erpc/Dockerfile @@ -1,21 +1,21 @@ # Config bundler step FROM oven/bun:latest AS bundler -RUN mkdir -p /temp/dev +RUN mkdir -p /tmp/dev # Bundle everything in a single erpc.js file -COPY . /temp/dev -RUN cd /temp/dev && bun install --production -RUN cd /temp/dev && bun build --outfile ./erpc.js --minify --target node --external "@erpc-cloud/*" src/index.ts +COPY . /tmp/dev +RUN cd /tmp/dev && bun install --production +RUN cd /tmp/dev && bun build --outfile ./erpc.js --minify --target node --external "@erpc-cloud/*" src/index.ts # Final image #FROM erpc-dev AS final -FROM ghcr.io/erpc/erpc@sha256:c2e09378e5b7922428e8363c577fdf063aaf3d060e79ce44f8f9006c47bc80f6 AS final +FROM ghcr.io/erpc/erpc:0.0.35 AS final # Install curl, will be used for healthcheck RUN apt-get update && apt-get install -y curl # Copy the bundled config -COPY --from=bundler ./temp/dev/erpc.js /root/erpc.js +COPY --from=bundler ./tmp/dev/erpc.js /root/erpc.js # Run the server CMD ["./erpc-server"] \ No newline at end of file diff --git a/packages/erpc/src/storage.ts b/packages/erpc/src/storage.ts index 79d51f6..e261664 100644 --- a/packages/erpc/src/storage.ts +++ b/packages/erpc/src/storage.ts @@ -1,9 +1,12 @@ import { type CacheConfig, CacheEmptyBehaviorAllow, + CacheEmptyBehaviorIgnore, type CachePolicyConfig, type ConnectorConfig, DataFinalityStateFinalized, + DataFinalityStateRealtime, + DataFinalityStateUnfinalized, } from "@erpc-cloud/config"; if (!process.env.ERPC_DATABASE_URL) { @@ -22,22 +25,22 @@ const connectors = [ table: "rpc_cache", }, }, - // { - // id: "memory-unfinalized", - // driver: "memory", - // memory: { - // // max 4k items for unfinalized cache - // maxItems: 4_096, - // }, - // }, - // { - // id: "memory-realtime", - // driver: "memory", - // memory: { - // // Max 4k items for realtime cache - // maxItems: 4_096, - // }, - // }, + { + id: "memory-unfinalized", + driver: "memory", + memory: { + // max 4k items for unfinalized cache + maxItems: 4_096, + }, + }, + { + id: "memory-realtime", + driver: "memory", + memory: { + // Max 4k items for realtime cache + maxItems: 4_096, + }, + }, ] as const satisfies ConnectorConfig[]; /** @@ -54,37 +57,37 @@ const cachePolicies = [ finality: DataFinalityStateFinalized, empty: CacheEmptyBehaviorAllow, }, - // // Cache not finalized data for 2sec in the memory - // { - // connector: "memory-unfinalized", - // network: "*", - // method: "*", - // finality: DataFinalityStateUnfinalized, - // empty: CacheEmptyBehaviorIgnore, - // // 2sec in nanoseconds - // ttl: 2_000_000_000, - // maxItemSize: "20kb", - // }, - // // Cache realtime data for 2sec on the memory on arbitrum - // { - // connector: "memory-realtime", - // network: "evm:42161", - // method: "*", - // finality: DataFinalityStateRealtime, - // empty: CacheEmptyBehaviorIgnore, - // // 2sec in nanoseconds - // ttl: 2_000_000_000, - // }, - // // Cache realtime data for 30sec on arbitrum sepolia - // { - // connector: "memory-realtime", - // network: "evm:421614", - // method: "*", - // finality: DataFinalityStateRealtime, - // empty: CacheEmptyBehaviorIgnore, - // // 30sec in nanoseconds - // ttl: 30_000_000_000, - // }, + // Cache not finalized data for 2sec in the memory + { + connector: "memory-unfinalized", + network: "*", + method: "*", + finality: DataFinalityStateUnfinalized, + empty: CacheEmptyBehaviorIgnore, + // 2sec in nanoseconds + ttl: 2_000_000_000, + maxItemSize: "20kb", + }, + // Cache realtime data for 2sec on the memory on arbitrum + { + connector: "memory-realtime", + network: "evm:42161", + method: "*", + finality: DataFinalityStateRealtime, + empty: CacheEmptyBehaviorIgnore, + // 2sec in nanoseconds + ttl: 2_000_000_000, + }, + // Cache realtime data for 30sec on arbitrum sepolia + { + connector: "memory-realtime", + network: "evm:421614", + method: "*", + finality: DataFinalityStateRealtime, + empty: CacheEmptyBehaviorIgnore, + // 30sec in nanoseconds + ttl: 30_000_000_000, + }, ] as const satisfies CachePolicyConfig[]; /**