swcache to warpcache renaming hell

This commit is contained in:
asiaziola
2022-05-19 17:52:16 +02:00
parent 11d18a753a
commit f2555a8ed1
22 changed files with 53 additions and 53 deletions

View File

@@ -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<V> {
export interface BlockHeightWarpCache<V> {
/**
* returns cached value for the highest available in cache block that is not higher than `blockHeight`.
*/

View File

@@ -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<K = string, V = any> {
export interface WarpCache<K = string, V = any> {
/**
* gets value by its key
*/

View File

@@ -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<V = any> extends MemBlockHeightSwCache<V> {
private readonly fLogger = LoggerFactory.INST.create('FileBlockHeightSwCache');
export class FileBlockHeightWarpCache<V = any> extends MemBlockHeightWarpCache<V> {
private readonly fLogger = LoggerFactory.INST.create('FileBlockHeightWarpCache');
private isFlushing = false;

View File

@@ -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<StateCache<any>> {
private readonly kLogger = LoggerFactory.INST.create('KnexBlockHeightSwCache');
export class KnexStateCache extends MemBlockHeightWarpCache<StateCache<any>> {
private readonly kLogger = LoggerFactory.INST.create('KnexBlockHeightWarpCache');
private readonly lastFlushHeight: Map<string, number> = new Map();
private isFlushing = false;

View File

@@ -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<V = any> implements BlockHeightSwCache<V> {
private readonly logger = LoggerFactory.INST.create('MemBlockHeightSwCache');
export class MemBlockHeightWarpCache<V = any> implements BlockHeightWarpCache<V> {
private readonly logger = LoggerFactory.INST.create('MemBlockHeightWarpCache');
protected storage: { [key: string]: Map<number, V> } = {};

View File

@@ -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<V = any> implements SwCache<string, V> {
export class MemCache<V = any> implements WarpCache<string, V> {
private readonly storage: { [key: string]: V } = {};
clearAll() {

View File

@@ -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<V = any> implements BlockHeightSwCache<V> {
export class RemoteBlockHeightCache<V = any> implements BlockHeightWarpCache<V> {
private axios: AxiosInstance;
/**

4
src/cache/index.ts vendored
View File

@@ -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';

View File

@@ -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;

View File

@@ -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<StateCache<unknown>>,
private readonly cache: BlockHeightWarpCache<StateCache<unknown>>,
executionContextModifiers: ExecutionContextModifier[] = []
) {
super(arweave, executionContextModifiers);

View File

@@ -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<string, ContractDefinition<unknown>>
protected readonly cache?: WarpCache<string, ContractDefinition<unknown>>
) {
this.arweaveWrapper = new ArweaveWrapper(arweave);
}

View File

@@ -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<HandlerApi<unknow
private readonly logger = LoggerFactory.INST.create('HandlerExecutorFactory');
// TODO: cache compiled wasm binaries here.
private readonly cache: SwCache<string, WebAssembly.Module> = new MemCache();
private readonly cache: WarpCache<string, WebAssembly.Module> = new MemCache();
constructor(private readonly arweave: Arweave) {}

View File

@@ -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<string, ContractDefinition<unknown>>
cache?: WarpCache<string, ContractDefinition<unknown>>
) {
super(arweave, cache);
this.baseUrl = stripTrailingSlash(baseUrl);

View File

@@ -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)]
);

View File

@@ -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<StateCache<unknown>>(maxStoredBlockHeights),
new MemBlockHeightWarpCache<StateCache<unknown>>(maxStoredBlockHeights),
[new Evolve(definitionLoader, executorFactory)]
);

View File

@@ -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<GQLEdgeInterface[]>
private readonly cache: BlockHeightWarpCache<GQLEdgeInterface[]>
) {}
async load(

View File

@@ -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<Api> implements ExecutorFactory<Api> {
constructor(
private readonly arweave: Arweave,
private readonly baseImplementation: ExecutorFactory<Api>,
private readonly cache: SwCache<string, Api>
private readonly cache: WarpCache<string, Api>
) {}
async create<State>(

View File

@@ -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<Cache>();
const arrayCache = new MemBlockHeightSwCache<Array<Cache>>();
const objectCache = new MemBlockHeightWarpCache<Cache>();
const arrayCache = new MemBlockHeightWarpCache<Array<Cache>>();
console.time('benchmark_object');
for (let i = 0; i < 10_000_000; i++) {

View File

@@ -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);

View File

@@ -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);

View File

@@ -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" });

View File

@@ -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);