From 974c04900df9b4b5994af8934366862909fcdb9f Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Tue, 14 Feb 2023 12:54:24 -0500 Subject: [PATCH 1/5] t6 is a beast --- deps/std/bytes/mod.ts | 1 - deps/std/http.ts | 1 + deps/std/http/file_server.ts | 1 - deps/std/http/http_status.ts | 1 - deps/std/http/server.ts | 1 - examples/failing.ts | 6 +++ fluent/rpc_runes.ts | 8 ++-- main.ts | 2 +- patterns/ink/InkRune.ts | 2 +- providers/frame/FrameProxyProvider.ts | 58 +++++++++++++-------------- rpc/provider/errors.ts | 2 +- rpc/provider/proxy.ts | 4 +- server/Provider.ts | 1 + server/factories.ts | 2 +- server/local.ts | 9 +++-- 15 files changed, 52 insertions(+), 47 deletions(-) delete mode 100644 deps/std/bytes/mod.ts create mode 100644 deps/std/http.ts delete mode 100644 deps/std/http/file_server.ts delete mode 100644 deps/std/http/http_status.ts delete mode 100644 deps/std/http/server.ts create mode 100644 examples/failing.ts diff --git a/deps/std/bytes/mod.ts b/deps/std/bytes/mod.ts deleted file mode 100644 index 9570c222e..000000000 --- a/deps/std/bytes/mod.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "https://deno.land/std@0.173.0/bytes/mod.ts" diff --git a/deps/std/http.ts b/deps/std/http.ts new file mode 100644 index 000000000..694e3c954 --- /dev/null +++ b/deps/std/http.ts @@ -0,0 +1 @@ +export * from "https://deno.land/std@0.173.0/http/mod.ts" diff --git a/deps/std/http/file_server.ts b/deps/std/http/file_server.ts deleted file mode 100644 index 38ccfc695..000000000 --- a/deps/std/http/file_server.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "https://deno.land/std@0.173.0/http/file_server.ts" diff --git a/deps/std/http/http_status.ts b/deps/std/http/http_status.ts deleted file mode 100644 index 93111d8a2..000000000 --- a/deps/std/http/http_status.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "https://deno.land/std@0.173.0/http/http_status.ts" diff --git a/deps/std/http/server.ts b/deps/std/http/server.ts deleted file mode 100644 index b37509bb7..000000000 --- a/deps/std/http/server.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "https://deno.land/std@0.173.0/http/server.ts" diff --git a/examples/failing.ts b/examples/failing.ts new file mode 100644 index 000000000..5b6e0d95d --- /dev/null +++ b/examples/failing.ts @@ -0,0 +1,6 @@ +import { alice } from "capi" +import { System as KSystem } from "kusama_dev/mod.ts" +import { System as PSystem } from "polkadot_dev/mod.ts" + +console.log(await PSystem.Account.entry([alice.publicKey]).run()) +console.log(await KSystem.Account.entry([alice.publicKey]).run()) diff --git a/fluent/rpc_runes.ts b/fluent/rpc_runes.ts index b285b0619..c09c03d5f 100644 --- a/fluent/rpc_runes.ts +++ b/fluent/rpc_runes.ts @@ -12,12 +12,12 @@ class RunRpcClient extends Run, } client?: rpc.Client - _evaluate(): Promise> { - return Promise.resolve(this.client ??= new rpc.Client(this.provider, this.discoveryValue)) + async _evaluate(): Promise> { + return this.client ??= new rpc.Client(this.provider, this.discoveryValue) } - override cleanup(): void { - this.client?.discard() + override async cleanup(): Promise { + await this.client?.discard() super.cleanup() } } diff --git a/main.ts b/main.ts index 2067baa27..0b4ec8eef 100644 --- a/main.ts +++ b/main.ts @@ -1,5 +1,5 @@ import * as flags from "./deps/std/flags.ts" -import { serve } from "./deps/std/http/server.ts" +import { serve } from "./deps/std/http.ts" import { PolkadotDevProvider, WssProvider, ZombienetProvider } from "./providers/frame/mod.ts" import { handler } from "./server/local.ts" import { Env } from "./server/mod.ts" diff --git a/patterns/ink/InkRune.ts b/patterns/ink/InkRune.ts index 65bd37ab8..7aa9c4231 100644 --- a/patterns/ink/InkRune.ts +++ b/patterns/ink/InkRune.ts @@ -1,4 +1,4 @@ -import { equals } from "../../deps/std/bytes/mod.ts" +import { equals } from "../../deps/std/bytes.ts" import { Chain, ClientRune, CodecRune, ExtrinsicRune, state } from "../../fluent/mod.ts" import { Event } from "../../primitives/mod.ts" import { Rune, RunicArgs, ValueRune } from "../../rune/mod.ts" diff --git a/providers/frame/FrameProxyProvider.ts b/providers/frame/FrameProxyProvider.ts index 6d3d12b02..4fea151a7 100644 --- a/providers/frame/FrameProxyProvider.ts +++ b/providers/frame/FrameProxyProvider.ts @@ -1,11 +1,12 @@ import { File } from "../../codegen/frame/mod.ts" +import { deferred } from "../../deps/std/async.ts" import { Client, proxyProvider } from "../../rpc/mod.ts" import { PathInfo } from "../../server/mod.ts" import { fromPathInfo } from "../../server/PathInfo.ts" import { FrameProvider } from "./FrameProvider.ts" export abstract class FrameProxyProvider extends FrameProvider { - override handle(request: Request, pathInfo: PathInfo): Promise { + override async handle(request: Request, pathInfo: PathInfo): Promise { if ( pathInfo.vRuntime && pathInfo.vRuntime !== "latest" && !pathInfo.filePath && request.headers.get("upgrade") === "websocket" @@ -19,33 +20,30 @@ export abstract class FrameProxyProvider extends FrameProvider { const url = await this.dynamicUrl(pathInfo) const server = new WebSocket(url) const { socket: client, response } = Deno.upgradeWebSocket(request) - server.addEventListener("close", () => { - try { - client.close() - } catch {} - }) - server.addEventListener("message", (event) => { - try { - client.send(event.data) - } catch { - client.close() - server.close() - } - }) - client.addEventListener("close", async () => { - try { - server.close() - } catch {} - }) - client.addEventListener("message", async (event) => { - try { - server.send(event.data) - } catch { - client.close() - server.close() - } - }) + setup(client, server) + setup(server, client) return response + + function setup(a: WebSocket, b: WebSocket) { + const ready = deferred() + b.addEventListener("open", () => { + ready.resolve() + }) + a.addEventListener("close", async () => { + try { + b.close() + } catch {} + }) + a.addEventListener("message", async (event) => { + try { + await ready + b.send(event.data) + } catch { + a.close() + b.close() + } + }) + } } abstract dynamicUrl(pathInfo: PathInfo): Promise @@ -73,11 +71,11 @@ export abstract class FrameProxyProvider extends FrameProvider { import * as C from "./capi.ts" import type { Chain } from "./mod.ts" - export const client = C.rpcClient(C.rpc.proxyProvider, "${url}")["_asCodegen"]() + export const discoveryValue = "${url}" - export const rawClient = new C.rpc.Client(C.rpc.proxyProvider, "${url}") + export const client = C.rpcClient(C.rpc.proxyProvider, discoveryValue)["_asCodegen"]() - export const discoveryValue = "${url}" + export const rawClient = new C.rpc.Client(C.rpc.proxyProvider, discoveryValue) `) } } diff --git a/rpc/provider/errors.ts b/rpc/provider/errors.ts index ef0f6e6cf..24cf4bb90 100644 --- a/rpc/provider/errors.ts +++ b/rpc/provider/errors.ts @@ -11,7 +11,7 @@ export class ProviderSendError extends Error { } export class ProviderHandlerError extends Error { - override readonly name = "ProviderInternalError" + override readonly name = "ProviderHandlerError" constructor(override readonly cause: Data) { super() } diff --git a/rpc/provider/proxy.ts b/rpc/provider/proxy.ts index 0eef10379..fa9a1f586 100644 --- a/rpc/provider/proxy.ts +++ b/rpc/provider/proxy.ts @@ -66,7 +66,9 @@ function connection( ws.addEventListener("close", (e) => { conn.forEachListener(new ProviderHandlerError(e)) }, controller) - return new ProviderConnection(ws, () => controller.abort()) + return new ProviderConnection(ws, () => { + controller.abort() + }) }) conn.addListener(listener) return conn diff --git a/server/Provider.ts b/server/Provider.ts index a63a6aa62..85172e3d7 100644 --- a/server/Provider.ts +++ b/server/Provider.ts @@ -1,3 +1,4 @@ +import { ConstRune } from "../fluent/ConstRune.ts" import { Env } from "./Env.ts" import { PathInfo } from "./PathInfo.ts" diff --git a/server/factories.ts b/server/factories.ts index 11a028584..fbe9b617b 100644 --- a/server/factories.ts +++ b/server/factories.ts @@ -1,6 +1,6 @@ import { escapeHtml } from "../deps/escape.ts" import * as shiki from "../deps/shiki.ts" -import { Status } from "../deps/std/http/http_status.ts" +import { Status } from "../deps/std/http.ts" import { CacheBase } from "../util/cache/base.ts" shiki.setCDN("https://unpkg.com/shiki/") diff --git a/server/local.ts b/server/local.ts index c8637f2d1..c9cf0104a 100644 --- a/server/local.ts +++ b/server/local.ts @@ -18,10 +18,11 @@ export function handler(env: Env) { } const provider = env.providers[generatorId]?.[providerId] if (provider) { - return await provider.handle(request, pathInfo).catch((e) => { - if (e instanceof Response) return e - return f.serverError(Deno.inspect(e)) - }) + try { + return await provider.handle(request, pathInfo) + } catch (e) { + return f.serverError(e instanceof Error ? e.message : Deno.inspect(e)) + } } } for (const dir of staticDirs) { From c6d6d8122ca2ebdaa13f40a327dc8f15f9672e20 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Tue, 14 Feb 2023 12:56:54 -0500 Subject: [PATCH 2/5] get rid of failing repro --- examples/failing.ts | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 examples/failing.ts diff --git a/examples/failing.ts b/examples/failing.ts deleted file mode 100644 index 5b6e0d95d..000000000 --- a/examples/failing.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { alice } from "capi" -import { System as KSystem } from "kusama_dev/mod.ts" -import { System as PSystem } from "polkadot_dev/mod.ts" - -console.log(await PSystem.Account.entry([alice.publicKey]).run()) -console.log(await KSystem.Account.entry([alice.publicKey]).run()) From 5fe789b2bf0766976f6cc31bfa0536922b396324 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Tue, 14 Feb 2023 12:58:35 -0500 Subject: [PATCH 3/5] get rid of accidental import --- server/Provider.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/server/Provider.ts b/server/Provider.ts index 85172e3d7..a63a6aa62 100644 --- a/server/Provider.ts +++ b/server/Provider.ts @@ -1,4 +1,3 @@ -import { ConstRune } from "../fluent/ConstRune.ts" import { Env } from "./Env.ts" import { PathInfo } from "./PathInfo.ts" From 796d236bc7bcc53ff63f009228af08c3c52da72c Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Tue, 14 Feb 2023 12:59:48 -0500 Subject: [PATCH 4/5] fix mistaken change in local server handler --- server/local.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/server/local.ts b/server/local.ts index c9cf0104a..f70c4d8f5 100644 --- a/server/local.ts +++ b/server/local.ts @@ -21,6 +21,7 @@ export function handler(env: Env) { try { return await provider.handle(request, pathInfo) } catch (e) { + if (e instanceof Response) return e return f.serverError(e instanceof Error ? e.message : Deno.inspect(e)) } } From 97b3f7a91ce40002026d8e66191889835b483d03 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Tue, 14 Feb 2023 13:01:13 -0500 Subject: [PATCH 5/5] fix another mistaken change to local --- server/local.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/local.ts b/server/local.ts index f70c4d8f5..a211f88b1 100644 --- a/server/local.ts +++ b/server/local.ts @@ -22,7 +22,7 @@ export function handler(env: Env) { return await provider.handle(request, pathInfo) } catch (e) { if (e instanceof Response) return e - return f.serverError(e instanceof Error ? e.message : Deno.inspect(e)) + return f.serverError(Deno.inspect(e)) } } }