Skip to content

Commit

Permalink
Support new foxy-farmer startup logging
Browse files Browse the repository at this point in the history
  • Loading branch information
felixbrucker committed Feb 16, 2024
1 parent 4836b47 commit 87ed5fb
Showing 1 changed file with 73 additions and 19 deletions.
92 changes: 73 additions & 19 deletions src/analyzer/startup-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {Dayjs} from 'dayjs'
import {mapFind} from '../util/map-find.js'

const chiaVersionRegex = /^chia-blockchain version: ([0-9.]+)$/
const foxyFarmerVersionRegex = /^Foxy-Farmer ([0-9.]+).*$/
const legacyFoxyFarmerVersionRegex = /^Foxy-Farmer ([0-9.]+) using config in (.+\.ya?ml)$/
const legacyFoxyFarmerHarvesterIdRegex = /^Harvester starting \(id=(\w+)\).*$/
const foxyFarmerInfoRegex = /^Foxy-Farmer version=([0-9.]+) backend=(\w+) harvester_id=(\w+) config_path=(.+\.ya?ml)$/
const foxyGhFarmerVersionRegex = /^Foxy-GH-Farmer ([0-9.]+).*$/
const startingServiceRegex = /^Starting service (\w+) \.\.\.$/
const databaseInfoRegex = /^using blockchain database (.+), which is version (\d+)$/
Expand All @@ -18,15 +20,22 @@ export interface DatabaseInfo {
version: number
}

export interface FoxyFarmerInfo {
version: string
backend: string
harvesterId?: string
configPath: string
}

export interface StartupInfo {
lastDaemonStart?: Dayjs
runningDurationInMs?: number
startedServices: string[]
chiaVersion?: string
isOgRelease: boolean
isOgPooling: boolean
foxyFarmerVersion?: string
foxyGhFarmerVersion?: string
foxyFarmerInfo?: FoxyFarmerInfo
databaseInfo?: DatabaseInfo
}

Expand Down Expand Up @@ -60,31 +69,76 @@ export function detectStartupInfo(infoLogLines: LogLine[], reversedInfoLogLines:
chiaVersion => chiaVersion !== undefined,
)

const foxyFarmerVersion = mapFind(
let foxyFarmerInfo: FoxyFarmerInfo|undefined = mapFind(
infoLogLinesSinceStartup,
logLine => {
const matches = logLine.message.match(foxyFarmerVersionRegex)
if (matches === null || matches.length !== 2) {
(logLine): FoxyFarmerInfo|undefined => {
const matches = logLine.message.match(foxyFarmerInfoRegex)
if (matches === null || matches.length !== 5) {
return
}

return matches[1]
return {
version: matches[1],
backend: matches[2],
harvesterId: matches[3],
configPath: matches[4],
}
},
foxyFarmerVersion => foxyFarmerVersion !== undefined,
)

const foxyGhFarmerVersion = mapFind(
infoLogLinesSinceStartup,
logLine => {
const matches = logLine.message.match(foxyGhFarmerVersionRegex)
if (matches === null || matches.length !== 2) {
return
if (foxyFarmerInfo === undefined) {
const legacyFoxyFarmerVersion = mapFind(
infoLogLinesSinceStartup,
logLine => {
const matches = logLine.message.match(legacyFoxyFarmerVersionRegex)
if (matches === null || matches.length !== 3) {
return
}

return {
version: matches[1],
configPath: matches[2],
}
},
foxyFarmerVersion => foxyFarmerVersion !== undefined,
)
if (legacyFoxyFarmerVersion !== undefined) {
const legacyFoxyFarmerHarvesterId = mapFind(
infoLogLinesSinceStartup,
logLine => {
const matches = logLine.message.match(legacyFoxyFarmerHarvesterIdRegex)
if (matches === null || matches.length !== 2) {
return
}

return matches[1]
},
foxyFarmerVersion => foxyFarmerVersion !== undefined,
)
foxyFarmerInfo = {
version: legacyFoxyFarmerVersion.version,
backend: 'bladebit',
harvesterId: legacyFoxyFarmerHarvesterId,
configPath: legacyFoxyFarmerVersion.configPath,
}
}
}

return matches[1]
},
foxyGhFarmerVersion => foxyGhFarmerVersion !== undefined,
)
let foxyGhFarmerVersion: string|undefined
if (foxyFarmerInfo === undefined) {
foxyGhFarmerVersion = mapFind(
infoLogLinesSinceStartup,
logLine => {
const matches = logLine.message.match(foxyGhFarmerVersionRegex)
if (matches === null || matches.length !== 2) {
return
}

return matches[1]
},
foxyGhFarmerVersion => foxyGhFarmerVersion !== undefined,
)
}

const startedServices = infoLogLines
.map(logLine => {
Expand Down Expand Up @@ -120,7 +174,7 @@ export function detectStartupInfo(infoLogLines: LogLine[], reversedInfoLogLines:
chiaVersion,
isOgRelease,
isOgPooling,
foxyFarmerVersion,
foxyFarmerInfo,
foxyGhFarmerVersion,
databaseInfo,
}
Expand Down

0 comments on commit 87ed5fb

Please sign in to comment.