fix(paths): use library's change_contact_path to avoid negative int error

_change_path_async manually set out_path and out_path_len on the contact
dict then called update_contact(contact) with path=None. This path reads
out_path_hash_mode from the contact dict, which is -1 when the contact
is in flood mode (after reset_path or device read with plen=255).
The encoding then produced: hop_count | (-1 << 6) = negative number,
causing "can't convert negative int to unsigned" in to_bytes().

Fix: use mc.commands.change_contact_path() which properly computes all
fields including out_path_hash_mode, avoiding the negative value issue.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
MarekWo
2026-03-23 20:07:35 +01:00
parent 8fd918d39b
commit bdcc68513d

View File

@@ -1086,12 +1086,8 @@ class DeviceManager:
async def _change_path_async(self, contact, path_hex: str, hash_size: int = 1):
"""Change contact path on device with proper hash_size encoding."""
hop_count = len(path_hex) // (hash_size * 2)
encoded_path_len = ((hash_size - 1) << 6) | hop_count
# Set encoded values on contact dict before calling update_contact
contact['out_path'] = path_hex
contact['out_path_len'] = encoded_path_len
await self.mc.commands.update_contact(contact)
path_hash_mode = hash_size - 1 # 0=1B, 1=2B, 2=3B
await self.mc.commands.change_contact_path(contact, path_hex, path_hash_mode=path_hash_mode)
async def _restore_primary_path(self, contact, contact_pubkey: str):
"""Restore the primary configured path on the device after retry exhaustion."""