Skip to content

Commit

Permalink
perf(cu): pass multiple arweave urls to WeaveDrive to leverage its fa…
Browse files Browse the repository at this point in the history
…llback mechanism
  • Loading branch information
TillaTheHun0 committed Nov 6, 2024
1 parent ba0329b commit 907fba1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 2 additions & 0 deletions servers/cu/src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export const createApis = async (ctx) => {
WASM_INSTANCE_CACHE_MAX_SIZE: ctx.WASM_INSTANCE_CACHE_MAX_SIZE,
WASM_BINARY_FILE_DIRECTORY: ctx.WASM_BINARY_FILE_DIRECTORY,
ARWEAVE_URL: ctx.ARWEAVE_URL,
GRAPHQL_URL: ctx.GRAPHQL_URL,
CHECKPOINT_GRAPHQL_URL: ctx.CHECKPOINT_GRAPHQL_URL,
DB_URL,
id: workerId,
MODE: ctx.MODE,
Expand Down
29 changes: 24 additions & 5 deletions servers/cu/src/effects/wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,32 @@ export function createWasmInstanceCache ({ MAX_SIZE }) {
})
}

export function addExtensionWith ({ ARWEAVE_URL }) {
export function addExtensionWith ({ ARWEAVE_URL, GRAPHQL_URL, CHECKPOINT_GRAPHQL_URL }) {
/**
* WeaveDrive supports passing multiple urls to use for arweave and gateway
* related operations, within the extension.
*
* NOTE: WeaveDrive doesn't distinguish between a host for the Arweave HTTP API
* and a host for the Arweave GraphQL gateway api (it conflates the two). So certain
* operations will always fail for certain hosts ie. Arweave HTTP API operations sent to a host
* that only hosts the GraphQL gateway api. Until WeaveDrive allows passing distinct urls
* for each use case, passing a _first_ host that implements both is the best we can do to mitigate.
*/
const weaveDriveUrls = Array.from(
/**
* dedupe in the case that the CU is configured to use the same host for multiple
* use-cases. This prevents WeaveDrive from falling back to the same url, and dictating
* its own retry mechanisms
*/
new Set([ARWEAVE_URL, GRAPHQL_URL, CHECKPOINT_GRAPHQL_URL].map(s => new URL(s).origin))
).join(',')

return async ({ extension }) => {
/**
* TODO: make this cleaner. Should we attach only api impls
* or other options (ie. ARWEAVE) as well here?
*/
if (extension === 'WeaveDrive') return { WeaveDrive, ARWEAVE: ARWEAVE_URL }
* TODO: make this cleaner. Should we attach only api impls
* or other options (ie. ARWEAVE) as well here?
*/
if (extension === 'WeaveDrive') return { WeaveDrive, ARWEAVE: weaveDriveUrls }
throw new Error(`Extension ${extension} api not found`)
}
}
Expand Down
6 changes: 5 additions & 1 deletion servers/cu/src/effects/worker/evaluator/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ export const createApis = async (ctx) => {

const evaluate = evaluateWith({
wasmInstanceCache,
addExtension: WasmClient.addExtensionWith({ ARWEAVE_URL: ctx.ARWEAVE_URL }),
addExtension: WasmClient.addExtensionWith({
ARWEAVE_URL: ctx.ARWEAVE_URL,
GRAPHQL_URL: ctx.GRAPHQL_URL,
CHECKPOINT_GRAPHQL_URL: ctx.CHECKPOINT_GRAPHQL_URL
}),
bootstrapWasmInstance: WasmClient.bootstrapWasmInstanceWith(),
saveEvaluation: AoEvaluationClient.saveEvaluationWith({ db: sqlite, logger: ctx.logger }),
ARWEAVE_URL: ctx.ARWEAVE_URL,
Expand Down

0 comments on commit 907fba1

Please sign in to comment.