fix(translator): make worker identity TLV optional and fix unwrap panic#300
Conversation
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 stratum-mining#295
93fe7df to
c48597e
Compare
Question: TLV logic seems inverted?While working on this fix, we noticed the original TLV logic sends the let tlv_fields = if is_non_aggregated() {
// builds and attaches UserIdentity TLV
} else {
None
};This seems backwards to us:
Is there a reason the TLV is sent in non-aggregated mode specifically? Or should the condition be This PR preserves the original condition (just adds the config flag and fixes the panic), but wanted to flag this for clarification. |
|
closed as unnecessary and in favor of #276 |
Summary
enable_worker_identity_tlvconfig option (default:true) to control whether theUserIdentityTLV is attached toSubmitSharesExtendedmessages.unwrap()with.ok()onUserIdentity::new()to prevent panics whenuser_identityexceeds the 32-byte TLV limitContext
The translator panics when
user_identityis a Bitcoin address (42-64 bytes) because theUserIdentityTLV has a hard 32-byte limit inextensions-sv2. This is relevant for solo mining setups where the SV2 server parses theuser_identityfromOpenExtendedMiningChannelto substitute the coinbase payout address. The address is correctly passed viaStr0255(up to 255 bytes) inOpenExtendedMiningChannel, but the TLV encoding on share submissions crashes due to the 32-byte constraint.Setting
enable_worker_identity_tlv = falseallows using Bitcoin addresses asuser_identitywithout crashing, at the cost of losing per-worker hashrate attribution in the TLV. The JD-client already behaves this way (it does not attachUserIdentityTLV to shares).Closes #295
Test plan
cargo checkpassescargo test -p translator_sv2)user_identityandenable_worker_identity_tlv = false— no crashuser_identityandenable_worker_identity_tlv = true— TLV attached as before