Skip to content

Commit

Permalink
Merge pull request #3932 from iron-fish/staging
Browse files Browse the repository at this point in the history
STAGING -> MASTER
  • Loading branch information
hughy committed May 25, 2023
2 parents 44a3e58 + 640e417 commit ccc100a
Show file tree
Hide file tree
Showing 133 changed files with 7,734 additions and 4,122 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/deploy-brew.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
name: Deploy Brew Tap Release
on: workflow_dispatch
on:
workflow_dispatch:
inputs:
refToBuild:
type: string

jobs:
Deploy:
name: Deploy
runs-on: macos-10.15
runs-on: macos-12

steps:
- name: Check out Git repository
uses: actions/checkout@v3
with:
ref: ${{ inputs.refToBuild }}

- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
shared-key: nodejs

- name: Cache Ironfish CLI Build
id: cache-ironfish-cli-build
uses: actions/cache@v3
with:
path: ironfish-cli/build.cli/ironfish-cli.tar.gz
key: ${{ github.sha }}

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18.12.1'
cache: 'yarn'

- name: Build Ironfish CLI
if: steps.cache-ironfish-cli-build.outputs.cache-hit != 'true'
run: ./ironfish-cli/scripts/build.sh

- name: Deploy Ironfish CLI Brew
Expand Down
168 changes: 129 additions & 39 deletions benchmarks/benches/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,69 +1,159 @@
use benchmarks::slow_config;
use criterion::{criterion_group, criterion_main, Criterion};
use benchmarks::{slow_config, very_slow_config};
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use ironfish_rust::{
assets::{asset::Asset, asset_identifier::NATIVE_ASSET},
test_util::make_fake_witness,
Note, ProposedTransaction, SaplingKey,
transaction::batch_verify_transactions,
Note, ProposedTransaction, SaplingKey, Transaction,
};

