Skip to content

Commit

Permalink
qml: set synced to whether node is in IBD or not
Browse files Browse the repository at this point in the history
This changes when we consider to be synced within the block clock's
perspective from a check on if verificationProgress is large enough to
a query on the node to see if it is in ibd or not
  • Loading branch information
jarolrod committed Aug 31, 2023
1 parent 8df54fe commit f6bb1b1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/qml/components/BlockClock.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Item {
property alias subText: subText.text
property int headerSize: 32
property bool connected: nodeModel.numOutboundPeers > 0
property bool synced: nodeModel.verificationProgress > 0.999
property bool synced: !nodeModel.inIBD
property string syncProgress: formatProgressPercentage(nodeModel.verificationProgress * 100)
property bool paused: false
property var syncState: formatRemainingSyncTime(nodeModel.remainingSyncTime)
Expand All @@ -49,7 +49,7 @@ Item {
verificationProgress: nodeModel.verificationProgress
paused: root.paused
connected: root.connected
synced: nodeModel.verificationProgress > 0.999
synced: root.synced
backgroundColor: Theme.color.neutral2
timeTickColor: Theme.color.neutral5
confirmationColors: Theme.color.confirmationColors
Expand Down
11 changes: 11 additions & 0 deletions src/qml/models/nodemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ void NodeModel::setBlockTipHeight(int new_height)
}
}


void NodeModel::setInIBD(bool new_ibd)
{
if (new_ibd != m_in_ibd) {
m_in_ibd = new_ibd;
Q_EMIT inIBDChanged();
}
}

void NodeModel::setNumOutboundPeers(int new_num)
{
if (new_num != m_num_outbound_peers) {
Expand Down Expand Up @@ -188,6 +197,7 @@ void NodeModel::ConnectToBlockTipSignal()
[this](SynchronizationState state, interfaces::BlockTip tip, double verification_progress) {
QMetaObject::invokeMethod(this, [=] {
setBlockTipHeight(tip.block_height);
setInIBD(m_node.isInitialBlockDownload());
setVerificationProgress(verification_progress);
setInHeaderSync(false);
setInPreHeaderSync(false);
Expand All @@ -202,6 +212,7 @@ void NodeModel::ConnectToHeaderTipSignal()

m_handler_notify_header_tip = m_node.handleNotifyHeaderTip(
[this](SynchronizationState sync_state, interfaces::BlockTip tip, bool presync) {
setInIBD(m_node.isInitialBlockDownload());
QMetaObject::invokeMethod(this, [=] {
if (presync) {
setInHeaderSync(false);
Expand Down
5 changes: 5 additions & 0 deletions src/qml/models/nodemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class NodeModel : public QObject
Q_OBJECT
Q_PROPERTY(int blockTipHeight READ blockTipHeight NOTIFY blockTipHeightChanged)
Q_PROPERTY(QString fullClientVersion READ fullClientVersion CONSTANT)
Q_PROPERTY(bool inIBD READ inIBD NOTIFY inIBDChanged)
Q_PROPERTY(int numOutboundPeers READ numOutboundPeers NOTIFY numOutboundPeersChanged)
Q_PROPERTY(int maxNumOutboundPeers READ maxNumOutboundPeers CONSTANT)
Q_PROPERTY(bool inHeaderSync READ inHeaderSync WRITE setInHeaderSync NOTIFY inHeaderSyncChanged)
Expand All @@ -44,6 +45,8 @@ class NodeModel : public QObject
int blockTipHeight() const { return m_block_tip_height; }
void setBlockTipHeight(int new_height);
QString fullClientVersion() const { return QString::fromStdString(FormatFullVersion()); }
bool inIBD() const { return m_in_ibd; }
void setInIBD(bool new_ibd);
int numOutboundPeers() const { return m_num_outbound_peers; }
void setNumOutboundPeers(int new_num);
int maxNumOutboundPeers() const { return m_max_num_outbound_peers; }
Expand Down Expand Up @@ -76,6 +79,7 @@ public Q_SLOTS:

Q_SIGNALS:
void blockTipHeightChanged();
void inIBDChanged();
void numOutboundPeersChanged();
void inHeaderSyncChanged();
void headerSyncProgressChanged();
Expand All @@ -96,6 +100,7 @@ public Q_SLOTS:
private:
// Properties that are exposed to QML.
int m_block_tip_height{0};
bool m_in_ibd;
int m_num_outbound_peers{0};
static constexpr int m_max_num_outbound_peers{MAX_OUTBOUND_FULL_RELAY_CONNECTIONS + MAX_BLOCK_RELAY_ONLY_CONNECTIONS};
bool m_in_header_sync;
Expand Down

0 comments on commit f6bb1b1

Please sign in to comment.