Skip to content

Commit a21f3dc

Browse files
committed
chore: strict evolve
1 parent d0000ca commit a21f3dc

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

src/__tests__/unit/evaluation-options.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('Evaluation options evaluator', () => {
2626
stackTrace: {
2727
saveState: false
2828
},
29+
strictEvolve: true,
2930
strictSortKey: false,
3031
throwOnInternalWriteError: true,
3132
transactionsPagesPerBatch: null,
@@ -66,6 +67,7 @@ describe('Evaluation options evaluator', () => {
6667
stackTrace: {
6768
saveState: false
6869
},
70+
strictEvolve: true,
6971
strictSortKey: false,
7072
throwOnInternalWriteError: true,
7173
transactionsPagesPerBatch: null,
@@ -101,6 +103,7 @@ describe('Evaluation options evaluator', () => {
101103
stackTrace: {
102104
saveState: false
103105
},
106+
strictEvolve: true,
104107
strictSortKey: false,
105108
throwOnInternalWriteError: true,
106109
transactionsPagesPerBatch: null,
@@ -133,6 +136,7 @@ describe('Evaluation options evaluator', () => {
133136
stackTrace: {
134137
saveState: false
135138
},
139+
strictEvolve: true,
136140
strictSortKey: false,
137141
throwOnInternalWriteError: true,
138142
transactionsPagesPerBatch: null,
@@ -165,6 +169,7 @@ describe('Evaluation options evaluator', () => {
165169
stackTrace: {
166170
saveState: false
167171
},
172+
strictEvolve: true,
168173
strictSortKey: false,
169174
throwOnInternalWriteError: true,
170175
transactionsPagesPerBatch: null,
@@ -197,6 +202,7 @@ describe('Evaluation options evaluator', () => {
197202
stackTrace: {
198203
saveState: false
199204
},
205+
strictEvolve: true,
200206
strictSortKey: false,
201207
throwOnInternalWriteError: true,
202208
transactionsPagesPerBatch: null,

src/contract/EvaluationOptionsEvaluator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ export class EvaluationOptionsEvaluator {
109109
useConstructor: (foreignOptions) => foreignOptions['useConstructor'],
110110
whitelistSources: () => this.rootOptions['whitelistSources'],
111111
transactionsPagesPerBatch: () => this.rootOptions['transactionsPagesPerBatch'],
112-
strictSortKey: () => this.rootOptions['strictSortKey']
112+
strictSortKey: () => this.rootOptions['strictSortKey'],
113+
strictEvolve: () => this.rootOptions['strictEvolve']
113114
};
114115

115116
private readonly notConflictingEvaluationOptions: (keyof EvaluationOptions)[] = [

src/core/modules/StateEvaluator.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ export class DefaultEvaluationOptions implements EvaluationOptions {
156156
transactionsPagesPerBatch = null;
157157

158158
strictSortKey = false;
159+
160+
strictEvolve = true;
159161
}
160162

161163
// an interface for the contract EvaluationOptions - can be used to change the behaviour of some features.
@@ -255,6 +257,9 @@ export interface EvaluationOptions {
255257
// - if it is, then we're requiring the SDK to have the state cached at this exact sortKey
256258
// - so that SDK won't load and evaluated missing interactions
257259
strictSortKey: boolean;
260+
261+
// whether NetworkCommunicationErrors during loading evolved sources are stopping contract evaluation
262+
strictEvolve: boolean;
258263
}
259264

260265
// https://github.com/nodejs/node/issues/40678 duh...

src/plugins/Evolve.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class Evolve implements ExecutionContextModifier {
3131
const contractTxId = executionContext.contractDefinition.txId;
3232
const evolvedSrcTxId = Evolve.evolvedSrcTxId(state);
3333
const currentSrcTxId = executionContext.contractDefinition.srcTxId;
34+
const evaluationOptions = executionContext.evaluationOptions;
3435

3536
if (evolvedSrcTxId) {
3637
if (currentSrcTxId !== evolvedSrcTxId) {
@@ -65,10 +66,17 @@ export class Evolve implements ExecutionContextModifier {
6566
) {
6667
throw e;
6768
} else {
68-
throw new SmartWeaveError(SmartWeaveErrorType.CONTRACT_NOT_FOUND, {
69-
message: `Error while evolving ${contractTxId} from ${currentSrcTxId} to ${evolvedSrcTxId}: ${e}`,
70-
requestedTxId: contractTxId
71-
});
69+
if (e.name === KnownErrors.NetworkCommunicationError && !evaluationOptions.strictEvolve) {
70+
this.logger.warn(
71+
`Error while evolving ${contractTxId} from ${currentSrcTxId} to ${evolvedSrcTxId}: ${e}`
72+
);
73+
return executionContext;
74+
} else {
75+
throw new SmartWeaveError(SmartWeaveErrorType.CONTRACT_NOT_FOUND, {
76+
message: `Error while evolving ${contractTxId} from ${currentSrcTxId} to ${evolvedSrcTxId}: ${e}`,
77+
requestedTxId: contractTxId
78+
});
79+
}
7280
}
7381
}
7482
}

0 commit comments

Comments
 (0)