Skip to content

Commit

Permalink
Merge pull request #2989 from iron-fish/staging
Browse files Browse the repository at this point in the history
STAGING -> MASTER
  • Loading branch information
mat-if authored Jan 20, 2023
2 parents 4f2d2a1 + e25db8f commit 4ab43f3
Show file tree
Hide file tree
Showing 32 changed files with 118 additions and 88 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-ironfish-rust-nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
working-directory: ./ironfish-rust-nodejs

- name: Build
run: yarn build --zig ${{ matrix.settings.target == 'x86_64-unknown-linux-gnu' && '--zig-abi-suffix=2.17' || ''}} --target ${{ matrix.settings.target }}
run: yarn build ${{ matrix.settings.target != 'x86_64-pc-windows-msvc' && '--zig' || '' }} ${{ matrix.settings.target == 'x86_64-unknown-linux-gnu' && '--zig-abi-suffix=2.17' || ''}} --target ${{ matrix.settings.target }}
working-directory: ./ironfish-rust-nodejs

- name: Upload artifact
Expand Down Expand Up @@ -140,4 +140,4 @@ jobs:
- name: Run tests natively
if: ${{ !matrix.settings.docker }}
run: npm run test:slow
working-directory: ./ironfish-rust-nodejs
working-directory: ./ironfish-rust-nodejs
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.61",
"version": "0.1.62",
"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 @@ -58,8 +58,8 @@
"dependencies": {
"@aws-sdk/client-cognito-identity": "3.215.0",
"@aws-sdk/client-s3": "3.127.0",
"@ironfish/rust-nodejs": "0.1.22",
"@ironfish/sdk": "0.0.38",
"@ironfish/rust-nodejs": "0.1.23",
"@ironfish/sdk": "0.0.39",
"@oclif/core": "1.23.1",
"@oclif/plugin-help": "5.1.12",
"@oclif/plugin-not-found": "2.3.1",
Expand Down
3 changes: 3 additions & 0 deletions ironfish-cli/src/commands/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export default class Reset extends IronfishCommand {
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(
Expand Down
26 changes: 23 additions & 3 deletions ironfish-cli/src/commands/service/faucet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* 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 { Asset } from '@ironfish/rust-nodejs'
import { Asset, isValidPublicAddress } from '@ironfish/rust-nodejs'
import { Meter, PromiseUtils, RpcConnectionError, RpcSocketClient, WebApi } from '@ironfish/sdk'
import { Flags } from '@oclif/core'
import { IronfishCommand } from '../../command'
Expand Down Expand Up @@ -126,14 +126,27 @@ export default class Faucet extends IronfishCommand {
return
}

let faucetTransactions = await api.getNextFaucetTransactions(MAX_RECIPIENTS_PER_TRANSACTION)
const unprocessedFaucetTransactions = await api.getNextFaucetTransactions(
MAX_RECIPIENTS_PER_TRANSACTION,
)

if (faucetTransactions.length === 0) {
if (unprocessedFaucetTransactions.length === 0) {
this.log('No faucet jobs, waiting 5s')
await PromiseUtils.sleep(5000)
return
}

const invalidFaucetTransactions = []
let faucetTransactions = []

for (const transaction of unprocessedFaucetTransactions) {
if (isValidPublicAddress(transaction.public_key)) {
faucetTransactions.push(transaction)
} else {
invalidFaucetTransactions.push(transaction)
}
}

const response = await client.getAccountBalance({ account })

if (BigInt(response.content.confirmed) < BigInt(FAUCET_AMOUNT + FAUCET_FEE)) {
Expand Down Expand Up @@ -200,5 +213,12 @@ export default class Faucet extends IronfishCommand {
for (const faucetTransaction of faucetTransactions) {
await api.completeFaucetTransaction(faucetTransaction.id, tx.content.hash)
}

for (const invalidFaucetTransactions of faucetTransactions) {
await api.completeFaucetTransaction(
invalidFaucetTransactions.id,
'0000000000000000000000000000000000000000000000000000000000000000',
)
}
}
}
2 changes: 1 addition & 1 deletion ironfish-cli/src/commands/wallet/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class Send extends IronfishCommand {
}

if (!to) {
to = await CliUx.ux.prompt('Enter the the public address of the recipient', {
to = await CliUx.ux.prompt('Enter the public address of the recipient', {
required: true,
})

Expand Down
4 changes: 2 additions & 2 deletions ironfish-rust-nodejs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ crate-type = ["cdylib"]
[dependencies]
base64 = "0.13.0"
ironfish_rust = { path = "../ironfish-rust" }
napi-derive = "2.9.3"
napi-derive = "2.9.5"

[dependencies.napi]
version = "2.10.4"
version = "2.10.9"
features = ["napi6"]

[build-dependencies]
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.22",
"version": "0.1.23",
"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.22",
"version": "0.1.23",
"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.22",
"version": "0.1.23",
"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.22",
"version": "0.1.23",
"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.22",
"version": "0.1.23",
"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.22",
"version": "0.1.23",
"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.22",
"version": "0.1.23",
"os": [
"win32"
],
Expand Down
4 changes: 2 additions & 2 deletions 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.22",
"version": "0.1.23",
"description": "Node.js bindings for Rust code required by the Iron Fish SDK",
"main": "index.js",
"types": "index.d.ts",
Expand Down Expand Up @@ -33,7 +33,7 @@
"node": "18.x"
},
"devDependencies": {
"@napi-rs/cli": "2.14.1",
"@napi-rs/cli": "2.14.3",
"@types/jest": "29.2.4",
"jest": "29.3.1",
"jest-jasmine2": "29.3.1",
Expand Down
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.38",
"version": "0.0.39",
"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.22",
"@ironfish/rust-nodejs": "0.1.23",
"@napi-rs/blake-hash": "1.3.1",
"axios": "0.21.4",
"blru": "0.1.6",
Expand Down
32 changes: 15 additions & 17 deletions ironfish/src/blockchain/blockchain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,10 @@ describe('Blockchain', () => {
let addedNoteA2 = (await nodeA.chain.notes.getLeaf(countNoteA + 1)).merkleHash
let addedNoteA3 = (await nodeA.chain.notes.getLeaf(countNoteA + 2)).merkleHash
let addedNoteA4 = (await nodeA.chain.notes.getLeaf(countNoteA + 3)).merkleHash
expect(addedNoteA1.equals(minersFeeA1.getNote(0).merkleHash())).toBe(true)
expect(addedNoteA2.equals(minersFeeA2.getNote(0).merkleHash())).toBe(true)
expect(addedNoteA3.equals(txA2.getNote(0).merkleHash())).toBe(true)
expect(addedNoteA4.equals(txA2.getNote(1).merkleHash())).toBe(true)
expect(addedNoteA1.equals(minersFeeA1.getNote(0).hash())).toBe(true)
expect(addedNoteA2.equals(minersFeeA2.getNote(0).hash())).toBe(true)
expect(addedNoteA3.equals(txA2.getNote(0).hash())).toBe(true)
expect(addedNoteA4.equals(txA2.getNote(1).hash())).toBe(true)

// Check nodeA has nullifiers from blockA2
expect(await nodeA.chain.nullifiers.size()).toBe(countNullifierA + 1)
Expand All @@ -499,11 +499,11 @@ describe('Blockchain', () => {
const addedNoteB3 = (await nodeB.chain.notes.getLeaf(countNoteB + 2)).merkleHash
const addedNoteB4 = (await nodeB.chain.notes.getLeaf(countNoteB + 3)).merkleHash
const addedNoteB5 = (await nodeB.chain.notes.getLeaf(countNoteB + 4)).merkleHash
expect(addedNoteB1.equals(minersFeeB1.getNote(0).merkleHash())).toBe(true)
expect(addedNoteB2.equals(minersFeeB2.getNote(0).merkleHash())).toBe(true)
expect(addedNoteB3.equals(minersFeeB3.getNote(0).merkleHash())).toBe(true)
expect(addedNoteB4.equals(txB3.getNote(0).merkleHash())).toBe(true)
expect(addedNoteB5.equals(txB3.getNote(1).merkleHash())).toBe(true)
expect(addedNoteB1.equals(minersFeeB1.getNote(0).hash())).toBe(true)
expect(addedNoteB2.equals(minersFeeB2.getNote(0).hash())).toBe(true)
expect(addedNoteB3.equals(minersFeeB3.getNote(0).hash())).toBe(true)
expect(addedNoteB4.equals(txB3.getNote(0).hash())).toBe(true)
expect(addedNoteB5.equals(txB3.getNote(1).hash())).toBe(true)

// Check nodeB has nullifiers from blockB3
expect(await nodeB.chain.nullifiers.size()).toBe(countNullifierB + 1)
Expand All @@ -523,11 +523,11 @@ describe('Blockchain', () => {
addedNoteA3 = (await nodeA.chain.notes.getLeaf(countNoteA + 2)).merkleHash
addedNoteA4 = (await nodeA.chain.notes.getLeaf(countNoteA + 3)).merkleHash
const addedNoteA5 = (await nodeA.chain.notes.getLeaf(countNoteA + 4)).merkleHash
expect(addedNoteA1.equals(minersFeeB1.getNote(0).merkleHash())).toBe(true)
expect(addedNoteA2.equals(minersFeeB2.getNote(0).merkleHash())).toBe(true)
expect(addedNoteA3.equals(minersFeeB3.getNote(0).merkleHash())).toBe(true)
expect(addedNoteA4.equals(txB3.getNote(0).merkleHash())).toBe(true)
expect(addedNoteA5.equals(txB3.getNote(1).merkleHash())).toBe(true)
expect(addedNoteA1.equals(minersFeeB1.getNote(0).hash())).toBe(true)
expect(addedNoteA2.equals(minersFeeB2.getNote(0).hash())).toBe(true)
expect(addedNoteA3.equals(minersFeeB3.getNote(0).hash())).toBe(true)
expect(addedNoteA4.equals(txB3.getNote(0).hash())).toBe(true)
expect(addedNoteA5.equals(txB3.getNote(1).hash())).toBe(true)

// Check nodeA's chain has removed blockA2 nullifiers and added blockB3
expect(await nodeA.chain.nullifiers.size()).toBe(countNullifierA + 1)
Expand Down Expand Up @@ -1312,9 +1312,7 @@ describe('Blockchain', () => {

const doubleSpend = await useBlockFixture(node.chain, async () => {
// The note to double spend
const note = await account.getDecryptedNote(
mined.transactions[0].getNote(0).merkleHash(),
)
const note = await account.getDecryptedNote(mined.transactions[0].getNote(0).hash())

Assert.isNotUndefined(note)
Assert.isNotNull(note.index)
Expand Down
3 changes: 2 additions & 1 deletion ironfish/src/fileStores/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const DEFAULT_USE_RPC_TCP = false
export const DEFAULT_USE_RPC_TLS = true
export const DEFAULT_POOL_HOST = '0.0.0.0'
export const DEFAULT_POOL_PORT = 9034
export const DEFAULT_NETWORK_ID = 0

export type ConfigOptions = {
bootstrapNodes: string[]
Expand Down Expand Up @@ -384,7 +385,7 @@ export class Config extends KeyStore<ConfigOptions> {
feeEstimatorPercentileLow: 10,
feeEstimatorPercentileMedium: 20,
feeEstimatorPercentileHigh: 30,
networkId: 2,
networkId: DEFAULT_NETWORK_ID,
customNetwork: '',
maxSyncedAgeBlocks: 60,
networkDefinitionPath: files.resolve(files.join(dataDir, 'network.json')),
Expand Down
3 changes: 2 additions & 1 deletion ironfish/src/fileStores/internal.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 { FileSystem } from '../fileSystems'
import { DEFAULT_NETWORK_ID } from './config'
import { KeyStore } from './keyStore'

export type InternalOptions = {
Expand All @@ -17,7 +18,7 @@ export const InternalOptionsDefaults: InternalOptions = {
networkIdentity: '',
telemetryNodeId: '',
rpcAuthToken: '',
networkId: 0,
networkId: DEFAULT_NETWORK_ID,
}

export class InternalStore extends KeyStore<InternalOptions> {
Expand Down
12 changes: 6 additions & 6 deletions ironfish/src/merkletree/hasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface MerkleHasher<E, H, SE extends JsonSerializable, SH extends Json
/**
* Get the hash of a given element
*/
merkleHash: (element: E) => H
hash: (element: E) => H

/**
* Combine two hashes to get the parent hash
Expand Down Expand Up @@ -66,8 +66,8 @@ export class NoteHasher
return this._merkleNoteHashSerde
}

merkleHash(note: NoteEncrypted): Buffer {
return note.merkleHash()
hash(note: NoteEncrypted): Buffer {
return note.hash()
}

combineHash(
Expand Down Expand Up @@ -97,7 +97,7 @@ export class ConcatHasher implements MerkleHasher<string, string, string, string
return left + right
}

merkleHash(element: string): string {
hash(element: string): string {
return element
}
}
Expand All @@ -124,7 +124,7 @@ export class RangeHasher implements MerkleHasher<string, string, string, string>
return leftSplit[0] + '-' + rightSplit[rightSplit.length - 1]
}

merkleHash(element: string): string {
hash(element: string): string {
return element
}
}
Expand All @@ -148,7 +148,7 @@ export class StructureHasher implements MerkleHasher<string, string, string, str
return `<${left}|${right}-${depth}>`
}

merkleHash(element: string): string {
hash(element: string): string {
return element
}
}
Loading

0 comments on commit 4ab43f3

Please sign in to comment.