From a21f3dce0e081d7dbe09f6f1de892868067b0859 Mon Sep 17 00:00:00 2001 From: ppedziwiatr Date: Tue, 16 Jan 2024 12:38:37 +0100 Subject: [PATCH] chore: strict evolve --- src/__tests__/unit/evaluation-options.test.ts | 6 ++++++ src/contract/EvaluationOptionsEvaluator.ts | 3 ++- src/core/modules/StateEvaluator.ts | 5 +++++ src/plugins/Evolve.ts | 16 ++++++++++++---- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/__tests__/unit/evaluation-options.test.ts b/src/__tests__/unit/evaluation-options.test.ts index fa9850cc..268a7df1 100644 --- a/src/__tests__/unit/evaluation-options.test.ts +++ b/src/__tests__/unit/evaluation-options.test.ts @@ -26,6 +26,7 @@ describe('Evaluation options evaluator', () => { stackTrace: { saveState: false }, + strictEvolve: true, strictSortKey: false, throwOnInternalWriteError: true, transactionsPagesPerBatch: null, @@ -66,6 +67,7 @@ describe('Evaluation options evaluator', () => { stackTrace: { saveState: false }, + strictEvolve: true, strictSortKey: false, throwOnInternalWriteError: true, transactionsPagesPerBatch: null, @@ -101,6 +103,7 @@ describe('Evaluation options evaluator', () => { stackTrace: { saveState: false }, + strictEvolve: true, strictSortKey: false, throwOnInternalWriteError: true, transactionsPagesPerBatch: null, @@ -133,6 +136,7 @@ describe('Evaluation options evaluator', () => { stackTrace: { saveState: false }, + strictEvolve: true, strictSortKey: false, throwOnInternalWriteError: true, transactionsPagesPerBatch: null, @@ -165,6 +169,7 @@ describe('Evaluation options evaluator', () => { stackTrace: { saveState: false }, + strictEvolve: true, strictSortKey: false, throwOnInternalWriteError: true, transactionsPagesPerBatch: null, @@ -197,6 +202,7 @@ describe('Evaluation options evaluator', () => { stackTrace: { saveState: false }, + strictEvolve: true, strictSortKey: false, throwOnInternalWriteError: true, transactionsPagesPerBatch: null, diff --git a/src/contract/EvaluationOptionsEvaluator.ts b/src/contract/EvaluationOptionsEvaluator.ts index 4118fb11..2cc9bf95 100644 --- a/src/contract/EvaluationOptionsEvaluator.ts +++ b/src/contract/EvaluationOptionsEvaluator.ts @@ -109,7 +109,8 @@ export class EvaluationOptionsEvaluator { useConstructor: (foreignOptions) => foreignOptions['useConstructor'], whitelistSources: () => this.rootOptions['whitelistSources'], transactionsPagesPerBatch: () => this.rootOptions['transactionsPagesPerBatch'], - strictSortKey: () => this.rootOptions['strictSortKey'] + strictSortKey: () => this.rootOptions['strictSortKey'], + strictEvolve: () => this.rootOptions['strictEvolve'] }; private readonly notConflictingEvaluationOptions: (keyof EvaluationOptions)[] = [ diff --git a/src/core/modules/StateEvaluator.ts b/src/core/modules/StateEvaluator.ts index 47502bbe..f04229ce 100644 --- a/src/core/modules/StateEvaluator.ts +++ b/src/core/modules/StateEvaluator.ts @@ -156,6 +156,8 @@ export class DefaultEvaluationOptions implements EvaluationOptions { transactionsPagesPerBatch = null; strictSortKey = false; + + strictEvolve = true; } // an interface for the contract EvaluationOptions - can be used to change the behaviour of some features. @@ -255,6 +257,9 @@ export interface EvaluationOptions { // - if it is, then we're requiring the SDK to have the state cached at this exact sortKey // - so that SDK won't load and evaluated missing interactions strictSortKey: boolean; + + // whether NetworkCommunicationErrors during loading evolved sources are stopping contract evaluation + strictEvolve: boolean; } // https://github.com/nodejs/node/issues/40678 duh... diff --git a/src/plugins/Evolve.ts b/src/plugins/Evolve.ts index ca3572a0..4bc67bce 100644 --- a/src/plugins/Evolve.ts +++ b/src/plugins/Evolve.ts @@ -31,6 +31,7 @@ export class Evolve implements ExecutionContextModifier { const contractTxId = executionContext.contractDefinition.txId; const evolvedSrcTxId = Evolve.evolvedSrcTxId(state); const currentSrcTxId = executionContext.contractDefinition.srcTxId; + const evaluationOptions = executionContext.evaluationOptions; if (evolvedSrcTxId) { if (currentSrcTxId !== evolvedSrcTxId) { @@ -65,10 +66,17 @@ export class Evolve implements ExecutionContextModifier { ) { throw e; } else { - throw new SmartWeaveError(SmartWeaveErrorType.CONTRACT_NOT_FOUND, { - message: `Error while evolving ${contractTxId} from ${currentSrcTxId} to ${evolvedSrcTxId}: ${e}`, - requestedTxId: contractTxId - }); + if (e.name === KnownErrors.NetworkCommunicationError && !evaluationOptions.strictEvolve) { + this.logger.warn( + `Error while evolving ${contractTxId} from ${currentSrcTxId} to ${evolvedSrcTxId}: ${e}` + ); + return executionContext; + } else { + throw new SmartWeaveError(SmartWeaveErrorType.CONTRACT_NOT_FOUND, { + message: `Error while evolving ${contractTxId} from ${currentSrcTxId} to ${evolvedSrcTxId}: ${e}`, + requestedTxId: contractTxId + }); + } } } }