From 7e8fb8d3a63772355c7d67572dc39b69664264e2 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Tue, 12 Sep 2023 11:02:23 -0500 Subject: [PATCH] feat(lmdb): use warp-contracts-lmdb for contract caching There are other options available, but in-memory can be a bit finicky when lots of requests come in. Eventually we should consider moving to a distributed DB cache (postgres) or sqlite/lmdb in EFS. --- src/middleware/warp.ts | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/middleware/warp.ts b/src/middleware/warp.ts index 1de9704..b5e115c 100644 --- a/src/middleware/warp.ts +++ b/src/middleware/warp.ts @@ -7,34 +7,22 @@ import { defaultCacheOptions, } from 'warp-contracts'; import { arweave } from './arweave'; +import { LmdbCache } from 'warp-contracts-lmdb'; LoggerFactory.INST.logLevel( (process.env.WARP_LOG_LEVEL as LogLevel) ?? 'fatal', ); /** - * TODO: ContractDefinitionsLoader does not have cache implemented when using custom arweave config, so use inMemory for now. Once it is updated, we should revert back to LMDB cache implementation. - * - * Reference: https://github.com/warp-contracts/warp/blob/cde7b07f9495f09e998b13d1fe2661b0af0a3b74/src/core/modules/impl/ContractDefinitionLoader.ts#L150-L165 - * e.g. - const warp = WarpFactory.forMainnet(defaultCacheOptions, true, arweave) - .useStateCache( - new LmdbCache(defaultCacheOptions) - ).useContractCache( - // Contract cache - new LmdbCache(defaultCacheOptions), - // Source cache - new LmdbCache(defaultCacheOptions) - ); -*/ + * TODO: consider using warp-contracts-postgres cache for distribution caching (or EFS with warp-contracts-lmdb or warp-contracts-sqlite) + */ const warp = WarpFactory.forMainnet( { ...defaultCacheOptions, - inMemory: true, }, true, arweave, -); +).useStateCache(new LmdbCache(defaultCacheOptions)); export function warpMiddleware(ctx: KoaContext, next: Next) { ctx.state.warp = warp;