Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
xyephy authored and Shourya742 committed Jul 6, 2024
1 parent 44a17cc commit 60840c0
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions protocols/v2/subprotocols/common-messages/src/setup_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 60840c0

Please sign in to comment.