refactor(python): define `MAX_RETRANSMISSION_COUNT` in `protocol_v2`
What changed, and why it matters
This commit is a simple code cleanup: it replaces a hardcoded number (50) with a named constant (`MAX_RETRANSMISSION_COUNT`) in the Python Trezor library. There is no functional change, no bug fix, and no security relevance visible in the diff.
No security action needed; treat as ordinary refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors protocol_v2.py by introducing module-level constant MAX_RETRANSMISSION_COUNT = 50 and using it as the retries= argument to _do_channel_allocation() inside prepare_channel_without_pairing(). The behavior is identical before and after; only readability/maintainability is improved.
Changed components
python/src/trezorlib/transport/thp/protocol_v2.pyInspect captured patch +3 / −1
diff --git a/python/src/trezorlib/transport/thp/protocol_v2.py b/python/src/trezorlib/transport/thp/protocol_v2.py
index d46786fb..eb57ffc5 100644
--- a/python/src/trezorlib/transport/thp/protocol_v2.py
+++ b/python/src/trezorlib/transport/thp/protocol_v2.py
@@ -37,6 +37,8 @@ LOG = logging.getLogger(__name__)
DEFAULT_SESSION_ID: int = 0
+MAX_RETRANSMISSION_COUNT = 50
+
if t.TYPE_CHECKING:
pass
MT = t.TypeVar("MT", bound=protobuf.MessageType)
@@ -128,7 +130,7 @@ class ProtocolV2Channel(Channel):
def prepare_channel_without_pairing(self, credential: bytes | None = None) -> int:
self._reset_sync_bits()
# allow skipping unrelated response packets (e.g. in case of retransmissions)
- self._do_channel_allocation(retries=50)
+ self._do_channel_allocation(retries=MAX_RETRANSMISSION_COUNT)
return self._do_handshake(credential=credential)
def _reset_sync_bits(self) -> None:
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.