Skip to content

Commit

Permalink
feat: storing state of contracts with no interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
ppedziwiatr committed Aug 15, 2022
1 parent aeb3884 commit 9d337dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/core/modules/impl/CacheableStateEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
EvalStateResult,
ExecutionContext,
ExecutionContextModifier,
HandlerApi
genesisSortKey,
HandlerApi,
LexicographicalInteractionsSorter
} from '@warp/core';
import Arweave from 'arweave';
import { GQLNodeInterface } from '@warp/legacy';
Expand Down Expand Up @@ -76,10 +78,12 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator {
return cachedState;
} else {
executionContext.handler?.initState(executionContext.contractDefinition.initState);
return new SortKeyCacheResult<EvalStateResult<State>>(
null, // no real sort-key - as we're returning the initial state
new EvalStateResult(executionContext.contractDefinition.initState, {}, {})
);
this.cLogger.debug('Inserting initial state into cache');
const stateToCache = new EvalStateResult(executionContext.contractDefinition.initState, {}, {});
// no real sort-key - as we're returning the initial state
await this.cache.put(new CacheKey(contractTxId, genesisSortKey), stateToCache);

return new SortKeyCacheResult<EvalStateResult<State>>(genesisSortKey, stateToCache);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/core/modules/impl/LexicographicalInteractionsSorter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { arrayToHex, GQLEdgeInterface, InteractionsSorter, LoggerFactory, Source
import Arweave from 'arweave';

// note: this (i.e. padding to 13 digits) should be safe between years ~1966 and ~2286
const firstSortKeyMs = ''.padEnd(13, '0');
const lastSortKeyMs = ''.padEnd(13, '9');
const defaultArweaveMs = ''.padEnd(13, '0');

export const sortingFirst = ''.padEnd(64, '0');
export const sortingLast = ''.padEnd(64, 'z');

export const genesisSortKey = `${''.padStart(12, '0')},${firstSortKeyMs},${sortingFirst}`;

/**
* implementation that is based on current's SDK sorting alg.
*/
Expand Down

0 comments on commit 9d337dc

Please sign in to comment.