Skip to content

Commit c48597e

Browse files
committed
fix(translator): make worker identity TLV optional and fix unwrap panic
Add `enable_worker_identity_tlv` config option (default: true) to control whether UserIdentity TLV is attached to SubmitSharesExtended messages. When disabled, the translator skips TLV encoding, matching JD-client behavior. Also replace .unwrap() with .ok() on UserIdentity::new() to prevent panics when user_identity exceeds the 32-byte TLV limit (e.g. when using Bitcoin addresses as user_identity). Closes #295
1 parent 72cc650 commit c48597e

10 files changed

Lines changed: 62 additions & 4 deletions

miner-apps/translator/config-examples/mainnet/tproxy-config-hosted-pool-example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ user_identity = "your_username_here"
1919
# Aggregate channels: if true, all miners share one upstream channel; if false, each miner gets its own channel
2020
aggregate_channels = true
2121

22+
# Attach worker identity TLV to share submissions for per-worker hashrate tracking
23+
# (extension 0x0002). Disable when using Bitcoin addresses as user_identity, since
24+
# addresses exceed the 32-byte TLV limit.
25+
enable_worker_identity_tlv = true
26+
2227
# Enable this option to set a predefined log file path.
2328
# When enabled, logs will always be written to this file.
2429
# The CLI option --log-file (or -f) will override this setting if provided.

miner-apps/translator/config-examples/mainnet/tproxy-config-local-jdc-example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ user_identity = "your_username_here"
1919
# Aggregate channels: if true, all miners share one upstream channel; if false, each miner gets its own channel
2020
aggregate_channels = false
2121

22+
# Attach worker identity TLV to share submissions for per-worker hashrate tracking
23+
# (extension 0x0002). Disable when using Bitcoin addresses as user_identity, since
24+
# addresses exceed the 32-byte TLV limit.
25+
enable_worker_identity_tlv = true
26+
2227
# Enable this option to set a predefined log file path.
2328
# When enabled, logs will always be written to this file.
2429
# The CLI option --log-file (or -f) will override this setting if provided.

miner-apps/translator/config-examples/mainnet/tproxy-config-local-pool-example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ user_identity = "your_username_here"
1919
# Aggregate channels: if true, all miners share one upstream channel; if false, each miner gets its own channel
2020
aggregate_channels = true
2121

22+
# Attach worker identity TLV to share submissions for per-worker hashrate tracking
23+
# (extension 0x0002). Disable when using Bitcoin addresses as user_identity, since
24+
# addresses exceed the 32-byte TLV limit.
25+
enable_worker_identity_tlv = true
26+
2227
# Enable this option to set a predefined log file path.
2328
# When enabled, logs will always be written to this file.
2429
# The CLI option --log-file (or -f) will override this setting if provided.

miner-apps/translator/config-examples/signet/tproxy-config-local-jdc-example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ user_identity = "your_username_here"
1919
# Aggregate channels: if true, all miners share one upstream channel; if false, each miner gets its own channel
2020
aggregate_channels = false
2121

22+
# Attach worker identity TLV to share submissions for per-worker hashrate tracking
23+
# (extension 0x0002). Disable when using Bitcoin addresses as user_identity, since
24+
# addresses exceed the 32-byte TLV limit.
25+
enable_worker_identity_tlv = true
26+
2227
# Enable this option to set a predefined log file path.
2328
# When enabled, logs will always be written to this file.
2429
# The CLI option --log-file (or -f) will override this setting if provided.

miner-apps/translator/config-examples/signet/tproxy-config-local-pool-example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ user_identity = "your_username_here"
1919
# Aggregate channels: if true, all miners share one upstream channel; if false, each miner gets its own channel
2020
aggregate_channels = true
2121

22+
# Attach worker identity TLV to share submissions for per-worker hashrate tracking
23+
# (extension 0x0002). Disable when using Bitcoin addresses as user_identity, since
24+
# addresses exceed the 32-byte TLV limit.
25+
enable_worker_identity_tlv = true
26+
2227
# Enable this option to set a predefined log file path.
2328
# When enabled, logs will always be written to this file.
2429
# The CLI option --log-file (or -f) will override this setting if provided.

miner-apps/translator/config-examples/testnet4/tproxy-config-hosted-pool-example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ user_identity = "your_username_here"
1919
# Aggregate channels: if true, all miners share one upstream channel; if false, each miner gets its own channel
2020
aggregate_channels = true
2121

22+
# Attach worker identity TLV to share submissions for per-worker hashrate tracking
23+
# (extension 0x0002). Disable when using Bitcoin addresses as user_identity, since
24+
# addresses exceed the 32-byte TLV limit.
25+
enable_worker_identity_tlv = true
26+
2227
# Enable this option to set a predefined log file path.
2328
# When enabled, logs will always be written to this file.
2429
# The CLI option --log-file (or -f) will override this setting if provided.

miner-apps/translator/config-examples/testnet4/tproxy-config-local-jdc-example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ user_identity = "your_username_here"
1919
# Aggregate channels: if true, all miners share one upstream channel; if false, each miner gets its own channel
2020
aggregate_channels = false
2121

