Skip to content

Commit

Permalink
Merge branch 'develop' into deps/tokio
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek authored Nov 28, 2024
2 parents c75eef9 + c8f8e6d commit 885947d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
19 changes: 16 additions & 3 deletions abci/src/server/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ impl<'a> Codec {

Self::process_worker_queues(codec, request_tx, response_rx, cancel).await;
}

/// Worker that moves messages between codec and requests and responses
/// queues.
///
/// Reads messages from ABCI Client from `codec`, sends them to Tenderdash
/// via `request_tx`, receives Tenderdash responses from `response_rx`
/// and forwards to
///
/// ## Error handling
///
/// On error, it cancels the `cancel` [CancellationToken] and exits.
/// It causes `response_rx` to be closed.
async fn process_worker_queues<L: AsyncRead + AsyncWrite + Unpin>(
mut codec: Framed<L, Coder>,
request_tx: Sender<proto::abci::Request>,
Expand Down Expand Up @@ -149,9 +161,10 @@ impl<'a> Codec {
}

pub fn send(&self, value: Response) -> Result<(), Error> {
self.response_tx
.blocking_send(value)
.map_err(|e| Error::Async(e.to_string()))
self.response_tx.blocking_send(value).map_err(|_| {
// channel closed, `process_worker_queues` either errored or cancelled
Error::Cancelled()
})
}
}

Expand Down
8 changes: 6 additions & 2 deletions abci/tests/kvstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,21 @@ fn test_kvstore() {
fs::set_permissions(SOCKET, perms).expect("set perms");

let socket_uri = bind_address.to_string();
let _td = common::docker::TenderdashDocker::new("tenderdash", None, &socket_uri);
let td = common::docker::TenderdashDocker::new("tenderdash", None, &socket_uri);

let next_client = server.next_client();
tracing::debug!(?next_client, "next client");
assert!(matches!(
server.next_client(),
next_client,
Err(tenderdash_abci::Error::Cancelled())
));
drop(server);

let kvstore_app = kvstore.into_inner().expect("kvstore lock is poisoned");
assert_eq!(kvstore_app.persisted_state, state_reference);
assert_eq!(kvstore_app.last_block_height, 1);

drop(td);
}

/// An example storage.
Expand Down

0 comments on commit 885947d

Please sign in to comment.