This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
feat: improve smoldot integration #374
Merged
+243
−72
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6abb9e5
feat: improve smoldot integration
kratico ef0d5fd
feat: map provider.send errors
kratico 69c14f4
feat: handle smoldot errors
kratico eff66b1
feat: make ProviderSendError.egressMessage non optional
kratico b2cb196
feat: update smoldot connection options
kratico e262b4f
feat: add smoldot props
kratico 91c6d6e
fix: smoldot test props
kratico 11cce07
chore: update smoldot cpu limit to .25
kratico 0c4c694
feat: remove extra pendingCalls checks
kratico File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from "https://deno.land/x/[email protected].3/index-deno.js"; | ||
export * from "https://deno.land/x/[email protected].6/index-deno.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,143 @@ | ||
// TODO | ||
import { deferred } from "../../deps/std/async.ts"; | ||
import { assertExists, assertNotInstanceOf } from "../../deps/std/testing/asserts.ts"; | ||
import { ProviderListener } from "./base.ts"; | ||
import { smoldotProvider } from "./smoldot.ts"; | ||
|
||
const POLKADOT_CHAIN_SPEC_URL = | ||
"https://raw.githubusercontent.com/paritytech/substrate-connect/main/packages/connect/src/connector/specs/polkadot.json"; | ||
|
||
Deno.test({ | ||
name: "Smoldot Provider", | ||
ignore: true, | ||
async fn() { | ||
const stopped = deferred(); | ||
const polkadotChainSpec = await (await fetch(POLKADOT_CHAIN_SPEC_URL)).text(); | ||
const provider = smoldotProvider(polkadotChainSpec, (message) => { | ||
assertNotInstanceOf(message, Error); | ||
assertExists(message.result); | ||
stopped.resolve(); | ||
sanitizeOps: false, | ||
sanitizeResources: false, | ||
async fn(t) { | ||
await t.step({ | ||
name: "relay chain connection", | ||
async fn() { | ||
const relayChainSpec = await ( | ||
await fetch( | ||
"https://raw.githubusercontent.com/paritytech/substrate-connect/main/packages/connect/src/connector/specs/polkadot.json", | ||
) | ||
) | ||
.text(); | ||
const pendingSubscriptionId = deferred<string>(); | ||
const initialized = deferred(); | ||
const unsubscribed = deferred(); | ||
const checks: ProviderListener<any, any>[] = [ | ||
// check for chainHead_unstable_follow subscription | ||
(message) => { | ||
assertNotInstanceOf(message, Error); | ||
assertExists(message.result); | ||
pendingSubscriptionId.resolve(message.result); | ||
}, | ||
// check for chainHead_unstable_follow initialized event | ||
(message) => { | ||
assertNotInstanceOf(message, Error); | ||
assertExists(message.params?.result); | ||
if (message.params?.result.event === "initialized") { | ||
initialized.resolve(); | ||
} | ||
}, | ||
// check for chainHead_unstable_unfollow unsubscribe | ||
(message) => { | ||
assertNotInstanceOf(message, Error); | ||
if (message?.result === null) { | ||
unsubscribed.resolve(); | ||
} | ||
}, | ||
]; | ||
const provider = smoldotProvider({ relayChainSpec }, (message) => { | ||
if (checks.length > 1) { | ||
checks.shift()!(message); | ||
} else { | ||
checks[0]!(message); | ||
} | ||
}); | ||
provider.send({ | ||
jsonrpc: "2.0", | ||
id: provider.nextId(), | ||
method: "chainHead_unstable_follow", | ||
params: [false], | ||
}); | ||
const subscriptionId = await pendingSubscriptionId; | ||
await initialized; | ||
provider.send({ | ||
jsonrpc: "2.0", | ||
id: provider.nextId(), | ||
method: "chainHead_unstable_unfollow", | ||
params: [subscriptionId], | ||
}); | ||
await unsubscribed; | ||
const providerRelease = await provider.release(); | ||
assertNotInstanceOf(providerRelease, Error); | ||
}, | ||
}); | ||
provider.send({ | ||
jsonrpc: "2.0", | ||
id: provider.nextId(), | ||
method: "system_health", | ||
params: [], | ||
await t.step({ | ||
name: "parachain connection", | ||
async fn() { | ||
const relayChainSpec = await ( | ||
await fetch( | ||
"https://raw.githubusercontent.com/paritytech/substrate-connect/main/packages/connect/src/connector/specs/westend2.json", | ||
) | ||
) | ||
.text(); | ||
const parachainSpec = await ( | ||
await fetch( | ||
"https://raw.githubusercontent.com/paritytech/substrate-connect/main/projects/demo/src/assets/westend-westmint.json", | ||
) | ||
) | ||
.text(); | ||
const pendingSubscriptionId = deferred<string>(); | ||
const initialized = deferred(); | ||
const unsubscribed = deferred(); | ||
const checks: ProviderListener<any, any>[] = [ | ||
// check for chainHead_unstable_follow subscription | ||
(message) => { | ||
assertNotInstanceOf(message, Error); | ||
assertExists(message.result); | ||
pendingSubscriptionId.resolve(message.result); | ||
}, | ||
// check for chainHead_unstable_follow initialized event | ||
(message) => { | ||
assertNotInstanceOf(message, Error); | ||
assertExists(message.params?.result); | ||
if (message.params?.result.event === "initialized") { | ||
initialized.resolve(); | ||
} | ||
}, | ||
// check for chainHead_unstable_unfollow unsubscribe | ||
(message) => { | ||
assertNotInstanceOf(message, Error); | ||
if (message?.result === null) { | ||
unsubscribed.resolve(); | ||
} | ||
}, | ||
]; | ||
const provider = smoldotProvider( | ||
{ parachainSpec, relayChainSpec }, | ||
(message) => { | ||
if (checks.length > 1) { | ||
checks.shift()!(message); | ||
} else { | ||
checks[0]!(message); | ||
} | ||
}, | ||
); | ||
provider.send({ | ||
jsonrpc: "2.0", | ||
id: provider.nextId(), | ||
method: "chainHead_unstable_follow", | ||
params: [false], | ||
}); | ||
const subscriptionId = await pendingSubscriptionId; | ||
await initialized; | ||
provider.send({ | ||
jsonrpc: "2.0", | ||
id: provider.nextId(), | ||
method: "chainHead_unstable_unfollow", | ||
params: [subscriptionId], | ||
}); | ||
await unsubscribed; | ||
const providerRelease = await provider.release(); | ||
assertNotInstanceOf(providerRelease, Error); | ||
}, | ||
}); | ||
|
||
await stopped; | ||
await provider.release(); | ||
}, | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Smoldot seems to not clear a few timers started in