Skip to content

Commit

Permalink
feat: iw validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ppedziwiatr committed Jun 18, 2023
1 parent 977ab7a commit 0032813
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/contract/InnerWritesEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class InnerWritesEvaluator {
return result;
}

private evalForeignCalls(rootContractTxId: string, interaction: InteractionCall, result: Array<string>) {
evalForeignCalls(rootContractTxId: string, interaction: InteractionCall, result: Array<string>) {
Object.keys(interaction.interactionInput.foreignContractCalls).forEach((foreignContractCallKey) => {
const foreignContractCall = interaction.interactionInput.foreignContractCalls[foreignContractCallKey];
if (foreignContractCall.innerCallType == 'write') {
Expand Down
35 changes: 27 additions & 8 deletions src/core/modules/impl/DefaultStateEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ContractInteraction, HandlerApi, InteractionResult } from './HandlerExe
import { TagsParser } from './TagsParser';
import { VrfPluginFunctions } from '../../WarpPlugin';
import { BasicSortKeyCache } from '../../../cache/BasicSortKeyCache';
import { InnerWritesEvaluator } from '../../../contract/InnerWritesEvaluator';

type EvaluationProgressInput = {
contractTxId: string;
Expand Down Expand Up @@ -239,22 +240,40 @@ export abstract class DefaultStateEvaluator implements StateEvaluator {

this.logger.debug(`${indent(depth)}Interaction evaluation`, singleInteractionBenchmark.elapsed());

if (result.type === 'exception' && ignoreExceptions !== true) {
throw new Error(`Exception while processing ${JSON.stringify(interaction)}:\n${result.errorMessage}`);
}

if (internalWrites && contract.isRoot()) {
const innerWritesEvaluator = new InnerWritesEvaluator();
const iwEvaluatorResult = [];
innerWritesEvaluator.evalForeignCalls(contract.txId(), interactionCall, iwEvaluatorResult);
const tagsInnerWrites = this.tagsParser.getInteractWritesContracts(missingInteraction);
if (
iwEvaluatorResult.length == tagsInnerWrites.length &&
tagsInnerWrites.every((elem) => iwEvaluatorResult.includes(elem))
) {
validity[missingInteraction.id] = result.type === 'ok';
currentState = result.state;
} else {
validity[missingInteraction.id] = false;
errorMessage = `[SDK] Inner writes do not match - tags:${tagsInnerWrites}, evaluated: ${iwEvaluatorResult}`;
errorMessages[missingInteraction.id] = errorMessage;
}
} else {
validity[missingInteraction.id] = result.type === 'ok';
currentState = result.state;
}

interactionCall.update({
cacheHit: false,
outputState: stackTrace.saveState ? currentState : undefined,
executionTime: singleInteractionBenchmark.elapsed(true) as number,
valid: validity[missingInteraction.id],
errorMessage: errorMessage,
errorMessage,
gasUsed: result.gasUsed
});

if (result.type === 'exception' && ignoreExceptions !== true) {
throw new Error(`Exception while processing ${JSON.stringify(interaction)}:\n${result.errorMessage}`);
}

validity[missingInteraction.id] = result.type === 'ok';
currentState = result.state;

const toCache = new EvalStateResult(currentState, validity, errorMessages);
if (canBeCached(missingInteraction)) {
lastConfirmedTxState = {
Expand Down

0 comments on commit 0032813

Please sign in to comment.