Skip to content

Commit

Permalink
Merge pull request #3286 from iron-fish/staging
Browse files Browse the repository at this point in the history
  • Loading branch information
danield9tqh authored Feb 3, 2023
2 parents 693ff0f + 3758032 commit aaba8cb
Show file tree
Hide file tree
Showing 116 changed files with 4,807 additions and 560 deletions.
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Pull requests are the best way to propose a new change to the codebase.
- Fork the repo
- Create a branch from `staging`
- Find or create one or more issues that your change will fix, using our [new issue form](https://github.com/iron-fish/ironfish/issues/new/choose).
- ALL pull requests must refence a verified issue. If the issue is not verified, that has to happen before the PR is reviewed.
- ALL pull requests must reference a verified issue. If the issue is not verified, that has to happen before the PR is reviewed.
- Note that team members looking at a PR will try to verify any issues referenced before doing the review. As long as the issue is solid, this should be a fast process!
- Open a pull request against `staging`

Expand All @@ -35,7 +35,7 @@ Once the PR is created, one of the maintainers will review it and merge it. Refe
Please read our [README.md](./README.md) first, to learn how to set up Iron Fish.

If you don't know what contribution you can work on, here are a few suggestions:
- Start with our list of "good first issues", which can be [found here](https://github.com/iron-fish/ironfish/contribute), or take a look at our current [list of verified issues](https://github.com/iron-fish/ironfish/issues?q=is%3Aopen+is%3Aissue+label%3Averified).
- Start with our list of "good first issues", which can be [found here](https://github.com/iron-fish/ironfish/contribute), or take a look at our current [list of verified issues](https://github.com/iron-fish/ironfish/issues?q=is%3Aopen+is%3Aissue+label%3Averified).
- Claim the issue if you are interested in working on it.
- Take a look at our current [pull requests](https://github.com/iron-fish/ironfish/pulls) and help review them.
- Help us add new tests. More testing allows everyone to ship quality code faster.
Expand All @@ -44,7 +44,7 @@ If you don't know what contribution you can work on, here are a few suggestions:

# Feature Request

The purpose of a Feature Request is to explain an improvement you would like to make to Iron Fish, and get consensus from the core development team of Iron Fish. The reason is that we want to make sure your change fits inside of the product vision, and that you don't try to fix a bug in a piece of code already being refactored.
The purpose of a Feature Request is to explain an improvement you would like to make to Iron Fish and get consensus from the core development team of Iron Fish. The reason is that we want to make sure your change fits inside of the product vision and that you don't try to fix a bug in a piece of code already being refactored.

You can submit a Feature Request by filing an issue here: https://github.com/iron-fish/ironfish/issues/new/choose

Expand All @@ -53,11 +53,11 @@ You can submit a Feature Request by filing an issue here: https://github.com/iro
If you are working on something in one of these categories, we will not accept your PR if you don't open a Feature Request.

- #### Upgrading Package Versions
- This is a common attack vector by malicious agents. We lock down our packages for this very reason, and only allow the core team to upgrade packages unless you submit a Feature Request first explaining why you want to upgrade the package.
- This is a common attack vector by malicious agents. We lock down our packages for this very reason and only allow the core team to upgrade packages unless you submit a Feature Request first explaining why you want to upgrade the package.
- #### Upgrading Node Versions
- There is a large impact in upgrading node versions. Iron Fish takes advantage of many experimental node features, some of which are not fully fleshed out. We use workers and native code boundaries. Node is also known to introduce bugs in newer versions, even LTS. Because of this, there is production testing we do on our side when upgrading node to ensure it's compatible. Because of this, we don't allow users to upgrade our node versions unless a Feature Request is filed.
- #### Refactor a core system
- Often engineers have visions for core systems, and may be in the process of changing them. Feature Requests help avoid overlap and having your changes overwritten. Some core systems include: MerkleTree, Blockchain, PeerNetwork, Verifier, and Consensus.
- Often engineers have visions for core systems and they may be in the process of changing them. Feature Requests help avoid overlap and having your changes overwritten. Some core systems include: MerkleTree, Blockchain, PeerNetwork, Verifier, and Consensus.
- #### Making new product design decisions that have no precedent
- This one is more complicated. If our product works one way, and you open a PR to change the core product principles to work in another way, then we are going to close your PR as it does not fit into our vision. Try to match existing precedent as much as possible in your code.
- #### Tests for CLI commands
Expand Down
4 changes: 0 additions & 4 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ flags:
paths:
- ironfish-rust
carryforward: true
ironfish-cli:
paths:
- ironfish-cli
carryforward: true
ironfish:
paths:
- ironfish
Expand Down
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.63",
"version": "0.1.64",
"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,13 +59,14 @@
"@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.24",
"@ironfish/sdk": "0.0.40",
"@ironfish/rust-nodejs": "0.1.25",
"@ironfish/sdk": "0.0.41",
"@oclif/core": "1.23.1",
"@oclif/plugin-help": "5.1.12",
"@oclif/plugin-not-found": "2.3.1",
"@types/tar": "6.1.1",
"axios": "0.21.4",
"bech32": "2.0.0",
"blessed": "0.1.81",
"blru": "0.1.6",
"buffer-map": "0.0.7",
Expand Down
4 changes: 4 additions & 0 deletions ironfish-cli/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export abstract class IronfishCommand extends Command {
} catch (error: unknown) {
if (hasUserResponseError(error)) {
this.log(error.codeMessage)

if (error.codeStack) {
this.sdk.logger.debug(error.codeStack)
}
} else if (error instanceof ExitError) {
throw error
} else if (error instanceof CLIError) {
Expand Down
58 changes: 50 additions & 8 deletions ironfish-cli/src/commands/ceremony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +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 { contribute } from '@ironfish/rust-nodejs'
import { ErrorUtils, PromiseUtils } from '@ironfish/sdk'
import { ErrorUtils, PromiseUtils, TimeUtils } from '@ironfish/sdk'
import { CliUx, Flags } from '@oclif/core'
import axios from 'axios'
import fsAsync from 'fs/promises'
Expand All @@ -20,13 +20,16 @@ export default class Ceremony extends IronfishCommand {
[DataDirFlagKey]: DataDirFlag,
host: Flags.string({
parse: (input: string) => Promise.resolve(input.trim()),
default: 'https://ceremony.ironfish.network',
default: 'ceremony.ironfish.network',
description: 'Host address of the ceremony coordination server',
}),
port: Flags.integer({
default: 9040,
description: 'Port of the ceremony coordination server',
}),
token: Flags.string({
required: false,
}),
}

async start(): Promise<void> {
Expand All @@ -41,27 +44,44 @@ export default class Ceremony extends IronfishCommand {
const outputPath = path.join(tempDir, 'newParams')

let localHash: string | null = null
let refreshEtaInterval: NodeJS.Timeout | null = null
let etaDate: Date | null = null

// Prompt for randomness
let randomness: string | null = await CliUx.ux.prompt(
'Provide some randomness to contribute to the ceremony. If none is provided, it will automatically be generated for you (press enter)',
`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`,
{ required: false },
)
randomness = randomness.length ? randomness : null

const name = await CliUx.ux.prompt(
`If you'd like to associate a name with this contribution, type it here, then press Enter. Otherwise, to contribute anonymously, just press Enter`,
{ required: false },
)

// Create the client and bind events
const client = new CeremonyClient({
host,
port,
logger: this.logger.withTag('ceremonyClient'),
})

client.onJoined.on(({ queueLocation }) => {
client.onJoined.on(({ queueLocation, estimate }) => {
refreshEtaInterval && clearInterval(refreshEtaInterval)

etaDate = new Date(Date.now() + estimate)

CliUx.ux.action.status = renderStatus(queueLocation, etaDate)
refreshEtaInterval = setInterval(() => {
CliUx.ux.action.status = renderStatus(queueLocation, etaDate)
}, 10 * 1000)

CliUx.ux.action.status = `Current position: ${queueLocation}`
})

client.onInitiateContribution.on(async ({ downloadLink, contributionNumber }) => {
CliUx.ux.action.stop()
refreshEtaInterval && clearInterval(refreshEtaInterval)

this.log(`Starting contribution. You are contributor #${contributionNumber}`)

Expand Down Expand Up @@ -98,6 +118,7 @@ export default class Ceremony extends IronfishCommand {

client.onInitiateUpload.on(async ({ uploadLink }) => {
CliUx.ux.action.stop()
refreshEtaInterval && clearInterval(refreshEtaInterval)

CliUx.ux.action.start(`Uploading your contribution`)

Expand Down Expand Up @@ -126,6 +147,7 @@ export default class Ceremony extends IronfishCommand {

client.onContributionVerified.on(({ hash, downloadLink, contributionNumber }) => {
CliUx.ux.action.stop()
refreshEtaInterval && clearInterval(refreshEtaInterval)

if (!localHash) {
this.log(
Expand Down Expand Up @@ -155,23 +177,35 @@ export default class Ceremony extends IronfishCommand {
this.exit(0)
})

client.onStopRetry.on(({ error }) => {
CliUx.ux.action.stop()
refreshEtaInterval && clearInterval(refreshEtaInterval)

this.log(`Stopping contribution: ${error}`)

client.stop(true)
})

// Retry connection until contributions are received
let connected = false
while (!connected) {
CliUx.ux.action.start('Connecting')
connected = await client.start()
CliUx.ux.action.stop(connected ? 'done' : 'error')
const error = await client.start()
connected = error === null
CliUx.ux.action.stop(error ? `Error connecting: ${error}` : 'done')

if (!connected) {
this.log('Unable to connect to contribution server. Retrying in 5 seconds.')
await PromiseUtils.sleep(5000)
continue
}

client.join(name, flags.token)

CliUx.ux.action.start('Waiting to contribute', undefined, { stdout: true })

const result = await client.waitForStop()
connected = result.success
connected = result.stopRetries

if (!connected) {
if (CliUx.ux.action.running) {
Expand All @@ -186,9 +220,17 @@ export default class Ceremony extends IronfishCommand {
}
}

const renderStatus = (queueLocation: number, etaDate: Date | null): string => {
return `Current position: ${queueLocation} ${
etaDate
? `(Estimated time remaining: ${TimeUtils.renderSpan(etaDate.getTime() - Date.now())})`
: ''
}`
}

const display256CharacterHash = (hash: string): string => {
// split string every 8 characters
let slices = hash.match(/.{1,8}/g) ?? []
let slices: string[] = hash.match(/.{1,8}/g) ?? []

const output = []
for (let i = 0; i < 4; i++) {
Expand Down
2 changes: 1 addition & 1 deletion ironfish-cli/src/commands/chain/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class Asset extends IronfishCommand {

static args = [
{
name: 'identifier',
name: 'id',
parse: (input: string): Promise<string> => Promise.resolve(input.trim()),
required: true,
description: 'The identifier of the asset',
Expand Down
26 changes: 6 additions & 20 deletions ironfish-cli/src/commands/peers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ import { CliUx, Flags } from '@oclif/core'
import blessed from 'blessed'
import { IronfishCommand } from '../../command'
import { RemoteFlags } from '../../flags'
import { CommandFlags } from '../../types'

type GetPeerResponsePeer = GetPeersResponse['peers'][0]

const STATE_COLUMN_HEADER = 'STATE'
const tableFlags = CliUx.ux.table.flags()
tableFlags.sort.default = STATE_COLUMN_HEADER

export class ListCommand extends IronfishCommand {
static description = `List all connected peers`

static flags = {
...RemoteFlags,
...tableFlags,
follow: Flags.boolean({
char: 'f',
default: false,
Expand All @@ -25,16 +29,6 @@ export class ListCommand extends IronfishCommand {
default: false,
description: 'Show all peers, not just connected peers',
}),
extended: Flags.boolean({
char: 'e',
default: false,
description: 'Display all information',
}),
sort: Flags.string({
char: 'o',
default: STATE_COLUMN_HEADER,
description: 'Sort by column header',
}),
agents: Flags.boolean({
char: 'a',
default: false,
Expand Down Expand Up @@ -94,14 +88,7 @@ export class ListCommand extends IronfishCommand {

function renderTable(
content: GetPeersResponse,
flags: {
extended: boolean
names: boolean
all: boolean
sort: string
agents: boolean
sequence: boolean
},
flags: CommandFlags<typeof ListCommand>,
): string {
let columns: CliUx.Table.table.Columns<GetPeerResponsePeer> = {
identity: {
Expand Down Expand Up @@ -201,8 +188,7 @@ function renderTable(

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

return result
Expand Down
39 changes: 39 additions & 0 deletions ironfish-cli/src/commands/service/ceremony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { RemoteFlags } from '../../flags'
import { CeremonyServer } from '../../trusted-setup/server'
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)

export default class Ceremony extends IronfishCommand {
static hidden = true

Expand All @@ -24,6 +29,34 @@ export default class Ceremony extends IronfishCommand {
description: 'S3 bucket to download and upload params to',
default: 'ironfish-contributions',
}),
contributionTimeoutMs: Flags.integer({
required: false,
description: 'Allowable milliseconds for a contributor to run the contribution script',
default: CONTRIBUTE_TIMEOUT_MS,
}),
uploadTimeoutMs: Flags.integer({
required: false,
description: 'Allowable milliseconds for a contributor to upload their new parameters',
default: UPLOAD_TIMEOUT_MS,
}),
presignedExpirationSec: Flags.integer({
required: false,
description: 'How many seconds the S3 pre-signed upload URL is valid for a contributor',
default: PRESIGNED_EXPIRATION_SEC,
}),
startDate: Flags.integer({
required: false,
description: 'When should the server start accepting contributions',
default: START_DATE,
}),
token: Flags.string({
required: true,
}),
skipIPCheck: Flags.boolean({
required: false,
description: 'Pass this flag if you want to skip checking for duplicate IPs',
default: false,
}),
}

async start(): Promise<void> {
Expand All @@ -43,6 +76,12 @@ export default class Ceremony extends IronfishCommand {
s3Bucket: flags.bucket,
s3Client: s3Client,
tempDir: this.sdk.config.tempDir,
contributionTimeoutMs: flags.contributionTimeoutMs,
uploadTimeoutMs: flags.uploadTimeoutMs,
presignedExpirationSec: flags.presignedExpirationSec,
startDate: flags.startDate,
token: flags.token,
enableIPBanning: !flags.skipIPCheck,
})

await server.start()
Expand Down
Loading

0 comments on commit aaba8cb

Please sign in to comment.