diff --git a/benches/benches/src/sv2/criterion_sv2_benchmark.rs b/benches/benches/src/sv2/criterion_sv2_benchmark.rs index 18fab853d9..c39126d3d5 100644 --- a/benches/benches/src/sv2/criterion_sv2_benchmark.rs +++ b/benches/benches/src/sv2/criterion_sv2_benchmark.rs @@ -53,10 +53,11 @@ fn client_sv2_setup_connection_serialize_deserialize(c: &mut Criterion) { let mut dst = vec![0; size]; let _serialized = frame.serialize(&mut dst); b.iter(|| { - let mut frame = StdFrame::from_bytes(black_box(dst.clone().into())).unwrap(); - let type_ = frame.get_header().unwrap().msg_type().clone(); - let payload = frame.payload(); - let _ = AnyMessage::try_from((type_, payload)).unwrap(); + if let Ok(mut frame) = StdFrame::from_bytes(black_box(dst.clone().into())) { + let msg_type = frame.header().msg_type().clone(); + let payload = frame.payload().unwrap(); + let _ = AnyMessage::try_from((msg_type, payload)).unwrap(); + } }); }); } @@ -94,10 +95,11 @@ fn client_sv2_open_channel_serialize_deserialize(c: &mut Criterion) { let mut dst = vec![0; size]; frame.serialize(&mut dst); b.iter(|| { - let mut frame = StdFrame::from_bytes(black_box(dst.clone().into())).unwrap(); - let type_ = frame.get_header().unwrap().msg_type().clone(); - let payload = frame.payload(); - black_box(AnyMessage::try_from((type_, payload)).unwrap()); + if let Ok(mut frame) = StdFrame::from_bytes(black_box(dst.clone().into())) { + let msg_type = frame.header().msg_type().clone(); + let payload = frame.payload().unwrap(); + black_box(AnyMessage::try_from((msg_type, payload)).unwrap()); + } }); }); } @@ -150,10 +152,11 @@ fn client_sv2_mining_message_submit_standard_serialize_deserialize(c: &mut Crite "client_sv2_mining_message_submit_standard_serialize_deserialize", |b| { b.iter(|| { - let mut frame = StdFrame::from_bytes(black_box(dst.clone().into())).unwrap(); - let type_ = frame.get_header().unwrap().msg_type().clone(); - let payload = frame.payload(); - black_box(AnyMessage::try_from((type_, payload)).unwrap()); + if let Ok(mut frame) = StdFrame::from_bytes(black_box(dst.clone().into())) { + let msg_type = frame.header().msg_type().clone(); + let payload = frame.payload().unwrap(); + black_box(AnyMessage::try_from((msg_type, payload)).unwrap()); + } }); }, ); diff --git a/benches/benches/src/sv2/iai_sv2_benchmark.rs b/benches/benches/src/sv2/iai_sv2_benchmark.rs index b049b9dc42..9965f9f01e 100644 --- a/benches/benches/src/sv2/iai_sv2_benchmark.rs +++ b/benches/benches/src/sv2/iai_sv2_benchmark.rs @@ -47,7 +47,7 @@ fn client_sv2_setup_connection_serialize_deserialize() { frame.serialize(&mut dst); let mut frame = StdFrame::from_bytes(black_box(dst.clone().into())).unwrap(); let type_ = frame.get_header().unwrap().msg_type().clone(); - let payload = frame.payload(); + let payload = frame.payload().unwrap(); black_box(AnyMessage::try_from((type_, payload))); } @@ -78,7 +78,7 @@ fn client_sv2_open_channel_serialize_deserialize() { frame.serialize(&mut dst); let mut frame = StdFrame::from_bytes(black_box(dst.clone().into())).unwrap(); let type_ = frame.get_header().unwrap().msg_type().clone(); - let payload = frame.payload(); + let payload = frame.payload().unwrap(); black_box(AnyMessage::try_from((type_, payload))); } @@ -128,7 +128,7 @@ fn client_sv2_mining_message_submit_standard_serialize_deserialize() { frame.serialize(&mut dst); let mut frame = StdFrame::from_bytes(black_box(dst.clone().into())).unwrap(); let type_ = frame.get_header().unwrap().msg_type().clone(); - let payload = frame.payload(); + let payload = frame.payload().unwrap(); black_box(AnyMessage::try_from((type_, payload))); } diff --git a/examples/interop-cpp/src/main.rs b/examples/interop-cpp/src/main.rs index 09950e94b0..90fd0e7886 100644 --- a/examples/interop-cpp/src/main.rs +++ b/examples/interop-cpp/src/main.rs @@ -127,7 +127,7 @@ mod main_ { stream.read_exact(buffer).unwrap(); if let Ok(mut f) = decoder.next_frame() { let msg_type = f.get_header().unwrap().msg_type(); - let payload = f.payload(); + let payload = f.payload().unwrap(); let message: Sv2Message = (msg_type, payload).try_into().unwrap(); match message { Sv2Message::SetupConnection(_) => panic!(), diff --git a/examples/ping-pong-with-noise/src/node.rs b/examples/ping-pong-with-noise/src/node.rs index 1ae042aa83..f8d1792fd7 100644 --- a/examples/ping-pong-with-noise/src/node.rs +++ b/examples/ping-pong-with-noise/src/node.rs @@ -99,7 +99,7 @@ impl Node { ) -> Message<'static> { match self.expected { Expected::Ping => { - let ping: Result = from_bytes(frame.payload()); + let ping: Result = from_bytes(frame.payload().unwrap()); match ping { Ok(ping) => { println!("Node {} received:", self.name); @@ -118,7 +118,7 @@ impl Node { } } Expected::Pong => { - let pong: Result = from_bytes(frame.payload()); + let pong: Result = from_bytes(frame.payload().unwrap()); match pong { Ok(pong) => { println!("Node {} received:", self.name); diff --git a/examples/ping-pong-without-noise/src/node.rs b/examples/ping-pong-without-noise/src/node.rs index 21edf617e1..64c9c74154 100644 --- a/examples/ping-pong-without-noise/src/node.rs +++ b/examples/ping-pong-without-noise/src/node.rs @@ -87,7 +87,7 @@ impl Node { ) -> Message<'static> { match self.expected { Expected::Ping => { - let ping: Result = from_bytes(frame.payload()); + let ping: Result = from_bytes(frame.payload().unwrap()); match ping { Ok(ping) => { println!("Node {} received:", self.name); @@ -107,7 +107,7 @@ impl Node { } } Expected::Pong => { - let pong: Result = from_bytes(frame.payload()); + let pong: Result = from_bytes(frame.payload().unwrap()); match pong { Ok(pong) => { println!("Node {} received:", self.name); diff --git a/protocols/v2/framing-sv2/src/framing.rs b/protocols/v2/framing-sv2/src/framing.rs index 77fe87d147..b7e742f9b8 100644 --- a/protocols/v2/framing-sv2/src/framing.rs +++ b/protocols/v2/framing-sv2/src/framing.rs @@ -84,10 +84,10 @@ impl + AsRef<[u8]>> Sv2Frame { /// This function is only intended as a fast way to get a reference to an /// already serialized payload. If the frame has not yet been /// serialized, this function should never be used (it will panic). - pub fn payload(&mut self) -> &mut [u8] { + pub fn payload(&mut self) -> Option<&mut [u8]> { match self { - Sv2Frame::Raw { serialized, .. } => &mut serialized.as_mut()[Header::SIZE..], - Sv2Frame::Payload { .. } => panic!("fixme"), + Sv2Frame::Raw { serialized, .. } => Some(&mut serialized.as_mut()[Header::SIZE..]), + Sv2Frame::Payload { .. } => None, } } diff --git a/protocols/v2/sv2-ffi/src/lib.rs b/protocols/v2/sv2-ffi/src/lib.rs index 9befa0ca73..02a3a22369 100644 --- a/protocols/v2/sv2-ffi/src/lib.rs +++ b/protocols/v2/sv2-ffi/src/lib.rs @@ -469,7 +469,10 @@ pub extern "C" fn next_frame(decoder: *mut DecoderWrapper) -> CResult header.msg_type(), None => return CResult::Err(Sv2Error::InvalidSv2Frame), }; - let payload = f.payload(); + let payload = match f.payload() { + Some(payload) => payload, + None => return CResult::Err(Sv2Error::InvalidSv2Frame), + }; let len = payload.len(); let ptr = payload.as_mut_ptr(); let payload = unsafe { std::slice::from_raw_parts_mut(ptr, len) }; @@ -761,7 +764,7 @@ mod tests { let mut decoded = decoder.next_frame().unwrap(); let msg_type = decoded.get_header().unwrap().msg_type(); - let payload = decoded.payload(); + let payload = decoded.payload().unwrap(); let decoded_message: Sv2Message = (msg_type, payload).try_into().unwrap(); let decoded_message = match decoded_message { Sv2Message::CoinbaseOutputDataSize(m) => m, @@ -813,7 +816,7 @@ mod tests { // Extract payload of the frame which is the NewTemplate message let msg_type = decoded.get_header().unwrap().msg_type(); - let payload = decoded.payload(); + let payload = decoded.payload().unwrap(); let decoded_message: Sv2Message = (msg_type, payload).try_into().unwrap(); let decoded_message = match decoded_message { Sv2Message::NewTemplate(m) => m, @@ -861,7 +864,7 @@ mod tests { let mut decoded = decoder.next_frame().unwrap(); let msg_type = decoded.get_header().unwrap().msg_type(); - let payload = decoded.payload(); + let payload = decoded.payload().unwrap(); let decoded_message: Sv2Message = (msg_type, payload).try_into().unwrap(); let decoded_message = match decoded_message { Sv2Message::RequestTransactionData(m) => m, @@ -911,7 +914,7 @@ mod tests { let mut decoded = decoder.next_frame().unwrap(); let msg_type = decoded.get_header().unwrap().msg_type(); - let payload = decoded.payload(); + let payload = decoded.payload().unwrap(); let decoded_message: Sv2Message = (msg_type, payload).try_into().unwrap(); let decoded_message = match decoded_message { Sv2Message::RequestTransactionDataError(m) => m, @@ -961,7 +964,7 @@ mod tests { let mut decoded = decoder.next_frame().unwrap(); let msg_type = decoded.get_header().unwrap().msg_type(); - let payload = decoded.payload(); + let payload = decoded.payload().unwrap(); let decoded_message: Sv2Message = (msg_type, payload).try_into().unwrap(); let decoded_message = match decoded_message { Sv2Message::RequestTransactionDataSuccess(m) => m, @@ -1006,7 +1009,7 @@ mod tests { let mut decoded = decoder.next_frame().unwrap(); let msg_type = decoded.get_header().unwrap().msg_type(); - let payload = decoded.payload(); + let payload = decoded.payload().unwrap(); let decoded_message: Sv2Message = (msg_type, payload).try_into().unwrap(); let decoded_message = match decoded_message { Sv2Message::SetNewPrevHash(m) => m, @@ -1051,7 +1054,7 @@ mod tests { let mut decoded = decoder.next_frame().unwrap(); let msg_type = decoded.get_header().unwrap().msg_type(); - let payload = decoded.payload(); + let payload = decoded.payload().unwrap(); let decoded_message: Sv2Message = (msg_type, payload).try_into().unwrap(); let decoded_message = match decoded_message { Sv2Message::SubmitSolution(m) => m, @@ -1109,7 +1112,7 @@ mod tests { let mut decoded = decoder.next_frame().unwrap(); let msg_type = decoded.get_header().unwrap().msg_type(); - let payload = decoded.payload(); + let payload = decoded.payload().unwrap(); let decoded_message: Sv2Message = (msg_type, payload).try_into().unwrap(); let decoded_message = match decoded_message { Sv2Message::ChannelEndpointChanged(m) => m, @@ -1145,7 +1148,7 @@ mod tests { let mut decoded = decoder.next_frame().unwrap(); let msg_type = decoded.get_header().unwrap().msg_type(); - let payload = decoded.payload(); + let payload = decoded.payload().unwrap(); let decoded_message: Sv2Message = (msg_type, payload).try_into().unwrap(); let decoded_message = match decoded_message { Sv2Message::SetupConnection(m) => m, @@ -1194,7 +1197,7 @@ mod tests { let mut decoded = decoder.next_frame().unwrap(); let msg_type = decoded.get_header().unwrap().msg_type(); - let payload = decoded.payload(); + let payload = decoded.payload().unwrap(); let decoded_message: Sv2Message = (msg_type, payload).try_into().unwrap(); let decoded_message = match decoded_message { Sv2Message::SetupConnectionError(m) => m, @@ -1243,7 +1246,7 @@ mod tests { let mut decoded = decoder.next_frame().unwrap(); let msg_type = decoded.get_header().unwrap().msg_type(); - let payload = decoded.payload(); + let payload = decoded.payload().unwrap(); let decoded_message: Sv2Message = (msg_type, payload).try_into().unwrap(); let decoded_message = match decoded_message { Sv2Message::SetupConnectionSuccess(m) => m, diff --git a/roles/jd-client/src/lib/downstream.rs b/roles/jd-client/src/lib/downstream.rs index 5b26cef2f7..57b1b3bca9 100644 --- a/roles/jd-client/src/lib/downstream.rs +++ b/roles/jd-client/src/lib/downstream.rs @@ -253,7 +253,7 @@ impl DownstreamMiningNode { /// Parse the received message and relay it to the right upstream pub async fn next(self_mutex: &Arc>, mut incoming: StdFrame) { let message_type = incoming.get_header().unwrap().msg_type(); - let payload = incoming.payload(); + let payload = incoming.payload().unwrap(); let routing_logic = roles_logic_sv2::routing_logic::MiningRoutingLogic::None; @@ -698,7 +698,7 @@ pub async fn listen_for_downstream_mining( let mut incoming: StdFrame = node.receiver.recv().await.unwrap().try_into().unwrap(); let message_type = incoming.get_header().unwrap().msg_type(); - let payload = incoming.payload(); + let payload = incoming.payload().unwrap(); let routing_logic = roles_logic_sv2::routing_logic::CommonRoutingLogic::None; let node = Arc::new(Mutex::new(node)); if let Some(upstream) = upstream { diff --git a/roles/jd-client/src/lib/job_declarator/mod.rs b/roles/jd-client/src/lib/job_declarator/mod.rs index 29fb2e4f2c..b76e471ee1 100644 --- a/roles/jd-client/src/lib/job_declarator/mod.rs +++ b/roles/jd-client/src/lib/job_declarator/mod.rs @@ -293,7 +293,7 @@ impl JobDeclarator { loop { let mut incoming: StdFrame = receiver.recv().await.unwrap().try_into().unwrap(); let message_type = incoming.get_header().unwrap().msg_type(); - let payload = incoming.payload(); + let payload = incoming.payload().unwrap(); let next_message_to_send = ParseServerJobDeclarationMessages::handle_message_job_declaration( self_mutex.clone(), diff --git a/roles/jd-client/src/lib/job_declarator/setup_connection.rs b/roles/jd-client/src/lib/job_declarator/setup_connection.rs index 0e7b6fd8aa..a1ddc613c9 100644 --- a/roles/jd-client/src/lib/job_declarator/setup_connection.rs +++ b/roles/jd-client/src/lib/job_declarator/setup_connection.rs @@ -58,7 +58,7 @@ impl SetupConnectionHandler { let mut incoming: StdFrame = receiver.recv().await.unwrap().try_into().unwrap(); let message_type = incoming.get_header().unwrap().msg_type(); - let payload = incoming.payload(); + let payload = incoming.payload().unwrap(); ParseUpstreamCommonMessages::handle_message_common( Arc::new(Mutex::new(SetupConnectionHandler {})), message_type, diff --git a/roles/jd-client/src/lib/template_receiver/mod.rs b/roles/jd-client/src/lib/template_receiver/mod.rs index f418318a88..51dd8fbd65 100644 --- a/roles/jd-client/src/lib/template_receiver/mod.rs +++ b/roles/jd-client/src/lib/template_receiver/mod.rs @@ -187,7 +187,7 @@ impl TemplateRx { let mut frame: StdFrame = handle_result!(tx_status.clone(), received.try_into()); let message_type = frame.get_header().unwrap().msg_type(); - let payload = frame.payload(); + let payload = frame.payload().expect("No payload set"); let next_message_to_send = ParseServerTemplateDistributionMessages::handle_message_template_distribution( diff --git a/roles/jd-client/src/lib/template_receiver/setup_connection.rs b/roles/jd-client/src/lib/template_receiver/setup_connection.rs index 505b945c3e..81fb0166c2 100644 --- a/roles/jd-client/src/lib/template_receiver/setup_connection.rs +++ b/roles/jd-client/src/lib/template_receiver/setup_connection.rs @@ -54,7 +54,7 @@ impl SetupConnectionHandler { .try_into() .expect("Failed to parse incoming SetupConnectionResponse"); let message_type = incoming.get_header().unwrap().msg_type(); - let payload = incoming.payload(); + let payload = incoming.payload().unwrap(); ParseUpstreamCommonMessages::handle_message_common( Arc::new(Mutex::new(SetupConnectionHandler {})), message_type, diff --git a/roles/jd-client/src/lib/upstream_sv2/upstream.rs b/roles/jd-client/src/lib/upstream_sv2/upstream.rs index b04efa3359..2228ae9b01 100644 --- a/roles/jd-client/src/lib/upstream_sv2/upstream.rs +++ b/roles/jd-client/src/lib/upstream_sv2/upstream.rs @@ -237,7 +237,12 @@ impl Upstream { return Err(framing_sv2::Error::ExpectedHandshakeFrame.into()); }; // Gets the message payload - let payload = incoming.payload(); + let payload = match incoming.payload() { + Some(payload) => payload, + None => { + return Err(framing_sv2::Error::ExpectedHandshakeFrame.into()); + } + }; // Handle the incoming message (should be either `SetupConnectionSuccess` or // `SetupConnectionError`) @@ -333,7 +338,7 @@ impl Upstream { let message_type = handle_result!(tx_status, message_type).msg_type(); - let payload = incoming.payload(); + let payload = incoming.payload().expect("Payload not found"); // Since this is not communicating with an SV2 proxy, but instead a custom SV1 // proxy where the routing logic is handled via the `Upstream`'s communication diff --git a/roles/jd-server/src/lib/job_declarator/mod.rs b/roles/jd-server/src/lib/job_declarator/mod.rs index 34d9e66de4..051e1e795f 100644 --- a/roles/jd-server/src/lib/job_declarator/mod.rs +++ b/roles/jd-server/src/lib/job_declarator/mod.rs @@ -206,7 +206,15 @@ impl JobDeclaratorDownstream { .ok_or_else(|| JdsError::Custom(String::from("No header set"))); let header = handle_result!(tx_status, header); let message_type = header.msg_type(); - let payload = frame.payload(); + let payload = match frame.payload() { + Some(p) => p, + None => { + handle_result!( + tx_status, + Err(JdsError::Custom("No payload set".to_string())) + ) + } + }; let next_message_to_send = ParseClientJobDeclarationMessages::handle_message_job_declaration( self_mutex.clone(), diff --git a/roles/mining-proxy/src/lib/downstream_mining.rs b/roles/mining-proxy/src/lib/downstream_mining.rs index 1880551196..c810de0e94 100644 --- a/roles/mining-proxy/src/lib/downstream_mining.rs +++ b/roles/mining-proxy/src/lib/downstream_mining.rs @@ -229,7 +229,7 @@ impl DownstreamMiningNode { /// Parse the received message and relay it to the right upstream pub async fn next(self_mutex: Arc>, mut incoming: StdFrame) { let message_type = incoming.get_header().unwrap().msg_type(); - let payload = incoming.payload(); + let payload = incoming.payload().unwrap(); let routing_logic = super::get_routing_logic(); @@ -500,7 +500,7 @@ pub async fn listen_for_downstream_mining(address: SocketAddr) { task::spawn(async move { let mut incoming: StdFrame = node.receiver.recv().await.unwrap().try_into().unwrap(); let message_type = incoming.get_header().unwrap().msg_type(); - let payload = incoming.payload(); + let payload = incoming.payload().unwrap(); let routing_logic = super::get_common_routing_logic(); let node = Arc::new(Mutex::new(node)); diff --git a/roles/mining-proxy/src/lib/upstream_mining.rs b/roles/mining-proxy/src/lib/upstream_mining.rs index e3f6eef999..864ea58139 100644 --- a/roles/mining-proxy/src/lib/upstream_mining.rs +++ b/roles/mining-proxy/src/lib/upstream_mining.rs @@ -412,7 +412,7 @@ impl UpstreamMiningNode { .unwrap(); let message_type = response.get_header().unwrap().msg_type(); - let payload = response.payload(); + let payload = response.payload().unwrap(); match (message_type, payload).try_into() { Ok(CommonMessages::SetupConnectionSuccess(_)) => { let receiver = self_mutex @@ -578,7 +578,7 @@ impl UpstreamMiningNode { pub async fn next(self_mutex: Arc>, mut incoming: StdFrame) { let message_type = incoming.get_header().unwrap().msg_type(); - let payload = incoming.payload(); + let payload = incoming.payload().unwrap(); let routing_logic = super::get_routing_logic(); @@ -616,7 +616,7 @@ impl UpstreamMiningNode { .unwrap(); let message_type = response.get_header().unwrap().msg_type(); - let payload = response.payload(); + let payload = response.payload().unwrap(); match (message_type, payload).try_into() { Ok(CommonMessages::SetupConnectionSuccess(m)) => { let receiver = self_mutex diff --git a/roles/pool/src/lib/mining_pool/mod.rs b/roles/pool/src/lib/mining_pool/mod.rs index 4b9d10b188..adc2a83d09 100644 --- a/roles/pool/src/lib/mining_pool/mod.rs +++ b/roles/pool/src/lib/mining_pool/mod.rs @@ -204,7 +204,10 @@ impl Downstream { .get_header() .ok_or_else(|| PoolError::Custom(String::from("No header set")))? .msg_type(); - let payload = incoming.payload(); + let payload = match incoming.payload() { + Some(p) => p, + None => return Err(PoolError::Custom(String::from("No payload set"))), + }; debug!( "Received downstream message type: {:?}, payload: {:?}", message_type, payload diff --git a/roles/pool/src/lib/mining_pool/setup_connection.rs b/roles/pool/src/lib/mining_pool/setup_connection.rs index f0c47e9a88..80babbd578 100644 --- a/roles/pool/src/lib/mining_pool/setup_connection.rs +++ b/roles/pool/src/lib/mining_pool/setup_connection.rs @@ -62,7 +62,10 @@ impl SetupConnectionHandler { .get_header() .ok_or_else(|| PoolError::Custom(String::from("No header set")))? .msg_type(); - let payload = incoming.payload(); + let payload = match incoming.payload() { + Some(p) => p, + None => return Err(PoolError::Custom(String::from("No payload set"))), + }; let response = ParseDownstreamCommonMessages::handle_message_common( self_.clone(), message_type, diff --git a/roles/pool/src/lib/template_receiver/mod.rs b/roles/pool/src/lib/template_receiver/mod.rs index 2eeaa554f8..fb3222a3e0 100644 --- a/roles/pool/src/lib/template_receiver/mod.rs +++ b/roles/pool/src/lib/template_receiver/mod.rs @@ -112,7 +112,13 @@ impl TemplateRx { .get_header() .ok_or_else(|| PoolError::Custom(String::from("No header set"))); let message_type = handle_result!(status_tx, message_type_res).msg_type(); - let payload = message_from_tp.payload(); + let payload = match message_from_tp.payload() { + Some(p) => p, + None => { + let err = PoolError::Custom(String::from("No payload set")); + handle_result!(status_tx, Err(err)) + } + }; let msg = handle_result!( status_tx, ParseServerTemplateDistributionMessages::handle_message_template_distribution( diff --git a/roles/pool/src/lib/template_receiver/setup_connection.rs b/roles/pool/src/lib/template_receiver/setup_connection.rs index 6687eadc67..684937d780 100644 --- a/roles/pool/src/lib/template_receiver/setup_connection.rs +++ b/roles/pool/src/lib/template_receiver/setup_connection.rs @@ -57,7 +57,10 @@ impl SetupConnectionHandler { .get_header() .ok_or_else(|| PoolError::Custom(String::from("No header set")))? .msg_type(); - let payload = incoming.payload(); + let payload = match incoming.payload() { + Some(p) => p, + None => return Err(PoolError::Custom(String::from("No payload set"))), + }; ParseUpstreamCommonMessages::handle_message_common( Arc::new(Mutex::new(SetupConnectionHandler {})), diff --git a/roles/test-utils/mining-device/src/main.rs b/roles/test-utils/mining-device/src/main.rs index 763f83af5a..4251d293d9 100644 --- a/roles/test-utils/mining-device/src/main.rs +++ b/roles/test-utils/mining-device/src/main.rs @@ -181,7 +181,7 @@ impl SetupConnectionHandler { let mut incoming: StdFrame = receiver.recv().await.unwrap().try_into().unwrap(); let message_type = incoming.get_header().unwrap().msg_type(); - let payload = incoming.payload(); + let payload = incoming.payload().unwrap(); ParseUpstreamCommonMessages::handle_message_common( self_, message_type, @@ -314,7 +314,7 @@ impl Device { loop { let mut incoming: StdFrame = receiver.recv().await.unwrap().try_into().unwrap(); let message_type = incoming.get_header().unwrap().msg_type(); - let payload = incoming.payload(); + let payload = incoming.payload().unwrap(); let next = Device::handle_message_mining( self_mutex.clone(), message_type, diff --git a/roles/translator/src/lib/upstream_sv2/upstream.rs b/roles/translator/src/lib/upstream_sv2/upstream.rs index 6aab5978e4..4854682a12 100644 --- a/roles/translator/src/lib/upstream_sv2/upstream.rs +++ b/roles/translator/src/lib/upstream_sv2/upstream.rs @@ -211,7 +211,10 @@ impl Upstream { return Err(framing_sv2::Error::ExpectedHandshakeFrame.into()); }; // Gets the message payload - let payload = incoming.payload(); + let payload = match incoming.payload() { + Some(payload) => payload, + None => return Err(framing_sv2::Error::ExpectedHandshakeFrame.into()), + }; // Handle the incoming message (should be either `SetupConnectionSuccess` or // `SetupConnectionError`) @@ -306,7 +309,7 @@ impl Upstream { let message_type = handle_result!(tx_status, message_type).msg_type(); - let payload = incoming.payload(); + let payload = incoming.payload().expect("Payload is None"); // Since this is not communicating with an SV2 proxy, but instead a custom SV1 // proxy where the routing logic is handled via the `Upstream`'s communication diff --git a/utils/message-generator/src/executor.rs b/utils/message-generator/src/executor.rs index f31991eca2..70cd4dae01 100644 --- a/utils/message-generator/src/executor.rs +++ b/utils/message-generator/src/executor.rs @@ -225,7 +225,7 @@ impl Executor { let mut message: Sv2Frame, _> = message.try_into().unwrap(); debug!("RECV {:#?}", message); let header = message.get_header().unwrap(); - let payload = message.payload(); + let payload = message.payload().unwrap(); match result { ActionResult::MatchMessageType(message_type) => { if header.msg_type() != *message_type { diff --git a/utils/message-generator/src/main.rs b/utils/message-generator/src/main.rs index e2633ed23a..4353dc91f8 100644 --- a/utils/message-generator/src/main.rs +++ b/utils/message-generator/src/main.rs @@ -659,8 +659,8 @@ mod test { (EitherFrame::Sv2(mut frame1), EitherFrame::Sv2(mut frame2)) => { let mt1 = frame1.get_header().unwrap().msg_type(); let mt2 = frame2.get_header().unwrap().msg_type(); - let p1 = frame1.payload(); - let p2 = frame2.payload(); + let p1 = frame1.payload().unwrap(); + let p2 = frame2.payload().unwrap(); let message1: Mining = (mt1, p1).try_into().unwrap(); let message2: Mining = (mt2, p2).try_into().unwrap(); match (message1, message2) {