Skip to content

Commit

Permalink
Merge pull request #7 from idky137/cratify_workspace
Browse files Browse the repository at this point in the history
Cratify workspace
  • Loading branch information
idky137 authored Apr 29, 2024
2 parents bad44f0 + 9ca636a commit c7e7e4a
Show file tree
Hide file tree
Showing 24 changed files with 384 additions and 392 deletions.
28 changes: 27 additions & 1 deletion Cargo.lock

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

43 changes: 8 additions & 35 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,35 +1,8 @@
[package]
name = "zingo-proxy"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "zproxy"
path = "bin/zproxy.rs"

[[bin]]
name = "nproxy"
path = "bin/nproxy.rs"

[[bin]]
name = "nserver"
path = "bin/nserver.rs"

[dependencies]
http = "0.2.4"
tokio = { version = "1", features = ["full"] }
tonic = "0.10.2"
# zcash_client_backend = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zingo_rc.2.1", features = ["lightwalletd-tonic"] }
zcash_client_backend = { git = "https://github.com/zingolabs/librustzcash.git", branch = "nym_integration", features = ["lightwalletd-tonic"] }
# zingo-netutils = { git = "https://github.com/aloearev/zingolib.git", branch = "cratify_netutils" }
zingo-netutils = { git = "https://github.com/zingolabs/zingolib.git", branch = "nym_integration" }
prost = "0.12"
bytes = "1.1"
tokio-socks = "0.5"
nym-sdk = { git = "https://github.com/nymtech/nym", branch = "master" }
nym-sphinx-addressing = { git = "https://github.com/nymtech/nym", branch = "master" }
nym-validator-client = { git = "https://github.com/nymtech/nym", branch = "master" }
nym-bin-common = { git = "https://github.com/nymtech/nym", branch = "master" }
nym-sphinx-anonymous-replies = { git = "https://github.com/nymtech/nym", branch = "master" }
ctrlc = "3.2.1"

[workspace]
members = [
"zingo-proxyd",
"zingo-rpc",
]

# Use the edition 2021 dependency resolver in the workspace, to match the crates
resolver = "2"
52 changes: 24 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,50 @@
A(n eventual) replacement for lightwalletd, written in Rust.

Currently connects to a lightwalletd, and acts as a man-in-the-middle proxy that does nothing.
Each RPC we wish to support will be added individually, by connecting to zcashd/zebrad and doing any nessisary processing.
Each RPC we wish to support will be added individually, by connecting to zebrad and doing any nessisary processing.
Eventually, we'll no longer have any calls that need to use the lightwalletd, and it can be removed from the network stack entirely.

A note to developers/consumers/contributers: The end goal is not an exact one-to-one port of all existing lwd functionaliy.
We seek to have at least the minimal functionality nessisary for zingo to connect to zingoproxy instead of a lightwalletd,
and continue to implement any useful caching/preprocessing we can add...but full backwards compatibilty with all preexisting lightwalletd RPCs is not likely.
We currently plan to hold the Service and Darkside RPC implementations, along with a Nym counterpart to the service RPCs for sending and recieving currency over the Nym Mixnet. And a Lightweight gRPC server for testing and development (this may be fleshed out to be a mainnet LightWalletD alternative in the future but is currently not a priority and will depend on zebrad).


# Zingo-RPC
will eventually hold the rust implementations of the LightWallet Service and Darkside RPCs, along with the wallet-side and server-side Nym Service implementations.

# Zingo-ProxyD
A lightweight gRPC server for testing and development. This should not be used to run mainnet nodes in its current form as it lacks the queueing and error checking logic necessary.

Zingo-ProxyD can also act as a Nym powered proxy between zcash wallets and LightWalletD, currently capable of sending zcash over the Nym Mixnet. This functionality is currently feature gated behind "nym_wallet", for wallet-side functionality, and "nym_server", for server-side functionality.

This is the POC and initial work on enabling zcash infrastructure to use the nym mixnet.

[Nym_POC](./docs/nym_poc.pdf) shows the current state of this work ands our vision for the future.

Our plan is to first enable wallets to send and recieve transactions via a nym powered proxy between wallets and a lightwalletd before looking at the wider zcash ecosystem.


# Dependencies
1) zebrad <https://github.com/ZcashFoundation/zebra.git>
2) lightwalletd <https://github.com/zcash/lightwalletd.git>
3) zingolib <https://github.com/zingolabs/zingolib.git> [if running zingo-cli]

# zproxy
# zingoproxyd
- To run tests:
1) Run `$ zebrad --config #PATH_TO_ZINGO_PROXY/zebrad.toml start`
2) Run `$ ./lightwalletd --no-tls-very-insecure --zcash-conf-path $PATH_TO_ZINGO_PROXY/zcash.conf --data-dir . --log-file /dev/stdout`
3) Run `$ cargo nextest run`

