Skip to content

Commit

Permalink
view: ✋ hoist url out of worker
Browse files Browse the repository at this point in the history
hoist the construction of a tonic channel out of the worker. move it to
the call-side, in the view server.
  • Loading branch information
cratelyn committed Jun 3, 2024
1 parent 8e66259 commit c60cfc6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
10 changes: 9 additions & 1 deletion crates/view/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
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"));
Expand Down
17 changes: 3 additions & 14 deletions crates/view/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit c60cfc6

Please sign in to comment.