Auto merge of #5205 - str4d:bump-rust-deps, r=str4d

Migrate to latest Rust dependencies

This brings in the Orchard dependencies, as well as a `metrics` feature we upstreamed.
This commit is contained in:
Homu 2021-06-09 15:26:37 +00:00
commit 8fbabc4740
9 changed files with 445 additions and 360 deletions

588
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -20,34 +20,31 @@ path = "src/rust/src/rustzcash.rs"
crate-type = ["staticlib"]
[dependencies]
bellman = "0.8"
bellman = "0.10"
blake2b_simd = "0.5"
blake2s_simd = "0.5"
bls12_381 = "0.3"
group = "0.8"
bls12_381 = "0.5"
group = "0.10"
libc = "0.2"
jubjub = "0.5"
jubjub = "0.7"
subtle = "2.2"
rand_core = "0.5.1"
rand_core = "0.6"
tracing = "0.1"
tracing-core = "0.1"
tracing-appender = "0.1"
zcash_history = "0.2"
zcash_primitives = "0.5"
zcash_proofs = "0.5"
ed25519-zebra = "2.0.0"
ed25519-zebra = "2.2.0"
# Metrics
hyper = { version = "=0.14.2", default-features = false, features = ["server", "tcp", "http1"] }
ipnet = "2"
metrics = "0.14.2"
metrics-exporter-prometheus = "0.3"
metrics = "0.16"
metrics-exporter-prometheus = "0.5"
thiserror = "1"
tokio = { version = "1.0", features = ["rt", "net", "time", "macros"] }
# Temporary workaround for https://github.com/myrrlyn/funty/issues/3
funty = "=1.1.0"
[dependencies.tracing-subscriber]
version = "0.2.12"
default-features = false
@ -57,3 +54,9 @@ features = ["ansi", "chrono", "env-filter"]
lto = true
panic = 'abort'
codegen-units = 1
[patch.crates-io]
ed25519-zebra = { git = "https://github.com/ZcashFoundation/ed25519-zebra.git", rev = "d3512400227a362d08367088ffaa9bd4142a69c7" }
orchard = { git = "https://github.com/zcash/orchard.git", rev = "cd1e72bbcd9f2e873408aa365537c89824cb7430" }
zcash_primitives = { git = "https://github.com/zcash/librustzcash.git", rev = "2ba80739710f2511b18b67a7f9e082d390427a00" }
zcash_proofs = { git = "https://github.com/zcash/librustzcash.git", rev = "2ba80739710f2511b18b67a7f9e082d390427a00" }

View File