- To run zingo-cli through zingo-proxy:
- To run zingo-cli through zingo-proxy, connecting to lightwalletd/zebrad locally:
1) Run `$ zebrad --config #PATH_TO_ZINGO_PROXY/zebrad.toml start`
2) Run `$ ./lightwalletd --no-tls-very-insecure --zcash-conf-path $PATH_TO_ZINGO_PROXY/zcash.conf --data-dir . --log-file /dev/stdout`
3) Run `$ cargo run --bin zproxy`
3) Run `$ cargo run --bin zingoproxyd`
3) Run `$ cargo run --release --package zingo-cli -- --chain "testnet" --server "127.0.0.1:8080" --data-dir ~/wallets/test_wallet`

# Nym-Proxy / Nym-Server
A nym powered proxy between zcash wallets and lightwalletd, currently capable of sending transactions.

This is the POC and initial work on enabling zcash infrastructure to use the nym mixnet.

[Nym_POC](./docs/nym_poc.pdf) shows the current state of this work ands our vision for the future.

Our plan is to first enable wallets to send and recieve transactions via a nym powered proxy between wallets and a lightwalletd before looking at the wider zcash ecosystem.

# nproxy/nserver
- To run zingo-cli through nym-proxy/server, connecting to lightwalletd/zebrad locally:
- To run zingo-cli through zingo-proxy, connecting to lightwalletd/zebrad locally, with the Nym functionality active:
1) Run `$ zebrad --config #PATH_TO_ZINGO_PROXY/zebrad.toml start`
2) Run `$ ./lightwalletd --no-tls-very-insecure --zcash-conf-path $PATH_TO_ZINGO_PROXY/zcash.conf --data-dir . --log-file /dev/stdout`
3) Run `$ cargo run --bin nserver`
3) Run `$ cargo run --bin zingoproxyd --features "nym_wallet"`
4) Copy nym address displayed
5) Run `$ cargo run --bin nproxy "nserver address copied"`
5) Run `$ cargo run --bin zingoproxyd --features "nym_server" -- "nserver address copied"`
6) Run `$ cargo run --release --package zingo-cli -- --chain "testnet" --server "127.0.0.1:8080" --data-dir ~/wallets/testnet_wallet`

- Nym-proxy/server can also be set up to connect directly to the official lightwalletd server running mainnet:
1) Two values, in src/nproxy.rs and src/nserver.rs must be changed:
- In src/nproxy.rs, on line 340, [lwd_uri_test] must be changed to [lwd_uri_main].
- In src/nserver.rs, on line 85, [zproxy_uri] must be changed to [lwd_uri_main].
2) Run `$ cargo run --bin nserver`
3) Copy nym address displayed
4) Run `$ cargo run --bin nproxy "nserver address copied"`
5) Run `$ cargo run --release --package zingo-cli -- --chain "mainnet" --server "127.0.0.1:8080" --data-dir ~/wallets/mainnet_wallet`

23 changes: 0 additions & 23 deletions bin/nproxy.rs

This file was deleted.

29 changes: 0 additions & 29 deletions bin/nserver.rs

This file was deleted.

16 changes: 0 additions & 16 deletions bin/zproxy.rs

This file was deleted.

9 changes: 0 additions & 9 deletions src/lib.rs

This file was deleted.

3 changes: 0 additions & 3 deletions src/zingo_utils.rs

This file was deleted.

46 changes: 46 additions & 0 deletions zingo-proxyd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[package]
name = "zingo-proxyd"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "zingoproxyd"
path = "src/bin/zingoproxyd.rs"

[lib]
name = "zingoproxylib"
path = "src/lib.rs"

[features]
nym_wallet = []
nym_server = []
test-features = []

[dependencies]
zingo-rpc = { path = "../zingo-rpc" }

http = "0.2.4"
tokio = { version = "1", features = ["full"] }
tonic = "0.10.2"
# zcash_client_backend = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zingo_rc.2.1", features = ["lightwalletd-tonic"] }
zcash_client_backend = { git = "https://github.com/zingolabs/librustzcash.git", branch = "nym_integration", features = ["lightwalletd-tonic"] }
# zingo-netutils = { git = "https://github.com/aloearev/zingolib.git", branch = "cratify_netutils" }
zingo-netutils = { git = "https://github.com/zingolabs/zingolib.git", branch = "nym_integration" }
prost = "0.12"
bytes = "1.1"
tokio-socks = "0.5"
nym-sdk = { git = "https://github.com/nymtech/nym", branch = "master" }
nym-sphinx-addressing = { git = "https://github.com/nymtech/nym", branch = "master" }
nym-validator-client = { git = "https://github.com/nymtech/nym", branch = "master" }
nym-bin-common = { git = "https://github.com/nymtech/nym", branch = "master" }
nym-sphinx-anonymous-replies = { git = "https://github.com/nymtech/nym", branch = "master" }
ctrlc = "3.2.1"

tower = { version = "0.4" }
hyper-rustls = { version = "0.23", features = ["http2"] }
tokio-rustls = "0.23"
hyper = { version = "0.14", features = ["full"] }
http-body = "0.4.4"
webpki-roots = "0.21.0"
rustls-pemfile = "1.0.0"

41 changes: 41 additions & 0 deletions zingo-proxyd/src/bin/zingoproxyd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//! Zingo-Proxy daemon
use std::time::Duration;
use std::{process, thread};

