Skip to content

Commit

Permalink
Add MG test to replicate issue
Browse files Browse the repository at this point in the history
Issue: when JDC changes upstream (because a SubmitShareError), it
disconnects also the TProxy.
To replicate this issue:
 - run a local template provider
 - run a pool applicationa that doesn't censor (i.e. the SRI pool)
 - run a jd-server application
 - from the MG test, run
`RUST_LOG=info cargo run
../../test/message-generator/test/change-upstream/change-upstream.json`
which is a mock for a pool that rejects the shares
 - launch a jd-client that connects to the pool's mock and the jds
 - launch the TProxy that connects to the jd-client
 - start mining with your favourite miner

At the first share relayed to the upstream the jdc disconnect the TProxy
All the config files needed are in `/test/config/change-upstream/`

The issue is fixed when this test is performed again, but the TProxy
reconnects to the jdc. The miner will likely continue mining on the
previous job (producing invalid shares) until a NewTemplate arrives
  • Loading branch information
lorbax committed Jul 9, 2024
1 parent 92a6fbf commit 183163f
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ min_extranonce2_size = 8
# Difficulty params
[downstream_difficulty_config]
# hashes/s of the weakest miner that will be connecting (e.g.: 10 Th/s = 10_000_000_000_000.0)
min_individual_miner_hashrate=10_000_000_000_000.0
min_individual_miner_hashrate=10_000_000.0
# target number of shares per minute the miner should be sending
shares_per_minute = 6.0

[upstream_difficulty_config]
# interval in seconds to elapse before updating channel hashrate with the pool
channel_diff_update_interval = 60
# estimated accumulated hashrate of all downstream miners (e.g.: 10 Th/s = 10_000_000_000_000.0)
channel_nominal_hashrate = 10_000_000_000_000.0
channel_nominal_hashrate = 10_000_000.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# SRI JDC config
downstream_address = "127.0.0.1"
downstream_port = 34265

# Version support
max_supported_version = 2
min_supported_version = 2

# Minimum extranonce2 size for downstream
# Max value: 16 (leaves 0 bytes for search space splitting of downstreams)
# Max value for CGminer: 8
# Min value: 2
min_extranonce2_size = 8

# Withhold
withhold = false

# Auth keys for open encrypted connection downstream
authority_public_key = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72"
authority_secret_key = "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n"
cert_validity_sec = 3600

# How many time the JDC try to reinitialize itself after a failure
retry = 10

# Template Provider config
# Local TP (this is pointing to localhost so you must run a TP locally for this configuration to work)
tp_address = "127.0.0.1:8442"
# Hosted testnet TP
# tp_address = "75.119.150.111:8442"

