Skip to content

Commit

Permalink
Merge #383: Put BlockClock into an error state if node init fails
Browse files Browse the repository at this point in the history
2b61d22 qml: Put BlockClock into an Error state if init fails (johnny9)

Pull request description:

  Initial step for adding error states to the NodeRunner

  Link to github actions build artifacts.

  [![Build Artifacts](https://img.shields.io/badge/Build%20Artifacts-green
  )]()

ACKs for top commit:
  pablomartin4btc:
    tACK 2b61d22
  MarnixCroes:
    tACK 2b61d22

Tree-SHA512: 5da6e8cde6e7d24dbd1adffa8014622e188e5ec1abc17b260ba696239c5cc7558a57c6650336549ccfb715cc17fb2b72f28dc107d86e3a21f46f307357525ac7
  • Loading branch information
hebasto committed Sep 6, 2024
2 parents 48bc2c8 + 2b61d22 commit b979bdc
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ QML_RES_ICONS = \
qml/res/icons/caret-right.png \
qml/res/icons/check.png \
qml/res/icons/cross.png \
qml/res/icons/error.png \
qml/res/icons/export.png \
qml/res/icons/gear.png \
qml/res/icons/gear-outline.png \
Expand Down
1 change: 1 addition & 0 deletions src/qml/bitcoin_qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<file alias="caret-right">res/icons/caret-right.png</file>
<file alias="check">res/icons/check.png</file>
<file alias="cross">res/icons/cross.png</file>
<file alias="error">res/icons/error.png</file>
<file alias="export">res/icons/export.png</file>
<file alias="gear">res/icons/gear.png</file>
<file alias="gear-outline">res/icons/gear-outline.png</file>
Expand Down
32 changes: 26 additions & 6 deletions src/qml/components/BlockClock.qml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Item {
property var syncState: Utils.formatRemainingSyncTime(nodeModel.remainingSyncTime)
property string syncTime: syncState.text
property bool estimating: syncState.estimating
property bool faulted: nodeModel.faulted

activeFocusOnTab: true

Expand All @@ -50,7 +51,7 @@ Item {
penWidth: dial.width / 50
timeRatioList: chainModel.timeRatioList
verificationProgress: nodeModel.verificationProgress
paused: root.paused
paused: root.paused || root.faulted
connected: root.connected
synced: nodeModel.verificationProgress > 0.999
backgroundColor: Theme.color.neutral2
Expand Down Expand Up @@ -143,7 +144,7 @@ Item {
maxNumOutboundPeers: nodeModel.maxNumOutboundPeers
indicatorDimensions: dial.width * (3/200)
indicatorSpacing: dial.width / 40
paused: root.paused
paused: root.paused || root.faulted
}

NetworkIndicator {
Expand All @@ -156,10 +157,13 @@ Item {

MouseArea {
anchors.fill: dial
cursorShape: Qt.PointingHandCursor
cursorShape: root.faulted ? Qt.ArrowCursor : Qt.PointingHandCursor
enabled: !root.faulted
onClicked: {
root.paused = !root.paused
nodeModel.pause = root.paused
if (!root.faulted) {
root.paused = !root.paused
nodeModel.pause = root.paused
}
}
FocusBorder {
visible: root.activeFocus
Expand All @@ -175,6 +179,7 @@ Item {
subText: root.syncTime
}
},

State {
name: "BLOCKCLOCK"; when: synced && !paused && connected
PropertyChanges {
Expand All @@ -186,7 +191,7 @@ Item {
},

State {
name: "PAUSE"; when: paused
name: "PAUSE"; when: paused && !faulted
PropertyChanges {
target: root
header: "Paused"
Expand All @@ -204,6 +209,20 @@ Item {
}
},

State {
name: "ERROR"; when: faulted
PropertyChanges {
target: root
header: "Error"
headerSize: dial.width * (3/25)
}
PropertyChanges {
target: bitcoinIcon
anchors.bottomMargin: dial.width / 40
icon.source: "image://images/error"
}
},

State {
name: "CONNECTING"; when: !paused && !connected
PropertyChanges {
Expand All @@ -224,6 +243,7 @@ Item {
}
]


function formatProgressPercentage(progress) {
if (progress >= 1) {
return Math.round(progress) + "%"
Expand Down
5 changes: 5 additions & 0 deletions src/qml/imageprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ QPixmap ImageProvider::requestPixmap(const QString& id, QSize* size, const QSize
return QIcon(":/icons/cross").pixmap(requested_size);
}

if (id == "error") {
*size = requested_size;
return QIcon(":/icons/error").pixmap(requested_size);
}

if (id == "export") {
*size = requested_size;
return QIcon(":/icons/export").pixmap(requested_size);
Expand Down
15 changes: 13 additions & 2 deletions src/qml/models/nodemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <QDateTime>
#include <QMetaObject>
#include <QTimerEvent>
#include <QString>

NodeModel::NodeModel(interfaces::Node& node)
: m_node{node}
Expand Down Expand Up @@ -93,6 +94,14 @@ void NodeModel::setPause(bool new_pause)
}
}

void NodeModel::setErrorState(bool faulted)
{
if (m_faulted != faulted) {
m_faulted = faulted;
Q_EMIT errorStateChanged(faulted);
}
}

void NodeModel::startNodeInitializionThread()
{
Q_EMIT requestedInitialize();
Expand All @@ -103,9 +112,11 @@ void NodeModel::requestShutdown()
Q_EMIT requestedShutdown();
}

void NodeModel::initializeResult([[maybe_unused]] bool success, interfaces::BlockAndHeaderTipInfo tip_info)
void NodeModel::initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
{
// TODO: Handle the `success` parameter,
if (!success) {
setErrorState(true);
}
setBlockTipHeight(tip_info.block_height);
setVerificationProgress(tip_info.verification_progress);

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 @@ -33,6 +33,7 @@ class NodeModel : public QObject
Q_PROPERTY(int remainingSyncTime READ remainingSyncTime NOTIFY remainingSyncTimeChanged)
Q_PROPERTY(double verificationProgress READ verificationProgress NOTIFY verificationProgressChanged)
Q_PROPERTY(bool pause READ pause WRITE setPause NOTIFY pauseChanged)
Q_PROPERTY(bool faulted READ errorState WRITE setErrorState NOTIFY errorStateChanged)

public:
explicit NodeModel(interfaces::Node& node);
Expand All @@ -49,6 +50,8 @@ class NodeModel : public QObject
void setVerificationProgress(double new_progress);
bool pause() const { return m_pause; }
void setPause(bool new_pause);
bool errorState() const { return m_faulted; }
void setErrorState(bool new_error);

Q_INVOKABLE float getTotalBytesReceived() const { return (float)m_node.getTotalBytesRecv(); }
Q_INVOKABLE float getTotalBytesSent() const { return (float)m_node.getTotalBytesSent(); }
Expand All @@ -70,6 +73,7 @@ public Q_SLOTS:
void requestedShutdown();
void verificationProgressChanged();
void pauseChanged(bool new_pause);
void errorStateChanged(bool new_error_state);

void setTimeRatioList(int new_time);
void setTimeRatioListInitial();
Expand All @@ -85,6 +89,7 @@ public Q_SLOTS:
int m_remaining_sync_time{0};
double m_verification_progress{0.0};
bool m_pause{false};
bool m_faulted{false};

int m_shutdown_polling_timer_id{0};

Expand Down
Binary file added src/qml/res/icons/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/qml/res/src/error.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b979bdc

Please sign in to comment.