Skip to content

Commit

Permalink
Merge pull request #3671 from iron-fish/staging
Browse files Browse the repository at this point in the history
STAGING -> MASTER v0.1.73
  • Loading branch information
danield9tqh authored Mar 20, 2023
2 parents 2c7f84a + 3c25cd9 commit dd7bcab
Show file tree
Hide file tree
Showing 87 changed files with 9,341 additions and 8,751 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/deploy-brew.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,13 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
BREW_GITHUB_USERNAME: ${{ secrets.BREW_GITHUB_USERNAME }}
BREW_GITHUB_TOKEN: ${{ secrets.BREW_GITHUB_TOKEN }}

- name: Deploy Ironfish CLI Brew to R2
run: ./ironfish-cli/scripts/deploy-brew.sh
env:
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
BREW_GITHUB_USERNAME: ${{ secrets.BREW_GITHUB_USERNAME }}
BREW_GITHUB_TOKEN: ${{ secrets.BREW_GITHUB_TOKEN }}
AWS_DEFAULT_REGION: auto
UPLOAD_TO_R2: true
7 changes: 7 additions & 0 deletions ironfish-cli/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ if (process.platform !== 'win32') {
require('@ironfish/rust-nodejs').initSignalHandler()
}

if (process.platform === 'win32' && process.arch === 'ia32') {
console.log(
`32-bit installations are not supported. You may have accidentally installed 32-bit Node.js. Please try reinstalling Node.js v18 (64-bit): https://nodejs.org/en/download/`,
)
process.exit(1)
}

