Trust pts values during apply_difference

See #3873.
This commit is contained in:
Lonami Exo 2022-09-20 12:52:24 +02:00
parent 64bc73c41e
commit 2f2a9901e2

View File

@ -305,20 +305,21 @@ class MessageBox:
def set_state(self, state, reset=True): def set_state(self, state, reset=True):
deadline = next_updates_deadline() deadline = next_updates_deadline()
# TODO there have been multiple reports where `end_get_diff(ENTRY_SECRET)` is used during `apply_difference`, if state.pts != NO_SEQ or not reset:
# but because the `map` no longer contains `ENTRY_SECRET`, `reset_deadline` fails. AFAIK that can only happen
# here (not sure why Telegram's update difference state lacks the new `qts`; this needs investigating).
# If the difference state does not contain info about `pts` or `qts`, ignore it and don't remove the state.
# This issue probably occurs with bot accounts only but I have not verified it.
if state.pts != NO_SEQ:
self.map[ENTRY_ACCOUNT] = State(pts=state.pts, deadline=deadline) self.map[ENTRY_ACCOUNT] = State(pts=state.pts, deadline=deadline)
elif reset: else:
self.map.pop(ENTRY_ACCOUNT, None) self.map.pop(ENTRY_ACCOUNT, None)
if state.qts != NO_SEQ: # Telegram seems to use the `qts` for bot accounts, but while applying difference,
# it might be reset back to 0. See issue #3873 for more details.
#
# During login, a value of zero would mean the `pts` is unknown,
# so the map shouldn't contain that entry.
# But while applying difference, if the value is zero, it (probably)
# truly means that's what should be used (hence the `reset` flag).
if state.qts != NO_SEQ or not reset:
self.map[ENTRY_SECRET] = State(pts=state.qts, deadline=deadline) self.map[ENTRY_SECRET] = State(pts=state.qts, deadline=deadline)
elif reset: else:
self.map.pop(ENTRY_SECRET, None) self.map.pop(ENTRY_SECRET, None)
self.date = state.date self.date = state.date