22+
# Attach worker identity TLV to share submissions for per-worker hashrate tracking
23+
# (extension 0x0002). Disable when using Bitcoin addresses as user_identity, since
24+
# addresses exceed the 32-byte TLV limit.
25+
enable_worker_identity_tlv = true
26+
2227
# Enable this option to set a predefined log file path.
2328
# When enabled, logs will always be written to this file.
2429
# The CLI option --log-file (or -f) will override this setting if provided.

miner-apps/translator/config-examples/testnet4/tproxy-config-local-pool-example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ user_identity = "your_username_here"
1919
# Aggregate channels: if true, all miners share one upstream channel; if false, each miner gets its own channel
2020
aggregate_channels = true
2121

22+
# Attach worker identity TLV to share submissions for per-worker hashrate tracking
23+
# (extension 0x0002). Disable when using Bitcoin addresses as user_identity, since
24+
# addresses exceed the 32-byte TLV limit.
25+
enable_worker_identity_tlv = true
26+
2227
# Enable this option to set a predefined log file path.
2328
# When enabled, logs will always be written to this file.
2429
# The CLI option --log-file (or -f) will override this setting if provided.

miner-apps/translator/src/lib/config.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ pub struct TranslatorConfig {
4949
/// If the upstream server doesn't support these, the translator will fail over to another
5050
/// upstream.
5151
pub required_extensions: Vec<u16>,
52+
/// Whether to attach a UserIdentity TLV to SubmitSharesExtended messages for per-worker
53+
/// hashrate tracking (extension 0x0002). When enabled, the user_identity must fit within
54+
/// the 32-byte TLV limit. Disable this when using Bitcoin addresses as user_identity,
55+
/// since addresses exceed 32 bytes.
56+
#[serde(default = "default_enable_worker_identity_tlv")]
57+
pub enable_worker_identity_tlv: bool,
5258
/// The path to the log file for the Translator.
5359
#[serde(default, deserialize_with = "opt_path_from_toml")]
5460
log_file: Option<PathBuf>,
@@ -63,6 +69,10 @@ fn default_monitoring_cache_refresh_secs() -> u64 {
6369
15
6470
}
6571

72+
fn default_enable_worker_identity_tlv() -> bool {
73+
true
74+
}
75+
6676
#[derive(Debug, Deserialize, Clone)]
6777
pub struct Upstream {
6878
/// The address of the upstream server.
@@ -100,6 +110,7 @@ impl TranslatorConfig {
100110
aggregate_channels: bool,
101111
supported_extensions: Vec<u16>,
102112
required_extensions: Vec<u16>,
113+
enable_worker_identity_tlv: bool,
103114
) -> Self {
104115
Self {
105116
upstreams,
@@ -113,6 +124,7 @@ impl TranslatorConfig {
113124
aggregate_channels,
114125
supported_extensions,
115126
required_extensions,
127+
enable_worker_identity_tlv,
116128
log_file: None,
117129
monitoring_address: None,
118130
monitoring_cache_refresh_secs: 15,
@@ -222,6 +234,7 @@ mod tests {
222234
true,
223235
vec![],
224236
vec![],
237+
true,
225238
);
226239

227240
assert_eq!(config.upstreams.len(), 1);
@@ -254,6 +267,7 @@ mod tests {
254267
false,
255268
vec![],
256269
vec![],
270+
true,
257271
);
258272

259273
assert!(config.log_dir().is_none());
@@ -288,6 +302,7 @@ mod tests {
288302
true,
289303
vec![],
290304
vec![],
305+
true,
291306
);
292307

293308
assert_eq!(config.upstreams.len(), 2);
@@ -315,6 +330,7 @@ mod tests {
315330
false,
316331
vec![],
317332
vec![],
333+
true,
318334
);
319335

320336
assert!(!config.downstream_difficulty_config.enable_vardiff);

miner-apps/translator/src/lib/sv1/sv1_server/sv1_server.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,18 +452,19 @@ impl Sv1Server {
452452
)
453453
.map_err(|_| TproxyError::shutdown(TproxyErrorKind::SV1Error))?;
454454

455-
// Only add TLV fields with user identity in non-aggregated mode
456-
let tlv_fields = if is_non_aggregated() {
455+
// Only add TLV fields with user identity in non-aggregated mode when enabled.
456+
// When disabled (or when user_identity exceeds the 32-byte TLV limit, e.g. Bitcoin
457+
// addresses), the TLV is omitted and shares are sent without per-worker identity.
458+
let tlv_fields = if self.config.enable_worker_identity_tlv && is_non_aggregated() {
457459
let user_identity_string = self
458460
.downstreams
459461
.get(&message.downstream_id)
460462
.unwrap()
461463
.downstream_data
462464
.super_safe_lock(|d| d.user_identity.clone());
463465
UserIdentity::new(&user_identity_string)
464-
.unwrap()
465-
.to_tlv()
466466
.ok()
467+
.and_then(|ui| ui.to_tlv().ok())
467468
.map(|tlv| vec![tlv])
468469
} else {
469470
None
@@ -1246,6 +1247,7 @@ mod tests {
12461247
true, // aggregate_channels
12471248
vec![], // supported_extensions
12481249
vec![], // required_extensions
1250+
true, // enable_worker_identity_tlv
12491251
)
12501252
}
12511253

0 commit comments

Comments
 (0)