pub fn simple(c: &mut Criterion) {
let key = SaplingKey::generate_key();
let public_address = key.public_address();
c.bench_function("transaction::simple", |b| {
b.iter_batched(
// Setup
|| {
let key = SaplingKey::generate_key();
let public_address = key.public_address();

let spend_note = Note::new(public_address, 42, "", NATIVE_ASSET, public_address);
let witness = make_fake_witness(&spend_note);
let spend_note = Note::new(public_address, 42, "", NATIVE_ASSET, public_address);
let witness = make_fake_witness(&spend_note);

let out_note = Note::new(public_address, 41, "", NATIVE_ASSET, public_address);
let out_note = Note::new(public_address, 41, "", NATIVE_ASSET, public_address);

c.bench_function("transaction::simple", |b| {
b.iter(|| {
let mut proposed = ProposedTransaction::new(key.clone());
(key, spend_note, witness, out_note)
},
// Benchmark
|(key, spend_note, witness, out_note)| {
let mut proposed = ProposedTransaction::new(key);

proposed.add_spend(spend_note.clone(), &witness).unwrap();
proposed.add_output(out_note.clone()).unwrap();
proposed.add_spend(spend_note, &witness).unwrap();
proposed.add_output(out_note).unwrap();

let tx = proposed.post(None, 1).unwrap();
let tx = proposed.post(None, 1).unwrap();

assert_eq!(tx.spends().len(), 1);
assert_eq!(tx.outputs().len(), 1);
})
assert_eq!(tx.spends().len(), 1);
assert_eq!(tx.outputs().len(), 1);
},
BatchSize::LargeInput,
);
});
}

pub fn all_descriptions(c: &mut Criterion) {
let key = SaplingKey::generate_key();
let public_address = key.public_address();
c.bench_function("transaction::all_descriptions", |b| {
b.iter_batched(
// Setup
|| {
let key = SaplingKey::generate_key();
let public_address = key.public_address();

let spend_note = Note::new(public_address, 42, "", NATIVE_ASSET, public_address);
let witness = make_fake_witness(&spend_note);
let spend_note = Note::new(public_address, 42, "", NATIVE_ASSET, public_address);
let witness = make_fake_witness(&spend_note);

let out_note = Note::new(public_address, 41, "", NATIVE_ASSET, public_address);
let out_note = Note::new(public_address, 41, "", NATIVE_ASSET, public_address);

let asset = Asset::new(public_address, "Testcoin", "A really cool coin").unwrap();
let asset_value = 10;
let asset = Asset::new(public_address, "Testcoin", "A really cool coin").unwrap();

c.bench_function("transaction::all_descriptions", |b| {
b.iter(|| {
let mut proposed = ProposedTransaction::new(key.clone());
(key, spend_note, witness, out_note, asset)
},
// Benchmark
|(key, spend_note, witness, out_note, asset)| {
let asset_value = 10;

let mut proposed = ProposedTransaction::new(key);

proposed.add_spend(spend_note, &witness).unwrap();
proposed.add_output(out_note).unwrap();
proposed.add_mint(asset, asset_value).unwrap();
proposed.add_burn(*asset.id(), asset_value).unwrap();

let tx = proposed.post(None, 1).unwrap();

assert_eq!(tx.spends().len(), 1);
assert_eq!(tx.outputs().len(), 1);
assert_eq!(tx.mints().len(), 1);
assert_eq!(tx.burns().len(), 1);
},
BatchSize::LargeInput,
);
});
}

pub fn verify(c: &mut Criterion) {
c.bench_function("transaction::verify", |b| {
b.iter_batched(
// Setup
|| {
let key = SaplingKey::generate_key();
let public_address = key.public_address();

let spend_note = Note::new(public_address, 42, "", NATIVE_ASSET, public_address);
let witness = make_fake_witness(&spend_note);

let out_note = Note::new(public_address, 41, "", NATIVE_ASSET, public_address);

proposed.add_spend(spend_note.clone(), &witness).unwrap();
proposed.add_output(out_note.clone()).unwrap();
proposed.add_mint(asset, asset_value).unwrap();
proposed.add_burn(*asset.id(), asset_value).unwrap();
let mut proposed = ProposedTransaction::new(key);

let tx = proposed.post(None, 1).unwrap();
proposed.add_spend(spend_note, &witness).unwrap();
proposed.add_output(out_note).unwrap();

assert_eq!(tx.spends().len(), 1);
assert_eq!(tx.outputs().len(), 1);
assert_eq!(tx.mints().len(), 1);
assert_eq!(tx.burns().len(), 1);
})
proposed.post(None, 1).unwrap()
},
// Benchmark
|tx| {
tx.verify().unwrap();
},
BatchSize::LargeInput,
);
});
}

pub fn batch_verify(c: &mut Criterion) {
c.bench_function("transaction::batch_verify", |b| {
b.iter_batched(
// Setup
|| {
const TRANSACTION_AMOUNT: usize = 5;

let mut transactions: Vec<Transaction> = Vec::with_capacity(TRANSACTION_AMOUNT);

for _ in 0..TRANSACTION_AMOUNT {
let key = SaplingKey::generate_key();
let public_address = key.public_address();

let spend_note =
Note::new(public_address, 42, "", NATIVE_ASSET, public_address);
let witness = make_fake_witness(&spend_note);

let out_note = Note::new(public_address, 41, "", NATIVE_ASSET, public_address);

let mut proposed = ProposedTransaction::new(key);

proposed.add_spend(spend_note, &witness).unwrap();
proposed.add_output(out_note).unwrap();

transactions.push(proposed.post(None, 1).unwrap());
}

transactions
},
// Benchmark
|transactions| {
batch_verify_transactions(transactions.iter()).unwrap();
},
BatchSize::LargeInput,
);
});
}

criterion_group! {
name = slow_benches;
config = slow_config();
targets = simple, all_descriptions
targets = simple, all_descriptions, verify
}
criterion_group! {
name = very_slow_benches;
config = very_slow_config();
targets = batch_verify,
}
criterion_main!(slow_benches);
criterion_main!(slow_benches, very_slow_benches);
9 changes: 9 additions & 0 deletions benchmarks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ use criterion::Criterion;
pub const LONG_BENCH_DURATION: Duration = Duration::from_secs(60);
pub const LONG_BENCH_SAMPLE_SIZE: usize = 50;

pub const VERY_LONG_BENCH_DURATION: Duration = Duration::from_secs(120);
pub const VERY_LONG_BENCH_SAMPLE_SIZE: usize = 20;

pub fn slow_config() -> Criterion {
Criterion::default()
.measurement_time(LONG_BENCH_DURATION)
.sample_size(LONG_BENCH_SAMPLE_SIZE)
}

pub fn very_slow_config() -> Criterion {
Criterion::default()
.measurement_time(VERY_LONG_BENCH_DURATION)
.sample_size(VERY_LONG_BENCH_SAMPLE_SIZE)
}
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": "1.2.0",
"version": "1.3.0",
"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,8 +60,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": "1.1.0",
"@ironfish/sdk": "1.2.0",
"@ironfish/rust-nodejs": "1.2.0",
"@ironfish/sdk": "1.3.0",
"@oclif/core": "1.23.1",
"@oclif/plugin-help": "5.1.12",
"@oclif/plugin-not-found": "2.3.1",
Expand Down
2 changes: 2 additions & 0 deletions ironfish-cli/src/commands/wallet/burn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ export class Burn extends IronfishCommand {
raw = await selectFee({
client,
transaction: params,
account: account,
confirmations: flags.confirmations,
logger: this.logger,
})
} else {
Expand Down
2 changes: 2 additions & 0 deletions ironfish-cli/src/commands/wallet/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ export class Mint extends IronfishCommand {
raw = await selectFee({
client,
transaction: params,
account: account,
confirmations: flags.confirmations,
logger: this.logger,
})
} else {
Expand Down
2 changes: 2 additions & 0 deletions ironfish-cli/src/commands/wallet/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ export class Send extends IronfishCommand {
raw = await selectFee({
client,
transaction: params,
account: from,
confirmations: flags.confirmations,
logger: this.logger,
})
} else {
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": "1.1.0",
"version": "1.2.0",
"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": "1.1.0",
"version": "1.2.0",
"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": "1.1.0",
"version": "1.2.0",
"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": "1.1.0",
"version": "1.2.0",
"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": "1.1.0",
"version": "1.2.0",
"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": "1.1.0",
"version": "1.2.0",
"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": "1.1.0",
"version": "1.2.0",
"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": "1.1.0",
"version": "1.2.0",
"description": "Node.js bindings for Rust code required by the Iron Fish SDK",
"main": "index.js",
"types": "index.d.ts",
Expand Down
6 changes: 1 addition & 5 deletions ironfish-rust-nodejs/src/nacl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@ impl BoxKeyPair {

#[napi(factory)]
pub fn from_hex(secret_hex: String) -> napi::Result<BoxKeyPair> {
let byte_vec =
let bytes: [u8; nacl::KEY_LENGTH] =
hex_to_bytes(&secret_hex).map_err(|_| to_napi_err("Unable to decode secret key"))?;

let bytes: [u8; nacl::KEY_LENGTH] = byte_vec
.try_into()
.map_err(|_| to_napi_err("Unable to convert secret key"))?;

let secret_key = bytes_to_secret_key(bytes);

Ok(BoxKeyPair {
Expand Down
Loading

0 comments on commit ccc100a

Please sign in to comment.