Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Port QuickJS to SideVM #1

Merged
merged 105 commits into from
Dec 1, 2023
Merged

Port QuickJS to SideVM #1

merged 105 commits into from
Dec 1, 2023

Conversation

kvinwang
Copy link
Collaborator

@kvinwang kvinwang commented Aug 10, 2023

Description

This PR ports QuickJS to SideVM and adds support for async IO.
There are a few implemented async APIs includes setTimeout/setInterval, fetch, XMLHttpRequest, httpListen.
See examples/ for features.

The execution lifetime

As a SideVM program, it need to be deployed by a pink contract.
At startup, sidevm-quickjs would query to the host pink contract (by sidevm_init_script) to get an entry js code to run. At any time when it running, the host pink contract can send more js code snippets to sidevm-quickjs instance to eval.
A sidevm-quickjs instance can host multiple js vm instances, each js instance is associated with it's name. The host pink contract can reset/destroy js instances at any time via sending message.

See the e2e test tests/tests/itWorks.ts for detail.

Related changes in pRuntime

This PR requires some changes to pRuntime to be applied:
Phala-Network/phala-blockchain#1366: for listening incoming HTTP request via pRPC endpoint.
Phala-Network/phala-blockchain#1398: for query init script from pink contract.
Phala-Network/phala-blockchain#1399: for charging sidevm instance and deploying to selected workers in transaction.

@kvinwang kvinwang marked this pull request as ready for review October 25, 2023 08:37
Copy link

@Leechael Leechael left a comment

Choose a reason for hiding this comment

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

lgtm

@Leechael
Copy link

Leechael commented Nov 23, 2023

I suggest added a way for writing test cases for polyfill, since there are lots of edge cases not yet covered (e.g. URL & URLSearchParams).

Updated: considering using core-js for polyfill since it always implemented almost all standard APIs.

tests/devphase.config.ts Outdated Show resolved Hide resolved
src/service_keeper.rs Outdated Show resolved Hide resolved
examples/httpListen.js Show resolved Hide resolved

Choose a reason for hiding this comment

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

What does this example show?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It shows handling incoming HTTP Request in CF workers style API. (PoC)

Choose a reason for hiding this comment

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

In my understanding, fetch() is a method to send http request. So incomingFetch doesn't sound reasonable to me. Maybe consider incomingHttpRequest or lowLevelHttpServer?

Copy link
Collaborator Author

@kvinwang kvinwang Nov 29, 2023

Choose a reason for hiding this comment

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

Maybe listeningFetchEvents? Because that's CF workers gave it the name.
There is already a low level http listening example.

Choose a reason for hiding this comment

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

Got it. I didn't research a lot, but I also searched on CF worker's example page and didn't find name like this. Good to use listeningFetchEvents

src/service/resource.rs Outdated Show resolved Hide resolved
src/host_functions/http_request.rs Outdated Show resolved Hide resolved
src/host_functions/timer.rs Show resolved Hide resolved
src/service_keeper.rs Show resolved Hide resolved
src/host_functions/http_listen.rs Outdated Show resolved Hide resolved
src/host_functions/http_listen.rs Outdated Show resolved Hide resolved
Copy link

@h4x3rotab h4x3rotab left a comment

Choose a reason for hiding this comment

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

LGTM

@kvinwang kvinwang merged commit 78731c8 into master Dec 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants