Skip to content

Commit

Permalink
Merge pull request #3546 from iron-fish/staging
Browse files Browse the repository at this point in the history
STAGING -> MASTER (02/24/23)
  • Loading branch information
ygao76 authored Feb 24, 2023
2 parents cbd402c + eebe32c commit 46295bc
Show file tree
Hide file tree
Showing 134 changed files with 10,455 additions and 8,016 deletions.
15 changes: 15 additions & 0 deletions ironfish-cli/STYLE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,18 @@ $ ironfish wallet:use
> ℹ️ Use [inquirer](https://github.com/sboudrias/Inquirer.js) to show prompts like this.
However, if prompting is required to complete a command, this means the user will not be able to script the command. Ensure that args or flags can always be provided to bypass the prompt. In this case, `ironfish wallet:use` can take in an argument for the account to set as default to skip the prompt.

## Output

### Progress

Many commands need to run long running operations. The CLI should not look like it's unresponsive. For example, `ironfish wallet:post` posts a transaction and optionally sends it to the network:

```
ironfish wallet:post 403662343137346
Posting the transaction... done
```

Use cli.action() from cli-ux to show this output. Using this component ensures that warnings and errors from the RPC are properly displayed, the spinner is displayed correctly when it is a tty, alternative output is used when not a tty, and that the spinner will work on the right platform.

Actions are displayed on stderr because they are out-of-band information on a running task.
7 changes: 4 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.68",
"version": "0.1.69",
"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 @@ -56,11 +56,12 @@
"oclif:version": "oclif readme && git add README.md"
},
"dependencies": {
"@aws-sdk/s3-request-presigner": "3.127.0",
"@aws-sdk/client-cognito-identity": "3.215.0",
"@aws-sdk/client-s3": "3.127.0",
"@aws-sdk/client-secrets-manager": "3.276.0",
"@aws-sdk/s3-request-presigner": "3.127.0",
"@ironfish/rust-nodejs": "0.1.27",
"@ironfish/sdk": "0.0.45",
"@ironfish/sdk": "0.0.46",
"@oclif/core": "1.23.1",
"@oclif/plugin-help": "5.1.12",
"@oclif/plugin-not-found": "2.3.1",
Expand Down
5 changes: 1 addition & 4 deletions ironfish-cli/src/commands/chain/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { IronfishCommand } from '../../command'
import { LocalFlags } from '../../flags'
import { SnapshotManifest } from '../../snapshot'
import { ProgressBar } from '../../types'
import { S3Utils } from '../../utils'
import { UrlUtils } from '../../utils/url'

export default class Download extends IronfishCommand {
Expand All @@ -35,9 +34,7 @@ export default class Download extends IronfishCommand {
char: 'm',
parse: (input: string) => Promise.resolve(input.trim()),
description: 'Manifest url to download snapshot from',
default: S3Utils.getDownloadUrl('ironfish-snapshots', 'manifest.json', {
accelerated: true,
}),
default: `https://snapshots.ironfish.network/manifest.json`,
}),
path: Flags.string({
char: 'p',
Expand Down
2 changes: 1 addition & 1 deletion ironfish-cli/src/commands/chain/prune.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { IronfishCommand } from '../../command'
import { LocalFlags } from '../../flags'

export default class Prune extends IronfishCommand {
static description = 'Removes old blocks from the chain'
static description = 'Remove old blocks from the chain'

static hidden = false

Expand Down
2 changes: 1 addition & 1 deletion ironfish-cli/src/commands/chain/rewind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ProgressBar } from '../../types'

export default class Rewind extends IronfishCommand {
static description =
'Rewinds the chain database to the given sequence by deleting all blocks with greater sequences'
'Rewind the chain database to the given sequence by deleting all blocks with greater sequences'

static args = [
{
Expand Down
25 changes: 19 additions & 6 deletions ironfish-cli/src/commands/fees.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/* 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 { RpcClient } from '@ironfish/sdk'
import {
DEFAULT_FEE_ESTIMATOR_MAX_BLOCK_HISTORY,
DEFAULT_FEE_ESTIMATOR_PERCENTILE_AVERAGE,
DEFAULT_FEE_ESTIMATOR_PERCENTILE_FAST,
DEFAULT_FEE_ESTIMATOR_PERCENTILE_SLOW,
RpcClient,
} from '@ironfish/sdk'
import { Flags } from '@oclif/core'
import { IronfishCommand } from '../command'
import { RemoteFlags } from '../flags'
Expand Down Expand Up @@ -37,18 +43,25 @@ export class FeeCommand extends IronfishCommand {
async explainFeeRates(client: RpcClient): Promise<void> {
const config = await client.getConfig()

const slow = config.content['feeEstimatorPercentileLow'] || '10'
const average = config.content['feeEstimatorPercentileMedium'] || '20'
const fast = config.content['feeEstimatorPercentileHigh'] || '30'
const numBlocks = config.content['feeEstimatorMaxBlockHistory'] || '10'
const slow =
config.content['feeEstimatorPercentileSlow'] || DEFAULT_FEE_ESTIMATOR_PERCENTILE_SLOW
const average =
config.content['feeEstimatorPercentileAverage'] ||
DEFAULT_FEE_ESTIMATOR_PERCENTILE_AVERAGE
const fast =
config.content['feeEstimatorPercentileFast'] || DEFAULT_FEE_ESTIMATOR_PERCENTILE_FAST
const numBlocks =
config.content['feeEstimatorMaxBlockHistory'] || DEFAULT_FEE_ESTIMATOR_MAX_BLOCK_HISTORY

this.log(
`Fee rates are estimated from the distribution of transaction fees over the last ${numBlocks} blocks.\n`,
)
this.log(
'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(
'The slow, average, and fast rates each come from a percentile in the distribution:',
)
this.log(`slow: ${slow}th`)
this.log(`average: ${average}th`)
this.log(`fast: ${fast}th`)
Expand Down
43 changes: 40 additions & 3 deletions ironfish-cli/src/commands/service/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* 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 { S3Client } from '@aws-sdk/client-s3'
import { GetSecretValueCommand, SecretsManagerClient } from '@aws-sdk/client-secrets-manager'
import { FileUtils, NodeUtils } from '@ironfish/sdk'
import { CliUx, Flags } from '@oclif/core'
import axios from 'axios'
Expand All @@ -14,8 +15,15 @@ import { SnapshotManifest } from '../../snapshot'
import { S3Utils, TarUtils } from '../../utils'

const SNAPSHOT_FILE_NAME = `ironfish_snapshot.tar.gz`
const R2_SECRET_NAME = 'r2-prod-access-key'
const R2_ENDPOINT = `https://a93bebf26da4c2fe205f71c896afcf89.r2.cloudflarestorage.com`

export default class CreateSnapshot extends IronfishCommand {
export type R2Secret = {
r2AccessKeyId: string
r2SecretAccessKey: string
}

export default class Snapshot extends IronfishCommand {
static hidden = true

static description = `Upload chain snapshot to a public bucket`
Expand Down Expand Up @@ -47,10 +55,15 @@ export default class CreateSnapshot extends IronfishCommand {
required: false,
description: 'Webhook to notify on successful snapshot upload',
}),
r2: Flags.boolean({
default: false,
allowNo: true,
description: 'Upload the snapshot to Cloudflare R2.',
}),
}

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

const bucket = flags.bucket

Expand Down Expand Up @@ -99,7 +112,31 @@ export default class CreateSnapshot extends IronfishCommand {
const snapshotBaseName = path.basename(SNAPSHOT_FILE_NAME, '.tar.gz')
const snapshotKeyName = `${snapshotBaseName}_${timestamp}.tar.gz`

const s3 = new S3Client({})
let s3 = new S3Client({})
if (flags.r2) {
const client = new SecretsManagerClient({})
const command = new GetSecretValueCommand({ SecretId: R2_SECRET_NAME })

this.log('Fetching secret from AWS Secrets Manager.')

const response = await client.send(command)

if (response.SecretString === undefined) {
this.log(`Failed to fetch R2 secret from AWS.`)
this.exit(1)
} else {
const secret = JSON.parse(response.SecretString) as R2Secret

s3 = new S3Client({
region: 'auto',
endpoint: R2_ENDPOINT,
credentials: {
accessKeyId: secret.r2AccessKeyId,
secretAccessKey: secret.r2SecretAccessKey,
},
})
}
}

CliUx.ux.action.start(`Uploading to ${bucket}`)
await S3Utils.uploadToBucket(
Expand Down
2 changes: 1 addition & 1 deletion ironfish-cli/src/commands/wallet/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class AssetsCommand extends IronfishCommand {
const assetNameWidth = flags.extended
? MAX_ASSET_NAME_COLUMN_WIDTH
: MIN_ASSET_NAME_COLUMN_WIDTH
let showHeader = true
let showHeader = !flags['no-header']

for await (const asset of response.contentStream()) {
CliUx.ux.table(
Expand Down
Loading

0 comments on commit 46295bc

Please sign in to comment.