From 3fd1ff979addedc58f3e29648c58d534a06ab8f1 Mon Sep 17 00:00:00 2001 From: xyephy Date: Mon, 20 May 2024 23:35:25 +0300 Subject: [PATCH 1/7] Add flag check logic for Job declarator protocol --- benches/Cargo.lock | 6 +-- protocols/Cargo.lock | 2 +- .../common-messages/src/setup_connection.rs | 41 +++++++++++++++++-- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/benches/Cargo.lock b/benches/Cargo.lock index 946b7c02b8..3964748381 100644 --- a/benches/Cargo.lock +++ b/benches/Cargo.lock @@ -373,7 +373,7 @@ dependencies = [ [[package]] name = "buffer_sv2" -version = "1.0.0" +version = "1.1.0" dependencies = [ "aes-gcm", ] @@ -497,7 +497,7 @@ checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "codec_sv2" -version = "1.1.0" +version = "1.2.0" dependencies = [ "binary_sv2", "buffer_sv2", @@ -1564,7 +1564,7 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "sv1_api" -version = "1.0.0" +version = "1.0.1" dependencies = [ "binary_sv2", "bitcoin_hashes 0.3.2", diff --git a/protocols/Cargo.lock b/protocols/Cargo.lock index fbe5ddceac..31450eea42 100644 --- a/protocols/Cargo.lock +++ b/protocols/Cargo.lock @@ -744,7 +744,7 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "sv1_api" -version = "1.0.0" +version = "1.0.1" dependencies = [ "binary_sv2", "bitcoin_hashes 0.3.2", diff --git a/protocols/v2/subprotocols/common-messages/src/setup_connection.rs b/protocols/v2/subprotocols/common-messages/src/setup_connection.rs index 49312b6865..bc1bb59bf4 100644 --- a/protocols/v2/subprotocols/common-messages/src/setup_connection.rs +++ b/protocols/v2/subprotocols/common-messages/src/setup_connection.rs @@ -84,8 +84,23 @@ impl<'decoder> SetupConnection<'decoder> { work_selection && version_rolling } - // TODO - _ => todo!(), + 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 + } + Protocol::TemplateDistributionProtocol | Protocol::JobDistributionProtocol => { + // Assuming these protocols do not define flags + false + } } } @@ -391,13 +406,31 @@ mod test { #[test] fn test_check_flag() { let protocol = crate::Protocol::MiningProtocol; - let flag_available = 0b_0000_0000_0000_0000_0000_0000_0000_0000; + let flag_avaiable = 0b_0000_0000_0000_0000_0000_0000_0000_0000; let flag_required = 0b_0000_0000_0000_0000_0000_0000_0000_0001; assert!(SetupConnection::check_flags( protocol, - flag_available, + 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 + )); + + 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 + )); } #[test] From bebd825f62a8a0ef67662365108ce134d97156a8 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Fri, 5 Jul 2024 07:36:19 -0400 Subject: [PATCH 2/7] Add MG test to test the flag change in setup connection --- .../messages/common_messages.json | 16 +++++ .../job-declarator-mock-invalid-flag.json | 38 ++++++++++ .../job-declarator-flag-test.json | 71 +++++++++++++++++++ .../job-declarator-flag-test.sh | 9 +++ 4 files changed, 134 insertions(+) create mode 100644 test/message-generator/mock/job-declarator-mock-invalid-flag.json create mode 100644 test/message-generator/test/job-declarator-flag-test/job-declarator-flag-test.json create mode 100755 test/message-generator/test/job-declarator-flag-test/job-declarator-flag-test.sh diff --git a/test/message-generator/messages/common_messages.json b/test/message-generator/messages/common_messages.json index ff5d200dd3..80ee1c68cb 100644 --- a/test/message-generator/messages/common_messages.json +++ b/test/message-generator/messages/common_messages.json @@ -48,6 +48,22 @@ }, "id": "setup_connection_job_declarator" }, + { + "message": { + "type": "SetupConnection", + "protocol": 1, + "min_version": 2, + "max_version": 2, + "flags": 6, + "endpoint_host": "", + "endpoint_port": 0, + "vendor": "", + "hardware_version": "", + "firmware": "", + "device_id": "" + }, + "id": "setup_connection_job_declarator_with_no_async_flag" + }, { "message": { "type": "SetupConnectionSuccess", diff --git a/test/message-generator/mock/job-declarator-mock-invalid-flag.json b/test/message-generator/mock/job-declarator-mock-invalid-flag.json new file mode 100644 index 0000000000..a14f0554bd --- /dev/null +++ b/test/message-generator/mock/job-declarator-mock-invalid-flag.json @@ -0,0 +1,38 @@ +{ + "version": "2", + "doc": [ + "This test does", + "Soft mock of JD", + "Connect to JDS", + "Receive Setup Connection Error as incorrect bits are set" + ], + "frame_builders": [ + { + "type": "automatic", + "message_id": "test/message-generator/messages/common_messages.json::setup_connection_job_declarator_with_no_async_flag" + } + ], + "actions": [ + { + "message_ids": ["setup_connection_job_declarator_with_no_async_flag"], + "role": "client", + "results": [ + { + "type": "match_message_type", + "value": "0x01" + } + + ], + "actiondoc": "This action sends SetupConnection and checks that .Success" + } + ], + "setup_commands": [], + "execution_commands": [], + "cleanup_commands": [], + "role": "client", + "downstream": { + "ip": "127.0.0.1", + "port": 34264, + "pub_key": "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" + } +} diff --git a/test/message-generator/test/job-declarator-flag-test/job-declarator-flag-test.json b/test/message-generator/test/job-declarator-flag-test/job-declarator-flag-test.json new file mode 100644 index 0000000000..feb4cf571e --- /dev/null +++ b/test/message-generator/test/job-declarator-flag-test/job-declarator-flag-test.json @@ -0,0 +1,71 @@ +{ + "version": "2", + "doc": [ + "This test does", + "Launch the jd-server" + ], + "frame_builders": [ + ], + "actions": [ + ], + "setup_commands": [ + { + "command": "cargo", + "args": [ + "llvm-cov", + "--no-report", + "run", + "-p", + "jd_server", + "--", + "-c", + "../test/config/jds-do-not-fail-on-wrong-txdatasucc/jds-config.toml" + ], + "conditions": { + "WithConditions": { + "conditions": [ + { + "output_string": "JD INITIALIZED", + "output_location": "StdOut", + "late_condition": false, + "condition": true + } + ], + "timer_secs": 300, + "warn_no_panic": false + } + } + }, + { + "command": "cargo", + "args": [ + "run", + "../../test/message-generator/mock/job-declarator-mock-invalid-flag.json" + ], + "conditions": { + "WithConditions": { + "conditions": [ + { + "output_string": "MATCHED MESSAGE TYPE 1", + "output_location": "StdOut", + "late_condition": false, + "condition": true + } + ], + "timer_secs": 600, + "warn_no_panic": false + } + } + } + ], + "execution_commands": [ + ], + "cleanup_commands": [ + { + "command": "pkill", + "args": ["-f", "jd_server", "-SIGINT"], + "conditions": "None" + } + ], + "role": "none" +} diff --git a/test/message-generator/test/job-declarator-flag-test/job-declarator-flag-test.sh b/test/message-generator/test/job-declarator-flag-test/job-declarator-flag-test.sh new file mode 100755 index 0000000000..e11ba44a6e --- /dev/null +++ b/test/message-generator/test/job-declarator-flag-test/job-declarator-flag-test.sh @@ -0,0 +1,9 @@ +cd roles +cargo llvm-cov --no-report -p pool_sv2 + +cd ../utils/message-generator/ +cargo build + +RUST_LOG=debug cargo run ../../test/message-generator/test/job-declarator-flag-test/job-declarator-flag-test.json || { echo 'mg test failed' ; exit 1; } + +sleep 10 From bac8c2e44e28ab9dda66cbbe254f6a50bdb77d08 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Sat, 6 Jul 2024 04:21:02 -0400 Subject: [PATCH 3/7] Add flag check at setup connection --- benches/Cargo.lock | 6 +- protocols/Cargo.lock | 2 +- .../common-messages/src/setup_connection.rs | 20 +- roles/Cargo.lock | 2 +- roles/jd-server/src/lib/job_declarator/mod.rs | 175 ++++++++++++------ .../jds-config.toml | 20 ++ .../messages/common_messages.json | 2 +- ...s-setup-connection-mock-invalid-flag.json} | 7 +- .../jds-setup-connection-flag-test.json} | 4 +- .../jds-setup-connection-flag-test.sh | 9 + .../job-declarator-flag-test.sh | 9 - 11 files changed, 167 insertions(+), 89 deletions(-) create mode 100644 test/config/jds-setup-connection-flag-test/jds-config.toml rename test/message-generator/mock/{job-declarator-mock-invalid-flag.json => jdc-mock-jds-setup-connection-mock-invalid-flag.json} (91%) rename test/message-generator/test/{job-declarator-flag-test/job-declarator-flag-test.json => jds-setup-connection-flag-test/jds-setup-connection-flag-test.json} (90%) create mode 100755 test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.sh delete mode 100755 test/message-generator/test/job-declarator-flag-test/job-declarator-flag-test.sh diff --git a/benches/Cargo.lock b/benches/Cargo.lock index 3964748381..946b7c02b8 100644 --- a/benches/Cargo.lock +++ b/benches/Cargo.lock @@ -373,7 +373,7 @@ dependencies = [ [[package]] name = "buffer_sv2" -version = "1.1.0" +version = "1.0.0" dependencies = [ "aes-gcm", ] @@ -497,7 +497,7 @@ checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "codec_sv2" -version = "1.2.0" +version = "1.1.0" dependencies = [ "binary_sv2", "buffer_sv2", @@ -1564,7 +1564,7 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "sv1_api" -version = "1.0.1" +version = "1.0.0" dependencies = [ "binary_sv2", "bitcoin_hashes 0.3.2", diff --git a/protocols/Cargo.lock b/protocols/Cargo.lock index 31450eea42..fbe5ddceac 100644 --- a/protocols/Cargo.lock +++ b/protocols/Cargo.lock @@ -744,7 +744,7 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "sv1_api" -version = "1.0.1" +version = "1.0.0" dependencies = [ "binary_sv2", "bitcoin_hashes 0.3.2", diff --git a/protocols/v2/subprotocols/common-messages/src/setup_connection.rs b/protocols/v2/subprotocols/common-messages/src/setup_connection.rs index bc1bb59bf4..32acaa8fd0 100644 --- a/protocols/v2/subprotocols/common-messages/src/setup_connection.rs +++ b/protocols/v2/subprotocols/common-messages/src/setup_connection.rs @@ -54,11 +54,11 @@ pub struct SetupConnection<'decoder> { impl<'decoder> SetupConnection<'decoder> { pub fn set_requires_standard_job(&mut self) { - self.flags |= 0b_0000_0000_0000_0000_0000_0000_0000_0001 + self.flags |= 0b_0000_0000_0000_0000_0000_0000_0000_0001; } pub fn set_async_job_nogotiation(&mut self) { - self.flags |= 0b_0000_0000_0000_0000_0000_0000_0000_0001 + self.flags |= 0b_0000_0000_0000_0000_0000_0000_0000_0001; } /// Check if passed flags support self flag @@ -71,11 +71,11 @@ impl<'decoder> SetupConnection<'decoder> { Protocol::MiningProtocol => { let available = available_flags.reverse_bits(); let required_flags = required_flags.reverse_bits(); - let requires_work_selection_passed = (required_flags >> 30) > 0; - let requires_version_rolling_passed = (required_flags >> 29) > 0; + let requires_work_selection_passed = required_flags >> 30 > 0; + let requires_version_rolling_passed = required_flags >> 29 > 0; - let requires_work_selection_self = (available >> 30) > 0; - let requires_version_rolling_self = (available >> 29) > 0; + let requires_work_selection_self = available >> 30 > 0; + let requires_version_rolling_self = available >> 29 > 0; let work_selection = !requires_work_selection_self || requires_work_selection_passed; @@ -98,7 +98,7 @@ impl<'decoder> SetupConnection<'decoder> { specific_flags_check && general_flags_check } Protocol::TemplateDistributionProtocol | Protocol::JobDistributionProtocol => { - // Assuming these protocols do not define flags + // These protocols do not define flags for setting up a connection. false } } @@ -325,7 +325,7 @@ impl<'decoder> binary_sv2::Decodable<'decoder> for Protocol { fn get_structure( _: &[u8], ) -> core::result::Result, binary_sv2::Error> { - let field: FieldMarker = 0_u8.into(); + let field: FieldMarker = (0_u8).into(); Ok(alloc::vec![field]) } fn from_decoded_fields( @@ -406,11 +406,11 @@ mod test { #[test] fn test_check_flag() { let protocol = crate::Protocol::MiningProtocol; - let flag_avaiable = 0b_0000_0000_0000_0000_0000_0000_0000_0000; + let flag_available = 0b_0000_0000_0000_0000_0000_0000_0000_0000; let flag_required = 0b_0000_0000_0000_0000_0000_0000_0000_0001; assert!(SetupConnection::check_flags( protocol, - flag_avaiable, + flag_available, flag_required )); diff --git a/roles/Cargo.lock b/roles/Cargo.lock index ea0dcfa1cb..bf54dcc038 100644 --- a/roles/Cargo.lock +++ b/roles/Cargo.lock @@ -2053,7 +2053,7 @@ dependencies = [ [[package]] name = "sv1_api" -version = "1.0.1" +version = "1.0.0" dependencies = [ "binary_sv2", "bitcoin_hashes 0.3.2", diff --git a/roles/jd-server/src/lib/job_declarator/mod.rs b/roles/jd-server/src/lib/job_declarator/mod.rs index dbfce89a67..2c230c75bc 100644 --- a/roles/jd-server/src/lib/job_declarator/mod.rs +++ b/roles/jd-server/src/lib/job_declarator/mod.rs @@ -3,12 +3,15 @@ use super::{error::JdsError, mempool::JDsMempool, status, Configuration, EitherF use async_channel::{Receiver, Sender}; use binary_sv2::{B0255, U256}; use codec_sv2::{HandshakeRole, Responder}; +use core::panic; use error_handling::handle_result; use key_utils::{Secp256k1PublicKey, Secp256k1SecretKey, SignatureService}; use network_helpers_sv2::noise_connection_tokio::Connection; use nohash_hasher::BuildNoHashHasher; use roles_logic_sv2::{ - common_messages_sv2::SetupConnectionSuccess, + common_messages_sv2::{ + Protocol, SetupConnection, SetupConnectionError, SetupConnectionSuccess, + }, handlers::job_declaration::{ParseClientJobDeclarationMessages, SendTo}, job_declaration_sv2::{DeclareMiningJob, SubmitSolutionJd}, parsers::{JobDeclaration, PoolMessages as JdsMessages}, @@ -175,8 +178,10 @@ impl JobDeclaratorDownstream { for transaction in job_transactions { match transaction { TransactionState::PresentInMempool(txid) => known_transactions.push(txid), - TransactionState::Missing => continue, - }; + TransactionState::Missing => { + continue; + } + } } known_transactions } @@ -230,26 +235,26 @@ impl JobDeclaratorDownstream { Ok(SendTo::Respond(m)) => { match m { JobDeclaration::AllocateMiningJobToken(_) => { - error!("Send unexpected message: AMJT") + error!("Send unexpected message: AMJT"); } JobDeclaration::AllocateMiningJobTokenSuccess(_) => { - debug!("Send message: AMJTS") + debug!("Send message: AMJTS"); } JobDeclaration::DeclareMiningJob(_) => { error!("Send unexpected message: DMJ"); } JobDeclaration::DeclareMiningJobError(_) => { - debug!("Send nmessage: DMJE") + debug!("Send nmessage: DMJE"); } JobDeclaration::DeclareMiningJobSuccess(_) => { debug!("Send message: DMJS. Updating the JDS mempool."); Self::send_txs_to_mempool(self_mutex.clone()).await; } JobDeclaration::IdentifyTransactions(_) => { - debug!("Send message: IT") + debug!("Send message: IT"); } JobDeclaration::IdentifyTransactionsSuccess(_) => { - error!("Send unexpected message: ITS") + error!("Send unexpected message: ITS"); } JobDeclaration::ProvideMissingTransactions(_) => { debug!("Send message: PMT. Updating the JDS mempool."); @@ -266,10 +271,17 @@ impl JobDeclaratorDownstream { error!("JD Server: unexpected relay new message {:?}", message); } Ok(SendTo::RelayNewMessageToRemote(remote, message)) => { - error!("JD Server: unexpected relay new message to remote. Remote: {:?}, Message: {:?}", remote, message); + error!( + "JD Server: unexpected relay new message to remote. Remote: {:?}, Message: {:?}", + remote, + message + ); } Ok(SendTo::RelaySameMessageToRemote(remote)) => { - error!("JD Server: unexpected relay same message to remote. Remote: {:?}", remote); + error!( + "JD Server: unexpected relay same message to remote. Remote: {:?}", + remote + ); } Ok(SendTo::Multiple(multiple)) => { error!("JD Server: unexpected multiple messages: {:?}", multiple); @@ -279,26 +291,33 @@ impl JobDeclaratorDownstream { Some(JobDeclaration::SubmitSolution(message)) => { match Self::collect_txs_in_job(self_mutex.clone()) { Ok(_) => { - info!("All transactions in downstream job are recognized correctly by the JD Server"); - match JobDeclaratorDownstream::get_block_hex( - self_mutex.clone(), - message, - ) { - Ok(hexdata) => { - let _ = - new_block_sender.send(hexdata).await; - } - Err(e) => { - handle_result!(tx_status, Err(*e)) - } - }; + info!( + "All transactions in downstream job are recognized correctly by the JD Server" + ); + let hexdata = + match JobDeclaratorDownstream::get_block_hex( + self_mutex.clone(), + message, + ) { + Ok(inner) => inner, + Err(e) => { + error!( + "Received solution but encountered error: {:?}", + e + ); + recv.close(); + //TODO should we brake it? + break; + } + }; + let _ = new_block_sender.send(hexdata).await; } Err(error) => { error!("Missing transactions: {:?}", error); // TODO print here the ip of the downstream let known_transactions = JobDeclaratorDownstream::get_transactions_in_job( - self_mutex.clone(), + self_mutex.clone() ); let retrieve_transactions = AddTrasactionsToMempoolInner { @@ -327,7 +346,7 @@ impl JobDeclaratorDownstream { }; } _ = tokio::time::sleep(Duration::from_secs(60)) => {} - }; + } } }; } @@ -430,54 +449,94 @@ impl JobDeclarator { new_block_sender: Sender, sender_add_txs_to_mempool: Sender, ) { - let listner = TcpListener::bind(&config.listen_jd_address).await.unwrap(); - while let Ok((stream, _)) = listner.accept().await { + let listener = TcpListener::bind(&config.listen_jd_address).await.unwrap(); + + while let Ok((stream, _)) = listener.accept().await { let responder = Responder::from_authority_kp( &config.authority_public_key.into_bytes(), &config.authority_secret_key.into_bytes(), std::time::Duration::from_secs(config.cert_validity_sec), ) .unwrap(); + let addr = stream.peer_addr(); if let Ok((receiver, sender, _, _)) = Connection::new(stream, HandshakeRole::Responder(responder)).await { - let setup_message_from_proxy_jd = receiver.recv().await.unwrap(); - info!( - "Setup connection message from proxy: {:?}", - setup_message_from_proxy_jd - ); + match receiver.recv().await { + Ok(EitherFrame::Sv2(mut sv2_message)) => { + debug!("Received SV2 message: {:?}", sv2_message); + let payload = sv2_message.payload(); - let setup_connection_success_to_proxy = SetupConnectionSuccess { - used_version: 2, - // Setup flags for async_mining_allowed - flags: 0b_0000_0000_0000_0000_0000_0000_0000_0001, - }; - let sv2_frame: StdFrame = - JdsMessages::Common(setup_connection_success_to_proxy.into()) - .try_into() - .unwrap(); - let sv2_frame = sv2_frame.into(); - info!("Sending success message for proxy"); - sender.send(sv2_frame).await.unwrap(); + if let Ok(setup_connection) = + binary_sv2::from_bytes::(payload) + { + let flag = setup_connection.flags; + let is_valid = SetupConnection::check_flags( + Protocol::JobDeclarationProtocol, + flag, + 1, + ); - let jddownstream = Arc::new(Mutex::new(JobDeclaratorDownstream::new( - receiver.clone(), - sender.clone(), - &config, - mempool.clone(), - // each downstream has its own sender (multi producer single consumer) - sender_add_txs_to_mempool.clone(), - ))); + if is_valid { + let success_message = SetupConnectionSuccess { + used_version: 2, + flags: 0b_0000_0000_0000_0000_0000_0000_0000_0001, + }; + info!("Sending success message for proxy"); + let sv2_frame: StdFrame = JdsMessages::Common(success_message.into()) + .try_into() + .expect("Failed to convert setup connection response message to standard frame"); + + sender.send(sv2_frame.into()).await.unwrap(); + + let jddownstream = + Arc::new(Mutex::new(JobDeclaratorDownstream::new( + receiver.clone(), + sender.clone(), + &config, + mempool.clone(), + sender_add_txs_to_mempool.clone(), // each downstream has its own sender (multi producer single consumer) + ))); + + JobDeclaratorDownstream::start( + jddownstream, + status_tx.clone(), + new_block_sender.clone(), + ); + } else { + let error_message = SetupConnectionError { + flags: flag, + error_code: "unsupported-feature-flags" + .to_string() + .into_bytes() + .try_into() + .unwrap(), + }; + info!("Sending error message for proxy"); + let sv2_frame: StdFrame = JdsMessages::Common(error_message.into()) + .try_into() + .expect("Failed to convert setup connection response message to standard frame"); - JobDeclaratorDownstream::start( - jddownstream, - status_tx.clone(), - new_block_sender.clone(), - ); + sender.send(sv2_frame.into()).await.unwrap(); + } + } else { + error!("Error parsing SetupConnection message"); + } + } + Ok(EitherFrame::HandShake(handshake_message)) => { + error!( + "Unexpected handshake message from upstream: {:?} at {:?}", + handshake_message, addr + ); + } + Err(e) => { + error!("Error receiving message: {:?}", e); + } + } } else { - error!("Can not connect {:?}", addr); + error!("Cannot connect to {:?}", addr); } } } diff --git a/test/config/jds-setup-connection-flag-test/jds-config.toml b/test/config/jds-setup-connection-flag-test/jds-config.toml new file mode 100644 index 0000000000..acda73227c --- /dev/null +++ b/test/config/jds-setup-connection-flag-test/jds-config.toml @@ -0,0 +1,20 @@ +# SRI Pool config +authority_public_key = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" +authority_secret_key = "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n" +cert_validity_sec = 3600 + +# list of compressed or uncompressed pubkeys for coinbase payout (only supports 1 item in the array at this point) +coinbase_outputs = [ + { output_script_type = "P2WPKH", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" }, +] + +listen_jd_address = "127.0.0.1:34264" + +core_rpc_url = "" +core_rpc_port = 18332 +core_rpc_user = "" +core_rpc_pass = "" +# Time interval used for JDS mempool update +[mempool_update_interval] +unit = "secs" +value = 1 \ No newline at end of file diff --git a/test/message-generator/messages/common_messages.json b/test/message-generator/messages/common_messages.json index 80ee1c68cb..65cc32a9a9 100644 --- a/test/message-generator/messages/common_messages.json +++ b/test/message-generator/messages/common_messages.json @@ -54,7 +54,7 @@ "protocol": 1, "min_version": 2, "max_version": 2, - "flags": 6, + "flags": 0, "endpoint_host": "", "endpoint_port": 0, "vendor": "", diff --git a/test/message-generator/mock/job-declarator-mock-invalid-flag.json b/test/message-generator/mock/jdc-mock-jds-setup-connection-mock-invalid-flag.json similarity index 91% rename from test/message-generator/mock/job-declarator-mock-invalid-flag.json rename to test/message-generator/mock/jdc-mock-jds-setup-connection-mock-invalid-flag.json index a14f0554bd..8cb2338d74 100644 --- a/test/message-generator/mock/job-declarator-mock-invalid-flag.json +++ b/test/message-generator/mock/jdc-mock-jds-setup-connection-mock-invalid-flag.json @@ -2,7 +2,7 @@ "version": "2", "doc": [ "This test does", - "Soft mock of JD", + "Soft mock of JDC", "Connect to JDS", "Receive Setup Connection Error as incorrect bits are set" ], @@ -19,11 +19,10 @@ "results": [ { "type": "match_message_type", - "value": "0x01" + "value": "0x02" } - ], - "actiondoc": "This action sends SetupConnection and checks that .Success" + "actiondoc": "This action sends SetupConnection and checks that .Error" } ], "setup_commands": [], diff --git a/test/message-generator/test/job-declarator-flag-test/job-declarator-flag-test.json b/test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.json similarity index 90% rename from test/message-generator/test/job-declarator-flag-test/job-declarator-flag-test.json rename to test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.json index feb4cf571e..403b1eb4f9 100644 --- a/test/message-generator/test/job-declarator-flag-test/job-declarator-flag-test.json +++ b/test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.json @@ -19,7 +19,7 @@ "jd_server", "--", "-c", - "../test/config/jds-do-not-fail-on-wrong-txdatasucc/jds-config.toml" + "../test/config/jds-setup-connection-flag-test/jds-config.toml" ], "conditions": { "WithConditions": { @@ -40,7 +40,7 @@ "command": "cargo", "args": [ "run", - "../../test/message-generator/mock/job-declarator-mock-invalid-flag.json" + "../../test/message-generator/mock/jdc-mock-jds-setup-connection-mock-invalid-flag.json" ], "conditions": { "WithConditions": { diff --git a/test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.sh b/test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.sh new file mode 100755 index 0000000000..b32716fe30 --- /dev/null +++ b/test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.sh @@ -0,0 +1,9 @@ +cd roles +cargo llvm-cov --no-report -p pool_sv2 + +cd ../utils/message-generator/ +cargo build + +RUST_LOG=debug cargo run ../../test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.json || { echo 'mg test failed' ; exit 1; } + +sleep 10 diff --git a/test/message-generator/test/job-declarator-flag-test/job-declarator-flag-test.sh b/test/message-generator/test/job-declarator-flag-test/job-declarator-flag-test.sh deleted file mode 100755 index e11ba44a6e..0000000000 --- a/test/message-generator/test/job-declarator-flag-test/job-declarator-flag-test.sh +++ /dev/null @@ -1,9 +0,0 @@ -cd roles -cargo llvm-cov --no-report -p pool_sv2 - -cd ../utils/message-generator/ -cargo build - -RUST_LOG=debug cargo run ../../test/message-generator/test/job-declarator-flag-test/job-declarator-flag-test.json || { echo 'mg test failed' ; exit 1; } - -sleep 10 From d018b88a6c0ae84ef442e2cfe5d90fe8758e5e9a Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Thu, 18 Jul 2024 12:36:40 -0400 Subject: [PATCH 4/7] Change MG test with flag filter logic --- .../common-messages/src/setup_connection.rs | 22 ++++++++----------- roles/jd-server/src/lib/job_declarator/mod.rs | 2 +- ...ds-setup-connection-mock-invalid-flag.json | 13 +++++++++-- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/protocols/v2/subprotocols/common-messages/src/setup_connection.rs b/protocols/v2/subprotocols/common-messages/src/setup_connection.rs index 32acaa8fd0..0c5522d6b1 100644 --- a/protocols/v2/subprotocols/common-messages/src/setup_connection.rs +++ b/protocols/v2/subprotocols/common-messages/src/setup_connection.rs @@ -91,11 +91,15 @@ impl<'decoder> SetupConnection<'decoder> { 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 + match ( + requires_async_job_mining_self, + requires_async_job_mining_passed, + ) { + (true, true) => true, + (true, false) => true, + (false, true) => false, + (false, false) => true, + } } Protocol::TemplateDistributionProtocol | Protocol::JobDistributionProtocol => { // These protocols do not define flags for setting up a connection. @@ -423,14 +427,6 @@ mod test { available_flags, required_flags )); - - 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 - )); } #[test] diff --git a/roles/jd-server/src/lib/job_declarator/mod.rs b/roles/jd-server/src/lib/job_declarator/mod.rs index 2c230c75bc..aaf94e353d 100644 --- a/roles/jd-server/src/lib/job_declarator/mod.rs +++ b/roles/jd-server/src/lib/job_declarator/mod.rs @@ -475,8 +475,8 @@ impl JobDeclarator { let flag = setup_connection.flags; let is_valid = SetupConnection::check_flags( Protocol::JobDeclarationProtocol, - flag, 1, + flag, ); if is_valid { diff --git a/test/message-generator/mock/jdc-mock-jds-setup-connection-mock-invalid-flag.json b/test/message-generator/mock/jdc-mock-jds-setup-connection-mock-invalid-flag.json index 8cb2338d74..633be8d07f 100644 --- a/test/message-generator/mock/jdc-mock-jds-setup-connection-mock-invalid-flag.json +++ b/test/message-generator/mock/jdc-mock-jds-setup-connection-mock-invalid-flag.json @@ -18,8 +18,17 @@ "role": "client", "results": [ { - "type": "match_message_type", - "value": "0x02" + "type": "match_message_field", + "value": [ + "CommonMessages", + "SetupConnectionSuccess", + [ + [ + "flags", + {"U32": 1} + ] + ] + ] } ], "actiondoc": "This action sends SetupConnection and checks that .Error" From 61337970a0a110438c7142045fb58251808837b4 Mon Sep 17 00:00:00 2001 From: plebhash Date: Thu, 18 Jul 2024 16:00:19 -0300 Subject: [PATCH 5/7] introduce `async_mining_allowed` as JDS config parameter before issue #853 was reported, JDS would simply support async jobs by default and completely ignore this flag. but checking this flag implies that JDS could either support async jobs or not, and that is what this commit does. a new `asyn_mining_allowed` parameter is introduced to the TOML config files, and that is used when: - checking for the flags of `SetupConnection` messages - responding to `AllocateMiningJobToken` messages --- .../config-examples/jds-config-hosted-example.toml | 3 +++ .../config-examples/jds-config-local-example.toml | 3 +++ roles/jd-server/src/lib/job_declarator/message_handler.rs | 2 +- roles/jd-server/src/lib/job_declarator/mod.rs | 8 ++++++-- roles/jd-server/src/lib/mod.rs | 6 ++++++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/roles/jd-server/config-examples/jds-config-hosted-example.toml b/roles/jd-server/config-examples/jds-config-hosted-example.toml index 328cffd520..999a69ae35 100644 --- a/roles/jd-server/config-examples/jds-config-hosted-example.toml +++ b/roles/jd-server/config-examples/jds-config-hosted-example.toml @@ -1,3 +1,6 @@ +# Async Job Support +async_mining_allowed = true + # SRI Pool config authority_public_key = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" authority_secret_key = "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n" diff --git a/roles/jd-server/config-examples/jds-config-local-example.toml b/roles/jd-server/config-examples/jds-config-local-example.toml index a3c7622aca..dc8ce0555d 100644 --- a/roles/jd-server/config-examples/jds-config-local-example.toml +++ b/roles/jd-server/config-examples/jds-config-local-example.toml @@ -1,3 +1,6 @@ +# Async Job Support +async_mining_allowed = true + # SRI Pool config authority_public_key = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" authority_secret_key = "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n" diff --git a/roles/jd-server/src/lib/job_declarator/message_handler.rs b/roles/jd-server/src/lib/job_declarator/message_handler.rs index 96887bdd0e..b71eb96ca7 100644 --- a/roles/jd-server/src/lib/job_declarator/message_handler.rs +++ b/roles/jd-server/src/lib/job_declarator/message_handler.rs @@ -49,7 +49,7 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream { request_id: message.request_id, mining_job_token: token.to_le_bytes().to_vec().try_into().unwrap(), coinbase_output_max_additional_size: 100, - async_mining_allowed: true, + async_mining_allowed: self.async_mining_allowed, coinbase_output: self.coinbase_output.clone().try_into().unwrap(), }; let message_enum = JobDeclaration::AllocateMiningJobTokenSuccess(message_success); diff --git a/roles/jd-server/src/lib/job_declarator/mod.rs b/roles/jd-server/src/lib/job_declarator/mod.rs index aaf94e353d..d1dfcdf05c 100644 --- a/roles/jd-server/src/lib/job_declarator/mod.rs +++ b/roles/jd-server/src/lib/job_declarator/mod.rs @@ -47,6 +47,7 @@ pub struct AddTrasactionsToMempool { #[derive(Debug)] pub struct JobDeclaratorDownstream { + async_mining_allowed: bool, sender: Sender, receiver: Receiver, // TODO this should be computed for each new template so that fees are included @@ -70,6 +71,7 @@ pub struct JobDeclaratorDownstream { impl JobDeclaratorDownstream { pub fn new( + async_mining_allowed: bool, receiver: Receiver, sender: Sender, config: &Configuration, @@ -89,6 +91,7 @@ impl JobDeclaratorDownstream { .expect("Invalid coinbase output in config"); Self { + async_mining_allowed, receiver, sender, coinbase_output, @@ -475,14 +478,14 @@ impl JobDeclarator { let flag = setup_connection.flags; let is_valid = SetupConnection::check_flags( Protocol::JobDeclarationProtocol, - 1, + config.async_mining_allowed as u32, flag, ); if is_valid { let success_message = SetupConnectionSuccess { used_version: 2, - flags: 0b_0000_0000_0000_0000_0000_0000_0000_0001, + flags: (setup_connection.flags & 1u32), }; info!("Sending success message for proxy"); let sv2_frame: StdFrame = JdsMessages::Common(success_message.into()) @@ -493,6 +496,7 @@ impl JobDeclarator { let jddownstream = Arc::new(Mutex::new(JobDeclaratorDownstream::new( + (setup_connection.flags & 1u32) != 0u32, // this takes a bool instead of u32 receiver.clone(), sender.clone(), &config, diff --git a/roles/jd-server/src/lib/mod.rs b/roles/jd-server/src/lib/mod.rs index 5fb12c75eb..e71a3b4763 100644 --- a/roles/jd-server/src/lib/mod.rs +++ b/roles/jd-server/src/lib/mod.rs @@ -57,6 +57,8 @@ pub struct CoinbaseOutput { #[derive(Debug, Deserialize, Clone)] pub struct Configuration { + #[serde(default = "default_true")] + pub async_mining_allowed: bool, pub listen_jd_address: String, pub authority_public_key: Secp256k1PublicKey, pub authority_secret_key: Secp256k1SecretKey, @@ -70,6 +72,10 @@ pub struct Configuration { pub mempool_update_interval: Duration, } +fn default_true() -> bool { + true +} + fn duration_from_toml<'de, D>(deserializer: D) -> Result where D: serde::Deserializer<'de>, From 7bb7811c952018815d07ec59cbac2a0a3b3e96e8 Mon Sep 17 00:00:00 2001 From: plebhash Date: Thu, 18 Jul 2024 16:25:44 -0300 Subject: [PATCH 6/7] fix MG tests for JD SetupConnection flags as already described in the previous commit, we introduced a new JDS config parameter (`async_mining_allowed`) so now, we need 2 separate tests: - a JDS that supports async jobs - a JDS that does not support async jobs and for each test, we need a mock that: - sends a `SetupConnection` with flag 0 and asserts the expected outcome - sends a `SetupConnection` with flag 1 and asserts the expected outcome if JDS does not support async jobs and receives a `SetupConnection` with flag 1, the expected outcome is `SetupConnection.Error` in all other cases, the expected outcome is a `SetupConnection.Success` with the same flag as the original `SetupConnection` --- .../jds-config-with-async-support.toml} | 3 + .../jds-config-without-async-support.toml | 23 +++++ ...flag-0-for-jds-setupconnection-tests.json} | 8 +- ...ds-setupconnection-with-async-support.json | 46 ++++++++++ ...setupconnection-without-async-support.json | 40 ++++++++ ...s-setupconnection-with-async-support.json} | 31 ++++++- ...jds-setupconnection-with-async-support.sh} | 2 +- ...setupconnection-without-async-support.json | 92 +++++++++++++++++++ ...s-setupconnection-without-async-support.sh | 9 ++ 9 files changed, 244 insertions(+), 10 deletions(-) rename test/config/{jds-setup-connection-flag-test/jds-config.toml => jds-setupconnection-flag-test/jds-config-with-async-support.toml} (93%) create mode 100644 test/config/jds-setupconnection-flag-test/jds-config-without-async-support.toml rename test/message-generator/mock/{jdc-mock-jds-setup-connection-mock-invalid-flag.json => jdc-mock-flag-0-for-jds-setupconnection-tests.json} (81%) create mode 100644 test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-with-async-support.json create mode 100644 test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-without-async-support.json rename test/message-generator/test/{jds-setup-connection-flag-test/jds-setup-connection-flag-test.json => jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.json} (62%) rename test/message-generator/test/{jds-setup-connection-flag-test/jds-setup-connection-flag-test.sh => jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.sh} (58%) create mode 100644 test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.json create mode 100755 test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.sh diff --git a/test/config/jds-setup-connection-flag-test/jds-config.toml b/test/config/jds-setupconnection-flag-test/jds-config-with-async-support.toml similarity index 93% rename from test/config/jds-setup-connection-flag-test/jds-config.toml rename to test/config/jds-setupconnection-flag-test/jds-config-with-async-support.toml index acda73227c..379fee5613 100644 --- a/test/config/jds-setup-connection-flag-test/jds-config.toml +++ b/test/config/jds-setupconnection-flag-test/jds-config-with-async-support.toml @@ -1,3 +1,6 @@ +# Async Job Support +async_mining_allowed = true + # SRI Pool config authority_public_key = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" authority_secret_key = "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n" diff --git a/test/config/jds-setupconnection-flag-test/jds-config-without-async-support.toml b/test/config/jds-setupconnection-flag-test/jds-config-without-async-support.toml new file mode 100644 index 0000000000..c846552769 --- /dev/null +++ b/test/config/jds-setupconnection-flag-test/jds-config-without-async-support.toml @@ -0,0 +1,23 @@ +# Async Job Support +async_mining_allowed = false + +# SRI Pool config +authority_public_key = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" +authority_secret_key = "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n" +cert_validity_sec = 3600 + +# list of compressed or uncompressed pubkeys for coinbase payout (only supports 1 item in the array at this point) +coinbase_outputs = [ + { output_script_type = "P2WPKH", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" }, +] + +listen_jd_address = "127.0.0.1:34264" + +core_rpc_url = "" +core_rpc_port = 18332 +core_rpc_user = "" +core_rpc_pass = "" +# Time interval used for JDS mempool update +[mempool_update_interval] +unit = "secs" +value = 1 \ No newline at end of file diff --git a/test/message-generator/mock/jdc-mock-jds-setup-connection-mock-invalid-flag.json b/test/message-generator/mock/jdc-mock-flag-0-for-jds-setupconnection-tests.json similarity index 81% rename from test/message-generator/mock/jdc-mock-jds-setup-connection-mock-invalid-flag.json rename to test/message-generator/mock/jdc-mock-flag-0-for-jds-setupconnection-tests.json index 633be8d07f..e80141297f 100644 --- a/test/message-generator/mock/jdc-mock-jds-setup-connection-mock-invalid-flag.json +++ b/test/message-generator/mock/jdc-mock-flag-0-for-jds-setupconnection-tests.json @@ -3,8 +3,8 @@ "doc": [ "This test does", "Soft mock of JDC", - "Connect to JDS", - "Receive Setup Connection Error as incorrect bits are set" + "Connect to JDS (where it doesn't matter if it supports async jobs or not)", + "Send SetupConnection with flag 0 (no async jobs) and expect SetupConnection.Success with flag 0" ], "frame_builders": [ { @@ -25,13 +25,13 @@ [ [ "flags", - {"U32": 1} + { "U32": 0 } ] ] ] } ], - "actiondoc": "This action sends SetupConnection and checks that .Error" + "actiondoc": "This action sends SetupConnection and expects SetupConnection.Success with flag 0" } ], "setup_commands": [], diff --git a/test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-with-async-support.json b/test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-with-async-support.json new file mode 100644 index 0000000000..edbd83e13e --- /dev/null +++ b/test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-with-async-support.json @@ -0,0 +1,46 @@ +{ + "version": "2", + "doc": [ + "This test does", + "Soft mock of JDC", + "Connect to JDS (that supports async jobs)", + "Send SetupConnection with flag 1 (async jobs) and expect SetupConnection.Success with flag 1" + ], + "frame_builders": [ + { + "type": "automatic", + "message_id": "test/message-generator/messages/common_messages.json::setup_connection_job_declarator" + } + ], + "actions": [ + { + "message_ids": ["setup_connection_job_declarator"], + "role": "client", + "results": [ + { + "type": "match_message_field", + "value": [ + "CommonMessages", + "SetupConnectionSuccess", + [ + [ + "flags", + { "U32": 1 } + ] + ] + ] + } + ], + "actiondoc": "This action sends SetupConnection and expects SetupConnection.Success with flag 1" + } + ], + "setup_commands": [], + "execution_commands": [], + "cleanup_commands": [], + "role": "client", + "downstream": { + "ip": "127.0.0.1", + "port": 34264, + "pub_key": "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" + } +} diff --git a/test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-without-async-support.json b/test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-without-async-support.json new file mode 100644 index 0000000000..eeaf19ca59 --- /dev/null +++ b/test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-without-async-support.json @@ -0,0 +1,40 @@ +{ + "version": "2", + "doc": [ + "This test does", + "Soft mock of JDC", + "Connect to JDS (that does not support async jobs)", + "Send SetupConnection with flag 1 (async jobs) and expect SetupConnection.Error" + ], + "frame_builders": [ + { + "type": "automatic", + "message_id": "test/message-generator/messages/common_messages.json::setup_connection_job_declarator" + } + ], + "actions": [ + { + "message_ids": ["setup_connection_job_declarator"], + "role": "client", + "results": [ + { + "type": "match_message_type", + "value": "0x02" + }, + { + "type": "close_connection" + } + ], + "actiondoc": "This action sends SetupConnection and expects SetupConnection.Error" + } + ], + "setup_commands": [], + "execution_commands": [], + "cleanup_commands": [], + "role": "client", + "downstream": { + "ip": "127.0.0.1", + "port": 34264, + "pub_key": "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" + } +} diff --git a/test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.json b/test/message-generator/test/jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.json similarity index 62% rename from test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.json rename to test/message-generator/test/jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.json index 403b1eb4f9..c0d781d69c 100644 --- a/test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.json +++ b/test/message-generator/test/jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.json @@ -19,7 +19,7 @@ "jd_server", "--", "-c", - "../test/config/jds-setup-connection-flag-test/jds-config.toml" + "../test/config/jds-setupconnection-flag-test/jds-config-with-async-support.toml" ], "conditions": { "WithConditions": { @@ -40,16 +40,37 @@ "command": "cargo", "args": [ "run", - "../../test/message-generator/mock/jdc-mock-jds-setup-connection-mock-invalid-flag.json" + "../../test/message-generator/mock/jdc-mock-flag-0-for-jds-setupconnection-tests.json" ], "conditions": { "WithConditions": { "conditions": [ { - "output_string": "MATCHED MESSAGE TYPE 1", - "output_location": "StdOut", + "output_string": "TEST FAILED", + "output_location": "StdErr", "late_condition": false, - "condition": true + "condition": false + } + ], + "timer_secs": 600, + "warn_no_panic": false + } + } + }, + { + "command": "cargo", + "args": [ + "run", + "../../test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-with-async-support.json" + ], + "conditions": { + "WithConditions": { + "conditions": [ + { + "output_string": "TEST FAILED", + "output_location": "StdErr", + "late_condition": false, + "condition": false } ], "timer_secs": 600, diff --git a/test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.sh b/test/message-generator/test/jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.sh similarity index 58% rename from test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.sh rename to test/message-generator/test/jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.sh index b32716fe30..87dcf97e9d 100755 --- a/test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.sh +++ b/test/message-generator/test/jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.sh @@ -4,6 +4,6 @@ cargo llvm-cov --no-report -p pool_sv2 cd ../utils/message-generator/ cargo build -RUST_LOG=debug cargo run ../../test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.json || { echo 'mg test failed' ; exit 1; } +RUST_LOG=debug cargo run ../../test/message-generator/test/jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.json || { echo 'mg test failed' ; exit 1; } sleep 10 diff --git a/test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.json b/test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.json new file mode 100644 index 0000000000..15eb2e978a --- /dev/null +++ b/test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.json @@ -0,0 +1,92 @@ +{ + "version": "2", + "doc": [ + "This test does", + "Launch the jd-server" + ], + "frame_builders": [ + ], + "actions": [ + ], + "setup_commands": [ + { + "command": "cargo", + "args": [ + "llvm-cov", + "--no-report", + "run", + "-p", + "jd_server", + "--", + "-c", + "../test/config/jds-setupconnection-flag-test/jds-config-without-async-support.toml" + ], + "conditions": { + "WithConditions": { + "conditions": [ + { + "output_string": "JD INITIALIZED", + "output_location": "StdOut", + "late_condition": false, + "condition": true + } + ], + "timer_secs": 300, + "warn_no_panic": false + } + } + }, + { + "command": "cargo", + "args": [ + "run", + "../../test/message-generator/mock/jdc-mock-flag-0-for-jds-setupconnection-tests.json" + ], + "conditions": { + "WithConditions": { + "conditions": [ + { + "output_string": "TEST FAILED", + "output_location": "StdErr", + "late_condition": false, + "condition": false + } + ], + "timer_secs": 600, + "warn_no_panic": false + } + } + }, + { + "command": "cargo", + "args": [ + "run", + "../../test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-without-async-support.json" + ], + "conditions": { + "WithConditions": { + "conditions": [ + { + "output_string": "TEST FAILED", + "output_location": "StdErr", + "late_condition": false, + "condition": false + } + ], + "timer_secs": 600, + "warn_no_panic": false + } + } + } + ], + "execution_commands": [ + ], + "cleanup_commands": [ + { + "command": "pkill", + "args": ["-f", "jd_server", "-SIGINT"], + "conditions": "None" + } + ], + "role": "none" +} diff --git a/test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.sh b/test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.sh new file mode 100755 index 0000000000..151cec4ff2 --- /dev/null +++ b/test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.sh @@ -0,0 +1,9 @@ +cd roles +cargo llvm-cov --no-report -p pool_sv2 + +cd ../utils/message-generator/ +cargo build + +RUST_LOG=debug cargo run ../../test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.json || { echo 'mg test failed' ; exit 1; } + +sleep 10 From 51a20d8b079ad5935c5682df8cc7c471158a7c20 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Thu, 25 Jul 2024 07:03:12 -0400 Subject: [PATCH 7/7] Add check flags protocols docs --- .../common-messages/src/setup_connection.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/protocols/v2/subprotocols/common-messages/src/setup_connection.rs b/protocols/v2/subprotocols/common-messages/src/setup_connection.rs index 0c5522d6b1..763907b0be 100644 --- a/protocols/v2/subprotocols/common-messages/src/setup_connection.rs +++ b/protocols/v2/subprotocols/common-messages/src/setup_connection.rs @@ -69,6 +69,17 @@ impl<'decoder> SetupConnection<'decoder> { // [1] [1] -> true // [0] [1] -> false Protocol::MiningProtocol => { + // Evaluates protocol requirements based on flag bits. + // + // Checks if the current protocol meets the required flags for work selection and version rolling + // by reversing the bits of `available_flags` and `required_flags`. It extracts the 30th and 29th + // bits to determine if work selection and version rolling are needed. + // + // Returns `true` if: + // - The work selection requirement is satisfied or not needed. + // - The version rolling requirement is satisfied or not needed. + // + // Otherwise, returns `false`. let available = available_flags.reverse_bits(); let required_flags = required_flags.reverse_bits(); let requires_work_selection_passed = required_flags >> 30 > 0; @@ -85,6 +96,13 @@ impl<'decoder> SetupConnection<'decoder> { work_selection && version_rolling } Protocol::JobDeclarationProtocol => { + // Determines if asynchronous job mining is required based on flag bits. + // + // Reverses the bits of `available_flags` and `required_flags`, extracts the 31st bit from each, + // and evaluates if the condition is met using these bits. Returns `true` or `false` based on: + // - True if `requires_async_job_mining_self` is true, or both are true. + // - False if `requires_async_job_mining_self` is false and `requires_async_job_mining_passed` is true. + // - True otherwise. let available = available_flags.reverse_bits(); let required = required_flags.reverse_bits();