Skip to content

Commit

Permalink
Merge pull request #3638 from iron-fish/staging
Browse files Browse the repository at this point in the history
STAGING -> MASTER
  • Loading branch information
danield9tqh committed Mar 11, 2023
2 parents 4127bb6 + 429afb5 commit 2c7f84a
Show file tree
Hide file tree
Showing 44 changed files with 1,056 additions and 100 deletions.
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.71",
"version": "0.1.72",
"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/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.28",
"@ironfish/sdk": "0.0.48",
"@ironfish/rust-nodejs": "0.1.29",
"@ironfish/sdk": "0.0.49",
"@oclif/core": "1.23.1",
"@oclif/plugin-help": "5.1.12",
"@oclif/plugin-not-found": "2.3.1",
Expand Down
12 changes: 9 additions & 3 deletions ironfish-cli/src/commands/faucet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ONE_FISH_IMAGE, TWO_FISH_IMAGE } from '../images'
const FAUCET_DISABLED = false

export class FaucetCommand extends IronfishCommand {
static description = `Receive coins from the Iron Fish official Faucet`
static description = `Receive coins from the Iron Fish official testnet Faucet`

static flags = {
...RemoteFlags,
Expand All @@ -33,10 +33,16 @@ export class FaucetCommand extends IronfishCommand {
this.exit(1)
}

this.log(ONE_FISH_IMAGE)

const client = await this.sdk.connectRpc()
const networkInfoResponse = await client.getNetworkInfo()

if (networkInfoResponse.content === null || networkInfoResponse.content.networkId !== 0) {
// not testnet
this.log(`The faucet is only available for testnet.`)
this.exit(1)
}

this.log(ONE_FISH_IMAGE)
let email = flags.email

if (!email) {
Expand Down
1 change: 1 addition & 0 deletions ironfish-cli/src/commands/wallet/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class PostCommand extends IronfishCommand {
}),
broadcast: Flags.boolean({
default: true,
allowNo: true,
description: 'Broadcast the transaction after posting',
}),
}
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-darwin-arm64",
"version": "0.1.28",
"version": "0.1.29",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-darwin-x64",
"version": "0.1.28",
"version": "0.1.29",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-linux-arm64-gnu",
"version": "0.1.28",
"version": "0.1.29",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/linux-arm64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-linux-arm64-musl",
"version": "0.1.28",
"version": "0.1.29",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-linux-x64-gnu",
"version": "0.1.28",
"version": "0.1.29",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/linux-x64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-linux-x64-musl",
"version": "0.1.28",
"version": "0.1.29",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-win32-x64-msvc",
"version": "0.1.28",
"version": "0.1.29",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs",
"version": "0.1.28",
"version": "0.1.29",
"description": "Node.js bindings for Rust code required by the Iron Fish SDK",
"main": "index.js",
"types": "index.d.ts",
Expand Down
16 changes: 8 additions & 8 deletions ironfish-rust-nodejs/tests/demo.test.slow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ describe('Demonstrate the Sapling API', () => {
const key = generateKey()

const transaction = new Transaction(key.spendingKey)
const note = new Note(key.publicAddress, BigInt(20), 'test', Asset.nativeId(), key.publicAddress)
const note = new Note(key.publicAddress, 20n, 'test', Asset.nativeId(), key.publicAddress)
transaction.output(note)

const serializedPostedTransaction = transaction.post_miners_fee()
const postedTransaction = new TransactionPosted(serializedPostedTransaction)

expect(postedTransaction.fee()).toEqual(BigInt(-20))
expect(postedTransaction.fee()).toEqual(-20n)
expect(postedTransaction.notesLength()).toBe(1)
expect(postedTransaction.spendsLength()).toBe(0)
expect(postedTransaction.hash().byteLength).toBe(32)
Expand All @@ -87,16 +87,16 @@ describe('Demonstrate the Sapling API', () => {

// Null characters are included in the memo string
expect(decryptedNote.memo().replace(/\0/g, '')).toEqual('test')
expect(decryptedNote.value()).toEqual(BigInt(20))
expect(decryptedNote.nullifier(key.viewKey, BigInt(0)).byteLength).toBeGreaterThan(BigInt(0))
expect(decryptedNote.value()).toEqual(20n)
expect(decryptedNote.nullifier(key.viewKey, 0n).byteLength).toBeGreaterThan(0n)
})

it(`Should create a standard transaction`, () => {
const key = generateKey()
const recipientKey = generateKey()

const minersFeeTransaction = new Transaction(key.spendingKey)
const minersFeeNote = new Note(key.publicAddress, BigInt(20), 'miner', Asset.nativeId(), key.publicAddress)
const minersFeeNote = new Note(key.publicAddress, 20n, 'miner', Asset.nativeId(), key.publicAddress)
minersFeeTransaction.output(minersFeeNote)

const postedMinersFeeTransaction = new TransactionPosted(minersFeeTransaction.post_miners_fee())
Expand All @@ -105,7 +105,7 @@ describe('Demonstrate the Sapling API', () => {
transaction.setExpiration(10)
const encryptedNote = new NoteEncrypted(postedMinersFeeTransaction.getNote(0))
const decryptedNote = Note.deserialize(encryptedNote.decryptNoteForOwner(key.incomingViewKey)!)
const newNote = new Note(recipientKey.publicAddress, BigInt(15), 'receive', Asset.nativeId(), minersFeeNote.owner())
const newNote = new Note(recipientKey.publicAddress, 15n, 'receive', Asset.nativeId(), minersFeeNote.owner())

let currentHash = encryptedNote.hash()
let authPath = Array.from({ length: 32 }, (_, depth) => {
Expand All @@ -128,10 +128,10 @@ describe('Demonstrate the Sapling API', () => {
transaction.spend(decryptedNote, witness)
transaction.output(newNote)

const postedTransaction = new TransactionPosted(transaction.post(key.publicAddress, BigInt(5)))
const postedTransaction = new TransactionPosted(transaction.post(key.publicAddress, 5n))

expect(postedTransaction.expiration()).toEqual(10)
expect(postedTransaction.fee()).toEqual(BigInt(5))
expect(postedTransaction.fee()).toEqual(5n)
expect(postedTransaction.notesLength()).toEqual(1)
expect(postedTransaction.spendsLength()).toEqual(1)
expect(postedTransaction.hash().byteLength).toEqual(32)
Expand Down
4 changes: 4 additions & 0 deletions ironfish-rust-nodejs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../config/tsconfig.base.json"
}

4 changes: 2 additions & 2 deletions ironfish/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/sdk",
"version": "0.0.48",
"version": "0.0.49",
"description": "SDK for running and interacting with an Iron Fish node",
"author": "Iron Fish <[email protected]> (https://ironfish.network)",
"main": "build/src/index.js",
Expand All @@ -18,7 +18,7 @@
],
"dependencies": {
"@ethersproject/bignumber": "5.7.0",
"@ironfish/rust-nodejs": "0.1.28",
"@ironfish/rust-nodejs": "0.1.29",
"@napi-rs/blake-hash": "1.3.3",
"axios": "0.21.4",
"bech32": "2.0.0",
Expand Down
7 changes: 2 additions & 5 deletions ironfish/src/consensus/verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class Verifier {
}

// Sum the total transaction fees
let totalTransactionFees = BigInt(0)
let totalTransactionFees = 0n
for (const transaction of otherTransactions) {
const transactionFee = transaction.fee()
if (transactionFee < 0) {
Expand All @@ -133,10 +133,7 @@ export class Verifier {
// minersFee should be (negative) miningReward + totalTransactionFees
const miningReward = this.chain.strategy.miningReward(block.header.sequence)

if (
minersFeeTransaction.fee() !==
BigInt(-1) * (BigInt(miningReward) + totalTransactionFees)
) {
if (minersFeeTransaction.fee() !== -1n * (BigInt(miningReward) + totalTransactionFees)) {
return { valid: false, reason: VerificationResultReason.INVALID_MINERS_FEE }
}

Expand Down
11 changes: 11 additions & 0 deletions ironfish/src/fileStores/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const DEFAULT_DISCORD_INVITE = 'https://discord.ironfish.network'
export const DEFAULT_USE_RPC_IPC = true
export const DEFAULT_USE_RPC_TCP = false
export const DEFAULT_USE_RPC_TLS = true
// TODO(daniel): Setting this to false until we can get HTTPS + basic auth
export const DEFAULT_USE_RPC_HTTP = false
export const DEFAULT_POOL_HOST = '::'
export const DEFAULT_POOL_PORT = 9034
export const DEFAULT_NETWORK_ID = 0
Expand All @@ -33,6 +35,7 @@ export type ConfigOptions = {
enableRpcIpc: boolean
enableRpcTcp: boolean
enableRpcTls: boolean
enableRpcHttp: boolean
enableSyncing: boolean
enableTelemetry: boolean
enableMetrics: boolean
Expand Down Expand Up @@ -93,6 +96,8 @@ export type ConfigOptions = {
rpcTcpPort: number
tlsKeyPath: string
tlsCertPath: string
rpcHttpHost: string
rpcHttpPort: number
/**
* The maximum number of peers we can be connected to at a time. Past this number,
* new connections will be rejected.
Expand Down Expand Up @@ -276,6 +281,7 @@ export const ConfigOptionsSchema: yup.ObjectSchema<Partial<ConfigOptions>> = yup
enableRpcIpc: yup.boolean(),
enableRpcTcp: yup.boolean(),
enableRpcTls: yup.boolean(),
enableRpcHttp: yup.boolean(),
enableSyncing: yup.boolean(),
enableTelemetry: yup.boolean(),
enableMetrics: yup.boolean(),
Expand All @@ -298,6 +304,8 @@ export const ConfigOptionsSchema: yup.ObjectSchema<Partial<ConfigOptions>> = yup
rpcTcpPort: YupUtils.isPort,
tlsKeyPath: yup.string().trim(),
tlsCertPath: yup.string().trim(),
rpcHttpHost: yup.string().trim(),
rpcHttpPort: YupUtils.isPort,
maxPeers: YupUtils.isPositiveInteger,
minPeers: YupUtils.isPositiveInteger,
targetPeers: yup.number().integer().min(1),
Expand Down Expand Up @@ -369,6 +377,7 @@ export class Config extends KeyStore<ConfigOptions> {
enableRpcIpc: DEFAULT_USE_RPC_IPC,
enableRpcTcp: DEFAULT_USE_RPC_TCP,
enableRpcTls: DEFAULT_USE_RPC_TLS,
enableRpcHttp: DEFAULT_USE_RPC_HTTP,
enableSyncing: true,
enableTelemetry: false,
enableMetrics: true,
Expand All @@ -388,6 +397,8 @@ export class Config extends KeyStore<ConfigOptions> {
rpcTcpPort: 8020,
tlsKeyPath: files.resolve(files.join(dataDir, 'certs', 'node-key.pem')),
tlsCertPath: files.resolve(files.join(dataDir, 'certs', 'node-cert.pem')),
rpcHttpHost: 'localhost',
rpcHttpPort: 8021,
maxPeers: 50,
confirmations: 2,
minPeers: 1,
Expand Down
98 changes: 98 additions & 0 deletions ironfish/src/migrations/data/026-timestamp-to-transactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* 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 { Logger } from '../../logger'
import { IronfishNode } from '../../node'
import { IDatabase, IDatabaseTransaction } from '../../storage'
import { createDB } from '../../storage/utils'
import { Account } from '../../wallet'
import { Migration } from '../migration'
import { GetStores } from './026-timestamp-to-transactions/stores'

export class Migration026 extends Migration {
path = __filename

prepare(node: IronfishNode): IDatabase {
return createDB({ location: node.config.walletDatabasePath })
}

async forward(
node: IronfishNode,
db: IDatabase,
_tx: IDatabaseTransaction | undefined,
logger: Logger,
): Promise<void> {
const accounts = []
const stores = GetStores(db)

for await (const account of stores.old.accounts.getAllValuesIter()) {
accounts.push(
new Account({
...account,
createdAt: null,
walletDb: node.wallet.walletDb,
}),
)
}

const accountsString =
accounts.length === 1 ? `${accounts.length} account` : `${accounts.length} accounts`
logger.info(`Indexing transaction timestamps for ${accountsString}`)

for (const account of accounts) {
logger.info('')
logger.info(` Indexing transaction timestamps for account ${account.name}`)

let transactionCount = 0
for await (const { timestamp, transaction } of stores.old.transactions.getAllValuesIter(
undefined,
account.prefixRange,
)) {
await stores.new.timestampToTransactionHash.put(
[account.prefix, [timestamp.getTime(), transaction.hash()]],
null,
)

transactionCount++
}

const transactionsString =
transactionCount === 1
? `${transactionCount} transaction`
: `${transactionCount} transactions`
logger.info(` Completed indexing ${transactionsString} for account ${account.name}`)
}

await stores.old.timestampToTransactionHash.clear()
logger.info('')
}

async backward(node: IronfishNode, db: IDatabase): Promise<void> {
const accounts = []
const stores = GetStores(db)

for await (const account of stores.old.accounts.getAllValuesIter()) {
accounts.push(
new Account({
...account,
createdAt: null,
walletDb: node.wallet.walletDb,
}),
)
}

for (const account of accounts) {
for await (const { timestamp, transaction } of stores.old.transactions.getAllValuesIter(
undefined,
account.prefixRange,
)) {
await stores.old.timestampToTransactionHash.put(
[account.prefix, timestamp.getTime()],
transaction.hash(),
)
}

await stores.new.timestampToTransactionHash.clear()
}
}
}
Loading

0 comments on commit 2c7f84a

Please sign in to comment.