extern crate ctrlc;

use zingo_rpc::nym::utils::nym_spawn;

Check failure on line 8 in zingo-proxyd/src/bin/zingoproxyd.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused import: `zingo_rpc::nym::utils::nym_spawn`

error: unused import: `zingo_rpc::nym::utils::nym_spawn` --> zingo-proxyd/src/bin/zingoproxyd.rs:8:5 | 8 | use zingo_rpc::nym::utils::nym_spawn; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D unused-imports` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unused_imports)]`

Check failure on line 8 in zingo-proxyd/src/bin/zingoproxyd.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused import: `zingo_rpc::nym::utils::nym_spawn`

error: unused import: `zingo_rpc::nym::utils::nym_spawn` --> zingo-proxyd/src/bin/zingoproxyd.rs:8:5 | 8 | use zingo_rpc::nym::utils::nym_spawn; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D unused-imports` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unused_imports)]`
use zingoproxylib::{nym_server::nym_serve, server::spawn_server};

Check failure on line 9 in zingo-proxyd/src/bin/zingoproxyd.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused import: `nym_server::nym_serve`

error: unused import: `nym_server::nym_serve` --> zingo-proxyd/src/bin/zingoproxyd.rs:9:21 | 9 | use zingoproxylib::{nym_server::nym_serve, server::spawn_server}; | ^^^^^^^^^^^^^^^^^^^^^

Check failure on line 9 in zingo-proxyd/src/bin/zingoproxyd.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused import: `nym_server::nym_serve`

error: unused import: `nym_server::nym_serve` --> zingo-proxyd/src/bin/zingoproxyd.rs:9:21 | 9 | use zingoproxylib::{nym_server::nym_serve, server::spawn_server}; | ^^^^^^^^^^^^^^^^^^^^^

#[tokio::main]
async fn main() {
ctrlc::set_handler(move || {
println!("Received Ctrl+C, exiting.");
process::exit(0);
})
.expect("Error setting Ctrl-C handler");

#[cfg(any(feature = "nym_wallet", feature = "nym_server"))]
{
nym_bin_common::logging::setup_logging();
}

#[cfg(any(not(feature = "nym_server"), feature = "nym_wallet"))]
{
let server_port = 8080;
spawn_server(server_port, 9067, 18232).await;
loop {
thread::sleep(Duration::from_secs(10));
}
}

#[cfg(all(feature = "nym_server", not(feature = "nym_wallet")))]
{
let path = "/tmp/nym_server";
let mut server = nym_spawn(path).await;
let our_address = server.nym_address();
println!("\nnserver - nym address: {our_address}");
nym_serve(&mut server).await;
}
}
8 changes: 8 additions & 0 deletions zingo-proxyd/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! Zingo-Proxy gRPC Server.
//! NOTE: This is currently a very simple implementation meant only for development and testing, and in its current form should not be used to run mainnet nodes.
#![warn(missing_docs)]
#![forbid(unsafe_code)]

pub mod nym_server;
pub mod server;
10 changes: 7 additions & 3 deletions src/nserver.rs → zingo-proxyd/src/nym_server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// nserver.rs [lib]
// use: nserver lib
//
//! Nym-gRPC server implementation.
use std::sync::Arc;

Expand All @@ -14,6 +12,7 @@ use tonic::Request;
use zcash_client_backend::proto::service::{RawTransaction, SendResponse};
use zingo_netutils::GrpcConnector;

/// Spawns a TPC listener that recieves encoded gRPC requests.
pub async fn tcp_listener(addr: &str) -> Result<(), Box<dyn std::error::Error>> {
let listener = TcpListener::bind(addr).await?;
println!("Server listening on {}", addr);
Expand All @@ -28,6 +27,7 @@ pub async fn tcp_listener(addr: &str) -> Result<(), Box<dyn std::error::Error>>
}
}

/// Receives and decodes encoded gRPC messages sent over TCP, processes them, encodes the response and sends it back to the sender.
pub async fn handle_connection(mut socket: TcpStream) -> Result<(), Box<dyn std::error::Error>> {
let mut buf = vec![0u8; 16384]; // Adjust buffer size as needed
let bytes_read = socket.read(&mut buf).await?;
Expand All @@ -53,6 +53,8 @@ pub async fn handle_connection(mut socket: TcpStream) -> Result<(), Box<dyn std:
Ok(())
}

/// Forwards the recieved gRPC request on to a Lightwalletd and returns the response.
/// NOTE: Currently only send_transaction has been implemented.
pub async fn process_request(
request: &RawTransaction,
) -> Result<SendResponse, Box<dyn std::error::Error>> {
Expand Down Expand Up @@ -85,6 +87,8 @@ pub async fn process_request(
Ok(response.into_inner())
}

/// Receives and decodes encoded gRPC messages sent over the nym mixnet, processes them, encodes the response.
/// The encoded response is sent back to the sender using a surb (single use reply block).
pub async fn nym_serve(client: &mut MixnetClient) {
let mut request_in: Vec<ReconstructedMessage> = Vec::new();
loop {
Expand Down
Loading

0 comments on commit c7e7e4a

Please sign in to comment.