warp-contracts / warp

An implementation of the Arweave SmartWeave smart contracts protocol.
MIT License
158 stars 44 forks source link

[BUG] - unable to set custom contract cache when using custom arweave gateway #483

Closed dtfiedler closed 9 months ago

dtfiedler commented 11 months ago

Describe the bug Unable to set custom ContractCache when using a custom arweave gateway. Appears that the default ContractDefinitionLoader and ArweaveGatewayBundledContractDefinitionLoader do not support nor implement the cache methods as seen here and here

To Reproduce Branch to reproduce in service here

Relevant code:

const arweave = new Arweave({
  protocol: 'https'
  port: 443
  host: 'ar-io.dev'
});

const warp = WarpFactory.forMainnet(
  { ...defaultCacheOptions, inMemory: false },
  true,
  arweave,
)
  .useStateCache(
    new LmdbCache(
      {
        ...defaultCacheOptions,
        dbLocation: `./cache/warp/lmdb/state`,
      },
      {
        minEntriesPerContract: 0,
        maxEntriesPerContract: 100,
      },
    ),
  )
  .useContractCache(
    new LmdbCache(
      {
        ...defaultCacheOptions,
        dbLocation: `./cache/warp/lmdb/contract`,
      },
      {
        minEntriesPerContract: 0,
        maxEntriesPerContract: 100,
      },
    ),
    new LmdbCache(
      {
        ...defaultCacheOptions,
        dbLocation: `./cache/warp/lmdb/source`,
      },
      {
        minEntriesPerContract: 0,
        maxEntriesPerContract: 100,
      },
    ),
  );

Error:

Error: No cache implemented for this loader
    at ContractDefinitionLoader.setSrcCache (/example-warp-evaluator/node_modules/warp-contracts/src/core/modules/impl/ContractDefinitionLoader.ts:156:11)
    at Warp.useContractCache (/example-warp-evaluator/node_modules/warp-contracts/src/core/Warp.ts:150:27)
    at Object.<anonymous> (/example-warp-evaluator/src/middleware/warp.ts:53:4)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module.m._compile (/example-warp-evaluator/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Object.require.extensions.<computed> [as .ts] (/example-warp-evaluator/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Function.Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)

Expected behavior You can provide useContractCache() with lmdb (and other SortKey caches) in the same manner you can when useArweaveGw is set to false in the WarpFactory.

Desktop (please complete the following information):

ppedziwiatr commented 11 months ago

yeah, I admit that caching is not implemented for the Arweave loaders - we will try to fix it soon (probably next week..)

ppedziwiatr commented 9 months ago

released in 1.4.33