warp-contracts / warp

An implementation of the Arweave SmartWeave smart contracts protocol.
MIT License
159 stars 44 forks source link

perf: deadlocks with isolated-vm #272

Closed ppedziwiatr closed 1 year ago

ppedziwiatr commented 2 years ago

Probably related to https://github.com/laverdet/isolated-vm/issues/302 https://github.com/laverdet/isolated-vm/issues/307 https://github.com/laverdet/isolated-vm/issues/321

Reproducible example:

/* eslint-disable */

import {defaultCacheOptions, LoggerFactory, WarpFactory} from "warp-contracts";
import {IvmPlugin} from "warp-contracts-ivm-plugin";

LoggerFactory.INST.logLevel('debug');
// LoggerFactory.INST.logLevel('none', 'DefaultStateEvaluator');
const logger = LoggerFactory.INST.create('ivm-example');

async function main() {
  const contractTxId = 'XIutiOKujGI21_ywULlBeyy-L9d8goHxt0ZyUayGaDg';

  const warp = WarpFactory
    .forMainnet({...defaultCacheOptions, inMemory: true})
    .use(new IvmPlugin({}));

  const result = await warp
    .contract(contractTxId)
    .setEvaluationOptions({
      allowBigInt: true,
      internalWrites: true,
    })
    .readState();

  console.log(result.cachedValue.validity);
}

main().catch((e) => console.error(e));

In my case it always hangs at 1201. interaction:

image

We need to generate a stacktrace and report this to library authors.

ppedziwiatr commented 2 years ago

Reading the above issues, it is probably also worth experimenting with isolated-vm version 4.3.6 (which probably requires downgrading the node to ver. 16).

If that won't help - try to temporarily remove the isolate disposal code - https://github.com/warp-contracts/warp-contracts-plugins/blob/main/warp-contracts-ivm-plugin/src/IvmHandlerApi.ts#L85

janekolszak commented 2 years ago

Downgrading to node 16.18.1, warp 1.2.30, isolated-vm in 4.3.6 works fine

janekolszak commented 2 years ago

https://github.com/laverdet/isolated-vm/issues/330

ppedziwiatr commented 1 year ago

https://github.com/laverdet/isolated-vm/issues/330#issuecomment-1353254772 @janekolszak ? although not sure if we want to use the isolated-vm...

ppedziwiatr commented 1 year ago

Let's stick with VM2 + separate node process (supplied by the bullmq's sandboxed processors).

With the possible addition of the https://github.com/taskforcesh/bullmq/issues/1555 - it should be 'good enough' for now.

In the future - consider switching to SES.