Skip to content

Commit c070290

Browse files
committed
Add AccrualChangedFromStakeOrMRC core signal
This adds a core UI signal that is activated when a stake or MRC payment occurs to the cpid that matches the walletholder. This ensures that the pending accrual will be immediately updated when a stake or MRC payment occurs that changes the accrual for the walletholder.
1 parent 3b2bcd8 commit c070290

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

src/gridcoin/tally.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
#include "gridcoin/accrual/null.h"
1010
#include "gridcoin/accrual/research_age.h"
1111
#include "gridcoin/accrual/snapshot.h"
12+
#include "gridcoin/researcher.h"
1213
#include "gridcoin/claim.h"
1314
#include "gridcoin/cpid.h"
1415
#include "gridcoin/quorum.h"
1516
#include "gridcoin/superblock.h"
1617
#include "gridcoin/tally.h"
1718
#include "util.h"
19+
#include "node/ui_interface.h"
1820

1921
#include <unordered_map>
2022

@@ -293,6 +295,14 @@ class ResearcherTally
293295
assert(pindex->nHeight > account.m_last_block_ptr->nHeight);
294296
account.m_last_block_ptr = pindex;
295297
}
298+
299+
const GRC::CpidOption walletholder_cpid = GRC::Researcher::Get()->Id().TryCpid();
300+
301+
// Signal that the stake results in an accrual change for the walletholder's cpid. This drastically reduces
302+
// the signal frequency.
303+
if (walletholder_cpid && *walletholder_cpid == cpid) {
304+
uiInterface.AccrualChangedFromStakeOrMRC();
305+
}
296306
}
297307

298308
//!
@@ -340,6 +350,14 @@ class ResearcherTally
340350
pindex->nHeight,
341351
account.m_last_block_ptr->nHeight
342352
);
353+
354+
const GRC::CpidOption walletholder_cpid = GRC::Researcher::Get()->Id().TryCpid();
355+
356+
// Signal that the stake results in an accrual change for the walletholder's cpid. This drastically reduces
357+
// the signal frequency.
358+
if (walletholder_cpid && *walletholder_cpid == cpid) {
359+
uiInterface.AccrualChangedFromStakeOrMRC();
360+
}
343361
}
344362
}
345363

src/node/ui_interface.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) 2010-2020 The Bitcoin Core developers
2+
// Copyright (c) 2014-2022 The Gridcoin developers
23
// Distributed under the MIT software license, see the accompanying
3-
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
// file COPYING or https://www.opensource.org/licenses/mit-license.php.
45

56
#include <node/ui_interface.h>
67

@@ -20,6 +21,7 @@ struct UISignals {
2021
boost::signals2::signal<CClientUIInterface::BannedListChangedSig> BannedListChanged;
2122
boost::signals2::signal<CClientUIInterface::MinerStatusChangedSig> MinerStatusChanged;
2223
boost::signals2::signal<CClientUIInterface::ResearcherChangedSig> ResearcherChanged;
24+
boost::signals2::signal<CClientUIInterface::AccrualChangedFromStakeOrMRCSig> AccrualChangedFromStakeOrMRC;
2325
boost::signals2::signal<CClientUIInterface::BeaconChangedSig> BeaconChanged;
2426
boost::signals2::signal<CClientUIInterface::NewPollReceivedSig> NewPollReceived;
2527
boost::signals2::signal<CClientUIInterface::NotifyScraperEventSig> NotifyScraperEvent;
@@ -46,6 +48,7 @@ ADD_SIGNALS_IMPL_WRAPPER(NotifyAlertChanged);
4648
ADD_SIGNALS_IMPL_WRAPPER(BannedListChanged);
4749
ADD_SIGNALS_IMPL_WRAPPER(MinerStatusChanged);
4850
ADD_SIGNALS_IMPL_WRAPPER(ResearcherChanged);
51+
ADD_SIGNALS_IMPL_WRAPPER(AccrualChangedFromStakeOrMRC);
4952
ADD_SIGNALS_IMPL_WRAPPER(BeaconChanged);
5053
ADD_SIGNALS_IMPL_WRAPPER(NewPollReceived);
5154
ADD_SIGNALS_IMPL_WRAPPER(NotifyScraperEvent);
@@ -69,6 +72,7 @@ void CClientUIInterface::NotifyNumConnectionsChanged(int newNumConnections) { re
6972
void CClientUIInterface::BannedListChanged() { return g_ui_signals.BannedListChanged(); }
7073
void CClientUIInterface::MinerStatusChanged(bool staking, double coin_weight) { return g_ui_signals.MinerStatusChanged(staking, coin_weight); }
7174
void CClientUIInterface::ResearcherChanged() { return g_ui_signals.ResearcherChanged(); }
75+
void CClientUIInterface::AccrualChangedFromStakeOrMRC() { return g_ui_signals.AccrualChangedFromStakeOrMRC(); }
7276
void CClientUIInterface::BeaconChanged() { return g_ui_signals.BeaconChanged(); }
7377
void CClientUIInterface::NewPollReceived(int64_t poll_time) { return g_ui_signals.NewPollReceived(poll_time); }
7478
void CClientUIInterface::NotifyAlertChanged(const uint256 &hash, ChangeType status) { return g_ui_signals.NotifyAlertChanged(hash, status); }

src/node/ui_interface.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) 2010 Satoshi Nakamoto
22
// Copyright (c) 2012-2020 The Bitcoin developers
3+
// Copyright (c) 2014-2022 The Gridcoin developers
34
// Distributed under the MIT/X11 software license, see the accompanying
45
// file COPYING or https://opensource.org/licenses/mit-license.php.
56

@@ -122,6 +123,9 @@ class CClientUIInterface
122123
/** Researcher context changed */
123124
ADD_SIGNALS_DECL_WRAPPER(ResearcherChanged, void);
124125

126+
/** Researcher context changed */
127+
ADD_SIGNALS_DECL_WRAPPER(AccrualChangedFromStakeOrMRC, void);
128+
125129
/** Beacon changed */
126130
ADD_SIGNALS_DECL_WRAPPER(BeaconChanged, void);
127131

src/qt/researcher/researchermodel.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ void ResearcherChanged(ResearcherModel* model)
4444
Q_ARG(GRC::ResearcherPtr, Researcher::Get()));
4545
}
4646

47+
//!
48+
//! \brief Model callback bound to the \c AccrualChangedFromStakeOrMRC core signal.
49+
//!
50+
void AccrualChangedFromStakeOrMRC(ResearcherModel* model)
51+
{
52+
LogPrint(LogFlags::QT, "GUI: received ResearcherChanged() core signal");
53+
54+
QMetaObject::invokeMethod(model, "accrualChanged", Qt::QueuedConnection);
55+
}
56+
4757
//!
4858
//! \brief Model callback bound to the \c BeaconChanged core signal.
4959
//!
@@ -645,6 +655,7 @@ void ResearcherModel::subscribeToCoreSignals()
645655
{
646656
// Connect signals to client
647657
uiInterface.ResearcherChanged_connect(std::bind(ResearcherChanged, this));
658+
uiInterface.AccrualChangedFromStakeOrMRC_connect(std::bind(AccrualChangedFromStakeOrMRC, this));
648659
uiInterface.BeaconChanged_connect(std::bind(BeaconChanged, this));
649660
}
650661

0 commit comments

Comments
 (0)