@ -137,12 +137,6 @@ Files: src/rust/include/tracing.h
Copyright: Copyright (c) 2020 Jack Grigg
License: Expat
Files: src/rust/src/metrics_ffi/prometheus.rs
Copyright:
2020-2021 The contributors to the metrics project
2021 Jack Grigg
License: Expat
Files: src/secp256k1/*
Copyright: Copyright (c) 2013 Pieter Wuille
License: Expat

View File

@ -1,5 +1,5 @@
use libc::{c_char, c_double};
use metrics::{try_recorder, GaugeValue, Key, KeyData, Label};
use metrics::{try_recorder, GaugeValue, Key, Label};
use metrics_exporter_prometheus::PrometheusBuilder;
use std::ffi::CStr;
use std::net::{IpAddr, SocketAddr};
@ -7,8 +7,6 @@ use std::ptr;
use std::slice;
use tracing::error;
mod prometheus;
#[no_mangle]
pub extern "C" fn metrics_run(
bind_address: *const c_char,
@ -64,11 +62,18 @@ pub extern "C" fn metrics_run(
prometheus_port,
);
prometheus::install(bind_address, PrometheusBuilder::new(), allow_ips).is_ok()
allow_ips
.into_iter()
.fold(
PrometheusBuilder::new().listen_address(bind_address),
|builder, subnet| builder.add_allowed(subnet),
)
.install()
.is_ok()
}
pub struct FfiCallsite {
key_data: KeyData,
key: Key,
}
#[no_mangle]
@ -98,7 +103,7 @@ pub extern "C" fn metrics_callsite(
.collect();
Box::into_raw(Box::new(FfiCallsite {
key_data: KeyData::from_parts(name, labels),
key: Key::from_parts(name, labels),
}))
}
@ -139,7 +144,7 @@ pub extern "C" fn metrics_key(
.collect();
Box::into_raw(Box::new(FfiKey {
inner: Key::Owned(KeyData::from_parts(name, labels)),
inner: Key::from_parts(name, labels),
}))
}
}
@ -148,7 +153,7 @@ pub extern "C" fn metrics_key(
pub extern "C" fn metrics_static_increment_counter(callsite: *const FfiCallsite, value: u64) {
if let Some(recorder) = try_recorder() {
let callsite = unsafe { callsite.as_ref().unwrap() };
recorder.increment_counter(Key::Borrowed(&callsite.key_data), value);
recorder.increment_counter(&callsite.key, value);
}
}
@ -157,7 +162,7 @@ pub extern "C" fn metrics_increment_counter(key: *mut FfiKey, value: u64) {
if let Some(recorder) = try_recorder() {
if !key.is_null() {
let key = unsafe { Box::from_raw(key) };
recorder.increment_counter(key.inner, value);
recorder.increment_counter(&key.inner, value);
}
}
}
@ -166,10 +171,7 @@ pub extern "C" fn metrics_increment_counter(key: *mut FfiKey, value: u64) {
pub extern "C" fn metrics_static_update_gauge(callsite: *const FfiCallsite, value: c_double) {
if let Some(recorder) = try_recorder() {
let callsite = unsafe { callsite.as_ref().unwrap() };
recorder.update_gauge(
Key::Borrowed(&callsite.key_data),
GaugeValue::Absolute(value),
);
recorder.update_gauge(&callsite.key, GaugeValue::Absolute(value));
}
}
@ -178,7 +180,7 @@ pub extern "C" fn metrics_update_gauge(key: *mut FfiKey, value: c_double) {
if let Some(recorder) = try_recorder() {
if !key.is_null() {
let key = unsafe { Box::from_raw(key) };
recorder.update_gauge(key.inner, GaugeValue::Absolute(value));
recorder.update_gauge(&key.inner, GaugeValue::Absolute(value));
}
}
}
@ -187,10 +189,7 @@ pub extern "C" fn metrics_update_gauge(key: *mut FfiKey, value: c_double) {
pub extern "C" fn metrics_static_increment_gauge(callsite: *const FfiCallsite, value: c_double) {
if let Some(recorder) = try_recorder() {
let callsite = unsafe { callsite.as_ref().unwrap() };
recorder.update_gauge(
Key::Borrowed(&callsite.key_data),
GaugeValue::Increment(value),
);
recorder.update_gauge(&callsite.key, GaugeValue::Increment(value));
}
}
@ -199,7 +198,7 @@ pub extern "C" fn metrics_increment_gauge(key: *mut FfiKey, value: c_double) {
if let Some(recorder) = try_recorder() {
if !key.is_null() {
let key = unsafe { Box::from_raw(key) };
recorder.update_gauge(key.inner, GaugeValue::Increment(value));
recorder.update_gauge(&key.inner, GaugeValue::Increment(value));
}
}
}
@ -208,10 +207,7 @@ pub extern "C" fn metrics_increment_gauge(key: *mut FfiKey, value: c_double) {
pub extern "C" fn metrics_static_decrement_gauge(callsite: *const FfiCallsite, value: c_double) {
if let Some(recorder) = try_recorder() {
let callsite = unsafe { callsite.as_ref().unwrap() };
recorder.update_gauge(
Key::Borrowed(&callsite.key_data),
GaugeValue::Decrement(value),
);
recorder.update_gauge(&callsite.key, GaugeValue::Decrement(value));
}
}
@ -220,7 +216,7 @@ pub extern "C" fn metrics_decrement_gauge(key: *mut FfiKey, value: c_double) {
if let Some(recorder) = try_recorder() {
if !key.is_null() {
let key = unsafe { Box::from_raw(key) };
recorder.update_gauge(key.inner, GaugeValue::Decrement(value));
recorder.update_gauge(&key.inner, GaugeValue::Decrement(value));
}
}
}
@ -229,7 +225,7 @@ pub extern "C" fn metrics_decrement_gauge(key: *mut FfiKey, value: c_double) {
pub extern "C" fn metrics_static_record_histogram(callsite: *const FfiCallsite, value: c_double) {
if let Some(recorder) = try_recorder() {
let callsite = unsafe { callsite.as_ref().unwrap() };
recorder.record_histogram(Key::Borrowed(&callsite.key_data), value);
recorder.record_histogram(&callsite.key, value);
}
}
@ -238,7 +234,7 @@ pub extern "C" fn metrics_record_histogram(key: *mut FfiKey, value: c_double) {
if let Some(recorder) = try_recorder() {
if !key.is_null() {
let key = unsafe { Box::from_raw(key) };
recorder.record_histogram(key.inner, value);
recorder.record_histogram(&key.inner, value);
}
}
}

View File

@ -1,124 +0,0 @@
// This is mostly code copied from metrics_exporter_prometheus. The copied portions are
// licensed under the same terms as the zcash codebase (reproduced below from
// https://github.com/metrics-rs/metrics/blob/main/metrics-exporter-prometheus/LICENSE):
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
use hyper::{
server::{conn::AddrStream, Server},
service::{make_service_fn, service_fn},
{Body, Error as HyperError, Response, StatusCode},
};
use metrics::SetRecorderError;
use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusRecorder};
use std::future::Future;
use std::io;
use std::net::SocketAddr;
use std::thread;
use thiserror::Error as ThisError;
use tokio::{pin, runtime, select};
/// Errors that could occur while installing a Prometheus recorder/exporter.
#[derive(Debug, ThisError)]
pub enum InstallError {
/// Creating the networking event loop did not succeed.
#[error("failed to spawn Tokio runtime for endpoint: {0}")]
Io(#[from] io::Error),
/// Binding/listening to the given address did not succeed.
#[error("failed to bind to given listen address: {0}")]
Hyper(#[from] HyperError),
/// Installing the recorder did not succeed.
#[error("failed to install exporter as global recorder: {0}")]
Recorder(#[from] SetRecorderError),
}
/// A copy of `PrometheusBuilder::build_with_exporter` that adds support for an IP address
/// or subnet allowlist.
pub(super) fn build(
bind_address: SocketAddr,
builder: PrometheusBuilder,
allow_ips: Vec<ipnet::IpNet>,
) -> Result<
(
PrometheusRecorder,
impl Future<Output = Result<(), HyperError>> + Send + 'static,
),
InstallError,
> {
let recorder = builder.build();
let handle = recorder.handle();
let server = Server::try_bind(&bind_address)?;
let exporter = async move {
let make_svc = make_service_fn(move |socket: &AddrStream| {
let remote_addr = socket.remote_addr().ip();
let allowed = allow_ips.iter().any(|subnet| subnet.contains(&remote_addr));
let handle = handle.clone();
async move {
Ok::<_, HyperError>(service_fn(move |_| {
let handle = handle.clone();
async move {
if allowed {
let output = handle.render();
Ok(Response::new(Body::from(output)))
} else {
Response::builder()
.status(StatusCode::FORBIDDEN)
.body(Body::empty())
}
}
}))
}
});
server.serve(make_svc).await
};
Ok((recorder, exporter))
}
/// A copy of `PrometheusBuilder::install` that adds support for an IP address or subnet
/// allowlist.
pub(super) fn install(
bind_address: SocketAddr,
builder: PrometheusBuilder,
allow_ips: Vec<ipnet::IpNet>,
) -> Result<(), InstallError> {
let runtime = runtime::Builder::new_current_thread()
.enable_all()
.build()?;
let (recorder, exporter) = {
let _guard = runtime.enter();
build(bind_address, builder, allow_ips)?
};
metrics::set_boxed_recorder(Box::new(recorder))?;
thread::Builder::new()
.name("zcash-prometheus".to_string())
.spawn(move || {
runtime.block_on(async move {
pin!(exporter);
loop {
select! {
_ = &mut exporter => {}
}
}
});
})?;
Ok(())
}

View File

@ -45,10 +45,12 @@ use zcash_primitives::{
block::equihash,
constants::{CRH_IVK_PERSONALIZATION, PROOF_GENERATION_KEY_GENERATOR, SPENDING_KEY_GENERATOR},
merkle_tree::MerklePath,
note_encryption::sapling_ka_agree,
primitives::{Diversifier, Note, PaymentAddress, ProofGenerationKey, Rseed, ViewingKey},
redjubjub::{self, Signature},
sapling::{merkle_hash, spend_sig},
sapling::{
note_encryption::sapling_ka_agree,
redjubjub::{self, Signature},
Diversifier, Note, PaymentAddress, ProofGenerationKey, Rseed, ViewingKey,
},
transaction::components::Amount,
zip32,
};

View File

@ -1,6 +1,6 @@
use group::{Group, GroupEncoding};
use rand_core::{OsRng, RngCore};
use zcash_primitives::primitives::{Diversifier, ViewingKey};
use zcash_primitives::sapling::{Diversifier, ViewingKey};
use crate::{
librustzcash_sapling_generate_r, librustzcash_sapling_ka_agree,

View File

@ -1,7 +1,7 @@
use group::GroupEncoding;
use zcash_primitives::{
constants::SPENDING_KEY_GENERATOR,
primitives::{Diversifier, Nullifier, ProofGenerationKey, Rseed},
sapling::{Diversifier, Nullifier, ProofGenerationKey, Rseed},
};
use crate::{

View File

@ -1,6 +1,6 @@
use zcash_primitives::{
constants::SPENDING_KEY_GENERATOR,
redjubjub::{PrivateKey, PublicKey, Signature},
sapling::redjubjub::{PrivateKey, PublicKey, Signature},
};
#[test]