From 6c02755d4b28fdffb05ee24b6fa7cd0078f655dd Mon Sep 17 00:00:00 2001 From: Julian Gruber Date: Tue, 5 Mar 2024 13:52:06 +0100 Subject: [PATCH 1/3] Disable voyager when running on Saturn node --- voyager.js | 69 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/voyager.js b/voyager.js index 3b636de..331c1db 100644 --- a/voyager.js +++ b/voyager.js @@ -45,31 +45,64 @@ new BasicTracerProvider().register() Zinnia.activity.info('Voyager benchmarking started') export async function runSaturnBenchmarkInterval() { - const random = Math.random() - if (random <= prodOpts.sampleRate) { - console.log('Running prod benchmark...') - try { - await runBenchmark(prodSaturn) - console.log('Prod benchmark successful!') - } catch (err) { - console.error(err) - } - Zinnia.jobCompleted() + let runningOnSaturnNode = false + try { + runningOnSaturnNode = await isRunningOnSaturnNode() + } catch (err) { + console.error( + 'Could not check if running on Saturn node', + { cause: err } + ) } - if (random <= testOpts.sampleRate) { - console.log('Running test benchmark...') - try { - await runBenchmark(testSaturn) - console.log('Test benchmark successful!') - } catch (err) { - console.error(err) + if (runningOnSaturnNode) { + console.log('Running on Saturn host, skipping benchmark') + } else { + const random = Math.random() + if (random <= prodOpts.sampleRate) { + console.log('Running prod benchmark...') + try { + await runBenchmark(prodSaturn) + console.log('Prod benchmark successful!') + } catch (err) { + console.error(err) + } + Zinnia.jobCompleted() + } + if (random <= testOpts.sampleRate) { + console.log('Running test benchmark...') + try { + await runBenchmark(testSaturn) + console.log('Test benchmark successful!') + } catch (err) { + console.error(err) + } + Zinnia.jobCompleted() } - Zinnia.jobCompleted() } console.log('Sleeping for 60s...') setTimeout(runSaturnBenchmarkInterval, 1000 * 60) } +async function getPublicIPv4Address () { + // TODO Replace with Voyager API once available + const res = await fetch(`https://api.filspark.com/inspect-request`) + const { cloudfareAddr: ip } = await res.json() + return ip +} + +async function isRunningOnSaturnNode () { + const ip = await getPublicIPv4Address() + const subdomain = ip.replaceAll('.', '-') + try { + await fetch(`https://${subdomain}.l1s.saturn.ms/`, { + redirect: 'manual' + }) + return true + } catch { + return false + } +} + export async function runBenchmark(saturn) { const { cidPath } = getWeightedRandomCid(gatewayCids) console.log(`Testing ${cidPath}...`) From d2083e7f690a41751b6fffa86236b6cfcf63eace Mon Sep 17 00:00:00 2001 From: Julian Gruber Date: Wed, 6 Mar 2024 12:54:43 +0100 Subject: [PATCH 2/3] refactor --- voyager.js | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/voyager.js b/voyager.js index 331c1db..70a3f76 100644 --- a/voyager.js +++ b/voyager.js @@ -57,32 +57,36 @@ export async function runSaturnBenchmarkInterval() { if (runningOnSaturnNode) { console.log('Running on Saturn host, skipping benchmark') } else { - const random = Math.random() - if (random <= prodOpts.sampleRate) { - console.log('Running prod benchmark...') - try { - await runBenchmark(prodSaturn) - console.log('Prod benchmark successful!') - } catch (err) { - console.error(err) - } - Zinnia.jobCompleted() - } - if (random <= testOpts.sampleRate) { - console.log('Running test benchmark...') - try { - await runBenchmark(testSaturn) - console.log('Test benchmark successful!') - } catch (err) { - console.error(err) - } - Zinnia.jobCompleted() - } + await runSaturnBenchmark() } console.log('Sleeping for 60s...') setTimeout(runSaturnBenchmarkInterval, 1000 * 60) } +async function runSaturnBenchmark() { + const random = Math.random() + if (random <= prodOpts.sampleRate) { + console.log('Running prod benchmark...') + try { + await runBenchmark(prodSaturn) + console.log('Prod benchmark successful!') + } catch (err) { + console.error(err) + } + Zinnia.jobCompleted() + } + if (random <= testOpts.sampleRate) { + console.log('Running test benchmark...') + try { + await runBenchmark(testSaturn) + console.log('Test benchmark successful!') + } catch (err) { + console.error(err) + } + Zinnia.jobCompleted() + } +} + async function getPublicIPv4Address () { // TODO Replace with Voyager API once available const res = await fetch(`https://api.filspark.com/inspect-request`) From 0af64391184491bdd1a32db198bce49cd57c2579 Mon Sep 17 00:00:00 2001 From: Julian Gruber Date: Wed, 6 Mar 2024 14:59:58 +0100 Subject: [PATCH 3/3] the api response changed --- voyager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/voyager.js b/voyager.js index 70a3f76..20a996d 100644 --- a/voyager.js +++ b/voyager.js @@ -90,7 +90,7 @@ async function runSaturnBenchmark() { async function getPublicIPv4Address () { // TODO Replace with Voyager API once available const res = await fetch(`https://api.filspark.com/inspect-request`) - const { cloudfareAddr: ip } = await res.json() + const { cloudflareAddr: ip } = await res.json() return ip }