diff --git a/examples/block-decode/src/main.rs b/examples/block-decode/src/main.rs index c6e9c11..312f1a0 100644 --- a/examples/block-decode/src/main.rs +++ b/examples/block-decode/src/main.rs @@ -1,7 +1,7 @@ use pallas::ledger::traverse::MultiEraBlock; fn main() { - let blocks = vec![ + let blocks = [ include_str!("blocks/byron.block"), include_str!("blocks/shelley.block"), include_str!("blocks/mary.block"), diff --git a/pallas-addresses/src/lib.rs b/pallas-addresses/src/lib.rs index baa802a..3660fc6 100644 --- a/pallas-addresses/src/lib.rs +++ b/pallas-addresses/src/lib.rs @@ -799,7 +799,7 @@ mod tests { let addr = Address::from_str(original).unwrap(); match addr { - Address::Byron(_) => assert!(matches!(addr.network(), None)), + Address::Byron(_) => assert!(addr.network().is_none()), _ => assert!(matches!(addr.network(), Some(Network::Mainnet))), } } diff --git a/pallas-network/src/facades.rs b/pallas-network/src/facades.rs index a9eba3a..ace6140 100644 --- a/pallas-network/src/facades.rs +++ b/pallas-network/src/facades.rs @@ -95,7 +95,7 @@ pub struct PeerServer { impl PeerServer { pub async fn accept(listener: &TcpListener, magic: u64) -> Result { - let (bearer, _) = Bearer::accept_tcp(&listener) + let (bearer, _) = Bearer::accept_tcp(listener) .await .map_err(Error::ConnectFailure)?; diff --git a/pallas-network/src/miniprotocols/blockfetch/client.rs b/pallas-network/src/miniprotocols/blockfetch/client.rs index adeb1f6..11b8c89 100644 --- a/pallas-network/src/miniprotocols/blockfetch/client.rs +++ b/pallas-network/src/miniprotocols/blockfetch/client.rs @@ -7,7 +7,7 @@ use crate::multiplexer; use super::{Message, State}; #[derive(Error, Debug)] -pub enum Error { +pub enum ClientError { #[error("attempted to receive message while agency is ours")] AgencyIsOurs, @@ -74,57 +74,60 @@ impl Client { } } - fn assert_agency_is_ours(&self) -> Result<(), Error> { + fn assert_agency_is_ours(&self) -> Result<(), ClientError> { if !self.has_agency() { - Err(Error::AgencyIsTheirs) + Err(ClientError::AgencyIsTheirs) } else { Ok(()) } } - fn assert_agency_is_theirs(&self) -> Result<(), Error> { + fn assert_agency_is_theirs(&self) -> Result<(), ClientError> { if self.has_agency() { - Err(Error::AgencyIsOurs) + Err(ClientError::AgencyIsOurs) } else { Ok(()) } } - fn assert_outbound_state(&self, msg: &Message) -> Result<(), Error> { + fn assert_outbound_state(&self, msg: &Message) -> Result<(), ClientError> { match (&self.0, msg) { (State::Idle, Message::RequestRange { .. }) => Ok(()), (State::Idle, Message::ClientDone) => Ok(()), - _ => Err(Error::InvalidOutbound), + _ => Err(ClientError::InvalidOutbound), } } - fn assert_inbound_state(&self, msg: &Message) -> Result<(), Error> { + fn assert_inbound_state(&self, msg: &Message) -> Result<(), ClientError> { match (&self.0, msg) { (State::Busy, Message::StartBatch) => Ok(()), (State::Busy, Message::NoBlocks) => Ok(()), (State::Streaming, Message::Block { .. }) => Ok(()), (State::Streaming, Message::BatchDone) => Ok(()), - _ => Err(Error::InvalidInbound), + _ => Err(ClientError::InvalidInbound), } } - pub async fn send_message(&mut self, msg: &Message) -> Result<(), Error> { + pub async fn send_message(&mut self, msg: &Message) -> Result<(), ClientError> { self.assert_agency_is_ours()?; self.assert_outbound_state(msg)?; - self.1.send_msg_chunks(msg).await.map_err(Error::Plexer)?; + self.1 + .send_msg_chunks(msg) + .await + .map_err(ClientError::Plexer)?; Ok(()) } - pub async fn recv_message(&mut self) -> Result { + pub async fn recv_message(&mut self) -> Result { self.assert_agency_is_theirs()?; - let msg = self.1.recv_full_msg().await.map_err(Error::Plexer)?; + let msg = self.1.recv_full_msg().await.map_err(ClientError::Plexer)?; self.assert_inbound_state(&msg)?; Ok(msg) } - pub async fn send_request_range(&mut self, range: (Point, Point)) -> Result<(), Error> { + pub async fn send_request_range(&mut self, range: (Point, Point)) -> Result<(), ClientError> { let msg = Message::RequestRange { range }; self.send_message(&msg).await?; self.0 = State::Busy; @@ -132,7 +135,7 @@ impl Client { Ok(()) } - pub async fn recv_while_busy(&mut self) -> Result { + pub async fn recv_while_busy(&mut self) -> Result { match self.recv_message().await? { Message::StartBatch => { info!("batch start"); @@ -144,7 +147,7 @@ impl Client { self.0 = State::Idle; Ok(None) } - _ => Err(Error::InvalidInbound), + _ => Err(ClientError::InvalidInbound), } } @@ -154,7 +157,7 @@ impl Client { /// /// * `range` - A tuple of two `Point` instances representing the start and /// end of the requested block range. - pub async fn request_range(&mut self, range: Range) -> Result { + pub async fn request_range(&mut self, range: Range) -> Result { self.send_request_range(range).await?; debug!("range requested"); self.recv_while_busy().await @@ -164,7 +167,7 @@ impl Client { /// /// Returns a block's body if a block is received, or `None` if the /// streaming has ended. - pub async fn recv_while_streaming(&mut self) -> Result, Error> { + pub async fn recv_while_streaming(&mut self) -> Result, ClientError> { debug!("waiting for stream"); match self.recv_message().await? { @@ -173,7 +176,7 @@ impl Client { self.0 = State::Idle; Ok(None) } - _ => Err(Error::InvalidInbound), + _ => Err(ClientError::InvalidInbound), } } @@ -185,20 +188,20 @@ impl Client { /// /// Returns the block's body if the block is found, or an `Error` if the /// block is not found or an invalid message is received. - pub async fn fetch_single(&mut self, point: Point) -> Result { + pub async fn fetch_single(&mut self, point: Point) -> Result { self.request_range((point.clone(), point)) .await? - .ok_or(Error::NoBlocks)?; + .ok_or(ClientError::NoBlocks)?; let body = self .recv_while_streaming() .await? - .ok_or(Error::InvalidInbound)?; + .ok_or(ClientError::InvalidInbound)?; debug!("body received"); match self.recv_while_streaming().await? { - Some(_) => Err(Error::InvalidInbound), + Some(_) => Err(ClientError::InvalidInbound), None => Ok(body), } } @@ -212,8 +215,10 @@ impl Client { /// /// Returns a vector of block bodies for the requested range, or an `Error` /// if the range is not found. - pub async fn fetch_range(&mut self, range: Range) -> Result, Error> { - self.request_range(range).await?.ok_or(Error::NoBlocks)?; + pub async fn fetch_range(&mut self, range: Range) -> Result, ClientError> { + self.request_range(range) + .await? + .ok_or(ClientError::NoBlocks)?; let mut all = vec![]; @@ -230,7 +235,7 @@ impl Client { /// /// Returns `Ok(())` if the message is sent successfully, or an `Error` if /// the agency is not ours. - pub async fn send_done(&mut self) -> Result<(), Error> { + pub async fn send_done(&mut self) -> Result<(), ClientError> { let msg = Message::ClientDone; self.send_message(&msg).await?; self.0 = State::Done; diff --git a/pallas-network/src/miniprotocols/blockfetch/server.rs b/pallas-network/src/miniprotocols/blockfetch/server.rs index d346a3b..00a7215 100644 --- a/pallas-network/src/miniprotocols/blockfetch/server.rs +++ b/pallas-network/src/miniprotocols/blockfetch/server.rs @@ -5,7 +5,7 @@ use crate::multiplexer; use super::{Body, Message, Range, State}; #[derive(Error, Debug)] -pub enum Error { +pub enum ServerError { #[error("attempted to receive message while agency is ours")] AgencyIsOurs, @@ -62,57 +62,60 @@ impl Server { } } - fn assert_agency_is_ours(&self) -> Result<(), Error> { + fn assert_agency_is_ours(&self) -> Result<(), ServerError> { if !self.has_agency() { - Err(Error::AgencyIsTheirs) + Err(ServerError::AgencyIsTheirs) } else { Ok(()) } } - fn assert_agency_is_theirs(&self) -> Result<(), Error> { + fn assert_agency_is_theirs(&self) -> Result<(), ServerError> { if self.has_agency() { - Err(Error::AgencyIsOurs) + Err(ServerError::AgencyIsOurs) } else { Ok(()) } } - fn assert_outbound_state(&self, msg: &Message) -> Result<(), Error> { + fn assert_outbound_state(&self, msg: &Message) -> Result<(), ServerError> { match (&self.0, msg) { (State::Busy, Message::NoBlocks) => Ok(()), (State::Busy, Message::StartBatch) => Ok(()), (State::Streaming, Message::Block { .. }) => Ok(()), (State::Streaming, Message::BatchDone) => Ok(()), - _ => Err(Error::InvalidOutbound), + _ => Err(ServerError::InvalidOutbound), } } - fn assert_inbound_state(&self, msg: &Message) -> Result<(), Error> { + fn assert_inbound_state(&self, msg: &Message) -> Result<(), ServerError> { match (&self.0, msg) { (State::Idle, Message::RequestRange { .. }) => Ok(()), (State::Idle, Message::ClientDone) => Ok(()), - _ => Err(Error::InvalidInbound), + _ => Err(ServerError::InvalidInbound), } } - pub async fn send_message(&mut self, msg: &Message) -> Result<(), Error> { + pub async fn send_message(&mut self, msg: &Message) -> Result<(), ServerError> { self.assert_agency_is_ours()?; self.assert_outbound_state(msg)?; - self.1.send_msg_chunks(msg).await.map_err(Error::Plexer)?; + self.1 + .send_msg_chunks(msg) + .await + .map_err(ServerError::Plexer)?; Ok(()) } - pub async fn recv_message(&mut self) -> Result { + pub async fn recv_message(&mut self) -> Result { self.assert_agency_is_theirs()?; - let msg = self.1.recv_full_msg().await.map_err(Error::Plexer)?; + let msg = self.1.recv_full_msg().await.map_err(ServerError::Plexer)?; self.assert_inbound_state(&msg)?; Ok(msg) } - pub async fn send_start_batch(&mut self) -> Result<(), Error> { + pub async fn send_start_batch(&mut self) -> Result<(), ServerError> { let msg = Message::StartBatch; self.send_message(&msg).await?; self.0 = State::Streaming; @@ -120,7 +123,7 @@ impl Server { Ok(()) } - pub async fn send_no_blocks(&mut self) -> Result<(), Error> { + pub async fn send_no_blocks(&mut self) -> Result<(), ServerError> { let msg = Message::NoBlocks; self.send_message(&msg).await?; self.0 = State::Idle; @@ -128,14 +131,14 @@ impl Server { Ok(()) } - pub async fn send_block(&mut self, body: Body) -> Result<(), Error> { + pub async fn send_block(&mut self, body: Body) -> Result<(), ServerError> { let msg = Message::Block { body }; self.send_message(&msg).await?; Ok(()) } - pub async fn send_batch_done(&mut self) -> Result<(), Error> { + pub async fn send_batch_done(&mut self) -> Result<(), ServerError> { let msg = Message::BatchDone; self.send_message(&msg).await?; self.0 = State::Idle; @@ -150,7 +153,7 @@ impl Server { /// progess the server state to `Busy`. If the message is a `ClientDone`, /// return None and progress the server state to `Done`. For any other /// incoming message type return an `Error`. - pub async fn recv_while_idle(&mut self) -> Result, Error> { + pub async fn recv_while_idle(&mut self) -> Result, ServerError> { match self.recv_message().await? { Message::RequestRange { range } => { self.0 = State::Busy; @@ -162,7 +165,7 @@ impl Server { Ok(None) } - _ => Err(Error::InvalidInbound), + _ => Err(ServerError::InvalidInbound), } } @@ -174,7 +177,7 @@ impl Server { /// /// * `blocks` - Ordered list of block bodies corresponding to the client's /// requested range. - pub async fn send_block_range(&mut self, blocks: Vec) -> Result<(), Error> { + pub async fn send_block_range(&mut self, blocks: Vec) -> Result<(), ServerError> { if blocks.is_empty() { self.send_no_blocks().await } else { diff --git a/pallas-network/src/miniprotocols/chainsync/client.rs b/pallas-network/src/miniprotocols/chainsync/client.rs index e79c870..f7eb54c 100644 --- a/pallas-network/src/miniprotocols/chainsync/client.rs +++ b/pallas-network/src/miniprotocols/chainsync/client.rs @@ -9,7 +9,7 @@ use crate::multiplexer; use super::{BlockContent, HeaderContent, IntersectResponse, Message, State, Tip}; #[derive(Error, Debug)] -pub enum Error { +pub enum ClientError { #[error("attempted to receive message while agency is ours")] AgencyIsOurs, @@ -79,32 +79,32 @@ where } } - fn assert_agency_is_ours(&self) -> Result<(), Error> { + fn assert_agency_is_ours(&self) -> Result<(), ClientError> { if !self.has_agency() { - Err(Error::AgencyIsTheirs) + Err(ClientError::AgencyIsTheirs) } else { Ok(()) } } - fn assert_agency_is_theirs(&self) -> Result<(), Error> { + fn assert_agency_is_theirs(&self) -> Result<(), ClientError> { if self.has_agency() { - Err(Error::AgencyIsOurs) + Err(ClientError::AgencyIsOurs) } else { Ok(()) } } - fn assert_outbound_state(&self, msg: &Message) -> Result<(), Error> { + fn assert_outbound_state(&self, msg: &Message) -> Result<(), ClientError> { match (&self.0, msg) { (State::Idle, Message::RequestNext) => Ok(()), (State::Idle, Message::FindIntersect(_)) => Ok(()), (State::Idle, Message::Done) => Ok(()), - _ => Err(Error::InvalidOutbound), + _ => Err(ClientError::InvalidOutbound), } } - fn assert_inbound_state(&self, msg: &Message) -> Result<(), Error> { + fn assert_inbound_state(&self, msg: &Message) -> Result<(), ClientError> { match (&self.0, msg) { (State::CanAwait, Message::RollForward(_, _)) => Ok(()), (State::CanAwait, Message::RollBackward(_, _)) => Ok(()), @@ -113,7 +113,7 @@ where (State::MustReply, Message::RollBackward(_, _)) => Ok(()), (State::Intersect, Message::IntersectFound(_, _)) => Ok(()), (State::Intersect, Message::IntersectNotFound(_)) => Ok(()), - _ => Err(Error::InvalidInbound), + _ => Err(ClientError::InvalidInbound), } } @@ -127,11 +127,14 @@ where /// /// Returns an error if the agency is not ours or if the outbound state is /// invalid. - pub async fn send_message(&mut self, msg: &Message) -> Result<(), Error> { + pub async fn send_message(&mut self, msg: &Message) -> Result<(), ClientError> { self.assert_agency_is_ours()?; self.assert_outbound_state(msg)?; - self.1.send_msg_chunks(msg).await.map_err(Error::Plexer)?; + self.1 + .send_msg_chunks(msg) + .await + .map_err(ClientError::Plexer)?; Ok(()) } @@ -142,10 +145,10 @@ where /// /// Returns an error if the agency is not theirs or if the inbound state is /// invalid. - pub async fn recv_message(&mut self) -> Result, Error> { + pub async fn recv_message(&mut self) -> Result, ClientError> { self.assert_agency_is_theirs()?; - let msg = self.1.recv_full_msg().await.map_err(Error::Plexer)?; + let msg = self.1.recv_full_msg().await.map_err(ClientError::Plexer)?; self.assert_inbound_state(&msg)?; @@ -163,7 +166,7 @@ where /// /// Returns an error if the message cannot be sent or if it's not valid for /// the current state of the client. - pub async fn send_find_intersect(&mut self, points: Vec) -> Result<(), Error> { + pub async fn send_find_intersect(&mut self, points: Vec) -> Result<(), ClientError> { let msg = Message::FindIntersect(points); self.send_message(&msg).await?; self.0 = State::Intersect; @@ -178,7 +181,7 @@ where /// # Errors /// /// Returns an error if the inbound message is invalid. - pub async fn recv_intersect_response(&mut self) -> Result { + pub async fn recv_intersect_response(&mut self) -> Result { debug!("waiting for intersect response"); match self.recv_message().await? { @@ -190,7 +193,7 @@ where self.0 = State::Idle; Ok((None, tip)) } - _ => Err(Error::InvalidInbound), + _ => Err(ClientError::InvalidInbound), } } @@ -205,12 +208,15 @@ where /// /// Returns an error if the intersection point cannot be found or if there /// is a communication error. - pub async fn find_intersect(&mut self, points: Vec) -> Result { + pub async fn find_intersect( + &mut self, + points: Vec, + ) -> Result { self.send_find_intersect(points).await?; self.recv_intersect_response().await } - pub async fn send_request_next(&mut self) -> Result<(), Error> { + pub async fn send_request_next(&mut self) -> Result<(), ClientError> { let msg = Message::RequestNext; self.send_message(&msg).await?; self.0 = State::CanAwait; @@ -223,7 +229,7 @@ where /// # Errors /// /// Returns an error if the inbound message is invalid. - pub async fn recv_while_can_await(&mut self) -> Result, Error> { + pub async fn recv_while_can_await(&mut self) -> Result, ClientError> { match self.recv_message().await? { Message::AwaitReply => { self.0 = State::MustReply; @@ -237,7 +243,7 @@ where self.0 = State::Idle; Ok(NextResponse::RollBackward(a, b)) } - _ => Err(Error::InvalidInbound), + _ => Err(ClientError::InvalidInbound), } } @@ -246,7 +252,7 @@ where /// # Errors /// /// Returns an error if the inbound message is invalid. - pub async fn recv_while_must_reply(&mut self) -> Result, Error> { + pub async fn recv_while_must_reply(&mut self) -> Result, ClientError> { match self.recv_message().await? { Message::RollForward(a, b) => { self.0 = State::Idle; @@ -256,7 +262,7 @@ where self.0 = State::Idle; Ok(NextResponse::RollBackward(a, b)) } - _ => Err(Error::InvalidInbound), + _ => Err(ClientError::InvalidInbound), } } @@ -266,7 +272,7 @@ where /// /// Returns an error if the message cannot be sent or if the state is not /// idle. - pub async fn request_next(&mut self) -> Result, Error> { + pub async fn request_next(&mut self) -> Result, ClientError> { debug!("requesting next block"); self.send_request_next().await?; @@ -280,12 +286,12 @@ where /// /// Returns an error if the intersection point cannot be found or if there /// is a communication error. - pub async fn intersect_origin(&mut self) -> Result { + pub async fn intersect_origin(&mut self) -> Result { debug!("intersecting origin"); let (point, _) = self.find_intersect(vec![Point::Origin]).await?; - point.ok_or(Error::IntersectionNotFound) + point.ok_or(ClientError::IntersectionNotFound) } /// Attempts to intersect the chain at the latest known tip @@ -294,17 +300,17 @@ where /// /// Returns an error if the intersection point cannot be found or if there /// is a communication error. - pub async fn intersect_tip(&mut self) -> Result { + pub async fn intersect_tip(&mut self) -> Result { let (_, Tip(point, _)) = self.find_intersect(vec![Point::Origin]).await?; debug!(?point, "found tip value"); let (point, _) = self.find_intersect(vec![point]).await?; - point.ok_or(Error::IntersectionNotFound) + point.ok_or(ClientError::IntersectionNotFound) } - pub async fn send_done(&mut self) -> Result<(), Error> { + pub async fn send_done(&mut self) -> Result<(), ClientError> { let msg = Message::Done; self.send_message(&msg).await?; self.0 = State::Done; diff --git a/pallas-network/src/miniprotocols/chainsync/server.rs b/pallas-network/src/miniprotocols/chainsync/server.rs index ae58e47..1c137b3 100644 --- a/pallas-network/src/miniprotocols/chainsync/server.rs +++ b/pallas-network/src/miniprotocols/chainsync/server.rs @@ -9,7 +9,7 @@ use crate::multiplexer; use super::{BlockContent, HeaderContent, Message, State, Tip}; #[derive(Error, Debug)] -pub enum Error { +pub enum ServerError { #[error("attempted to receive message while agency is ours")] AgencyIsOurs, @@ -75,23 +75,23 @@ where } } - fn assert_agency_is_ours(&self) -> Result<(), Error> { + fn assert_agency_is_ours(&self) -> Result<(), ServerError> { if !self.has_agency() { - Err(Error::AgencyIsTheirs) + Err(ServerError::AgencyIsTheirs) } else { Ok(()) } } - fn assert_agency_is_theirs(&self) -> Result<(), Error> { + fn assert_agency_is_theirs(&self) -> Result<(), ServerError> { if self.has_agency() { - Err(Error::AgencyIsOurs) + Err(ServerError::AgencyIsOurs) } else { Ok(()) } } - fn assert_outbound_state(&self, msg: &Message) -> Result<(), Error> { + fn assert_outbound_state(&self, msg: &Message) -> Result<(), ServerError> { match (&self.0, msg) { (State::CanAwait, Message::RollForward(_, _)) => Ok(()), (State::CanAwait, Message::RollBackward(_, _)) => Ok(()), @@ -100,16 +100,16 @@ where (State::MustReply, Message::RollBackward(_, _)) => Ok(()), (State::Intersect, Message::IntersectFound(_, _)) => Ok(()), (State::Intersect, Message::IntersectNotFound(_)) => Ok(()), - _ => Err(Error::InvalidOutbound), + _ => Err(ServerError::InvalidOutbound), } } - fn assert_inbound_state(&self, msg: &Message) -> Result<(), Error> { + fn assert_inbound_state(&self, msg: &Message) -> Result<(), ServerError> { match (&self.0, msg) { (State::Idle, Message::RequestNext) => Ok(()), (State::Idle, Message::FindIntersect(_)) => Ok(()), (State::Idle, Message::Done) => Ok(()), - _ => Err(Error::InvalidInbound), + _ => Err(ServerError::InvalidInbound), } } @@ -123,11 +123,14 @@ where /// /// Returns an error if the agency is not ours or if the outbound state is /// invalid. - pub async fn send_message(&mut self, msg: &Message) -> Result<(), Error> { + pub async fn send_message(&mut self, msg: &Message) -> Result<(), ServerError> { self.assert_agency_is_ours()?; self.assert_outbound_state(msg)?; - self.1.send_msg_chunks(msg).await.map_err(Error::Plexer)?; + self.1 + .send_msg_chunks(msg) + .await + .map_err(ServerError::Plexer)?; Ok(()) } @@ -138,10 +141,10 @@ where /// /// Returns an error if the agency is not theirs or if the inbound state is /// invalid. - async fn recv_message(&mut self) -> Result, Error> { + async fn recv_message(&mut self) -> Result, ServerError> { self.assert_agency_is_theirs()?; - let msg = self.1.recv_full_msg().await.map_err(Error::Plexer)?; + let msg = self.1.recv_full_msg().await.map_err(ServerError::Plexer)?; self.assert_inbound_state(&msg)?; @@ -154,7 +157,7 @@ where /// /// Returns an error if the agency is not theirs or if the inbound message /// is invalid for Idle protocol state. - pub async fn recv_while_idle(&mut self) -> Result, Error> { + pub async fn recv_while_idle(&mut self) -> Result, ServerError> { match self.recv_message().await? { Message::FindIntersect(points) => { self.0 = State::Intersect; @@ -169,7 +172,7 @@ where Ok(None) } - _ => Err(Error::InvalidInbound), + _ => Err(ServerError::InvalidInbound), } } @@ -183,7 +186,7 @@ where /// /// Returns an error if the message cannot be sent or if it's not valid for /// the current state of the server. - pub async fn send_intersect_not_found(&mut self, tip: Tip) -> Result<(), Error> { + pub async fn send_intersect_not_found(&mut self, tip: Tip) -> Result<(), ServerError> { debug!("send intersect not found"); let msg = Message::IntersectNotFound(tip); @@ -205,7 +208,11 @@ where /// /// Returns an error if the message cannot be sent or if it's not valid for /// the current state of the server. - pub async fn send_intersect_found(&mut self, point: Point, tip: Tip) -> Result<(), Error> { + pub async fn send_intersect_found( + &mut self, + point: Point, + tip: Tip, + ) -> Result<(), ServerError> { debug!("send intersect found ({point:?}"); let msg = Message::IntersectFound(point, tip); @@ -227,7 +234,7 @@ where /// /// Returns an error if the message cannot be sent or if it's not valid for /// the current state of the server. - pub async fn send_roll_forward(&mut self, content: O, tip: Tip) -> Result<(), Error> { + pub async fn send_roll_forward(&mut self, content: O, tip: Tip) -> Result<(), ServerError> { debug!("send roll forward"); let msg = Message::RollForward(content, tip); @@ -248,7 +255,7 @@ where /// /// Returns an error if the message cannot be sent or if it's not valid for /// the current state of the server. - pub async fn send_roll_backward(&mut self, point: Point, tip: Tip) -> Result<(), Error> { + pub async fn send_roll_backward(&mut self, point: Point, tip: Tip) -> Result<(), ServerError> { debug!("send roll backward {point:?}"); let msg = Message::RollBackward(point, tip); @@ -269,7 +276,7 @@ where /// /// Returns an error if the message cannot be sent or if it's not valid for /// the current state of the server. - pub async fn send_await_reply(&mut self) -> Result<(), Error> { + pub async fn send_await_reply(&mut self) -> Result<(), ServerError> { debug!("send await reply"); let msg = Message::AwaitReply; diff --git a/pallas-network/src/multiplexer.rs b/pallas-network/src/multiplexer.rs index 73b505d..d1e4ce7 100644 --- a/pallas-network/src/multiplexer.rs +++ b/pallas-network/src/multiplexer.rs @@ -501,7 +501,7 @@ mod tests { let channel = AgentChannel::for_client(0, &ingress, &egress); - egress.0.send((0 ^ 0x8000, input)).unwrap(); + egress.0.send((0x8000, input)).unwrap(); let mut buf = ChannelBuffer::new(channel); @@ -525,7 +525,7 @@ mod tests { while !input.is_empty() { let chunk = Vec::from(input.drain(0..2).as_slice()); - egress.0.send((0 ^ 0x8000, chunk)).unwrap(); + egress.0.send((0x8000, chunk)).unwrap(); } let mut buf = ChannelBuffer::new(channel); diff --git a/pallas-network/tests/plexer.rs b/pallas-network/tests/plexer.rs index f31e95f..8ae0720 100644 --- a/pallas-network/tests/plexer.rs +++ b/pallas-network/tests/plexer.rs @@ -9,7 +9,7 @@ async fn setup_passive_muxer() -> Plexer { .await .unwrap(); - println!("listening for connections on port {}", P); + println!("listening for connections on port {P}"); let (bearer, _) = Bearer::accept_tcp(&server).await.unwrap(); diff --git a/pallas-network/tests/protocols.rs b/pallas-network/tests/protocols.rs index 98e9ae1..59de6a5 100644 --- a/pallas-network/tests/protocols.rs +++ b/pallas-network/tests/protocols.rs @@ -30,7 +30,7 @@ pub async fn chainsync_history_happy_path() { .await .unwrap(); - println!("{:?}", point); + println!("{point:?}"); assert!(matches!(client.state(), chainsync::State::Idle)); @@ -127,7 +127,7 @@ pub async fn blockfetch_happy_path() { println!("streaming..."); - assert!(matches!(range_ok, Ok(_))); + assert!(range_ok.is_ok()); for _ in 0..1 { let next = client.recv_while_streaming().await.unwrap(); @@ -142,7 +142,7 @@ pub async fn blockfetch_happy_path() { let next = client.recv_while_streaming().await.unwrap(); - assert!(matches!(next, None)); + assert!(next.is_none()); client.send_done().await.unwrap(); diff --git a/pallas-primitives/src/alonzo/json.rs b/pallas-primitives/src/alonzo/json.rs index 3f2c2e6..31bd969 100644 --- a/pallas-primitives/src/alonzo/json.rs +++ b/pallas-primitives/src/alonzo/json.rs @@ -88,7 +88,7 @@ mod tests { #[test] fn test_datums_serialize_as_expected() { - let test_blocks = vec![( + let test_blocks = [( include_str!("../../../test_data/alonzo9.block"), include_str!("../../../test_data/alonzo9.datums"), )]; @@ -118,7 +118,7 @@ mod tests { #[test] fn test_native_scripts_serialize_as_expected() { - let test_blocks = vec![( + let test_blocks = [( include_str!("../../../test_data/alonzo9.block"), include_str!("../../../test_data/alonzo9.native"), )]; diff --git a/pallas-primitives/src/alonzo/model.rs b/pallas-primitives/src/alonzo/model.rs index 1111813..ad17600 100644 --- a/pallas-primitives/src/alonzo/model.rs +++ b/pallas-primitives/src/alonzo/model.rs @@ -1639,7 +1639,7 @@ mod tests { #[test] fn header_isomorphic_decoding_encoding() { - let test_headers = vec![ + let test_headers = [ // peculiar alonzo header used as origin for a vasil devnet include_str!("../../../test_data/alonzo26.header"), ]; diff --git a/pallas-primitives/src/babbage/model.rs b/pallas-primitives/src/babbage/model.rs index 56a9ded..2cf4946 100644 --- a/pallas-primitives/src/babbage/model.rs +++ b/pallas-primitives/src/babbage/model.rs @@ -745,7 +745,7 @@ mod tests { #[test] fn block_isomorphic_decoding_encoding() { - let test_blocks = vec![ + let test_blocks = [ include_str!("../../../test_data/babbage1.block"), include_str!("../../../test_data/babbage2.block"), include_str!("../../../test_data/babbage3.block"), diff --git a/pallas-primitives/src/byron/model.rs b/pallas-primitives/src/byron/model.rs index 3c56b26..59a69f3 100644 --- a/pallas-primitives/src/byron/model.rs +++ b/pallas-primitives/src/byron/model.rs @@ -829,7 +829,7 @@ mod tests { fn boundary_block_isomorphic_decoding_encoding() { type BlockWrapper = (u16, EbBlock); - let test_blocks = vec![include_str!("../../../test_data/genesis.block")]; + let test_blocks = [include_str!("../../../test_data/genesis.block")]; for (idx, block_str) in test_blocks.iter().enumerate() { println!("decoding test block {}", idx + 1); @@ -849,7 +849,7 @@ mod tests { fn main_block_isomorphic_decoding_encoding() { type BlockWrapper<'b> = (u16, MintedBlock<'b>); - let test_blocks = vec![ + let test_blocks = [ //include_str!("../../../test_data/genesis.block"), include_str!("../../../test_data/byron1.block"), include_str!("../../../test_data/byron2.block"), @@ -876,7 +876,7 @@ mod tests { #[test] fn header_isomorphic_decoding_encoding() { - let subjects = vec![include_str!("../../../test_data/byron1.header")]; + let subjects = [include_str!("../../../test_data/byron1.header")]; for (idx, str) in subjects.iter().enumerate() { println!("decoding test header {}", idx + 1); diff --git a/pallas-traverse/src/hashes.rs b/pallas-traverse/src/hashes.rs index 044abf9..de9b9dd 100644 --- a/pallas-traverse/src/hashes.rs +++ b/pallas-traverse/src/hashes.rs @@ -184,7 +184,7 @@ mod tests { let (_, block_model): BlockWrapper = minicbor::decode(&block_bytes[..]).expect("error decoding cbor for file"); - let valid_hashes = vec![ + let valid_hashes = [ "8ae0cd531635579a9b52b954a840782d12235251fb1451e5c699e864c677514a", "bb5bb4e1c09c02aa199c60e9f330102912e3ef977bb73ecfd8f790945c6091d4", "8cdd88042ddb6c800714fb1469fb1a1a93152aae3c87a81f2a3016f2ee5c664a", @@ -212,7 +212,7 @@ mod tests { let (_, block_model): BlockWrapper = minicbor::decode(&block_bytes[..]) .unwrap_or_else(|_| panic!("error decoding cbor for file {block_idx}")); - let valid_hashes = vec!["3fad302595665b004971a6b76909854a39a0a7ecdbff3692f37b77ae37dbe882"]; + let valid_hashes = ["3fad302595665b004971a6b76909854a39a0a7ecdbff3692f37b77ae37dbe882"]; for (tx_idx, tx) in block_model.transaction_bodies.iter().enumerate() { let original_hash = tx.original_hash();