Skip to content

Commit

Permalink
v1.4.36-beta.3
Browse files Browse the repository at this point in the history
  • Loading branch information
asiaziola committed Aug 10, 2024
1 parent 94582bb commit d29fab0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "warp-contracts",
"version": "1.4.36-beta.2",
"version": "1.4.36-beta.3",
"description": "An implementation of the SmartWeave smart contract protocol.",
"types": "./lib/types/index.d.ts",
"main": "./lib/cjs/index.js",
Expand Down
20 changes: 19 additions & 1 deletion src/core/modules/impl/handler/JsHandlerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { deepCopy, timeout } from '../../../../utils/utils';
import { ContractError, ContractInteraction, InteractionData, InteractionResult } from '../HandlerExecutorFactory';
import { genesisSortKey } from '../LexicographicalInteractionsSorter';
import { AbstractContractHandler } from './AbstractContractHandler';
import { Benchmark } from '../../../../logging/Benchmark';

const INIT_FUNC_NAME = '__init';
const throwErrorWithName = (name: string, message: string) => {
Expand Down Expand Up @@ -39,10 +40,13 @@ export class JsHandlerApi<State> extends AbstractContractHandler<State> {
): Promise<InteractionResult<State, Result>> {
const { interaction, interactionTx } = interactionData;

const initialHandleBenchmark = Benchmark.measure();
this.setupSwGlobal(interactionData);
this.enableInternalWrites(executionContext, interactionTx);

this.assertNotConstructorCall<Input>(interaction);
initialHandleBenchmark.stop();
this.logger.info('Initial handle benchmark', initialHandleBenchmark.stop());

return await this.runContractFunction(executionContext, interaction, currentResult.state);
}
Expand Down Expand Up @@ -138,20 +142,34 @@ export class JsHandlerApi<State> extends AbstractContractHandler<State> {
interaction: InteractionData<Input>['interaction'],
state: State
): Promise<InteractionResult<State, Result>> {
const stateCloneBenchmark = Benchmark.measure();
const stateClone = deepCopy(state);
stateCloneBenchmark.stop();
this.logger.info('State clone benchmark', stateCloneBenchmark.elapsed());
const timeoutBenchmark = Benchmark.measure();
const { timeoutId, timeoutPromise } = timeout(
executionContext.evaluationOptions.maxInteractionEvaluationTimeSeconds
);
timeoutBenchmark.stop();
this.logger.info('timeout benchmark', timeoutBenchmark.elapsed());

try {
const openKvBenchmark = Benchmark.measure();
await this.swGlobal.kv.open();
await this.swGlobal.kv.begin();
openKvBenchmark.stop();
this.logger.info('openKvBenchmark', openKvBenchmark.elapsed());

const handlerResultBenchmark = Benchmark.measure();
const handlerResult = await Promise.race([timeoutPromise, this.contractFunction(stateClone, interaction)]);
handlerResultBenchmark.stop();
this.logger.info('handlerResultBenchmark', handlerResultBenchmark.elapsed());

if (handlerResult && (handlerResult.state !== undefined || handlerResult.result !== undefined)) {
const kvCommitBenchmark = Benchmark.measure();
await this.swGlobal.kv.commit();

kvCommitBenchmark.stop();
this.logger.info('kvCommitBenchmark', kvCommitBenchmark.elapsed());
let interactionEvent: InteractionCompleteEvent = null;

if (handlerResult.event) {
Expand Down

0 comments on commit d29fab0

Please sign in to comment.