if (process.versions.node.split('.')[0] !== '18') {
console.log(
`NodeJS version ${process.versions.node} is not compatible. Must have Node v18 installed: https://nodejs.org/en/download/`,
Expand Down
4 changes: 2 additions & 2 deletions ironfish-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ironfish",
"version": "0.1.72",
"version": "0.1.73",
"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 @@ -60,7 +60,7 @@
"@aws-sdk/client-secrets-manager": "3.276.0",
"@aws-sdk/s3-request-presigner": "3.127.0",
"@ironfish/rust-nodejs": "0.1.29",
"@ironfish/sdk": "0.0.49",
"@ironfish/sdk": "0.0.50",
"@oclif/core": "1.23.1",
"@oclif/plugin-help": "5.1.12",
"@oclif/plugin-not-found": "2.3.1",
Expand Down
27 changes: 22 additions & 5 deletions ironfish-cli/scripts/deploy-brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ UPLOAD_HASH=$(shasum -a 256 $SOURCE_PATH | awk '{print $1}')

UPLOAD_NAME=ironfish-cli-$GIT_HASH.tar.gz
UPLOAD_URL=s3://ironfish-cli/$UPLOAD_NAME
PUBLIC_URL=https://ironfish-cli.s3.amazonaws.com/$UPLOAD_NAME

if [ -z "${UPLOAD_TO_R2-}" ];
then
PUBLIC_URL=https://ironfish-cli.s3.amazonaws.com/$UPLOAD_NAME
else
PUBLIC_URL=https://releases.ironfish.network/$UPLOAD_NAME
fi

echo ""
echo "GIT HASH: $GIT_HASH"
Expand All @@ -38,13 +44,24 @@ echo "UPLOAD URL: $UPLOAD_URL"
echo "PUBLIC URL: $PUBLIC_URL"
echo ""

if aws s3api head-object --bucket ironfish-cli --key $UPLOAD_NAME > /dev/null 2>&1 ; then
if [ -z "${UPLOAD_TO_R2-}" ];
then
if aws s3api head-object --bucket ironfish-cli --key $UPLOAD_NAME > /dev/null 2>&1 ; then
echo "Release already uploaded: $PUBLIC_URL"
exit 1
fi
fi

echo "Uploading $SOURCE_NAME to $UPLOAD_URL"
aws s3 cp $SOURCE_PATH $UPLOAD_URL
echo "Uploading $SOURCE_NAME to $UPLOAD_URL"
aws s3 cp $SOURCE_PATH $UPLOAD_URL
else
if aws s3api head-object --bucket ironfish-cli --endpoint-url https://a93bebf26da4c2fe205f71c896afcf89.r2.cloudflarestorage.com --key $UPLOAD_NAME > /dev/null 2>&1 ; then
echo "Release already uploaded: $PUBLIC_URL"
exit 1
fi

echo "Uploading $SOURCE_NAME to $UPLOAD_URL"
aws s3 cp $SOURCE_PATH $UPLOAD_URL --endpoint-url https://a93bebf26da4c2fe205f71c896afcf89.r2.cloudflarestorage.com
fi

echo ""
echo "You are almost finished! To finish the process you need to update update url and sha256 in"
Expand Down
25 changes: 25 additions & 0 deletions ironfish-cli/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ import {
ConfigFlagKey,
DataDirFlagKey,
RpcAuthFlagKey,
RpcHttpHostFlagKey,
RpcHttpPortFlagKey,
RpcTcpHostFlagKey,
RpcTcpPortFlagKey,
RpcTcpTlsFlag,
RpcTcpTlsFlagKey,
RpcUseHttpFlag,
RpcUseHttpFlagKey,
RpcUseIpcFlag,
RpcUseIpcFlagKey,
RpcUseTcpFlag,
Expand All @@ -40,6 +44,9 @@ export type FLAGS =
| typeof RpcUseTcpFlagKey
| typeof RpcTcpHostFlagKey
| typeof RpcTcpPortFlagKey
| typeof RpcUseHttpFlagKey
| typeof RpcHttpHostFlagKey
| typeof RpcHttpPortFlagKey
| typeof RpcTcpTlsFlagKey
| typeof VerboseFlagKey
| typeof RpcAuthFlagKey
Expand Down Expand Up @@ -132,6 +139,24 @@ export abstract class IronfishCommand extends Command {
configOverrides.rpcTcpPort = rpcTcpPortFlag
}

const rpcConnectHttpFlag = getFlag(flags, RpcUseHttpFlagKey)
if (
typeof rpcConnectHttpFlag === 'boolean' &&
rpcConnectHttpFlag !== RpcUseHttpFlag.default
) {
configOverrides.enableRpcHttp = rpcConnectHttpFlag
}

const rpcHttpHostFlag = getFlag(flags, RpcHttpHostFlagKey)
if (typeof rpcHttpHostFlag === 'string') {
configOverrides.rpcHttpHost = rpcHttpHostFlag
}

const rpcHttpPortFlag = getFlag(flags, RpcHttpPortFlagKey)
if (typeof rpcHttpPortFlag === 'number') {
configOverrides.rpcHttpPort = rpcHttpPortFlag
}

const rpcTcpTlsFlag = getFlag(flags, RpcTcpTlsFlagKey)
if (typeof rpcTcpTlsFlag === 'boolean' && rpcTcpTlsFlag !== RpcTcpTlsFlag.default) {
configOverrides.enableRpcTls = rpcTcpTlsFlag
Expand Down
7 changes: 0 additions & 7 deletions ironfish-cli/src/commands/ceremony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ export default class Ceremony extends IronfishCommand {
let refreshEtaInterval: NodeJS.Timeout | null = null
let etaDate: Date | null = null

// Trusted setup has ended but this command may still be needed in case of future
// setups / network upgrades. So for now, just exit the command with some information
this.log(
`The trusted setup ceremony was completed on Mar 3, 2023. For more information on the trusted setup process and its completion please read https://setup.ironfish.network.`,
)
this.exit(0)

// Prompt for randomness
let randomness: string | null = await CliUx.ux.prompt(
`If you'd like to contribute your own randomness to the ceremony, type it here, then press Enter. For more information on where this should come from and its importance, please read https://setup.ironfish.network. If you'd like the command to generate some randomness for you, just press Enter`,
Expand Down
28 changes: 7 additions & 21 deletions ironfish-cli/src/commands/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,20 @@ export default class Reset extends IronfishCommand {
async start(): Promise<void> {
const { flags } = await this.parse(Reset)

let confirmed = flags.confirm

const warningMessage =
`\n/!\\ WARNING: This will permanently delete your wallets. You can back them up by loading the previous version of ironfish and running ironfish export. /!\\\n` +
'\nHave you read the warning? (Y)es / (N)o'

confirmed = flags.confirm || (await CliUx.ux.confirm(warningMessage))

if (!confirmed) {
this.log('Reset aborted.')
this.exit(0)
}

this.sdk.internal.set('networkId', this.sdk.config.defaults.networkId)
this.sdk.internal.set('isFirstRun', true)
await this.sdk.internal.save()
const walletDatabasePath = this.sdk.config.walletDatabasePath
const chainDatabasePath = this.sdk.config.chainDatabasePath
const hostFilePath: string = this.sdk.config.files.join(
this.sdk.config.dataDir,
HOST_FILE_NAME,
)

const message =
'\nYou are about to destroy your node databases. The following directories and files will be deleted:\n' +
`\nWallet: ${walletDatabasePath}` +
'\nYou are about to destroy your local copy of the blockchain. The following directories and files will be deleted:\n' +
`\nBlockchain: ${chainDatabasePath}` +
`\nHosts: ${hostFilePath}` +
'\nYour wallet, accounts, and keys will NOT be deleted.' +
`\n\nAre you sure? (Y)es / (N)o`

confirmed = flags.confirm || (await CliUx.ux.confirm(message))
const confirmed = flags.confirm || (await CliUx.ux.confirm(message))

if (!confirmed) {
this.log('Reset aborted.')
Expand All @@ -72,11 +55,14 @@ export default class Reset extends IronfishCommand {
CliUx.ux.action.start('Deleting databases...')

await Promise.all([
fsAsync.rm(walletDatabasePath, { recursive: true, force: true }),
fsAsync.rm(chainDatabasePath, { recursive: true, force: true }),
fsAsync.rm(hostFilePath, { recursive: true, force: true }),
])

this.sdk.internal.set('networkId', this.sdk.config.defaults.networkId)
this.sdk.internal.set('isFirstRun', true)
await this.sdk.internal.save()

CliUx.ux.action.stop('Databases deleted successfully')
}
}
23 changes: 20 additions & 3 deletions ironfish-cli/src/commands/service/ceremony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { S3Utils } from '../../utils'
const CONTRIBUTE_TIMEOUT_MS = 5 * 60 * 1000
const UPLOAD_TIMEOUT_MS = 5 * 60 * 1000
const PRESIGNED_EXPIRATION_SEC = 5 * 60
const START_DATE = 1676318400000 // Mon Feb 13 2023 12:00:00 GMT-0800 (Pacific Standard Time)
const START_DATE = 1681146000000 // Monday, April 10, 2023 10:00:00 AM GMT-07:00 (Pacific Daylight Time)

export default class Ceremony extends IronfishCommand {
static hidden = true
Expand All @@ -29,6 +29,14 @@ export default class Ceremony extends IronfishCommand {
description: 'S3 bucket to download and upload params to',
default: 'ironfish-contributions',
}),
downloadPrefix: Flags.string({
char: 'b',
parse: (input: string) => Promise.resolve(input.trim()),
required: false,
description: 'Prefix for contribution download URLs',
// TODO: update this to non-dev endpoint to avoid rate limiting
default: 'https://pub-6a239e04e140459087cf392ffc3245b1.r2.dev',
}),
contributionTimeoutMs: Flags.integer({
required: false,
description: 'Allowable milliseconds for a contributor to run the contribution script',
Expand Down Expand Up @@ -65,7 +73,15 @@ export default class Ceremony extends IronfishCommand {
const DEFAULT_HOST = '0.0.0.0'
const DEFAULT_PORT = 9040

const s3Client = S3Utils.getS3Client(true)
const r2Credentials = await S3Utils.getR2Credentials()

if (r2Credentials === undefined) {
this.logger.log('Failed getting R2 credentials from AWS')
this.exit(0)
return
}

const r2Client = S3Utils.getR2S3Client(r2Credentials)

setLogPrefixFromConfig(`[%tag%]`)

Expand All @@ -74,7 +90,8 @@ export default class Ceremony extends IronfishCommand {
port: DEFAULT_PORT,
host: DEFAULT_HOST,
s3Bucket: flags.bucket,
s3Client: s3Client,
downloadPrefix: flags.downloadPrefix,
s3Client: r2Client,
tempDir: this.sdk.config.tempDir,
contributionTimeoutMs: flags.contributionTimeoutMs,
uploadTimeoutMs: flags.uploadTimeoutMs,
Expand Down
28 changes: 6 additions & 22 deletions ironfish-cli/src/commands/service/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* 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 @@ -15,8 +14,6 @@ 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 type R2Secret = {
r2AccessKeyId: string
Expand Down Expand Up @@ -114,28 +111,15 @@ export default class Snapshot extends IronfishCommand {

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

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.`)
if (r2Credentials === undefined) {
this.logger.log('Failed getting R2 credentials 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,
},
})
return
}

s3 = S3Utils.getR2S3Client(r2Credentials)
}

CliUx.ux.action.start(`Uploading to ${bucket}`)
Expand Down
6 changes: 6 additions & 0 deletions ironfish-cli/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import {
ConfigFlagKey,
DataDirFlag,
DataDirFlagKey,
RpcHttpHostFlag,
RpcHttpHostFlagKey,
RpcHttpPortFlag,
RpcHttpPortFlagKey,
RpcTcpHostFlag,
RpcTcpHostFlagKey,
RpcTcpPortFlag,
Expand Down Expand Up @@ -42,6 +46,8 @@ export default class Start extends IronfishCommand {
[RpcTcpTlsFlagKey]: RpcTcpTlsFlag,
[RpcTcpHostFlagKey]: RpcTcpHostFlag,
[RpcTcpPortFlagKey]: RpcTcpPortFlag,
[RpcHttpHostFlagKey]: RpcHttpHostFlag,
[RpcHttpPortFlagKey]: RpcHttpPortFlag,
bootstrap: Flags.string({
char: 'b',
description: 'Comma-separated addresses of bootstrap nodes to connect to',
Expand Down
14 changes: 7 additions & 7 deletions ironfish-cli/src/commands/stop.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* 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 { IronfishNode, RpcConnectionError } from '@ironfish/sdk'
import { IronfishNode } from '@ironfish/sdk'
import { CliUx } from '@oclif/core'
import { IronfishCommand } from '../command'
import { RemoteFlags } from '../flags'

Expand All @@ -17,13 +18,12 @@ export default class StopCommand extends IronfishCommand {
async start(): Promise<void> {
await this.parse(StopCommand)

await this.sdk.client.connect().catch((e) => {
if (e instanceof RpcConnectionError) {
this.exit(0)
}
throw e
})
await this.sdk.client.connect()

CliUx.ux.action.start('Asking node to shut down...')

await this.sdk.client.stopNode()

CliUx.ux.action.stop('done.')
}
}
Loading

0 comments on commit dd7bcab

Please sign in to comment.