From c60cfc645c333ad5f6420e2a295c11b7afbfaba1 Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Wed, 29 May 2024 00:00:00 +0000 Subject: [PATCH] =?UTF-8?q?view:=20=E2=9C=8B=20hoist=20url=20out=20of=20wo?= =?UTF-8?q?rker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hoist the construction of a tonic channel out of the worker. move it to the call-side, in the view server. --- crates/view/src/service.rs | 10 +++++++++- crates/view/src/worker.rs | 17 +++-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/crates/view/src/service.rs b/crates/view/src/service.rs index 76c2c489ef..1f1b05ec6f 100644 --- a/crates/view/src/service.rs +++ b/crates/view/src/service.rs @@ -122,9 +122,17 @@ impl ViewServer { /// To create multiple [`ViewService`]s, clone the [`ViewService`] returned /// by this method, rather than calling it multiple times. That way, each clone /// will be backed by the same scanning task, rather than each spawning its own. + #[instrument(skip_all)] pub async fn new(storage: Storage, node: Url) -> anyhow::Result { + let channel = Channel::from_shared(node.to_string()) + .with_context(|| "could not parse node URI")? + .connect() + .await + .with_context(|| "could not connect to grpc server") + .tap_err(|error| tracing::error!(?error, "could not connect to grpc server"))?; + let (worker, state_commitment_tree, error_slot, sync_height_rx) = - Worker::new(storage.clone(), node.clone()) + Worker::new(storage.clone(), channel) .tap(|_| tracing::trace!("constructing view server worker")) .await? .tap(|_| tracing::debug!("constructed view server worker")); diff --git a/crates/view/src/worker.rs b/crates/view/src/worker.rs index 047a8c11da..1fb59c1a36 100644 --- a/crates/view/src/worker.rs +++ b/crates/view/src/worker.rs @@ -27,11 +27,10 @@ use penumbra_proto::core::{ }; use penumbra_sct::{CommitmentSource, Nullifier}; use penumbra_transaction::Transaction; -use tap::{Tap, TapFallible}; +use tap::Tap; use tokio::sync::{watch, RwLock}; use tonic::transport::Channel; use tracing::instrument; -use url::Url; use crate::{ sync::{scan_block, FilteredBlock}, @@ -55,13 +54,10 @@ impl Worker { /// - a shared, in-memory SCT instance; /// - a shared error slot; /// - a channel for notifying the client of sync progress. - #[instrument( - skip(storage), - fields(url = %node) - )] + #[instrument(skip_all)] pub async fn new( storage: Storage, - node: Url, + channel: Channel, ) -> Result< ( Self, @@ -88,13 +84,6 @@ impl Worker { // Mark the current height as seen, since it's not new. sync_height_rx.borrow_and_update(); - let channel = Channel::from_shared(node.to_string()) - .with_context(|| "could not parse node URI")? - .connect() - .await - .with_context(|| "could not connect to grpc server") - .tap_err(|error| tracing::error!(?error, "could not connect to grpc server"))?; - Ok(( Self { storage,