-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Zinnia Runtime and Peer Checker module (#92)
* feat: install Zinnia runtime Add another post-install step to download `zinniad` for running Zinnia modules. Signed-off-by: Miroslav Bajtoš <[email protected]> * feat: install mod-peer-checker Signed-off-by: Miroslav Bajtoš <[email protected]> * feat: run peer checker module via Zinnia Signed-off-by: Miroslav Bajtoš <[email protected]> * fix formatting Signed-off-by: Miroslav Bajtoš <[email protected]> * fixup! windows zinniad extension Signed-off-by: Miroslav Bajtoš <[email protected]> * test: fix never ending test Signed-off-by: Miroslav Bajtoš <[email protected]> * upgrade zinniad to v0.7.0 * Update commands/station.js Co-authored-by: Julian Gruber <[email protected]> * update tests Signed-off-by: Miroslav Bajtoš <[email protected]> * ci: execute Docker image and test activity Signed-off-by: Miroslav Bajtoš <[email protected]> * fixup! fix failing tests Signed-off-by: Miroslav Bajtoš <[email protected]> * fixup! docker CI workflow Signed-off-by: Miroslav Bajtoš <[email protected]> * troubleshoot docker CI not running Signed-off-by: Miroslav Bajtoš <[email protected]> * enable Docker workflow for all pushes * Revert "troubleshoot docker CI not running" This reverts commit 11a56e7. * more docker tweaks Signed-off-by: Miroslav Bajtoš <[email protected]> * feat: switch base Docker image to full `node:18` We cannot use `node:18-alpine` because Zinnia does not support that yet. I tried to use `node:18-slim`, but Saturn L2 was not able to start in that system. The Node.js project recommends to use `node:18`, so we should be fine. See https://github.com/nodejs/docker-node#image-variants Signed-off-by: Miroslav Bajtoš <[email protected]> * fixup! standard coding style Signed-off-by: Miroslav Bajtoš <[email protected]> * fix zip assets on windows * fixup! remove github from zinnia module repo name Signed-off-by: Miroslav Bajtoš <[email protected]> * bump zinnia to 0.8.0 Signed-off-by: Miroslav Bajtoš <[email protected]> * rename Module Runtime to Zinnia Signed-off-by: Miroslav Bajtoš <[email protected]> * move mocha config to config file and add --exit Signed-off-by: Miroslav Bajtoš <[email protected]> * make test/station easier to troubleshoot Signed-off-by: Miroslav Bajtoš <[email protected]> * fix expected Saturn messages Signed-off-by: Miroslav Bajtoš <[email protected]> --------- Signed-off-by: Miroslav Bajtoš <[email protected]> Co-authored-by: Julian Gruber <[email protected]>
- Loading branch information
1 parent
a2a27f2
commit 53d4912
Showing
12 changed files
with
262 additions
and
38 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
timeout: 15000 | ||
exit: true |
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
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 |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import timers from 'node:timers/promises' | ||
import { execa } from 'execa' | ||
import * as Sentry from '@sentry/node' | ||
import { installBinaryModule, downloadSourceFiles, getBinaryModuleExecutable } from './modules.js' | ||
import { moduleBinaries } from './paths.js' | ||
|
||
const ZINNIA_DIST_TAG = 'v0.8.0' | ||
const ZINNIA_MODULES = [ | ||
{ | ||
module: 'peer-checker', | ||
repo: 'filecoin-station/mod-peer-checker', | ||
distTag: 'v1.0.0' | ||
} | ||
] | ||
|
||
export async function install () { | ||
await Promise.all([ | ||
installBinaryModule({ | ||
module: 'zinnia', | ||
repo: 'filecoin-station/zinnia', | ||
distTag: ZINNIA_DIST_TAG, | ||
executable: 'zinniad', | ||
targets: [ | ||
{ platform: 'darwin', arch: 'arm64', asset: 'zinniad-macos-arm64.zip' }, | ||
{ platform: 'darwin', arch: 'x64', asset: 'zinniad-macos-x64.zip' }, | ||
{ platform: 'linux', arch: 'arm64', asset: 'zinniad-linux-arm64.tar.gz' }, | ||
{ platform: 'linux', arch: 'x64', asset: 'zinniad-linux-x64.tar.gz' }, | ||
{ platform: 'win32', arch: 'x64', asset: 'zinniad-windows-x64.zip' } | ||
] | ||
}), | ||
|
||
...Object.values(ZINNIA_MODULES).map(downloadSourceFiles) | ||
]) | ||
} | ||
|
||
async function start ({ | ||
FIL_WALLET_ADDRESS, | ||
STATE_ROOT, | ||
CACHE_ROOT, | ||
metricsStream, | ||
activityStream, | ||
logStream | ||
}) { | ||
logStream.write('Starting Zinnia') | ||
|
||
const zinniadExe = getBinaryModuleExecutable({ module: 'zinnia', executable: 'zinniad' }) | ||
const modules = [ | ||
// all paths are relative to `moduleBinaries` | ||
'peer-checker/peer-checker.js' | ||
] | ||
const childProcess = execa(zinniadExe, modules, { | ||
cwd: moduleBinaries, | ||
env: { | ||
FIL_WALLET_ADDRESS, | ||
STATE_ROOT, | ||
CACHE_ROOT | ||
} | ||
}) | ||
|
||
const readyPromise = new Promise((resolve, reject) => { | ||
childProcess.stdout.setEncoding('utf-8') | ||
childProcess.stdout.on('data', data => { | ||
logStream.write(data) | ||
handleEvents({ activityStream, metricsStream }, data) | ||
}) | ||
|
||
childProcess.stderr.setEncoding('utf-8') | ||
childProcess.stderr.on('data', data => { | ||
logStream.write(data) | ||
}) | ||
|
||
childProcess.stdout.once('data', _data => { | ||
// This is based on an implicit assumption that zinniad reports an info activity | ||
// after it starts | ||
resolve() | ||
}) | ||
childProcess.catch(reject) | ||
}) | ||
|
||
childProcess.on('close', code => { | ||
logStream.write(`Zinnia closed all stdio with code ${code ?? '<no code>'}`) | ||
childProcess.stderr.removeAllListeners() | ||
childProcess.stdout.removeAllListeners() | ||
Sentry.captureException('Zinnia exited') | ||
}) | ||
|
||
childProcess.on('exit', (code, signal) => { | ||
const reason = signal ? `via signal ${signal}` : `with code: ${code}` | ||
const msg = `Zinnia exited ${reason}` | ||
logStream.write(msg) | ||
activityStream.write({ type: 'info', message: msg }) | ||
}) | ||
|
||
try { | ||
await Promise.race([ | ||
readyPromise, | ||
timers.setTimeout(500) | ||
]) | ||
} catch (err) { | ||
const errorMsg = err instanceof Error ? err.message : '' + err | ||
const message = `Cannot start Zinnia: ${errorMsg}` | ||
logStream.write(message) | ||
activityStream.write({ type: 'error', message }) | ||
} | ||
} | ||
|
||
function handleEvents ({ activityStream, metricsStream }, text) { | ||
text | ||
.trimEnd() | ||
.split(/\n/g) | ||
.forEach(line => { | ||
try { | ||
const event = JSON.parse(line) | ||
switch (event.type) { | ||
case 'activity:info': | ||
activityStream.write({ | ||
type: 'info', | ||
message: event.message.replace(/Module Runtime/, 'Zinnia'), | ||
source: event.module ?? 'Zinnia' | ||
}) | ||
break | ||
|
||
case 'activity:error': | ||
activityStream.write({ | ||
type: 'error', | ||
message: event.message.replace(/Module Runtime/, 'Zinnia'), | ||
source: event.module ?? 'Zinnia' | ||
}) | ||
break | ||
|
||
case 'jobs-completed': | ||
metricsStream.write({ totalJobsCompleted: event.total, totalEarnings: '0' }) | ||
break | ||
|
||
default: | ||
console.error('Ignoring Zinnia event of unknown type:', event) | ||
} | ||
} catch (err) { | ||
console.error('Ignoring malformed Zinnia event:', line) | ||
} | ||
}) | ||
} | ||
|
||
export { start } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.