penumbra-zone / tower-abci

Tower-based ABCI interface.
MIT License
75 stars 24 forks source link

server: 🌽 `listen_channel` for in-memory connections #41

Closed cratelyn closed 7 months ago

cratelyn commented 7 months ago

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.

hdevalence commented 7 months ago

I'm not sure this is the right approach for that testing use-case.

tower-abci is a compatibility layer to bridge the bespoke Tendermint socket protocol to a more reasonable, request/response-oriented API.

Using it in an in-memory test would mean translating all the requests and responses through the TSP wire encoding and then back, re-interpreting them as requests and responses, and then feeding them into the generic C: Service<...> passed into the tower_abci::Server. But if the test code is instantiating the tower_abci::Server, it already has a consensus service that it's plugging in (the C: Service<...> mapping ConsensusRequests to ConsensusResponses), and it could just call that Service directly.

I'm not sure whether this was made explicit, but that was the intent of the C in the Engine<C> we sketched while pairing: passing in a generic consensus Service into the Engine means it can make ABCI requests directly (using the tower::Service API, or the convenience methods in ServiceExt), without any need for extra encoding.