fix(amm): cancel cached reads on endpoint change

This commit is contained in:
Ricardo Guilherme Schmidt 2026-07-17 20:10:31 -03:00
parent d36afdf072
commit f8c0fa63c0
No known key found for this signature in database
GPG Key ID: 1396EA17DE132FFE
2 changed files with 19 additions and 1 deletions

View File

@ -163,8 +163,13 @@ void SequencerClient::readAccount(const QString& accountId,
m_cache.remove(accountId); m_cache.remove(accountId);
if (!forceRefresh && m_cache.contains(accountId)) { if (!forceRefresh && m_cache.contains(accountId)) {
const WalletAccountRead cached = m_cache.value(accountId); const WalletAccountRead cached = m_cache.value(accountId);
const quint64 generation = m_generation;
QTimer::singleShot(0, this, QTimer::singleShot(0, this,
[callback = std::move(callback), cached]() mutable { callback(cached); }); [this, callback = std::move(callback), cached, accountId,
generation]() mutable {
callback(generation == m_generation
? cached : WalletAccountRead { accountId });
});
return; return;
} }
if (forceRefresh && m_activeReadIds.contains(accountId)) { if (forceRefresh && m_activeReadIds.contains(accountId)) {

View File

@ -531,6 +531,13 @@ int main(int argc, char** argv)
"forced-refresh sequencer should listen")) "forced-refresh sequencer should listen"))
return 1; return 1;
forcedRefreshServer.holdResponses(); forcedRefreshServer.holdResponses();
bool staleCachedCompleted = false;
QVector<WalletAccountRead> staleCachedRead;
sequencer.readAccounts({ holding.address }, false,
[&](QVector<WalletAccountRead> reads) {
staleCachedRead = std::move(reads);
staleCachedCompleted = true;
});
if (!expect(sequencerConfig.resize(0) && sequencerConfig.seek(0), if (!expect(sequencerConfig.resize(0) && sequencerConfig.seek(0),
"forced-refresh config should rewind")) "forced-refresh config should rewind"))
return 1; return 1;
@ -541,6 +548,12 @@ int main(int argc, char** argv)
if (!expect(sequencer.configure(sequencerConfig.fileName()), if (!expect(sequencer.configure(sequencerConfig.fileName()),
"forced-refresh sequencer should configure")) "forced-refresh sequencer should configure"))
return 1; return 1;
QCoreApplication::processEvents(QEventLoop::AllEvents, 10);
if (!expect(staleCachedCompleted
&& staleCachedRead.size() == 1
&& !staleCachedRead.constFirst().ok(),
"cached read should fail after sequencer reconfiguration"))
return 1;
bool ordinaryCompleted = false; bool ordinaryCompleted = false;
bool forcedCompleted = false; bool forcedCompleted = false;