Skip to content

Commit

Permalink
update miners command descriptions, add json to pool status (#5234)
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-if authored Aug 13, 2024
1 parent 430496f commit 7966996
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ironfish-cli/src/commands/miners/pools/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { RemoteFlags } from '../../../flags'
import { getExplorer } from '../../../utils/explorer'

export class StartPool extends IronfishCommand {
static description = `Start a mining pool that connects to a node`
static description = `start a mining pool`

static flags = {
...RemoteFlags,
Expand Down
17 changes: 13 additions & 4 deletions ironfish-cli/src/commands/miners/pools/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ import { Flags } from '@oclif/core'
import blessed from 'blessed'
import dns from 'dns'
import { IronfishCommand } from '../../../command'
import { JsonFlags } from '../../../flags'
import * as ui from '../../../ui'

export class PoolStatus extends IronfishCommand {
static description = `Show the status of a mining pool`
static description = `show the mining pool's status`
static enableJsonFlag = true

static flags = {
...JsonFlags,
address: Flags.string({
char: 'a',
description: 'The public address for which to retrieve pool share data',
Expand All @@ -41,7 +44,7 @@ export class PoolStatus extends IronfishCommand {
}),
}

async start(): Promise<void> {
async start(): Promise<unknown> {
const { flags } = await this.parse(PoolStatus)

if (flags.address && !isValidPublicAddress(flags.address)) {
Expand Down Expand Up @@ -71,11 +74,17 @@ export class PoolStatus extends IronfishCommand {
}

if (!flags.follow) {
let poolStatus
stratum.onConnected.on(() => stratum.getStatus(flags.address))
stratum.onStatus.on((status) => this.log(this.renderStatus(status)))
stratum.onStatus.on((status) => {
this.log(this.renderStatus(status))
poolStatus = status
})
stratum.start()
await waitForEmit(stratum.onStatus)
this.exit(0)
stratum.stop()

return poolStatus
}

this.logger.pauseLogs()
Expand Down
2 changes: 1 addition & 1 deletion ironfish-cli/src/commands/miners/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { IronfishCommand } from '../../command'
import { RemoteFlags } from '../../flags'

export class Miner extends IronfishCommand {
static description = `Start a miner and subscribe to new blocks for the node`
static description = `start a miner`

updateInterval: SetIntervalToken | null = null

Expand Down
12 changes: 10 additions & 2 deletions ironfish/src/mining/stratum/clients/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export abstract class StratumClient {
readonly version: number

private started: boolean
private isClosing = false
private id: number | null
private connected: boolean
private connectWarned: boolean
Expand Down Expand Up @@ -85,6 +86,10 @@ export abstract class StratumClient {
}

private async startConnecting(): Promise<void> {
if (this.isClosing) {
return
}

if (this.disconnectUntil && this.disconnectUntil > Date.now()) {
this.connectTimeout = setTimeout(() => void this.startConnecting(), 60 * 1000)
return
Expand Down Expand Up @@ -114,6 +119,7 @@ export abstract class StratumClient {
}

stop(): void {
this.isClosing = true
void this.close()

if (this.connectTimeout) {
Expand Down Expand Up @@ -191,11 +197,13 @@ export abstract class StratumClient {
}

this.logger.info(message)
} else {
} else if (!this.isClosing) {
this.logger.info('Disconnected from pool unexpectedly. Reconnecting.')
}

this.connectTimeout = setTimeout(() => void this.startConnecting(), 5000)
if (!this.isClosing) {
this.connectTimeout = setTimeout(() => void this.startConnecting(), 5000)
}
}

protected onError = (error: unknown): void => {
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/mining/stratum/clients/tcpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class StratumTcpClient extends StratumClient {

protected onSocketDisconnect = (): void => {
this.client?.off('error', this.onError)
this.client?.off('close', this.onDisconnect)
this.client?.off('close', this.onSocketDisconnect)
this.client?.off('data', this.onSocketData)
this.onDisconnect()
}
Expand Down

0 comments on commit 7966996

Please sign in to comment.