Skip to content

QuickJSPlugin: read external data#33

Open
8bcb wants to merge 3 commits intomainfrom
asiaziola/read-external
Open

QuickJSPlugin: read external data#33
8bcb wants to merge 3 commits intomainfrom
asiaziola/read-external

Conversation

@8bcb
Copy link
Contributor

@8bcb 8bcb commented Dec 3, 2024

No description provided.

@8bcb 8bcb requested review from Tadeuchi and ppedziwiatr December 3, 2024 13:09
@@ -1,6 +1,6 @@
{
"name": "warp-contracts-plugin-quickjs",
"version": "1.1.12",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

async readExternal(processIdHandle: QuickJSHandle, actionHandle: QuickJSHandle) {
const processId = this.vm.getString(processIdHandle);
const action = this.vm.getString(actionHandle);
const { dryrun } = await import('@permaweb/aoconnect');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why dynamic import?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already discussed

tags: [{ name: 'Action', value: action }],
data: '1234'
});
return JSON.parse(readRes.Messages[0].Data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe there is no point in parsing the response if we need to stringify it again to pass it to the quickjs..

quickJsEvaluator.evalLogging();
quickJsEvaluator.evalPngJS();
quickJsEvaluator.evalRedStone();
quickJsEvaluator.evalExternal();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't evalExternal and dummyPromiseEval also be called only if isSourceAsync?

Date: false,
Proxy: false,
Promise: false,
Promise: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we set this dynamically based on isSourceAsync?

constructor(
private readonly vm: QuickJSContext,
private readonly runtime: QuickJSRuntime,
private readonly quickJS: QuickJSWASMModule,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the QuickJSWASMModule import can also now be removed?

this.initState(state);
}
return this.runContractFunction(message, env);
return await this.runContractFunction(message, env);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically await is not needed here

const result = this.vm.evalCode(`(async () => {
return await __handleDecorator(${JSON.stringify(message)}, ${JSON.stringify(env)})
})()`);
const promiseHandle = this.vm.unwrapResult(result);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how are erros how handled? e.g. what if dry-run timeouts?

evalExternal() {
const readExternalHandle = this.vm.newFunction('readExternal', (processIdHandle, actionHandle) => {
const promise = this.vm.newPromise();
this.readExternal(processIdHandle, actionHandle).then((result) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we also somehow handle errors here and pass some error info to the quickjs?

const processId = this.vm.getString(processIdHandle);
const action = this.vm.getString(actionHandle);
const { dryrun } = await import('@permaweb/aoconnect');
const readRes = await dryrun({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the default timeout for the dryrun? maybe we should it limit to sth. like 10s?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont know what's the default but i've added some logic so the error is thrown if dryrun is executing more than 10s

});
return JSON.parse(readRes.Messages[0].Data);
try {
const result = await Promise.race<{
Copy link
Contributor

@ppedziwiatr ppedziwiatr Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the issue with race is that the 'timeout' promise won't be removed even if the 'raced' promise is settled.
https://stackoverflow.com/a/39852372

It is already handled by a timeout implementation in warp sdk - https://github.com/warp-contracts/warp/blob/main/src/utils/utils.ts#L52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants