Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put BlockClock into an error state if node init fails #383

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,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/info.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 @@ -74,6 +74,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="info">res/icons/info.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 @@ -30,6 +30,7 @@ Item {
property var syncState: formatRemainingSyncTime(nodeModel.remainingSyncTime)
property string syncTime: syncState.text
property bool estimating: syncState.estimating
property bool faulted: nodeModel.faulted

activeFocusOnTab: true

Expand All @@ -47,7 +48,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 @@ -140,7 +141,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 @@ -152,10 +153,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 @@ -171,6 +175,7 @@ Item {
subText: root.syncTime
}
},

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

State {
name: "PAUSE"; when: paused
name: "PAUSE"; when: paused && !faulted
PropertyChanges {
target: root
header: "Paused"
Expand All @@ -200,6 +205,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 @@ -220,6 +239,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.
Loading