Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid JDS dropping connection on SubmitSolution with missing txs #1025

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/mg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ jobs:
- name: Run jds-do-not-stackoverflow-when-no-token
run: sh ./test/message-generator/test/jds-do-not-stackoverflow-when-no-token/jds-do-not-stackoverflow-when-no-token.sh

jds-receive-solution-while-processing-declared-job:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install cargo-llvm-cov
run: cargo install cargo-llvm-cov
- name: Run jds-receive-solution-while-processing-declared-job
run: sh ./test/message-generator/test/jds-receive-solution-while-processing-declared-job/jds-receive-solution-while-processing-declared-job.sh

pool-sri-test-1-standard:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -171,6 +181,7 @@ jobs:
jds-do-not-fail-on-wrong-tsdatasucc,
jds-do-not-panic-if-jdc-close-connection,
jds-do-not-stackoverflow-when-no-token,
jds-receive-solution-while-processing-declared-job,
pool-sri-test-1-standard,
pool-sri-test-close-channel,
pool-sri-test-extended_0,
Expand All @@ -192,6 +203,7 @@ jobs:
[ "${{ needs.jds-do-not-fail-on-wrong-tsdatasucc.result }}" != "success" ] ||
[ "${{ needs.jds-do-not-panic-if-jdc-close-connection.result }}" != "success" ] ||
[ "${{ needs.jds-do-not-stackoverflow-when-no-token.result }}" != "success" ] ||
[ "${{ needs.jds-receive-solution-while-processing-declared-job.result }}" != "success" ] ||
[ "${{ needs.pool-sri-test-1-standard.result }}" != "success" ] ||
[ "${{ needs.pool-sri-test-close-channel.result }}" != "success" ] ||
[ "${{ needs.pool-sri-test-extended_0.result }}" != "success" ] ||
Expand Down
45 changes: 19 additions & 26 deletions roles/jd-server/src/lib/job_declarator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,23 +280,18 @@ impl JobDeclaratorDownstream {
match Self::collect_txs_in_job(self_mutex.clone()) {
Ok(_) => {
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;
match JobDeclaratorDownstream::get_block_hex(
plebhash marked this conversation as resolved.
Show resolved Hide resolved
self_mutex.clone(),
message,
) {
Ok(hexdata) => {
let _ =
new_block_sender.send(hexdata).await;
}
Err(e) => {
handle_result!(tx_status, Err(*e))
}
};
}
Err(error) => {
error!("Missing transactions: {:?}", error);
Expand All @@ -316,22 +311,20 @@ impl JobDeclaratorDownstream {
.unwrap();
tokio::select! {
_ = JDsMempool::add_tx_data_to_mempool(mempool, retrieve_transactions) => {
let hexdata = match JobDeclaratorDownstream::get_block_hex(
match JobDeclaratorDownstream::get_block_hex(
self_mutex.clone(),
message.clone(),
) {
Ok(inner) => inner,
Ok(hexdata) => {
let _ = new_block_sender.send(hexdata).await;
},
Err(e) => {
error!(
"Error retrieving transactions: {:?}",
e
handle_result!(
tx_status,
Err(*e)
);
recv.close();
//TODO should we brake it?
break;
}
};
let _ = new_block_sender.send(hexdata).await;
}
_ = tokio::time::sleep(Duration::from_secs(60)) => {}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = 48332
core_rpc_user = ""
core_rpc_pass = ""
# Time interval used for JDS mempool update
[mempool_update_interval]
unit = "secs"
value = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
"version": "2",
"doc": [
"This test does",
"Mock JDC",
"Send SetupConnection and await for SetupConnection.Success",
"Send AllocateMiningJobToken0 and await for AllocateMiningJobToken.Success0",
"Send AllocateMiningJobToken1 and await for AllocateMiningJobToken.Success1",
"Send DeclareMiningJob and await for ProvideMissingTransactions",
"Send SubmitSolution and assert that connection was sustained"
plebhash marked this conversation as resolved.
Show resolved Hide resolved
],
"job_declaration_messages": [
{
"message": {
"type": "AllocateMiningJobToken",
"user_identifier": "",
"request_id": 0,
"coinbase_tx_outputs": []
},
"id": "allocate_mining_job_token0"
},
{
"message": {
"type": "AllocateMiningJobToken",
"user_identifier": "",
"request_id": 1,
"coinbase_tx_outputs": []
},
"id": "allocate_mining_job_token1"
},
{
"message": {
"type": "DeclareMiningJob",
"request_id": 0,
"mining_job_token": [1, 0, 0, 0],
"version": 0,
"coinbase_prefix": [2, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 55, 2, 128, 121, 0, 83, 116, 114, 97, 116, 117, 109, 32, 118, 50, 32, 83, 82, 73, 32, 80, 111, 111, 108],
"coinbase_suffix": [255, 255, 255, 255, 2, 168, 247, 5, 42, 1, 0, 0, 0, 22, 0, 20, 235, 225, 183, 220, 194, 147, 204, 170, 14, 231, 67, 168, 111, 137, 223, 130, 88, 194, 8, 252, 0, 0, 0, 0, 0, 0, 0, 0, 38, 106, 36, 170, 33, 169, 237, 226, 201, 13, 62, 213, 94, 164, 53, 216, 76, 246, 14, 110, 125, 255, 48, 66, 12, 220, 90, 217, 209, 75, 129, 37, 185, 117, 116, 254, 30, 81, 159, 1, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"tx_short_hash_nonce": 0,
"tx_short_hash_list": [[95, 135, 113, 8, 147, 179]],
"tx_hash_list_hash": [133, 189, 184, 91, 252, 203, 225, 42, 233, 16, 77, 119, 76, 134, 93, 189, 192, 159, 221, 130, 150, 196, 18, 32, 54, 212, 138, 255, 57, 63, 118, 74],
"excess_data": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
},
"id": "declare_mining_job"
},
{
"message": {
"type": "SubmitSolution",
"extranonce": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0],
"prev_hash": [184, 103, 138, 88, 153, 105, 236, 29, 123, 246, 107, 203, 1, 33, 10, 122, 188, 139, 218, 141, 62, 177, 158, 101, 125, 92, 214, 150, 199, 220, 29, 8],
"ntime": 0,
"nonce": 0,
"nbits": 0,
"version": 0
},
"id": "submit_solution"
}
],
"frame_builders": [
{
"type": "automatic",
"message_id": "test/message-generator/messages/common_messages.json::setup_connection_job_declarator"
},
{
"type": "automatic",
"message_id": "allocate_mining_job_token0"
},
{
"type": "automatic",
"message_id": "allocate_mining_job_token1"
},
{
"type": "automatic",
"message_id": "declare_mining_job"
},
{
"type": "automatic",
"message_id": "submit_solution"
}
],
"actions": [
{
"message_ids": ["setup_connection_job_declarator"],
"role": "client",
"results": [
{
"type": "match_message_type",
"value": "0x01"
}
],
"actiondoc": "This action sends SetupConnection and awaits for a SetupConnection.Success"
},
{
"message_ids": ["allocate_mining_job_token0"],
"role": "client",
"results": [
{
"type": "match_message_type",
"value": "0x51"
}
],
"actiondoc": "This action sends AllocateMiningJobToken0 and awaits for a AllocateMiningJobToken.Success0"
},
{
"message_ids": ["allocate_mining_job_token1"],
"role": "client",
"results": [
{
"type": "match_message_type",
"value": "0x51"
}
],
"actiondoc": "This action sends AllocateMiningJobToken1 and awaits for a AllocateMiningJobToken.Success1"
},
{
"message_ids": ["declare_mining_job"],
"role": "client",
"results": [
{
"type": "match_message_type",
"value": "0x55"
}
],
"actiondoc": "This action sends DeclareMiningJob and awaits for a ProvideMissingTransactions"
},
{
"message_ids": ["submit_solution"],
"role": "client",
"results": [
{
"type": "sustain_connection"
}
],
"actiondoc": "This action sends SubmitSolution and asserts that connection was sustained"
}
],
"setup_commands": [],
"execution_commands": [],
"cleanup_commands": [],
"role": "client",
"downstream": {
"ip": "127.0.0.1",
"port": 34264,
"pub_key": "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"version": "2",
"doc": [
"This test does",
"Launch real JDS",
"Mock a JDC that sends SubmitSolution before ProvideMissingTransactionsSuccess"
],
"frame_builders": [
],
"actions": [
],
"setup_commands": [
{
"command": "cargo",
"args": [
"llvm-cov",
"--no-report",
"run",
"-p",
"jd_server",
"--",
"-c",
"../test/config/jds-receive-solution-while-processing-declared-job/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/jdc-mock-jds-receive-solution-while-processing-declared-job.json"
],

"conditions": {
"WithConditions": {
"conditions": [
{
"output_string": "TEST FAIL",
"output_location": "StdErr",
"condition": false,
"late_condition": false
}
],
"timer_secs": 600,
"warn_no_panic": true
}
}
},
{
"command": "sleep",
"args": ["1000"],
"conditions": "None"
}
],
"execution_commands": [
],
"cleanup_commands": [
{
"command": "pkill",
"args": ["-f", "jd_server", "-SIGINT"],
"late_condition": false,
"conditions": "None"
}
],
"role": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cd roles
cargo llvm-cov --no-report -p jd_server

cd ../utils/message-generator/
cargo build

RUST_LOG=debug cargo run ../../test/message-generator/test/jds-receive-solution-while-processing-declared-job/jds-receive-solution-while-processing-declared-job.json || { echo 'mg test failed' ; exit 1; }

sleep 10
Loading