mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-07-23 15:23:16 +00:00
fix(amm): reload changed sequencer configuration
This commit is contained in:
parent
ba23429fc4
commit
1d1db9ba4e
@ -217,10 +217,7 @@ void AmmUiBackend::syncWalletState()
|
|||||||
setSequencerAddr(state.sequencerAddress);
|
setSequencerAddr(state.sequencerAddress);
|
||||||
setSequencerReachable(state.sequencerReachable);
|
setSequencerReachable(state.sequencerReachable);
|
||||||
|
|
||||||
if (m_sequencerConfigPath != state.configPath || !m_sequencer->isConfigured()) {
|
m_sequencer->configure(state.configPath);
|
||||||
m_sequencerConfigPath = state.configPath;
|
|
||||||
m_sequencer->configure(state.configPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool addressChanged = previousAddress != state.sequencerAddress;
|
const bool addressChanged = previousAddress != state.sequencerAddress;
|
||||||
if (addressChanged) {
|
if (addressChanged) {
|
||||||
|
|||||||
@ -78,7 +78,6 @@ private:
|
|||||||
|
|
||||||
ActiveNetwork m_network;
|
ActiveNetwork m_network;
|
||||||
QVariantMap m_newPositionHints;
|
QVariantMap m_newPositionHints;
|
||||||
QString m_sequencerConfigPath;
|
|
||||||
bool m_identityProbeInFlight = false;
|
bool m_identityProbeInFlight = false;
|
||||||
quint64 m_contextGeneration = 0;
|
quint64 m_contextGeneration = 0;
|
||||||
struct PendingTransaction {
|
struct PendingTransaction {
|
||||||
|
|||||||
@ -82,36 +82,40 @@ SequencerClient::SequencerClient(AmmClient* client, QObject* parent)
|
|||||||
|
|
||||||
bool SequencerClient::configure(const QString& configPath)
|
bool SequencerClient::configure(const QString& configPath)
|
||||||
{
|
{
|
||||||
|
QUrl endpoint;
|
||||||
|
QByteArray authorization;
|
||||||
|
QFile file(configPath);
|
||||||
|
bool valid = file.open(QIODevice::ReadOnly);
|
||||||
|
if (valid) {
|
||||||
|
const QJsonDocument document = QJsonDocument::fromJson(file.readAll());
|
||||||
|
const QJsonObject config = document.object();
|
||||||
|
endpoint = QUrl(config.value(QStringLiteral("sequencer_addr")).toString());
|
||||||
|
const QString scheme = endpoint.scheme().toLower();
|
||||||
|
valid = document.isObject() && endpoint.isValid() && !endpoint.host().isEmpty()
|
||||||
|
&& (scheme == QStringLiteral("http") || scheme == QStringLiteral("https"));
|
||||||
|
if (valid) {
|
||||||
|
const QJsonObject basicAuth = config.value(QStringLiteral("basic_auth")).toObject();
|
||||||
|
const QString username = basicAuth.value(QStringLiteral("username")).toString();
|
||||||
|
const QString password = basicAuth.value(QStringLiteral("password")).toString();
|
||||||
|
if (!username.isEmpty()) {
|
||||||
|
authorization = QByteArrayLiteral("Basic ")
|
||||||
|
+ (username + QLatin1Char(':') + password).toUtf8().toBase64();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!valid) {
|
||||||
|
endpoint = QUrl();
|
||||||
|
authorization.clear();
|
||||||
|
}
|
||||||
|
if (endpoint == m_endpoint && authorization == m_authorization)
|
||||||
|
return valid;
|
||||||
|
|
||||||
++m_generation;
|
++m_generation;
|
||||||
cancelPendingReads();
|
cancelPendingReads();
|
||||||
clear();
|
clear();
|
||||||
QFile file(configPath);
|
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
|
||||||
m_endpoint = QUrl();
|
|
||||||
m_authorization.clear();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const QJsonDocument document = QJsonDocument::fromJson(file.readAll());
|
|
||||||
const QJsonObject config = document.object();
|
|
||||||
const QUrl endpoint(config.value(QStringLiteral("sequencer_addr")).toString());
|
|
||||||
const QString scheme = endpoint.scheme().toLower();
|
|
||||||
if (!document.isObject() || !endpoint.isValid() || endpoint.host().isEmpty()
|
|
||||||
|| (scheme != QStringLiteral("http") && scheme != QStringLiteral("https"))) {
|
|
||||||
m_endpoint = QUrl();
|
|
||||||
m_authorization.clear();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_endpoint = endpoint;
|
m_endpoint = endpoint;
|
||||||
m_authorization.clear();
|
m_authorization = authorization;
|
||||||
const QJsonObject basicAuth = config.value(QStringLiteral("basic_auth")).toObject();
|
return valid;
|
||||||
const QString username = basicAuth.value(QStringLiteral("username")).toString();
|
|
||||||
const QString password = basicAuth.value(QStringLiteral("password")).toString();
|
|
||||||
if (!username.isEmpty()) {
|
|
||||||
m_authorization = QByteArrayLiteral("Basic ")
|
|
||||||
+ (username + QLatin1Char(':') + password).toUtf8().toBase64();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SequencerClient::readAccounts(const QStringList& accountIds,
|
void SequencerClient::readAccounts(const QStringList& accountIds,
|
||||||
|
|||||||
@ -445,5 +445,41 @@ int main(int argc, char** argv)
|
|||||||
"holding read should recover from the sequencer"))
|
"holding read should recover from the sequencer"))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
const int requestsBeforeUnchangedConfig = server.requestCount();
|
||||||
|
if (!expect(sequencer.configure(sequencerConfig.fileName()),
|
||||||
|
"unchanged sequencer config should remain valid"))
|
||||||
|
return 1;
|
||||||
|
QVector<WalletAccountRead> unchangedConfigRead;
|
||||||
|
if (!expect(waitForAccounts(sequencer, { holding.address }, false,
|
||||||
|
&unchangedConfigRead),
|
||||||
|
"cached read after unchanged config should complete"))
|
||||||
|
return 1;
|
||||||
|
if (!expect(server.requestCount() == requestsBeforeUnchangedConfig,
|
||||||
|
"unchanged config should preserve the account cache"))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
LocalRpcServer replacementServer;
|
||||||
|
if (!expect(replacementServer.listen(),
|
||||||
|
"replacement sequencer should listen"))
|
||||||
|
return 1;
|
||||||
|
if (!expect(sequencerConfig.resize(0) && sequencerConfig.seek(0),
|
||||||
|
"sequencer config should rewind"))
|
||||||
|
return 1;
|
||||||
|
sequencerConfig.write(QJsonDocument(QJsonObject {
|
||||||
|
{ QStringLiteral("sequencer_addr"), replacementServer.endpoint() },
|
||||||
|
}).toJson(QJsonDocument::Compact));
|
||||||
|
sequencerConfig.flush();
|
||||||
|
if (!expect(sequencer.configure(sequencerConfig.fileName()),
|
||||||
|
"same-path endpoint update should configure"))
|
||||||
|
return 1;
|
||||||
|
QVector<WalletAccountRead> replacementRead;
|
||||||
|
if (!expect(waitForAccounts(sequencer, { holding.address }, false,
|
||||||
|
&replacementRead),
|
||||||
|
"same-path endpoint read should complete"))
|
||||||
|
return 1;
|
||||||
|
if (!expect(replacementServer.requestCount() == 1,
|
||||||
|
"same-path endpoint update should clear cache and use new sequencer"))
|
||||||
|
return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user