Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workaround #500

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading