From 60840c066b5ae66301d706c2721c5c8b1e9e0d95 Mon Sep 17 00:00:00 2001 From: xyephy Date: Mon, 20 May 2024 23:18:22 +0300 Subject: [PATCH] Fix #853 --- .../common-messages/src/setup_connection.rs | 42 +++++++------------ 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/protocols/v2/subprotocols/common-messages/src/setup_connection.rs b/protocols/v2/subprotocols/common-messages/src/setup_connection.rs index f7eca3875f..016fd27381 100644 --- a/protocols/v2/subprotocols/common-messages/src/setup_connection.rs +++ b/protocols/v2/subprotocols/common-messages/src/setup_connection.rs @@ -83,19 +83,16 @@ impl<'decoder> SetupConnection<'decoder> { !requires_version_rolling_self || requires_version_rolling_passed; work_selection && version_rolling - } + }, Protocol::JobDeclarationProtocol => { let available = available_flags.reverse_bits(); let required = required_flags.reverse_bits(); - - let requires_async_job_mining_passed = (required >> 31) & 1 > 0; - let requires_async_job_mining_self = (available >> 31) & 1 > 0; - - let specific_flags_check = !requires_async_job_mining_self || requires_async_job_mining_passed; - let general_flags_check = (available & required) == required; - - specific_flags_check && general_flags_check - } + + let requires_async_job_mining_passed = (required >> 31) > 0; + let requires_async_job_mining_self = (available >> 31) > 0; + + !requires_async_job_mining_self || requires_async_job_mining_passed + }, Protocol::TemplateDistributionProtocol | Protocol::JobDistributionProtocol => { // Assuming these protocols do not define flags false @@ -403,25 +400,16 @@ mod test { use core::convert::TryInto; #[test] - fn test_check_flag() { - let protocol = crate::Protocol::MiningProtocol; - let flag_avaiable = 0b_0000_0000_0000_0000_0000_0000_0000_0000; + fn test_check_flags() { + let protocol = Protocol::MiningProtocol; + let flag_available = 0b_0000_0000_0000_0000_0000_0000_0000_0001; let flag_required = 0b_0000_0000_0000_0000_0000_0000_0000_0001; - assert!(SetupConnection::check_flags( - protocol, - flag_avaiable, - flag_required - )); - - let protocol = crate::Protocol::JobDeclarationProtocol; - - let available_flags = 0b_1000_0000_0000_0000_0000_0000_0000_0000; - let required_flags = 0b_1000_0000_0000_0000_0000_0000_0000_0000; - assert!(SetupConnection::check_flags(protocol, available_flags, required_flags)); + assert!(SetupConnection::check_flags(protocol, flag_available, flag_required)); - let available_flags = 0b_0000_0000_0000_0000_0000_0000_0000_0000; - let required_flags = 0b_1000_0000_0000_0000_0000_0000_0000_0000; - assert!(!SetupConnection::check_flags(protocol, available_flags, required_flags)); + let protocol = Protocol::JobDeclarationProtocol; + let flag_available = 0b_1000_0000_0000_0000_0000_0000_0000_0000; + let flag_required = 0b_1000_0000_0000_0000_0000_0000_0000_0000; + assert!(SetupConnection::check_flags(protocol, flag_available, flag_required)); } #[test]