diff --git a/src/core/modules/impl/CacheableStateEvaluator.ts b/src/core/modules/impl/CacheableStateEvaluator.ts index c2e4efc1..625ce9a1 100644 --- a/src/core/modules/impl/CacheableStateEvaluator.ts +++ b/src/core/modules/impl/CacheableStateEvaluator.ts @@ -4,7 +4,9 @@ import { EvalStateResult, ExecutionContext, ExecutionContextModifier, - HandlerApi + genesisSortKey, + HandlerApi, + LexicographicalInteractionsSorter } from '@warp/core'; import Arweave from 'arweave'; import { GQLNodeInterface } from '@warp/legacy'; @@ -76,10 +78,12 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator { return cachedState; } else { executionContext.handler?.initState(executionContext.contractDefinition.initState); - return new SortKeyCacheResult>( - 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>(genesisSortKey, stateToCache); } } diff --git a/src/core/modules/impl/LexicographicalInteractionsSorter.ts b/src/core/modules/impl/LexicographicalInteractionsSorter.ts index 5ce539de..eb4f9a67 100644 --- a/src/core/modules/impl/LexicographicalInteractionsSorter.ts +++ b/src/core/modules/impl/LexicographicalInteractionsSorter.ts @@ -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. */