From bdcc68513d5175cef416dc67c63b71cd222f84e9 Mon Sep 17 00:00:00 2001 From: MarekWo Date: Mon, 23 Mar 2026 20:07:35 +0100 Subject: [PATCH] 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 --- app/device_manager.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/device_manager.py b/app/device_manager.py index f593903..e619cca 100644 --- a/app/device_manager.py +++ b/app/device_manager.py @@ -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."""