Skip to content

Commit

Permalink
v1.4.36-beta.13
Browse files Browse the repository at this point in the history
  • Loading branch information
asiaziola committed Aug 13, 2024
1 parent df94d5c commit e992433
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "warp-contracts",
"version": "1.4.36-beta.10",
"version": "1.4.36-beta.13",
"description": "An implementation of the SmartWeave smart contract protocol.",
"types": "./lib/types/index.d.ts",
"main": "./lib/cjs/index.js",
Expand Down
11 changes: 9 additions & 2 deletions src/cache/impl/LevelDbCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SortKeyCacheRangeOptions } from '../SortKeyCacheRangeOptions';
import { AbstractSublevel, AbstractSublevelOptions } from 'abstract-level/types/abstract-sublevel';
import { AbstractChainedBatch } from 'abstract-level/types/abstract-chained-batch';
import { AbstractKeyIteratorOptions } from 'abstract-level/types/abstract-iterator';
import { Benchmark } from '../../logging/Benchmark';

/**
* The LevelDB is a lexicographically sorted key-value database - so it's ideal for this use case
Expand Down Expand Up @@ -141,7 +142,10 @@ export class LevelDbCache<V> implements SortKeyCache<V> {
}

async put(stateCacheKey: CacheKey, value: V): Promise<void> {
await this.setClientValue(stateCacheKey, new ClientValueWrapper(value));
const putBenchmark = Benchmark.measure();
this.setClientValue(stateCacheKey, new ClientValueWrapper(value)).then();
putBenchmark.stop();
this.logger.info('putBenchmark', putBenchmark.elapsed());
}

/**
Expand All @@ -158,14 +162,17 @@ export class LevelDbCache<V> implements SortKeyCache<V> {
}

private async setClientValue(stateCacheKey: CacheKey, valueWrapper: ClientValueWrapper<V>): Promise<void> {
const setClientValueBenchmark = Benchmark.measure();
this.validateKey(stateCacheKey.key);
const contractCache = this.db.sublevel<string, ClientValueWrapper<V>>(stateCacheKey.key, this.subLevelOptions);
// manually opening to fix https://github.com/Level/level/issues/221
await contractCache.open();
await contractCache.put(stateCacheKey.sortKey, valueWrapper);
contractCache.put(stateCacheKey.sortKey, valueWrapper).then();
if (this._rollbackBatch) {
this._rollbackBatch.del(stateCacheKey.sortKey, { sublevel: contractCache });
}
setClientValueBenchmark.stop();
this.logger.info('setClientValue', setClientValueBenchmark.elapsed());
}

async delete(key: string): Promise<void> {
Expand Down
6 changes: 6 additions & 0 deletions src/contract/states/ContractInteractionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,15 @@ export class ContractInteractionState implements InteractionState {
forceStore = false
) {
if (states.size > 1 || forceStore) {
const doStoreJsonLoopBenchmark = Benchmark.measure();
for (const [k, v] of states) {
const doStoreJsonSingularBenchmark = Benchmark.measure();
this._warp.stateEvaluator.putInCache(k, interaction, v).then();
doStoreJsonSingularBenchmark.stop();
this.logger.info(`doStoreJsonSingularBenchmark, ${k}`, doStoreJsonSingularBenchmark.elapsed());
}
doStoreJsonLoopBenchmark.stop();
this.logger.info('doStoreJsonLoopBenchmark', doStoreJsonLoopBenchmark.elapsed());
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/core/modules/impl/CacheableStateEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator {
transaction: GQLNodeInterface,
state: EvalStateResult<State>
): Promise<void> {
const putInCacheBenchmark = Benchmark.measure();
if (transaction.dry) {
return;
}
Expand All @@ -194,8 +195,13 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator {
sortKey: transaction.sortKey,
dry: transaction.dry
});
putInCacheBenchmark.stop();
this.cLogger.info('putInCacheBenchmark', putInCacheBenchmark.elapsed());

await this.cache.put(new CacheKey(contractTxId, transaction.sortKey), stateToCache);
const putInCacheFunc = Benchmark.measure();
this.cache.put(new CacheKey(contractTxId, transaction.sortKey), stateToCache).then();
putInCacheFunc.stop();
this.cLogger.info('putInCacheFunc', putInCacheFunc.elapsed());
}

async syncState<State>(
Expand Down

0 comments on commit e992433

Please sign in to comment.