Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ This command outputs metrics and activity events:
$ station
{
"totalJobsCompleted": 161,
"totalEarnings": "0"
"rewardsScheduledForAddress": "0"
}
[4/19/2023, 9:26:54 PM] INFO Saturn Node will try to connect to the Saturn Orchestrator...
[4/19/2023, 9:26:54 PM] INFO Saturn Node was able to connect to the Orchestrator and will now start connecting to the Saturn network...
Expand Down
1 change: 1 addition & 0 deletions lib/abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"type":"constructor","inputs":[{"internalType":"address","name":"admin","type":"address"}]},{"type":"function","name":"DEFAULT_ADMIN_ROLE","inputs":[],"outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view"},{"type":"function","name":"EVALUATE_ROLE","inputs":[],"outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view"},{"type":"function","name":"MAX_SCORE","inputs":[],"outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view"},{"type":"function","name":"addMeasurements","inputs":[{"internalType":"string","name":"cid","type":"string"}],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable"},{"type":"function","name":"adminAdvanceRound","inputs":[],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"availableBalance","inputs":[],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"function","name":"balanceHeld","inputs":[],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"function","name":"balances","inputs":[{"internalType":"address","name":"","type":"address"}],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"function","name":"currentRoundEndBlockNumber","inputs":[],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"function","name":"currentRoundIndex","inputs":[],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"function","name":"currentRoundRoundReward","inputs":[],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"function","name":"getRoleAdmin","inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view"},{"type":"function","name":"grantRole","inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"hasRole","inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view"},{"type":"function","name":"maxTransfersPerTx","inputs":[],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"function","name":"minBalanceForTransfer","inputs":[],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"function","name":"nextRoundLength","inputs":[],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"function","name":"participantCountReadyForTransfer","inputs":[],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"function","name":"participantCountScheduledForTransfer","inputs":[],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"function","name":"previousRoundIndex","inputs":[],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"function","name":"previousRoundRemainingReward","inputs":[],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"function","name":"previousRoundRoundReward","inputs":[],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"function","name":"previousRoundTotalScores","inputs":[],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"function","name":"readyForTransfer","inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view"},{"type":"function","name":"releaseRewards","inputs":[],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"renounceRole","inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"callerConfirmation","type":"address"}],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"revokeRole","inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"rewardsScheduledFor","inputs":[{"internalType":"address","name":"participant","type":"address"}],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"function","name":"roundReward","inputs":[],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"function","name":"scheduledForTransfer","inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view"},{"type":"function","name":"setMaxTransfersPerTx","inputs":[{"internalType":"uint256","name":"_maxTransfersPerTx","type":"uint256"}],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"setNextRoundLength","inputs":[{"internalType":"uint256","name":"_nextRoundLength","type":"uint256"}],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"setRoundReward","inputs":[{"internalType":"uint256","name":"_roundReward","type":"uint256"}],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"setScores","inputs":[{"internalType":"uint256","name":"roundIndex","type":"uint256"},{"internalType":"address payable[]","name":"addresses","type":"address[]"},{"internalType":"uint64[]","name":"scores","type":"uint64[]"}],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"supportsInterface","inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view"},{"type":"function","name":"tick","inputs":[],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"validateScores","inputs":[{"internalType":"uint64[]","name":"scores","type":"uint64[]"}],"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view"},{"type":"event","name":"MeasurementsAdded","inputs":[{"name":"cid","type":"string","indexed":false},{"name":"roundIndex","type":"uint256","indexed":false},{"name":"sender","type":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RoleAdminChanged","inputs":[{"name":"role","type":"bytes32","indexed":true},{"name":"previousAdminRole","type":"bytes32","indexed":true},{"name":"newAdminRole","type":"bytes32","indexed":true}],"anonymous":false},{"type":"event","name":"RoleGranted","inputs":[{"name":"role","type":"bytes32","indexed":true},{"name":"account","type":"address","indexed":true},{"name":"sender","type":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RoleRevoked","inputs":[{"name":"role","type":"bytes32","indexed":true},{"name":"account","type":"address","indexed":true},{"name":"sender","type":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RoundStart","inputs":[{"name":"roundIndex","type":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"Transfer","inputs":[{"name":"to","type":"address","indexed":true},{"name":"amount","type":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"TransferFailed","inputs":[{"name":"to","type":"address","indexed":true},{"name":"amount","type":"uint256","indexed":false}],"anonymous":false},{"type":"error","name":"AccessControlBadConfirmation","inputs":[]},{"type":"error","name":"AccessControlUnauthorizedAccount","inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"neededRole","type":"bytes32"}]},{"type":"receive"}]
2 changes: 1 addition & 1 deletion lib/bacalhau.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ async function updateStats ({ apiUrl, onMetrics }) {
'number. Is: ' + JSON.stringify(stats)
throw new Error(msg)
}
onMetrics({ totalJobsCompleted, totalEarnings: '0' })
onMetrics({ totalJobsCompleted, rewardsScheduledForAddress: '0' })
}

