Skip to content

Commit

Permalink
Revert "⚗️ Custom methods caching policies"
Browse files Browse the repository at this point in the history
This reverts commit 26bf5ba.
  • Loading branch information
KONFeature committed Dec 19, 2024
1 parent 26bf5ba commit 5c51764
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 208 deletions.
10 changes: 5 additions & 5 deletions packages/erpc/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Config bundler step
FROM oven/bun:latest AS bundler
RUN mkdir -p /tmp/dev
RUN mkdir -p /temp/dev

# Bundle everything in a single erpc.js file
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
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

# Final image
#FROM erpc-dev AS final
Expand All @@ -15,7 +15,7 @@ FROM ghcr.io/erpc/erpc@sha256:c2e09378e5b7922428e8363c577fdf063aaf3d060e79ce44f8
RUN apt-get update && apt-get install -y curl

# Copy the bundled config
COPY --from=bundler ./tmp/dev/erpc.js /root/erpc.js
COPY --from=bundler ./temp/dev/erpc.js /root/erpc.js

# Run the server
CMD ["./erpc-server"]
203 changes: 0 additions & 203 deletions packages/erpc/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,213 +87,10 @@ const cachePolicies = [
// },
] as const satisfies CachePolicyConfig[];

/**
* Custom caching methods
* - Added blockHash on the `eth_getLogs` method
*/
const methods = {
// Static methods that return fixed values:
eth_chainId: {
finalized: true,
},
net_version: {
finalized: true,
},

// Realtime methods that change frequently (i.e. on every block):
eth_hashrate: {
realtime: true,
},
eth_mining: {
realtime: true,
},
eth_syncing: {
realtime: true,
},
net_peerCount: {
realtime: true,
},
eth_gasPrice: {
realtime: true,
},
eth_maxPriorityFeePerGas: {
realtime: true,
},
eth_blobBaseFee: {
realtime: true,
},
eth_blockNumber: {
realtime: true,
},
erigon_blockNumber: {
realtime: true,
},

// Methods with block references in request/response:
// Make sure number is first in the array if hash is also present
eth_getLogs: {
reqRefs: [
[0, "fromBlock"],
[0, "toBlock"],
[0, "blockHash"],
],
},
eth_getBlockByHash: {
reqRefs: [[0]],
respRefs: [["number"], ["hash"]],
},
eth_getBlockByNumber: {
reqRefs: [[0]],
respRefs: [["number"], ["hash"]],
},
eth_getTransactionByBlockHashAndIndex: {
reqRefs: [[0]],
respRefs: [["blockNumber"], ["blockHash"]],
},
eth_getTransactionByBlockNumberAndIndex: {
reqRefs: [[0]],
respRefs: [["blockNumber"], ["blockHash"]],
},
eth_getUncleByBlockHashAndIndex: {
reqRefs: [[0]],
respRefs: [["number"], ["hash"]],
},
eth_getUncleByBlockNumberAndIndex: {
reqRefs: [[0]],
respRefs: [["number"], ["hash"]],
},
eth_getBlockTransactionCountByHash: {
reqRefs: [[0]],
},
eth_getBlockTransactionCountByNumber: {
reqRefs: [[0]],
},
eth_getUncleCountByBlockHash: {
reqRefs: [[0]],
},
eth_getUncleCountByBlockNumber: {
reqRefs: [[0]],
},
eth_getStorageAt: {
reqRefs: [[2]],
},
eth_getBalance: {
reqRefs: [[1]],
},
eth_getTransactionCount: {
reqRefs: [[1]],
},
eth_getCode: {
reqRefs: [[1]],
},
eth_call: {
reqRefs: [[1]],
},
eth_getProof: {
reqRefs: [[2]],
},
arbtrace_call: {
reqRefs: [[2]],
},
eth_feeHistory: {
reqRefs: [[1]],
},
eth_getAccount: {
reqRefs: [[1]],
},
eth_estimateGas: {
reqRefs: [[1]],
},
debug_traceCall: {
reqRefs: [[1]],
},
eth_simulateV1: {
reqRefs: [[1]],
},
erigon_getBlockByTimestamp: {
reqRefs: [[1]],
},
arbtrace_callMany: {
reqRefs: [[1]],
},
eth_getBlockReceipts: {
reqRefs: [[0]],
},
trace_block: {
reqRefs: [[0]],
},
debug_traceBlockByNumber: {
reqRefs: [[0]],
},
trace_replayBlockTransactions: {
reqRefs: [[0]],
},
debug_storageRangeAt: {
reqRefs: [[0]],
},
debug_traceBlockByHash: {
reqRefs: [[0]],
},
debug_getRawBlock: {
reqRefs: [[0]],
},
debug_getRawHeader: {
reqRefs: [[0]],
},
debug_getRawReceipts: {
reqRefs: [[0]],
},
erigon_getHeaderByNumber: {
reqRefs: [[0]],
},
arbtrace_block: {
reqRefs: [[0]],
},
arbtrace_replayBlockTransactions: {
reqRefs: [[0]],
},

// Special methods that can be cached regardless of block:
// Most often finality of these responses is 'unknown'.
// For these data it is safe to keep the data in cache even after reorg,
// because if client explcitly querying such data (e.g. a specific tx hash receipt)
// they know it might be reorged from a separate process.
// For example this is not safe to do for eth_getBlockByNumber because users
// require the method to always give them current accurate data (even if it's reorged).
// Using "*" as request blockRef means that these data are safe be cached irrevelant of their block.
eth_getTransactionReceipt: {
reqRefs: [["*"]],
respRefs: [["blockNumber"], ["blockHash"]],
},
eth_getTransactionByHash: {
reqRefs: [["*"]],
respRefs: [["blockNumber"], ["blockHash"]],
},
arbtrace_replayTransaction: {
reqRefs: [["*"]],
},
trace_replayTransaction: {
reqRefs: [["*"]],
},
debug_traceTransaction: {
reqRefs: [["*"]],
},
trace_rawTransaction: {
reqRefs: [["*"]],
},
trace_transaction: {
reqRefs: [["*"]],
},
debug_traceBlock: {
reqRefs: [["*"]],
},
} as unknown as CacheConfig["methods"];

/**
* Export our final cache config
*/
export const cacheConfig = {
connectors,
policies: cachePolicies,
methods,
} as const satisfies CacheConfig;

0 comments on commit 5c51764

Please sign in to comment.