# Solo Mining config
# List of coinbase outputs used to build the coinbase tx in case of Solo Mining (as last-resort solution of the pools fallback system)
# ! Put your Extended Public Key or Script as output_script_value !
# ! Right now only one output is supported, so comment all the ones you don't need !
# For P2PK, P2PKH, P2WPKH, P2TR a public key is needed. For P2SH and P2WSH, a redeem script is needed.
coinbase_outputs = [
#{ output_script_type = "P2PK", output_script_value = "0372c47307e5b75ce365daf835f226d246c5a7a92fe24395018d5552123354f086" },
#{ output_script_type = "P2PKH", output_script_value = "0372c47307e5b75ce365daf835f226d246c5a7a92fe24395018d5552123354f086" },
#{ output_script_type = "P2SH", output_script_value = "00142ef89234bc95136eb9e6fee9d32722ebd8c1f0ab" },
#{ output_script_type = "P2WSH", output_script_value = "00142ef89234bc95136eb9e6fee9d32722ebd8c1f0ab" },
{ output_script_type = "P2WPKH", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" },
#{ output_script_type = "P2TR", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" },
]

[timeout]
unit = "secs"
value = 1

# List of upstreams (JDS) used as backup endpoints
# In case of shares refused by the JDS, the fallback system will propose the same job to the next upstream in this list
[[upstreams]]
authority_pubkey = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72"
pool_address = "127.0.0.1:44254"
jd_address = "127.0.0.1:34264"
# Pool signature (string to be included in coinbase tx)
pool_signature = "Stratum v2 SRI Pool"
[[upstreams]]
authority_pubkey = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72"
pool_address = "127.0.0.1:34254"
jd_address = "127.0.0.1:34264"
# Pool signature (string to be included in coinbase tx)
pool_signature = "Stratum v2 SRI Pool"

# [[upstreams]]
# authority_pubkey = "2di19GHYQnAZJmEpoUeP7C3Eg9TCcksHr23rZCC83dvUiZgiDL"
# pool_address = "127.0.0.1:34254"
# jd_address = "127.0.0.1:34264"
# Pool signature (string to be included in coinbase tx)
# pool_signature = "Stratum v2 SRI Pool"
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SRI Pool config
authority_public_key = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72"
authority_secret_key = "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n"
cert_validity_sec = 3600

# List of coinbase outputs used to build the coinbase tx
# ! Right now only one output is supported, so comment all the ones you don't need !
# For P2PK, P2PKH, P2WPKH, P2TR a public key is needed. For P2SH and P2WSH, a redeem script is needed.
coinbase_outputs = [
#{ output_script_type = "P2PK", output_script_value = "0372c47307e5b75ce365daf835f226d246c5a7a92fe24395018d5552123354f086" },
#{ output_script_type = "P2PKH", output_script_value = "0372c47307e5b75ce365daf835f226d246c5a7a92fe24395018d5552123354f086" },
#{ output_script_type = "P2SH", output_script_value = "00142ef89234bc95136eb9e6fee9d32722ebd8c1f0ab" },
#{ output_script_type = "P2WSH", output_script_value = "00142ef89234bc95136eb9e6fee9d32722ebd8c1f0ab" },
{ output_script_type = "P2WPKH", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" },
#{ output_script_type = "P2TR", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" },
]

# SRI Pool JD config
listen_jd_address = "0.0.0.0:34264"
# RPC config for mempool (it can be also the same TP if correctly configured)
core_rpc_url = "http://127.0.0.1"
core_rpc_port = 18332
core_rpc_user = "username"
core_rpc_pass = "password"
# Time interval used for JDS mempool update
[mempool_update_interval]
unit = "secs"
value = 1
25 changes: 25 additions & 0 deletions test/config/change-upstream/pool-config-local-tp-example.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SRI Pool config
authority_public_key = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72"
authority_secret_key = "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n"
cert_validity_sec = 3600
test_only_listen_adress_plain = "0.0.0.0:34250"
listen_address = "0.0.0.0:34254"

# List of coinbase outputs used to build the coinbase tx
# ! Right now only one output is supported, so comment all the ones you don't need !
# For P2PK, P2PKH, P2WPKH, P2TR a public key is needed. For P2SH and P2WSH, a redeem script is needed.
coinbase_outputs = [
#{ output_script_type = "P2PK", output_script_value = "0372c47307e5b75ce365daf835f226d246c5a7a92fe24395018d5552123354f086" },
#{ output_script_type = "P2PKH", output_script_value = "0372c47307e5b75ce365daf835f226d246c5a7a92fe24395018d5552123354f086" },
#{ output_script_type = "P2SH", output_script_value = "00142ef89234bc95136eb9e6fee9d32722ebd8c1f0ab" },
#{ output_script_type = "P2WSH", output_script_value = "00142ef89234bc95136eb9e6fee9d32722ebd8c1f0ab" },
{ output_script_type = "P2WPKH", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" },
#{ output_script_type = "P2TR", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" },
]

# Pool signature (string to be included in coinbase tx)
pool_signature = "Stratum v2 SRI Pool"

# Template Provider config
# Local TP (this is pointing to localhost so you must run a TP locally for this configuration to work)
tp_address = "127.0.0.1:8442"
38 changes: 38 additions & 0 deletions test/config/change-upstream/tproxy-config-local-jdc-example.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Braiins Pool Upstream Connection
# upstream_authority_pubkey = "u95GEReVMjK6k5YqiSFNqqTnKU4ypU2Wm8awa6tmbmDmk1bWt"
# upstream_address = "18.196.32.109"
# upstream_port = 3336

# Local SRI JDC Upstream Connection
upstream_address = "127.0.0.1"
upstream_port = 34265
upstream_authority_pubkey = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72"

# Local Mining Device Downstream Connection
downstream_address = "0.0.0.0"
downstream_port = 34255

# Version support
max_supported_version = 2
min_supported_version = 2

# Minimum extranonce2 size for downstream
# Max value: 16 (leaves 0 bytes for search space splitting of downstreams)
# Max value for CGminer: 8
# Min value: 2
min_extranonce2_size = 8

# Difficulty params
[downstream_difficulty_config]
# hashes/s of the weakest miner that will be connecting
min_individual_miner_hashrate=18_000_000.0
# minimum number of shares needed before a mining.set_difficulty is sent for updating targets
miner_num_submits_before_update=5
# target number of shares per minute the miner should be sending
shares_per_minute = 100.0

[upstream_difficulty_config]
# interval in seconds to elapse before updating channel hashrate with the pool
channel_diff_update_interval = 60
# estimated accumulated hashrate of all downstream miners
channel_nominal_hashrate = 18_000_000.0
120 changes: 120 additions & 0 deletions test/message-generator/test/change-upstream/change-upstream.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"version": "2",
"doc": [
"This test does",
"Acts like a pool that refuses share with JobDeclatarion",
"Waits for SetupConnection",
"Sends a SetupConnection.Success and waits that a SetCustomMiningJob is received",
"Sends a SetCustomMiningJob.Success and waits that UpdateChannel is received",
"Waits that SubmitShare is received",
"Responds with SubmitShare.Error"
],
"frame_builders": [
{
"type": "automatic",
"message_id": "test/message-generator/messages/mining_messages.json::open_extended_mining_channel_success"
},
{
"type": "automatic",
"message_id": "test/message-generator/messages/common_messages.json::setup_connection_success_tproxy"
},
{
"type": "automatic",
"message_id": "test/message-generator/messages/mining_messages.json::set_custom_mining_job_success"
},
{
"type": "automatic",
"message_id": "test/message-generator/messages/mining_messages.json::submit_shares_error"
}
],
"actions": [
{
"message_ids": [],
"role": "server",
"results": [
{
"type": "match_message_type",
"value": "0x00"
}
],
"actiondoc": "This action checks that a Setupconnection message is received"
},
{
"message_ids": ["setup_connection_success_tproxy"],
"role": "server",
"results": [
{
"type": "match_message_type",
"value": "0x13"
}
],
"actiondoc": "This action sends SetupConnection.Success and check that a OpenExtendedfMiningChannel is received"
},
{
"message_ids": ["open_extended_mining_channel_success"],
"role": "server",
"results": [
{
"type": "get_message_field",
"value": [
"MiningProtocol",
"SetCustomMiningJob",
[
[
"request_id",
"custom_job_req_id"
]
]
]
}
],
"actiondoc": "This action sends open_extended_mining_channel_success, and a wait for a SetCustomMiningJoband get the req id"
},
{
"message_ids": ["set_custom_mining_job_success"],
"role": "server",
"results": [
{
"type": "match_message_type",
"value": "0x16"
}
],
"actiondoc": "This action sends a SetCustomMiningJob.Success and check that UpdateChannel is received"
},
{
"message_ids": [],
"role": "server",
"results": [
{
"type": "match_message_type",
"value": "0x1b"
}
],
"actiondoc": "This action check submit_shares is received"
},
{
"message_ids": ["submit_shares_error"],
"role": "server",
"results": [],
"actiondoc": "This action a submit_shares_error"
}
],
"setup_commands": [
],
"execution_commands": [
],
"cleanup_commands": [
{
"command": "sleep",
"args": ["100000000000"],
"conditions": "None"
}
],
"role": "server",
"upstream": {
"ip": "127.0.0.1",
"port": 44254,
"pub_key": "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72",
"secret_key": "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n"
}
}

0 comments on commit 183163f

Please sign in to comment.