Skip to content

Commit

Permalink
Merge pull request #3364 from iron-fish/staging
Browse files Browse the repository at this point in the history
STAGING -> MASTER (2023-02-09)
  • Loading branch information
NullSoldier authored Feb 9, 2023
2 parents f3fdfa1 + e167eb2 commit 12abe5b
Show file tree
Hide file tree
Showing 130 changed files with 5,775 additions and 1,398 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Node.js CI
on:
pull_request:
branches:
- '*'
- '**'
push:
branches:
- master
Expand Down
6 changes: 3 additions & 3 deletions ironfish-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ironfish",
"version": "0.1.65",
"version": "0.1.66",
"description": "CLI for running and interacting with an Iron Fish node",
"author": "Iron Fish <[email protected]> (https://ironfish.network)",
"main": "build/src/index.js",
Expand Down Expand Up @@ -59,8 +59,8 @@
"@aws-sdk/s3-request-presigner": "3.127.0",
"@aws-sdk/client-cognito-identity": "3.215.0",
"@aws-sdk/client-s3": "3.127.0",
"@ironfish/rust-nodejs": "0.1.25",
"@ironfish/sdk": "0.0.42",
"@ironfish/rust-nodejs": "0.1.26",
"@ironfish/sdk": "0.0.43",
"@oclif/core": "1.23.1",
"@oclif/plugin-help": "5.1.12",
"@oclif/plugin-not-found": "2.3.1",
Expand Down
51 changes: 51 additions & 0 deletions ironfish-cli/src/commands/chain/power.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { FileUtils } from '@ironfish/sdk'
import { parseNumber } from '../../args'
import { IronfishCommand } from '../../command'
import { LocalFlags } from '../../flags'

export default class Power extends IronfishCommand {
static description = "Show the network's hash power (hash/s)"

static flags = {
...LocalFlags,
}

static args = [
{
name: 'blocks',
parse: (input: string): Promise<number | null> => Promise.resolve(parseNumber(input)),
required: false,
description:
'The number of blocks to look back to calculate the power. This value must be > 0',
},
{
name: 'sequence',
parse: (input: string): Promise<number | null> => Promise.resolve(parseNumber(input)),
required: false,
description: 'The sequence of the latest block from when to estimate network speed ',
},
]

async start(): Promise<void> {
const { args } = await this.parse(Power)
const inputBlocks = args.blocks as number | null | undefined
const inputSequence = args.sequence as number | null | undefined

await this.sdk.client.connect()

const data = await this.sdk.client.getNetworkHashPower({
blocks: inputBlocks,
sequence: inputSequence,
})

const { hashesPerSecond, blocks, sequence } = data.content
const formattedHashesPerSecond = FileUtils.formatHashRate(hashesPerSecond)

this.log(
`The network power for block ${sequence} was ${formattedHashesPerSecond} averaged over ${blocks} previous blocks.`,
)
}
}
18 changes: 9 additions & 9 deletions ironfish-cli/src/commands/fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ export class FeeCommand extends IronfishCommand {
const feeRates = await client.estimateFeeRates()

this.log('Fee Rates ($ORE/kB)')
this.log(`low: ${feeRates.content.low || ''}`)
this.log(`medium: ${feeRates.content.medium || ''}`)
this.log(`high: ${feeRates.content.high || ''}`)
this.log(`slow: ${feeRates.content.slow || ''}`)
this.log(`average: ${feeRates.content.average || ''}`)
this.log(`fast: ${feeRates.content.fast || ''}`)
}

async explainFeeRates(client: RpcClient): Promise<void> {
const config = await client.getConfig()

const low = config.content['feeEstimatorPercentileLow'] || '10'
const medium = config.content['feeEstimatorPercentileMedium'] || '20'
const high = config.content['feeEstimatorPercentileHigh'] || '30'
const slow = config.content['feeEstimatorPercentileLow'] || '10'
const average = config.content['feeEstimatorPercentileMedium'] || '20'
const fast = config.content['feeEstimatorPercentileHigh'] || '30'
const numBlocks = config.content['feeEstimatorMaxBlockHistory'] || '10'

this.log(
Expand All @@ -49,9 +49,9 @@ export class FeeCommand extends IronfishCommand {
'The fee rate for each transaction is computed by dividing the transaction fee in $ORE by the size of the transaction in kB.\n',
)
this.log('The low, medium, and high rates each come from a percentile in the distribution:')
this.log(`low: ${low}th`)
this.log(`medium: ${medium}th`)
this.log(`high: ${high}th`)
this.log(`slow: ${slow}th`)
this.log(`average: ${average}th`)
this.log(`fast: ${fast}th`)
this.log('')
}
}
32 changes: 28 additions & 4 deletions ironfish-cli/src/commands/miners/pools/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
MiningPool,
parseUrl,
StringUtils,
TlsUtils,
WebhookNotifier,
} from '@ironfish/sdk'
import { Flags } from '@oclif/core'
Expand Down Expand Up @@ -39,13 +40,14 @@ export class StartPool extends IronfishCommand {
allowNo: true,
description: 'Whether the pool should payout or not. Useful for solo miners',
}),
balancePercentPayout: Flags.integer({
description: 'Whether the pool should payout or not. Useful for solo miners',
}),
banning: Flags.boolean({
description: 'Whether the pool should ban peers for errors or bad behavior',
allowNo: true,
}),
tls: Flags.boolean({
description: 'Whether the pool should listen for connections over tls',
allowNo: true,
}),
}

pool: MiningPool | null = null
Expand Down Expand Up @@ -112,6 +114,27 @@ export class StartPool extends IronfishCommand {
}
}

