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

gui, util: Add AccrualChangedFromStakeOrMRC core signal #2503

Merged
merged 2 commits into from
Apr 28, 2022
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
18 changes: 18 additions & 0 deletions src/gridcoin/tally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
#include "gridcoin/accrual/null.h"
#include "gridcoin/accrual/research_age.h"
#include "gridcoin/accrual/snapshot.h"
#include "gridcoin/researcher.h"
#include "gridcoin/claim.h"
#include "gridcoin/cpid.h"
#include "gridcoin/quorum.h"
#include "gridcoin/superblock.h"
#include "gridcoin/tally.h"
#include "util.h"
#include "node/ui_interface.h"

#include <unordered_map>

Expand Down Expand Up @@ -293,6 +295,14 @@ class ResearcherTally
assert(pindex->nHeight > account.m_last_block_ptr->nHeight);
account.m_last_block_ptr = pindex;
}

const GRC::CpidOption walletholder_cpid = GRC::Researcher::Get()->Id().TryCpid();

// Signal that the stake results in an accrual change for the walletholder's cpid. This drastically reduces
// the signal frequency.
if (walletholder_cpid && *walletholder_cpid == cpid) {
uiInterface.AccrualChangedFromStakeOrMRC();
}
}

//!
Expand Down Expand Up @@ -340,6 +350,14 @@ class ResearcherTally
pindex->nHeight,
account.m_last_block_ptr->nHeight
);

const GRC::CpidOption walletholder_cpid = GRC::Researcher::Get()->Id().TryCpid();

// Signal that the stake results in an accrual change for the walletholder's cpid. This drastically reduces
// the signal frequency.
if (walletholder_cpid && *walletholder_cpid == cpid) {
uiInterface.AccrualChangedFromStakeOrMRC();
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/node/ui_interface.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2010-2020 The Bitcoin Core developers
// Copyright (c) 2014-2022 The Gridcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
// file COPYING or https://www.opensource.org/licenses/mit-license.php.

#include <node/ui_interface.h>

Expand All @@ -20,6 +21,7 @@ struct UISignals {
boost::signals2::signal<CClientUIInterface::BannedListChangedSig> BannedListChanged;
boost::signals2::signal<CClientUIInterface::MinerStatusChangedSig> MinerStatusChanged;
boost::signals2::signal<CClientUIInterface::ResearcherChangedSig> ResearcherChanged;
boost::signals2::signal<CClientUIInterface::AccrualChangedFromStakeOrMRCSig> AccrualChangedFromStakeOrMRC;
boost::signals2::signal<CClientUIInterface::BeaconChangedSig> BeaconChanged;
boost::signals2::signal<CClientUIInterface::NewPollReceivedSig> NewPollReceived;
boost::signals2::signal<CClientUIInterface::NotifyScraperEventSig> NotifyScraperEvent;
Expand All @@ -46,6 +48,7 @@ ADD_SIGNALS_IMPL_WRAPPER(NotifyAlertChanged);
ADD_SIGNALS_IMPL_WRAPPER(BannedListChanged);
ADD_SIGNALS_IMPL_WRAPPER(MinerStatusChanged);
ADD_SIGNALS_IMPL_WRAPPER(ResearcherChanged);
ADD_SIGNALS_IMPL_WRAPPER(AccrualChangedFromStakeOrMRC);
ADD_SIGNALS_IMPL_WRAPPER(BeaconChanged);
ADD_SIGNALS_IMPL_WRAPPER(NewPollReceived);
ADD_SIGNALS_IMPL_WRAPPER(NotifyScraperEvent);
Expand All @@ -69,6 +72,7 @@ void CClientUIInterface::NotifyNumConnectionsChanged(int newNumConnections) { re
void CClientUIInterface::BannedListChanged() { return g_ui_signals.BannedListChanged(); }
void CClientUIInterface::MinerStatusChanged(bool staking, double coin_weight) { return g_ui_signals.MinerStatusChanged(staking, coin_weight); }
void CClientUIInterface::ResearcherChanged() { return g_ui_signals.ResearcherChanged(); }
void CClientUIInterface::AccrualChangedFromStakeOrMRC() { return g_ui_signals.AccrualChangedFromStakeOrMRC(); }
void CClientUIInterface::BeaconChanged() { return g_ui_signals.BeaconChanged(); }
void CClientUIInterface::NewPollReceived(int64_t poll_time) { return g_ui_signals.NewPollReceived(poll_time); }
void CClientUIInterface::NotifyAlertChanged(const uint256 &hash, ChangeType status) { return g_ui_signals.NotifyAlertChanged(hash, status); }
Expand Down
4 changes: 4 additions & 0 deletions src/node/ui_interface.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2012-2020 The Bitcoin developers
// Copyright (c) 2014-2022 The Gridcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or https://opensource.org/licenses/mit-license.php.

Expand Down Expand Up @@ -122,6 +123,9 @@ class CClientUIInterface
/** Researcher context changed */
ADD_SIGNALS_DECL_WRAPPER(ResearcherChanged, void);

/** Walletholder accrual changed as a result of stake or MRC to the walletholder */
ADD_SIGNALS_DECL_WRAPPER(AccrualChangedFromStakeOrMRC, void);

/** Beacon changed */
ADD_SIGNALS_DECL_WRAPPER(BeaconChanged, void);

Expand Down
11 changes: 11 additions & 0 deletions src/qt/researcher/researchermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ void ResearcherChanged(ResearcherModel* model)
Q_ARG(GRC::ResearcherPtr, Researcher::Get()));
}

//!
//! \brief Model callback bound to the \c AccrualChangedFromStakeOrMRC core signal.
//!
void AccrualChangedFromStakeOrMRC(ResearcherModel* model)
{
LogPrint(LogFlags::QT, "GUI: received ResearcherChanged() core signal");

QMetaObject::invokeMethod(model, "accrualChanged", Qt::QueuedConnection);
}

//!
//! \brief Model callback bound to the \c BeaconChanged core signal.
//!
Expand Down Expand Up @@ -645,6 +655,7 @@ void ResearcherModel::subscribeToCoreSignals()
{
// Connect signals to client
uiInterface.ResearcherChanged_connect(std::bind(ResearcherChanged, this));
uiInterface.AccrualChangedFromStakeOrMRC_connect(std::bind(AccrualChangedFromStakeOrMRC, this));
uiInterface.BeaconChanged_connect(std::bind(BeaconChanged, this));
}

Expand Down