function noop () {
Expand Down
8 changes: 4 additions & 4 deletions lib/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export class MetricsEvent {
/**
* @param {Object} options
* @param {Number} options.totalJobsCompleted
* @param {String} options.totalEarnings
* @param {String} options.rewardsScheduledForAddress
*/
constructor ({ totalJobsCompleted, totalEarnings }) {
constructor ({ totalJobsCompleted, rewardsScheduledForAddress }) {
this.totalJobsCompleted = totalJobsCompleted
this.totalEarnings = totalEarnings
this.rewardsScheduledForAddress = rewardsScheduledForAddress
}
}

Expand Down Expand Up @@ -47,7 +47,7 @@ export class Metrics {
this.moduleMetrics.set(moduleName, metrics)
const mergedMetrics = {
totalJobsCompleted: 0,
totalEarnings: '0'
rewardsScheduledForAddress: '0'
}
for (const [, metrics] of this.moduleMetrics) {
mergedMetrics.totalJobsCompleted += metrics.totalJobsCompleted
Expand Down
101 changes: 67 additions & 34 deletions lib/zinnia.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { installBinaryModule, downloadSourceFiles, getBinaryModuleExecutable } f
import { moduleBinaries } from './paths.js'
import os from 'node:os'
import { once } from 'node:events'
import { ethers } from 'ethers'
import fs from 'node:fs/promises'
import { fileURLToPath } from 'node:url'

const ZINNIA_DIST_TAG = 'v0.14.0'
const ZINNIA_MODULES = [
Expand Down Expand Up @@ -43,6 +46,22 @@ export async function run ({
onActivity,
onMetrics
}) {
const provider = new ethers.JsonRpcProvider(
'https://api.node.glif.io/rpc/v1',
null,
{ batchMaxCount: 1 }
)
const contract = new ethers.Contract(
'0xaaef78eaf86dcf34f275288752e892424dda9341',
JSON.parse(
await fs.readFile(
fileURLToPath(new URL('./abi.json', import.meta.url)),
'utf8'
)
),
provider
)
Comment on lines +49 to +63

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it weird that it's the Zinnia module that handles querying the smart contract for scheduled rewards.

In my mind, this functionality is not specific to Zinnia (or Bacalhau or any other module) and, therefore, it belongs to Station Core itself.

What are the arguments in favour of placing this new logic here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good question! My initial reasoning was that bacalhau doesn't use this, so it doesn't belong in core, above all modules. And who knows, maybe we will even add another trusted module in the future?

Otoh, it doesn't belong into Zinnia either, because it's the module's decision whether to use Meridian. ethers might even run in Zinnia, since for this we don't need to sign messages - or we could just use the jsonrpc endpoint directly - then we only need fetch. I think for this we need a way for Zinnia modules to log metrics.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Please update our checklist for deploying the new Meridian version to remind us that we need to update this place in Station Core, too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const zinniadExe = getBinaryModuleExecutable({ module: 'zinnia', executable: 'zinniad' })
const modules = [
// all paths are relative to `moduleBinaries`
Expand All @@ -59,7 +78,16 @@ export async function run ({

childProcess.stdout.setEncoding('utf-8')
childProcess.stdout.on('data', data => {
handleEvents({ onActivity, onMetrics, text: data })
handleEvents({
contract,
FIL_WALLET_ADDRESS,
onActivity,
onMetrics,
text: data
}).catch(err => {
console.error(err)
Sentry.captureException(err)
})
})
childProcess.stderr.pipe(process.stderr, { end: false })

Expand Down Expand Up @@ -91,42 +119,47 @@ export async function run ({
])
}

function handleEvents ({ onActivity, onMetrics, text }) {
async function handleEvents ({
contract,
FIL_WALLET_ADDRESS,
onActivity,
onMetrics,
text
.trimEnd()
.split(/\n/g)
.forEach(line => {
try {
const event = JSON.parse(line)
switch (event.type) {
case 'activity:info':
onActivity({
type: 'info',
message: event.message.replace(/Module Runtime/, 'Zinnia'),
source: event.module
})
break
}) {
for (const line of text.trimEnd().split(/\n/g)) {
try {
const event = JSON.parse(line)
switch (event.type) {
case 'activity:info':
onActivity({
type: 'info',
message: event.message.replace(/Module Runtime/, 'Zinnia'),
source: event.module
})
break

case 'activity:error':
onActivity({
type: 'error',
message: event.message.replace(/Module Runtime/, 'Zinnia'),
source: event.module
})
break
case 'activity:error':
onActivity({
type: 'error',
message: event.message.replace(/Module Runtime/, 'Zinnia'),
source: event.module
})
break

case 'jobs-completed':
onMetrics({
totalJobsCompleted: event.total,
totalEarnings: '0'
})
break
case 'jobs-completed':
onMetrics({
totalJobsCompleted: event.total,
rewardsScheduledForAddress:
(await contract.rewardsScheduledFor(FIL_WALLET_ADDRESS))
.toString()
Comment thread
bajtos marked this conversation as resolved.
Resolved
})
break

default:
console.error('Ignoring Zinnia event of unknown type:', event)
}
} catch (err) {
console.error('Ignoring malformed Zinnia event:', line)
default:
console.error('Ignoring Zinnia event of unknown type:', event)
}
})
} catch (err) {
console.error('Ignoring malformed Zinnia event:', line)
}
}
}
Loading