Skip to content

Commit

Permalink
server: 🌽 listen_channel for in-memory connections
Browse files Browse the repository at this point in the history
this introduces a `Server::listen_channel` interface. this is like the
existing `listen_tcp` or `listen_unix` methods, but instead applies to
an in-memory channel of `(read, write)` tuples.

this is motivated by work like penumbra-zone/penumbra#3588. to summarize
the motivation, it would be nice if we had a way to run a tower-abci
service in cargo tests, without needing to bind to an actual port, or
create a unix-domain socket within a temporary directory.
  • Loading branch information
cratelyn committed Feb 9, 2024
1 parent bc0352e commit 82a9bfb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/v037/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,29 @@ where
}
}
}

pub async fn listen_channel<R, W>(self, mut channel: tokio::sync::mpsc::Receiver<(R, W)>)
where
R: AsyncReadExt + std::marker::Unpin + Send + 'static,
W: AsyncWriteExt + std::marker::Unpin + Send + 'static,
{
tracing::info!("ABCI server starting on tokio channel");

match channel.recv().await {
Some((read, write)) => {
let conn = Connection {
consensus: self.consensus.clone(),
mempool: self.mempool.clone(),
info: self.info.clone(),
snapshot: self.snapshot.clone(),
};
tokio::spawn(async move { conn.run(read, write).await.unwrap() });
}
None => {
tracing::debug!("channel closed");
}
}
}
}

struct Connection<C, M, I, S> {
Expand Down

0 comments on commit 82a9bfb

Please sign in to comment.