Skip to content

Commit

Permalink
station core -> checker node
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber committed Feb 10, 2025
1 parent cd2303e commit c0b6867
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 157 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"assets/",
"dist/",
"@types/",
"core/"
"checker/"
],
"overrides": [
{
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-auto-approve-patch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- react-helmet-async
- tailwindcss
- '@glif/'
- '@filecoin-station/core'
- '@checkernetwork/node'
- npm
- ejs
- '@electron/notarize'
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ dev-app-update.yml
*.sw?
.tool-versions

core
checker
4 changes: 2 additions & 2 deletions build/after-pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exports.default = async function (context) {
: null
if (arch === 'universal') return
assert(arch, `Unknown architecture id: ${context.arch}`)
console.log(`Rebuild Station Core for arch=${arch}`)
console.log(`Rebuild Checker Node for arch=${arch}`)
const ps = spawn(
'node',
['scripts/post-install.js'],
Expand All @@ -32,7 +32,7 @@ exports.default = async function (context) {
'Filecoin Station.app',
'Contents',
'Resources',
'core'
'checker'
),
env: {
...process.env,
Expand Down
2 changes: 1 addition & 1 deletion electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ files:
- package.json

extraResources:
- 'core/**'
- 'checker/**'

beforePack: './build/before-pack.js'
afterPack: './build/after-pack.js'
Expand Down
51 changes: 28 additions & 23 deletions main/core.js → main/checker-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ const { parseEther } = require('ethers/lib/utils')
const { once } = require('node:events')
const { format } = require('node:util')

const log = require('electron-log').scope('core')
const log = require('electron-log').scope('checker')

/** @typedef {import('./typings').Context} Context */

// Core is installed separately from `node_modules`, since it needs a
// Checker Node is installed separately from `node_modules`, since it needs a
// self-contained dependency tree outside the asar archive.
const corePath = app.isPackaged
? join(process.resourcesPath, 'core', 'bin', 'station.js')
: join(__dirname, '..', 'core', 'bin', 'station.js')
log.info(format('Core binary: %s', corePath))
const checkerNodePath = app.isPackaged
? join(process.resourcesPath, 'checker', 'bin', 'checker.js')
: join(__dirname, '..', 'checker', 'bin', 'checker.js')
log.info(format('Checker Node binary: %s', checkerNodePath))

const logs = new Logs()
const activities = new Activities()
Expand Down Expand Up @@ -76,24 +76,24 @@ function maybeReportErrorToSentry (err, scopeFn) {
* @param {Context} ctx
*/
async function start (ctx) {
log.info('Starting Core...')
log.info('Starting Checker...')

const childProcess = fork(
corePath,
['--json', '--recreateStationIdOnError'],
checkerNodePath,
['--json', '--recreateCheckerIdOnError'],
{
env: {
...process.env,
FIL_WALLET_ADDRESS: await wallet.getAddress(),
PASSPHRASE: await wallet.signMessage('station core passhprase'),
PASSPHRASE: await wallet.signMessage('checker node passhprase'),
CACHE_ROOT: consts.CACHE_ROOT,
STATE_ROOT: consts.STATE_ROOT,
DEPLOYMENT_TYPE: 'station-desktop'
DEPLOYMENT_TYPE: 'checker-app'
},
stdio: ['pipe', 'pipe', 'pipe', 'ipc']
}
)
log.info(format('Core pid:', childProcess.pid))
log.info(format('Checker Node pid:', childProcess.pid))

assert(childProcess.stdout)
childProcess.stdout.setEncoding('utf8')
Expand All @@ -105,12 +105,12 @@ async function start (ctx) {
try {
event = JSON.parse(line)
} catch (_err) {
const err = new Error(`Failed to parse core event: ${line}`)
const err = new Error(`Failed to parse checker node event: ${line}`)
err.cause = _err
if (!line.includes('failed to detect network')) {
Sentry.captureException(err)
}
log.error(format('Cannot parse Core stdout:', err))
log.error(format('Cannot parse Checker Node stdout:', err))
return
}
switch (event.type) {
Expand All @@ -136,7 +136,7 @@ async function start (ctx) {
}
default: {
const err = new Error(
`Unknown Station Core event type "${event.type}": ${line}`
`Unknown Station Checker Node event type "${event.type}": ${line}`
)
log.error(format(err))
Sentry.captureException(err)
Expand All @@ -161,12 +161,14 @@ async function start (ctx) {
const reason = exitSignal
? `via signal ${exitSignal}`
: `with code: ${exitCode}`
const msg = `Core exited ${reason}`
const msg = `Checker Node exited ${reason}`
log.info(msg)
const exitReason = exitSignal || exitCode ? reason : null

const [closeCode] = await onceClosed
log.info(`Core closed all stdio with code ${closeCode ?? '<no code>'}`)
log.info(
`Checker Node closed all stdio with code ${closeCode ?? '<no code>'}`
)

if (closeCode === 2) {
// FIL_WALLET_ADDRESS did not pass our screening. There is not much
Expand All @@ -175,12 +177,15 @@ async function start (ctx) {
throw new Error('Invalid Filecoin wallet address')
}

maybeReportErrorToSentry('Core exited', (/** @type {any} */ scope) => {
// Sentry UI can't show the full 100 lines
scope.setExtra('logs', logs.getLastLines(20))
scope.setExtra('reason', exitReason)
return scope
})
maybeReportErrorToSentry(
'Checker Node exited',
(/** @type {any} */ scope) => {
// Sentry UI can't show the full 100 lines
scope.setExtra('logs', logs.getLastLines(20))
scope.setExtra('reason', exitReason)
return scope
}
)
}

module.exports = {
Expand Down
10 changes: 5 additions & 5 deletions main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const { ipcMainEvents, setupIpcMain } = require('./ipc')
const { BUILD_VERSION } = require('./consts')
const { ipcMain } = require('electron/main')
const os = require('os')
const core = require('./core')
const checkerNode = require('./checker-node')
const wallet = require('./wallet')
const settings = require('./settings')
const serve = require('electron-serve')
Expand Down Expand Up @@ -99,13 +99,13 @@ app.on('second-instance', () => {

/** @type {import('./typings').Context} */
const ctx = {
getActivities: () => core.getActivities(),
getActivities: () => checkerNode.getActivities(),

recordActivity: activity => {
ipcMain.emit(ipcMainEvents.ACTIVITY_LOGGED, activity)
},

getTotalJobsCompleted: () => core.getTotalJobsCompleted(),
getTotalJobsCompleted: () => checkerNode.getTotalJobsCompleted(),
setTotalJobsCompleted: (count) => {
ipcMain.emit(
ipcMainEvents.JOB_STATS_UPDATED,
Expand Down Expand Up @@ -179,10 +179,10 @@ async function run () {

await wallet.setup(ctx)
await telemetry.setup()
await core.setup(ctx)
await checkerNode.setup(ctx)
await settings.setup(ctx)

await core.run(ctx)
await checkerNode.run(ctx)
} catch (e) {
handleError(e)
}
Expand Down
2 changes: 1 addition & 1 deletion main/station-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const log = require('electron-log').scope('config')
const ConfigKeys = {
OnboardingCompleted: 'station.OnboardingCompleted',
TrayOperationExplained: 'station.TrayOperationExplained',
StationID: 'station.StationID',
CheckerID: 'station.CheckerID',
FilAddress: 'station.FilAddress',
DestinationFilAddress: 'station.DestinationFilAddress'
}
Expand Down
6 changes: 3 additions & 3 deletions main/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { Menu, Tray, app, ipcMain, nativeImage } = require('electron')
const { ipcMainEvents } = require('./ipc')
const path = require('path')
const assert = require('node:assert')
const core = require('./core')
const checkerNode = require('./checker-node')
const { formatTokenValue } = require('./utils')

/** @typedef {import('./typings').Context} Context */
Expand Down Expand Up @@ -86,7 +86,7 @@ const createContextMenu = (/** @type {Context} */ ctx) => {
}

module.exports = async function (/** @type {Context} */ ctx) {
tray = new Tray(getTrayIcon(false, core.isOnline()))
tray = new Tray(getTrayIcon(false, checkerNode.isOnline()))

const contextMenu = createContextMenu(ctx)
tray.setToolTip('Filecoin Station')
Expand All @@ -108,7 +108,7 @@ function setupIpcEventListeners (ctx) {
function updateTray () {
assert(tray)
tray.setImage(
getTrayIcon(ctx.getUpdaterStatus().readyToUpdate, core.isOnline())
getTrayIcon(ctx.getUpdaterStatus().readyToUpdate, checkerNode.isOnline())
)
const contextMenu = createContextMenu(ctx)
tray.setContextMenu(contextMenu)
Expand Down
Loading

0 comments on commit c0b6867

Please sign in to comment.