diff --git a/src/cache/BlockHeightSwCache.ts b/src/cache/BlockHeightWarpCache.ts similarity index 91% rename from src/cache/BlockHeightSwCache.ts rename to src/cache/BlockHeightWarpCache.ts index d9d4a0b..9c82ce0 100644 --- a/src/cache/BlockHeightSwCache.ts +++ b/src/cache/BlockHeightWarpCache.ts @@ -1,10 +1,10 @@ /** * A cache that stores its values depending on block height (eg.: contract's state cache). - * See {@link BsonFileBlockHeightSwCache} or {@link MemBlockHeightSwCache} + * See {@link BsonFileBlockHeightWarpCache} or {@link MemBlockHeightWarpCache} * * @typeParam V - type of value stored in cache, defaults to `any`. */ -export interface BlockHeightSwCache { +export interface BlockHeightWarpCache { /** * returns cached value for the highest available in cache block that is not higher than `blockHeight`. */ diff --git a/src/cache/SwCache.ts b/src/cache/WarpCache.ts similarity index 86% rename from src/cache/SwCache.ts rename to src/cache/WarpCache.ts index 53c7b95..f4b695a 100644 --- a/src/cache/SwCache.ts +++ b/src/cache/WarpCache.ts @@ -1,5 +1,5 @@ /** - * Base interface for SmartWeave Cache implementors. + * Base interface for Warp Cache implementors. * Useful for simple, non block-height dependant caches * - like contract's source code cache. * See {@link MemCache} for example implementation. @@ -7,7 +7,7 @@ * @typeParam K - type of the cache key, defaults to `string` * @typeParam V - type of the cache value, default to `any`. */ -export interface SwCache { +export interface WarpCache { /** * gets value by its key */ diff --git a/src/cache/impl/FileBlockHeightCache.ts b/src/cache/impl/FileBlockHeightCache.ts index 12c19f3..ed248fb 100644 --- a/src/cache/impl/FileBlockHeightCache.ts +++ b/src/cache/impl/FileBlockHeightCache.ts @@ -1,15 +1,15 @@ import fs from 'fs'; import path from 'path'; -import { BlockHeightKey, MemBlockHeightSwCache } from '@warp/cache'; +import { BlockHeightKey, MemBlockHeightWarpCache } from '@warp/cache'; import { Benchmark, LoggerFactory } from '@warp/logging'; import stringify from 'safe-stable-stringify'; /** - * An implementation of {@link BlockHeightSwCache} that stores its data in JSON files. + * An implementation of {@link BlockHeightWarpCache} that stores its data in JSON files. * * Main use-case is the per block height state cache for contracts. * - * This class extends standard {@link MemBlockHeightSwCache} and add features of + * This class extends standard {@link MemBlockHeightWarpCache} and add features of * 1. Loading cache from files to memory (during initialization) * 2. Flushing cache to files (only the "last" (ie. highest) block stored currently in memory * is being saved). @@ -37,8 +37,8 @@ import stringify from 'safe-stable-stringify'; * @Deprecated - a more mature persistent cache, based on LevelDB (or similar storage) * should be implemented. */ -export class FileBlockHeightSwCache extends MemBlockHeightSwCache { - private readonly fLogger = LoggerFactory.INST.create('FileBlockHeightSwCache'); +export class FileBlockHeightWarpCache extends MemBlockHeightWarpCache { + private readonly fLogger = LoggerFactory.INST.create('FileBlockHeightWarpCache'); private isFlushing = false; diff --git a/src/cache/impl/KnexStateCache.ts b/src/cache/impl/KnexStateCache.ts index f02e599..b45f5e8 100644 --- a/src/cache/impl/KnexStateCache.ts +++ b/src/cache/impl/KnexStateCache.ts @@ -1,4 +1,4 @@ -import { BlockHeightKey, MemBlockHeightSwCache } from '@warp/cache'; +import { BlockHeightKey, MemBlockHeightWarpCache } from '@warp/cache'; import { LoggerFactory } from '@warp/logging'; import { Knex } from 'knex'; import { StateCache } from '@warp'; @@ -11,12 +11,12 @@ type DbResult = { }; /** - * An implementation of {@link BlockHeightSwCache} that stores its data (ie. contracts state) + * An implementation of {@link BlockHeightWarpCache} that stores its data (ie. contracts state) * in a Knex-compatible storage (PostgreSQL, CockroachDB, MSSQL, MySQL, MariaDB, SQLite3, Oracle, and Amazon Redshift) * https://knexjs.org */ -export class KnexStateCache extends MemBlockHeightSwCache> { - private readonly kLogger = LoggerFactory.INST.create('KnexBlockHeightSwCache'); +export class KnexStateCache extends MemBlockHeightWarpCache> { + private readonly kLogger = LoggerFactory.INST.create('KnexBlockHeightWarpCache'); private readonly lastFlushHeight: Map = new Map(); private isFlushing = false; diff --git a/src/cache/impl/MemBlockHeightCache.ts b/src/cache/impl/MemBlockHeightCache.ts index 68603c5..28f7aec 100644 --- a/src/cache/impl/MemBlockHeightCache.ts +++ b/src/cache/impl/MemBlockHeightCache.ts @@ -1,12 +1,12 @@ -import { BlockHeightCacheResult, BlockHeightKey, BlockHeightSwCache } from '@warp/cache'; +import { BlockHeightCacheResult, BlockHeightKey, BlockHeightWarpCache } from '@warp/cache'; import { asc, deepCopy, desc } from '@warp/utils'; import { LoggerFactory } from '@warp/logging'; /** - * A simple, in-memory cache implementation of the BlockHeightSwCache + * A simple, in-memory cache implementation of the BlockHeightWarpCache */ -export class MemBlockHeightSwCache implements BlockHeightSwCache { - private readonly logger = LoggerFactory.INST.create('MemBlockHeightSwCache'); +export class MemBlockHeightWarpCache implements BlockHeightWarpCache { + private readonly logger = LoggerFactory.INST.create('MemBlockHeightWarpCache'); protected storage: { [key: string]: Map } = {}; diff --git a/src/cache/impl/MemCache.ts b/src/cache/impl/MemCache.ts index 2e2c451..74f96bd 100644 --- a/src/cache/impl/MemCache.ts +++ b/src/cache/impl/MemCache.ts @@ -1,9 +1,9 @@ -import { SwCache } from '@warp/cache'; +import { WarpCache } from '@warp/cache'; /** * A simple, in-memory cache, with keys being transaction ids (e.g. contract transaction id). */ -export class MemCache implements SwCache { +export class MemCache implements WarpCache { private readonly storage: { [key: string]: V } = {}; clearAll() { diff --git a/src/cache/impl/RemoteBlockHeightCache.ts b/src/cache/impl/RemoteBlockHeightCache.ts index 0f5358d..172b79d 100644 --- a/src/cache/impl/RemoteBlockHeightCache.ts +++ b/src/cache/impl/RemoteBlockHeightCache.ts @@ -1,14 +1,14 @@ -import { BlockHeightCacheResult, BlockHeightKey, BlockHeightSwCache } from '@warp/cache'; +import { BlockHeightCacheResult, BlockHeightKey, BlockHeightWarpCache } from '@warp/cache'; import axios, { AxiosInstance } from 'axios'; /** - * A {@link BlockHeightSwCache} implementation that delegates all its methods + * A {@link BlockHeightWarpCache} implementation that delegates all its methods * to remote endpoints. * * TODO: this could be further optimised - i.e. with the help of "level 1" memory cache * that would store max X elements - and would be backed up by the "level 2" remote cache. */ -export class RemoteBlockHeightCache implements BlockHeightSwCache { +export class RemoteBlockHeightCache implements BlockHeightWarpCache { private axios: AxiosInstance; /** diff --git a/src/cache/index.ts b/src/cache/index.ts index f0ce8e9..5a6eb42 100644 --- a/src/cache/index.ts +++ b/src/cache/index.ts @@ -8,5 +8,5 @@ export * from './impl/KnexStateCache'; export * from './impl/RemoteBlockHeightCache'; export * from './impl/MemCache'; -export * from './BlockHeightSwCache'; -export * from './SwCache'; +export * from './BlockHeightWarpCache'; +export * from './WarpCache'; diff --git a/src/core/WarpBuilder.ts b/src/core/WarpBuilder.ts index 304ab84..c4c529c 100644 --- a/src/core/WarpBuilder.ts +++ b/src/core/WarpBuilder.ts @@ -10,7 +10,7 @@ import { HandlerApi, InteractionsLoader, InteractionsSorter, - MemBlockHeightSwCache, + MemBlockHeightWarpCache, MemCache, WarpGatewayContractDefinitionLoader, WarpGatewayInteractionsLoader, @@ -47,7 +47,7 @@ export class WarpBuilder { ): WarpBuilder { this._interactionsLoader = new CacheableContractInteractionsLoader( value, - new MemBlockHeightSwCache(maxStoredInMemoryBlockHeights) + new MemBlockHeightWarpCache(maxStoredInMemoryBlockHeights) ); return this; } @@ -90,7 +90,7 @@ export class WarpBuilder { this._definitionLoader = new ContractDefinitionLoader(this._arweave, new MemCache()); this._interactionsLoader = new CacheableContractInteractionsLoader( new ArweaveGatewayInteractionsLoader(this._arweave), - new MemBlockHeightSwCache(1) + new MemBlockHeightWarpCache(1) ); this._useWarpGwInfo = false; return this; diff --git a/src/core/modules/impl/CacheableStateEvaluator.ts b/src/core/modules/impl/CacheableStateEvaluator.ts index 7e0ebb9..4abfe5f 100644 --- a/src/core/modules/impl/CacheableStateEvaluator.ts +++ b/src/core/modules/impl/CacheableStateEvaluator.ts @@ -1,4 +1,4 @@ -import { BlockHeightCacheResult, BlockHeightKey, BlockHeightSwCache } from '@warp/cache'; +import { BlockHeightCacheResult, BlockHeightKey, BlockHeightWarpCache } from '@warp/cache'; import { DefaultStateEvaluator, EvalStateResult, @@ -25,7 +25,7 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator { constructor( arweave: Arweave, - private readonly cache: BlockHeightSwCache>, + private readonly cache: BlockHeightWarpCache>, executionContextModifiers: ExecutionContextModifier[] = [] ) { super(arweave, executionContextModifiers); diff --git a/src/core/modules/impl/ContractDefinitionLoader.ts b/src/core/modules/impl/ContractDefinitionLoader.ts index 2ad4cdf..3f0f741 100644 --- a/src/core/modules/impl/ContractDefinitionLoader.ts +++ b/src/core/modules/impl/ContractDefinitionLoader.ts @@ -8,7 +8,7 @@ import { getTag, LoggerFactory, WarpTags, - SwCache + WarpCache } from '@warp'; import Arweave from 'arweave'; import Transaction from 'arweave/web/lib/transaction'; @@ -24,7 +24,7 @@ export class ContractDefinitionLoader implements DefinitionLoader { constructor( private readonly arweave: Arweave, // TODO: cache should be removed from the core layer and implemented in a wrapper of the core implementation - protected readonly cache?: SwCache> + protected readonly cache?: WarpCache> ) { this.arweaveWrapper = new ArweaveWrapper(arweave); } diff --git a/src/core/modules/impl/HandlerExecutorFactory.ts b/src/core/modules/impl/HandlerExecutorFactory.ts index 31ffe94..8fc28ed 100644 --- a/src/core/modules/impl/HandlerExecutorFactory.ts +++ b/src/core/modules/impl/HandlerExecutorFactory.ts @@ -11,7 +11,7 @@ import { MemCache, normalizeContractSource, SmartWeaveGlobal, - SwCache + WarpCache } from '@warp'; import { ContractHandlerApi } from './ContractHandlerApi'; import loader from '@assemblyscript/loader'; @@ -38,7 +38,7 @@ export class HandlerExecutorFactory implements ExecutorFactory = new MemCache(); + private readonly cache: WarpCache = new MemCache(); constructor(private readonly arweave: Arweave) {} diff --git a/src/core/modules/impl/WarpGatewayContractDefinitionLoader.ts b/src/core/modules/impl/WarpGatewayContractDefinitionLoader.ts index 47bff1e..961110b 100644 --- a/src/core/modules/impl/WarpGatewayContractDefinitionLoader.ts +++ b/src/core/modules/impl/WarpGatewayContractDefinitionLoader.ts @@ -1,4 +1,4 @@ -import { ContractDefinition, getTag, LoggerFactory, WarpTags, stripTrailingSlash, SwCache } from '@warp'; +import { ContractDefinition, getTag, LoggerFactory, WarpTags, stripTrailingSlash, WarpCache } from '@warp'; import Arweave from 'arweave'; import { ContractDefinitionLoader } from './ContractDefinitionLoader'; import 'redstone-isomorphic'; @@ -19,7 +19,7 @@ export class WarpGatewayContractDefinitionLoader extends ContractDefinitionLoade constructor( private readonly baseUrl: string, arweave: Arweave, - cache?: SwCache> + cache?: WarpCache> ) { super(arweave, cache); this.baseUrl = stripTrailingSlash(baseUrl); diff --git a/src/core/node/WarpNodeFactory.ts b/src/core/node/WarpNodeFactory.ts index 6e85017..1f40b1f 100644 --- a/src/core/node/WarpNodeFactory.ts +++ b/src/core/node/WarpNodeFactory.ts @@ -14,7 +14,7 @@ import { WarpWebFactory } from '@warp/core'; import { CacheableExecutorFactory, Evolve } from '@warp/plugins'; -import { FileBlockHeightSwCache, MemCache } from '@warp/cache'; +import { FileBlockHeightWarpCache, MemCache } from '@warp/cache'; import { Knex } from 'knex'; import { KnexStateCache } from '../../cache/impl/KnexStateCache'; @@ -61,7 +61,7 @@ export class WarpNodeFactory extends WarpWebFactory { const stateEvaluator = new CacheableStateEvaluator( arweave, - new FileBlockHeightSwCache(cacheBasePath, maxStoredInMemoryBlockHeights), + new FileBlockHeightWarpCache(cacheBasePath, maxStoredInMemoryBlockHeights), [new Evolve(definitionLoader, executorFactory)] ); diff --git a/src/core/web/WarpWebFactory.ts b/src/core/web/WarpWebFactory.ts index 33dc5ee..cf27091 100644 --- a/src/core/web/WarpWebFactory.ts +++ b/src/core/web/WarpWebFactory.ts @@ -14,7 +14,7 @@ import { WarpBuilder, StateCache } from '@warp/core'; -import { MemBlockHeightSwCache, MemCache, RemoteBlockHeightCache } from '@warp/cache'; +import { MemBlockHeightWarpCache, MemCache, RemoteBlockHeightCache } from '@warp/cache'; /** * A factory that simplifies the process of creating different versions of {@link Warp}. @@ -45,7 +45,7 @@ export class WarpWebFactory { const stateEvaluator = new CacheableStateEvaluator( arweave, - new MemBlockHeightSwCache>(maxStoredBlockHeights), + new MemBlockHeightWarpCache>(maxStoredBlockHeights), [new Evolve(definitionLoader, executorFactory)] ); diff --git a/src/plugins/CacheableContractInteractionsLoader.ts b/src/plugins/CacheableContractInteractionsLoader.ts index c40b8e3..9bddf59 100644 --- a/src/plugins/CacheableContractInteractionsLoader.ts +++ b/src/plugins/CacheableContractInteractionsLoader.ts @@ -1,7 +1,7 @@ import { Benchmark, BlockHeightKey, - BlockHeightSwCache, + BlockHeightWarpCache, EvaluationOptions, GQLEdgeInterface, InteractionsLoader, @@ -18,7 +18,7 @@ export class CacheableContractInteractionsLoader implements InteractionsLoader { constructor( private readonly baseImplementation: InteractionsLoader, - private readonly cache: BlockHeightSwCache + private readonly cache: BlockHeightWarpCache ) {} async load( diff --git a/src/plugins/CacheableExecutorFactory.ts b/src/plugins/CacheableExecutorFactory.ts index 3ba5286..b61bdbc 100644 --- a/src/plugins/CacheableExecutorFactory.ts +++ b/src/plugins/CacheableExecutorFactory.ts @@ -1,6 +1,6 @@ import Arweave from 'arweave'; import { ContractDefinition, EvaluationOptions, ExecutorFactory } from '@warp/core'; -import { SwCache } from '@warp/cache'; +import { WarpCache } from '@warp/cache'; import { LoggerFactory } from '@warp/logging'; /** @@ -12,7 +12,7 @@ export class CacheableExecutorFactory implements ExecutorFactory { constructor( private readonly arweave: Arweave, private readonly baseImplementation: ExecutorFactory, - private readonly cache: SwCache + private readonly cache: WarpCache ) {} async create( diff --git a/tools/cache-benchmark.ts b/tools/cache-benchmark.ts index 4c01f62..aba4cec 100644 --- a/tools/cache-benchmark.ts +++ b/tools/cache-benchmark.ts @@ -2,7 +2,7 @@ import Arweave from 'arweave'; import { LoggerFactory } from '../src'; import { TsLogFactory } from '../src/logging/node/TsLogFactory'; -import { MemBlockHeightSwCache } from '../src/cache/impl/MemBlockHeightCache'; +import { MemBlockHeightWarpCache } from '../src/cache/impl/MemBlockHeightCache'; type Cache = { ticker: string; @@ -14,8 +14,8 @@ async function main() { LoggerFactory.INST.logLevel('debug'); - const objectCache = new MemBlockHeightSwCache(); - const arrayCache = new MemBlockHeightSwCache>(); + const objectCache = new MemBlockHeightWarpCache(); + const arrayCache = new MemBlockHeightWarpCache>(); console.time('benchmark_object'); for (let i = 0; i < 10_000_000; i++) { diff --git a/tools/inner-write-2.ts b/tools/inner-write-2.ts index 5b52a56..4b6d11c 100644 --- a/tools/inner-write-2.ts +++ b/tools/inner-write-2.ts @@ -31,7 +31,7 @@ async function main() { LoggerFactory.INST.logLevel('debug', 'DefaultStateEvaluator'); LoggerFactory.INST.logLevel('debug', 'CacheableStateEvaluator'); LoggerFactory.INST.logLevel('debug', 'ContractHandler'); - LoggerFactory.INST.logLevel('debug', 'MemBlockHeightSwCache'); + LoggerFactory.INST.logLevel('debug', 'MemBlockHeightWarpCache'); */ const logger = LoggerFactory.INST.create('inner-write'); const arlocal = new ArLocal(1982, false); diff --git a/tools/inner-write.ts b/tools/inner-write.ts index e02b2c3..6ff7336 100644 --- a/tools/inner-write.ts +++ b/tools/inner-write.ts @@ -26,7 +26,7 @@ async function main() { /*LoggerFactory.INST.logLevel('debug', 'DefaultStateEvaluator'); LoggerFactory.INST.logLevel('debug', 'CacheableStateEvaluator'); LoggerFactory.INST.logLevel('debug', 'ContractHandler'); - LoggerFactory.INST.logLevel('debug', 'MemBlockHeightSwCache');*/ + LoggerFactory.INST.logLevel('debug', 'MemBlockHeightWarpCache');*/ const logger = LoggerFactory.INST.create('inner-write'); const arlocal = new ArLocal(1985, false); diff --git a/tools/server.js b/tools/server.js index f795778..a7982b8 100644 --- a/tools/server.js +++ b/tools/server.js @@ -1,7 +1,7 @@ /* eslint-disable */ const express = require('express'); const cors = require('cors'); -const { MemBlockHeightSwCache } = require('../lib/cjs/cache/impl/MemBlockHeightCache'); +const { MemBlockHeightWarpCache } = require('../lib/cjs/cache/impl/MemBlockHeightCache'); const app = express(); const port = 3000; @@ -10,8 +10,8 @@ app.use(express.json({ limit: "50mb", extended: true })); const caches = { - STATE: new MemBlockHeightSwCache(1), - INTERACTIONS: new MemBlockHeightSwCache(1) + STATE: new MemBlockHeightWarpCache(1), + INTERACTIONS: new MemBlockHeightWarpCache(1) }; // getLast @@ -90,7 +90,7 @@ app.put('/:type/:key/:blockHeight', async function (req, res, next) { app.listen(port, async () => { console.log(`Cache listening at http://localhost:${port}`); - // note: with current cache configuration (new MemBlockHeightSwCache(1)) + // note: with current cache configuration (new MemBlockHeightWarpCache(1)) // there should be at most one block height cached for given cache key. await caches['STATE'].put({ cacheKey: 'txId', blockHeight: 555 }, { foo: "bar555" }); await caches['STATE'].put({ cacheKey: 'txId', blockHeight: 556 }, { foo: "bar556" }); diff --git a/tools/stake.ts b/tools/stake.ts index ba94589..cf3618e 100644 --- a/tools/stake.ts +++ b/tools/stake.ts @@ -30,7 +30,7 @@ async function main() { LoggerFactory.INST.logLevel('debug', 'DefaultStateEvaluator'); LoggerFactory.INST.logLevel('debug', 'CacheableStateEvaluator'); LoggerFactory.INST.logLevel('debug', 'ContractHandler'); - LoggerFactory.INST.logLevel('debug', 'MemBlockHeightSwCache'); + LoggerFactory.INST.logLevel('debug', 'MemBlockHeightWarpCache'); */ const logger = LoggerFactory.INST.create('stake'); const arlocal = new ArLocal(1982, false);