if (!host) {
host = this.sdk.config.get('poolHost')
}

if (!port) {
port = this.sdk.config.get('poolPort')
}

let tlsOptions = undefined
if (flags.tls) {
const fileSystem = this.sdk.fileSystem
const nodeKeyPath = this.sdk.config.get('tlsKeyPath')
const nodeCertPath = this.sdk.config.get('tlsCertPath')
tlsOptions = await TlsUtils.getTlsOptions(
fileSystem,
nodeKeyPath,
nodeCertPath,
this.logger,
)
}

this.pool = await MiningPool.init({
config: this.sdk.config,
logger: this.logger,
Expand All @@ -120,8 +143,9 @@ export class StartPool extends IronfishCommand {
webhooks: webhooks,
host: host,
port: port,
balancePercentPayoutFlag: flags.balancePercentPayout,
banning: flags.banning,
tls: flags.tls,
tlsOptions: tlsOptions,
})

await this.pool.start()
Expand Down
18 changes: 12 additions & 6 deletions ironfish-cli/src/commands/miners/pools/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import {
createRootLogger,
FileUtils,
isValidPublicAddress,
MiningStatusMessage,
parseUrl,
PromiseUtils,
StratumClient,
StratumTcpClient,
StratumTlsClient,
waitForEmit,
} from '@ironfish/sdk'
import { Flags } from '@oclif/core'
Expand All @@ -33,6 +34,10 @@ export class PoolStatus extends IronfishCommand {
default: false,
description: 'Follow the status of the mining pool',
}),
tls: Flags.boolean({
description: 'Connect to pool over tls',
allowNo: true,
}),
}

async start(): Promise<void> {
Expand All @@ -57,11 +62,12 @@ export class PoolStatus extends IronfishCommand {
}
}

const stratum = new StratumClient({
host: host,
port: port,
logger: createRootLogger(),
})
let stratum: StratumClient
if (flags.tls) {
stratum = new StratumTlsClient({ host, port, logger: this.logger })
} else {
stratum = new StratumTcpClient({ host, port, logger: this.logger })
}

if (!flags.follow) {
stratum.onConnected.on(() => stratum.getStatus(flags.address))
Expand Down
16 changes: 14 additions & 2 deletions ironfish-cli/src/commands/miners/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
MiningSoloMiner,
parseUrl,
SetIntervalToken,
StratumTcpClient,
StratumTlsClient,
} from '@ironfish/sdk'
import { CliUx, Flags } from '@oclif/core'
import dns from 'dns'
Expand Down Expand Up @@ -46,6 +48,10 @@ export class Miner extends IronfishCommand {
allowNo: true,
description: 'Enable fancy hashpower display',
}),
tls: Flags.boolean({
description: 'Connect to pool over tls',
allowNo: true,
}),
}

async start(): Promise<void> {
Expand Down Expand Up @@ -99,13 +105,19 @@ export class Miner extends IronfishCommand {
`Starting to mine with public address: ${publicAddress} at pool ${host}:${port}${nameInfo}`,
)

let stratum
if (flags.tls) {
stratum = new StratumTlsClient({ host, port, logger: this.logger })
} else {
stratum = new StratumTcpClient({ host, port, logger: this.logger })
}

const miner = new MiningPoolMiner({
threadCount: flags.threads,
publicAddress,
logger: this.logger,
batchSize,
host: host,
port: port,
stratum,
name: flags.name,
})

Expand Down
89 changes: 89 additions & 0 deletions ironfish-cli/src/commands/peers/banned.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { BannedPeerResponse, GetBannedPeersResponse, PromiseUtils } from '@ironfish/sdk'
import { CliUx, Flags } from '@oclif/core'
import blessed from 'blessed'
import { IronfishCommand } from '../../command'
import { RemoteFlags } from '../../flags'

const tableFlags = CliUx.ux.table.flags()

export class BannedCommand extends IronfishCommand {
static description = `List all banned peers`

static flags = {
...RemoteFlags,
...tableFlags,
follow: Flags.boolean({
char: 'f',
default: false,
description: 'Follow the banned peers list live',
}),
}

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

if (!flags.follow) {
await this.sdk.client.connect()
const response = await this.sdk.client.getBannedPeers()
this.log(renderTable(response.content))
this.exit(0)
}

// Console log will create display issues with Blessed
this.logger.pauseLogs()

const screen = blessed.screen({ smartCSR: true, fullUnicode: true })
const text = blessed.text()
screen.append(text)

// eslint-disable-next-line no-constant-condition
while (true) {
const connected = await this.sdk.client.tryConnect()
if (!connected) {
text.clearBaseLine(0)
text.setContent('Connecting...')
screen.render()
await PromiseUtils.sleep(1000)
continue
}

const response = this.sdk.client.getBannedPeersStream()

for await (const value of response.contentStream()) {
text.clearBaseLine(0)
text.setContent(renderTable(value))
screen.render()
}
}
}
}

function renderTable(content: GetBannedPeersResponse): string {
const columns: CliUx.Table.table.Columns<BannedPeerResponse> = {
identity: {
minWidth: 45,
header: 'IDENTITY',
get: (row) => {
return row.identity
},
},
reason: {
minWidth: 15,
header: 'BAN REASON',
get: (row) => {
return row.reason
},
},
}

let result = ''

CliUx.ux.table(content.peers, columns, {
printLine: (line) => (result += `${String(line)}\n`),
})

return result
}
Loading

0 comments on commit 12abe5b

Please sign in to comment.