diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..244f826 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,48 @@ +name: Rust + +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + branches: + - main +env: + SCCACHE_GHA_ENABLED: "true" + RUSTC_WRAPPER: "sccache" + +jobs: + check: + runs-on: ubuntu-latest + steps: + - name: Checkout Source + uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v2 + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup protoc + uses: arduino/setup-protoc@v1.1.2 + - uses: actions-rs/cargo@v1 + with: + command: check + args: --all + lints: + name: fmt check + runs-on: ubuntu-latest + steps: + - name: Checkout Source + uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v2 + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup protoc + uses: arduino/setup-protoc@v1.1.2 + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all --check diff --git a/Cargo.lock b/Cargo.lock index 375648e..ac51390 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4891,6 +4891,7 @@ dependencies = [ [[package]] name = "tower-batch-control" version = "0.2.41-beta.11" +source = "git+https://github.com/willemolding/zebra?rev=185e404bed938e3aa916aee1ae6999a70efceddb#185e404bed938e3aa916aee1ae6999a70efceddb" dependencies = [ "futures", "futures-core", @@ -4924,6 +4925,7 @@ dependencies = [ [[package]] name = "tower-fallback" version = "0.2.41-beta.11" +source = "git+https://github.com/willemolding/zebra?rev=185e404bed938e3aa916aee1ae6999a70efceddb#185e404bed938e3aa916aee1ae6999a70efceddb" dependencies = [ "futures-core", "pin-project", @@ -5851,6 +5853,7 @@ dependencies = [ [[package]] name = "zebra-chain" version = "1.0.0-beta.35" +source = "git+https://github.com/willemolding/zebra?rev=185e404bed938e3aa916aee1ae6999a70efceddb#185e404bed938e3aa916aee1ae6999a70efceddb" dependencies = [ "bitflags 2.5.0", "bitflags-serde-legacy", @@ -5908,6 +5911,7 @@ dependencies = [ [[package]] name = "zebra-consensus" version = "1.0.0-beta.35" +source = "git+https://github.com/willemolding/zebra?rev=185e404bed938e3aa916aee1ae6999a70efceddb#185e404bed938e3aa916aee1ae6999a70efceddb" dependencies = [ "bellman", "blake2b_simd", @@ -5943,6 +5947,7 @@ dependencies = [ [[package]] name = "zebra-node-services" version = "1.0.0-beta.35" +source = "git+https://github.com/willemolding/zebra?rev=185e404bed938e3aa916aee1ae6999a70efceddb#185e404bed938e3aa916aee1ae6999a70efceddb" dependencies = [ "zebra-chain", ] @@ -5950,6 +5955,7 @@ dependencies = [ [[package]] name = "zebra-script" version = "1.0.0-beta.35" +source = "git+https://github.com/willemolding/zebra?rev=185e404bed938e3aa916aee1ae6999a70efceddb#185e404bed938e3aa916aee1ae6999a70efceddb" dependencies = [ "displaydoc", "thiserror", @@ -5960,6 +5966,7 @@ dependencies = [ [[package]] name = "zebra-state" version = "1.0.0-beta.35" +source = "git+https://github.com/willemolding/zebra?rev=185e404bed938e3aa916aee1ae6999a70efceddb#185e404bed938e3aa916aee1ae6999a70efceddb" dependencies = [ "bincode", "chrono", @@ -5993,6 +6000,7 @@ dependencies = [ [[package]] name = "zebra-test" version = "1.0.0-beta.35" +source = "git+https://github.com/willemolding/zebra?rev=185e404bed938e3aa916aee1ae6999a70efceddb#185e404bed938e3aa916aee1ae6999a70efceddb" dependencies = [ "color-eyre", "futures", diff --git a/Cargo.toml b/Cargo.toml index 5ade780..7de7ad9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,15 +49,16 @@ members = [ "cartezcash-lightwalletd", "tiny-cash", "tower-cartesi"] [workspace.dependencies] # patched zebra crates to support TinyCash network and expose things we need -# zebra-consensus = { git = "https://github.com/willemolding/zebra", rev = "a8d1aa146fc702878ca84f63fe5c32898ffbdfcc", default-features = false } -# zebra-state = { git = "https://github.com/willemolding/zebra", rev = "a8d1aa146fc702878ca84f63fe5c32898ffbdfcc", default-features = false } -# zebra-test = { git = "https://github.com/willemolding/zebra", rev = "a8d1aa146fc702878ca84f63fe5c32898ffbdfcc", default-features = false } -# zebra-chain = { git = "https://github.com/willemolding/zebra", rev = "a8d1aa146fc702878ca84f63fe5c32898ffbdfcc", default-features = false } +zebra-consensus = { git = "https://github.com/willemolding/zebra", rev = "185e404bed938e3aa916aee1ae6999a70efceddb", default-features = false } +zebra-state = { git = "https://github.com/willemolding/zebra", rev = "185e404bed938e3aa916aee1ae6999a70efceddb", default-features = false } +zebra-test = { git = "https://github.com/willemolding/zebra", rev = "185e404bed938e3aa916aee1ae6999a70efceddb", default-features = false } +zebra-chain = { git = "https://github.com/willemolding/zebra", rev = "185e404bed938e3aa916aee1ae6999a70efceddb", default-features = false } -zebra-consensus = { path = "../zebra/zebra-consensus", default-features = false } -zebra-state = { path = "../zebra/zebra-state", default-features = false } -zebra-test = { path = "../zebra/zebra-test", default-features = false } -zebra-chain = { path = "../zebra/zebra-chain", default-features = false } +# uncomment for local dev when modifying zebra +# zebra-consensus = { path = "../zebra/zebra-consensus", default-features = false } +# zebra-state = { path = "../zebra/zebra-state", default-features = false } +# zebra-test = { path = "../zebra/zebra-test", default-features = false } +# zebra-chain = { path = "../zebra/zebra-chain", default-features = false } [patch.crates-io] diff --git a/cartezcash-lightwalletd/src/service_impl.rs b/cartezcash-lightwalletd/src/service_impl.rs index 1cd39af..6755acb 100644 --- a/cartezcash-lightwalletd/src/service_impl.rs +++ b/cartezcash-lightwalletd/src/service_impl.rs @@ -14,11 +14,11 @@ use crate::proto::compact_formats::*; use crate::proto::service::compact_tx_streamer_server::CompactTxStreamer; use crate::proto::service::*; +use ethers::middleware::SignerMiddleware; use ethers::prelude::abigen; use ethers::providers::{Http, Provider}; use ethers::signers::{LocalWallet, Signer}; use ethers::types::{Address, Bytes}; -use ethers::middleware::SignerMiddleware; abigen!( IInputBox, @@ -57,13 +57,15 @@ where ) -> std::result::Result, tonic::Status> { tracing::info!("send_transaction called. Fowarding to InputBox contract"); - let provider = - Provider::::try_from("http://127.0.0.1:8545").unwrap(); + let provider = Provider::::try_from("http://127.0.0.1:8545").unwrap(); let wallet: LocalWallet = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" .parse() .unwrap(); - let client = std::sync::Arc::new(SignerMiddleware::new(provider, wallet.with_chain_id(31337_u64))); + let client = std::sync::Arc::new(SignerMiddleware::new( + provider, + wallet.with_chain_id(31337_u64), + )); // Instantiate the contract let contract = IInputBox::new( diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..624eb0e --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.76.0" diff --git a/src/main.rs b/src/main.rs index 0de4645..7f47d78 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,7 +43,12 @@ async fn main() -> Result<(), anyhow::Error> { let network = Network::Mainnet; - println!("Withdraw address is: {}", UnifiedAddress::from_receivers(Some(tiny_cash::mt_doom_address()), None).unwrap().encode(&MAIN_NETWORK)); + println!( + "Withdraw address is: {}", + UnifiedAddress::from_receivers(Some(tiny_cash::mt_doom_address()), None) + .unwrap() + .encode(&MAIN_NETWORK) + ); // TODO: Enable this when not debugging // tracing::info!("Initializing Halo2 verifier key"); @@ -59,8 +64,7 @@ async fn main() -> Result<(), anyhow::Error> { let state_service = Buffer::new(state_service, 30); let state_read_service = Buffer::new(state_read_service.boxed(), 30); - let mut cartezcash_app = - CarteZcashApp::new(network, state_service).await; + let mut cartezcash_app = CarteZcashApp::new(network, state_service).await; let svc = CompactTxStreamerServer::new(CompactTxStreamerImpl { state_read_service }); let addr = grpc_addr.parse()?; @@ -79,14 +83,12 @@ async fn main() -> Result<(), anyhow::Error> { } struct CarteZcashApp { - cartezcash: Buffer>, Request>, + cartezcash: + Buffer>, Request>, } impl CarteZcashApp { - pub async fn new( - network: Network, - state_service: StateService, - ) -> Self { + pub async fn new(network: Network, state_service: StateService) -> Self { // set up the services needed to run the rollup let verifier_service = tx::Verifier::new(network, state_service.clone()); let mut tinycash = Buffer::new( @@ -100,10 +102,7 @@ impl CarteZcashApp { initialize_network(&mut tinycash).await.unwrap(); Self { - cartezcash: Buffer::new( - BoxService::new(CarteZcashService::new(tinycash)), - 10, - ), + cartezcash: Buffer::new(BoxService::new(CarteZcashService::new(tinycash)), 10), } } } diff --git a/src/service/mod.rs b/src/service/mod.rs index e0a9449..ed6bb86 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -2,7 +2,6 @@ use futures_util::future::FutureExt; use std::future::Future; use std::pin::Pin; use tower::{BoxError, Service, ServiceExt}; -use zebra_chain::amount::{Amount, NonNegative}; pub use request::Request; diff --git a/src/service/request.rs b/src/service/request.rs index 9c54202..6392efd 100644 --- a/src/service/request.rs +++ b/src/service/request.rs @@ -66,16 +66,12 @@ impl TryFrom<(tower_cartesi::AdvanceStateMetadata, Vec)> for Request { transaction bytes // arbitrary size */ - let txn = zebra_chain::transaction::Transaction::zcash_deserialize(payload.as_slice())?; + let txn = + zebra_chain::transaction::Transaction::zcash_deserialize(payload.as_slice())?; - tracing::info!( - "Received transaction request {}", - txn.hash() - ); + tracing::info!("Received transaction request {}", txn.hash()); - Ok(Request::Transact { - txn, - }) + Ok(Request::Transact { txn }) } _ => anyhow::bail!("unrecognised sender {}", metadata.msg_sender.to_string()), } @@ -88,14 +84,8 @@ impl std::fmt::Debug for Request { Request::Deposit { amount, to } => { write!(f, "Deposit {} to {}", amount, to) } - Request::Transact { - txn, - } => { - write!( - f, - "Transact hash {}", - txn.hash(), - ) + Request::Transact { txn } => { + write!(f, "Transact hash {}", txn.hash(),) } } } diff --git a/tiny-cash/src/write.rs b/tiny-cash/src/write.rs index 89e35a8..2ef8b7c 100644 --- a/tiny-cash/src/write.rs +++ b/tiny-cash/src/write.rs @@ -8,7 +8,6 @@ use std::{ }; use tower::{Service, ServiceExt}; -use zebra_chain::{transaction::{Memo, Transaction}, transparent::Script}; use zebra_chain::transparent; use zebra_chain::{ amount::{Amount, NonNegative}, @@ -18,6 +17,10 @@ use zebra_chain::{ work::{difficulty::CompactDifficulty, equihash::Solution}, }; use zebra_chain::{block, serialization::ZcashDeserialize}; +use zebra_chain::{ + transaction::{Memo, Transaction}, + transparent::Script, +}; use zebra_consensus::transaction as tx; use crate::extract_burn_info; @@ -253,9 +256,5 @@ fn mint_coinbase_txn( } fn empty_coinbase_txn(height: Height) -> Transaction { - mint_coinbase_txn( - Amount::zero(), - &Script::new(&[0x0; 32]), - height, - ) + mint_coinbase_txn(Amount::zero(), &Script::new(&[0x0; 32]), height) } diff --git a/tower-cartesi/examples/echo.rs b/tower-cartesi/examples/echo.rs index 9872243..0eedafa 100644 --- a/tower-cartesi/examples/echo.rs +++ b/tower-cartesi/examples/echo.rs @@ -1,12 +1,12 @@ +use futures_util::FutureExt; use std::env; -use std::future::Future; use std::error::Error; +use std::future::Future; use std::pin::Pin; -use std::task::{Poll, Context}; -use futures_util::FutureExt; +use std::task::{Context, Poll}; -use tower_service::Service; use tower_cartesi::{listen_http, Request, Response}; +use tower_service::Service; type BoxError = Box; @@ -35,24 +35,22 @@ impl Service for EchoApp { type Error = Box; type Future = Pin> + Send>>; - fn poll_ready( - &mut self, - _cx: &mut Context<'_>, - ) -> Poll> { + fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) } fn call(&mut self, req: Request) -> Self::Future { match req { Request::AdvanceState { metadata, payload } => { - println!("Received advance state request {:?} \npayload {:?}:", metadata, payload); + println!( + "Received advance state request {:?} \npayload {:?}:", + metadata, payload + ); } Request::InspectState { payload } => { println!("Received inspect state request {:?}", payload); } } - async { - Ok(tower_cartesi::Response::empty_accept()) - }.boxed() + async { Ok(tower_cartesi::Response::empty_accept()) }.boxed() } } diff --git a/tower-cartesi/src/response.rs b/tower-cartesi/src/response.rs index 165f9b6..bb8f57c 100644 --- a/tower-cartesi/src/response.rs +++ b/tower-cartesi/src/response.rs @@ -17,7 +17,10 @@ impl Response { } pub fn add_voucher(&mut self, destination: ethereum_types::Address, payload: &[u8]) { - self.outputs.push(Output::Voucher{destination, payload: payload.to_vec() }); + self.outputs.push(Output::Voucher { + destination, + payload: payload.to_vec(), + }); } pub fn finish_message(&self) -> Finish {