Skip to content

Commit

Permalink
chore: strict evolve
Browse files Browse the repository at this point in the history
  • Loading branch information
ppedziwiatr committed Feb 2, 2024
1 parent d0000ca commit a21f3dc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/__tests__/unit/evaluation-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('Evaluation options evaluator', () => {
stackTrace: {
saveState: false
},
strictEvolve: true,
strictSortKey: false,
throwOnInternalWriteError: true,
transactionsPagesPerBatch: null,
Expand Down Expand Up @@ -66,6 +67,7 @@ describe('Evaluation options evaluator', () => {
stackTrace: {
saveState: false
},
strictEvolve: true,
strictSortKey: false,
throwOnInternalWriteError: true,
transactionsPagesPerBatch: null,
Expand Down Expand Up @@ -101,6 +103,7 @@ describe('Evaluation options evaluator', () => {
stackTrace: {
saveState: false
},
strictEvolve: true,
strictSortKey: false,
throwOnInternalWriteError: true,
transactionsPagesPerBatch: null,
Expand Down Expand Up @@ -133,6 +136,7 @@ describe('Evaluation options evaluator', () => {
stackTrace: {
saveState: false
},
strictEvolve: true,
strictSortKey: false,
throwOnInternalWriteError: true,
transactionsPagesPerBatch: null,
Expand Down Expand Up @@ -165,6 +169,7 @@ describe('Evaluation options evaluator', () => {
stackTrace: {
saveState: false
},
strictEvolve: true,
strictSortKey: false,
throwOnInternalWriteError: true,
transactionsPagesPerBatch: null,
Expand Down Expand Up @@ -197,6 +202,7 @@ describe('Evaluation options evaluator', () => {
stackTrace: {
saveState: false
},
strictEvolve: true,
strictSortKey: false,
throwOnInternalWriteError: true,
transactionsPagesPerBatch: null,
Expand Down
3 changes: 2 additions & 1 deletion src/contract/EvaluationOptionsEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)[] = [
Expand Down
5 changes: 5 additions & 0 deletions src/core/modules/StateEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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...
Expand Down
16 changes: 12 additions & 4 deletions src/plugins/Evolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
});
}
}
}
}
Expand Down

0 comments on commit a21f3dc

Please sign in to comment.