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

util, gui: Fix shutdown segfault and repair broken overview page staking status #1901

Merged
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
17 changes: 10 additions & 7 deletions src/gridcoin/gridcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ extern unsigned int nScraperSleep;
extern unsigned int nActiveBeforeSB;
extern bool fScraperActive;

extern ThreadHandler* netThreads;

void Scraper(bool bSingleShot = false);
void ScraperSubscriber();

Expand Down Expand Up @@ -150,9 +152,7 @@ void ThreadScraperSubscriber(void* parg)
//!
//! \brief Configure and initialize the scraper system.
//!
//! \param threads Used to start the scraper housekeeping threads.
//!
void InitializeScraper(ThreadHandlerPtr threads)
void InitializeScraper()
{
// Default to 300 sec (5 min), clamp to 60 minimum, 600 maximum - converted to milliseconds.
nScraperSleep = std::min<int64_t>(std::max<int64_t>(GetArg("-scrapersleep", 300), 60), 600) * 1000;
Expand All @@ -174,14 +174,14 @@ void InitializeScraper(ThreadHandlerPtr threads)
if (GetBoolArg("-scraper", false)) {
LogPrintf("Gridcoin: scraper enabled");

if (!threads->createThread(ThreadScraper, nullptr, "ThreadScraper")) {
if (!netThreads->createThread(ThreadScraper, nullptr, "ThreadScraper")) {
LogPrintf("ERROR: createThread(ThreadScraper) failed");
}
} else {
LogPrintf("Gridcoin: scraper disabled");
LogPrintf("Gridcoin: scraper subscriber housekeeping thread enabled");

if (!threads->createThread(ThreadScraperSubscriber, nullptr, "ScraperSubscriber")) {
if (!netThreads->createThread(ThreadScraperSubscriber, nullptr, "ScraperSubscriber")) {
LogPrintf("ERROR: createThread(ScraperSubscriber) failed");
}
}
Expand Down Expand Up @@ -279,7 +279,7 @@ bool fSnapshotRequest = false;
// Functions
// -----------------------------------------------------------------------------

bool GRC::Initialize(ThreadHandlerPtr threads, CBlockIndex* pindexBest)
bool GRC::Initialize(CBlockIndex* pindexBest)
{
LogPrintf("Gridcoin: initializing...");

Expand All @@ -291,7 +291,10 @@ bool GRC::Initialize(ThreadHandlerPtr threads, CBlockIndex* pindexBest)

InitializeContracts(pindexBest);
InitializeResearcherContext();
InitializeScraper(threads);

// The scraper is run on the netThreads group, because it shares data structures
// with scraper_net, which is run as part of the network node threads.
InitializeScraper();
InitializeExplorerFeatures();

return true;
Expand Down
3 changes: 1 addition & 2 deletions src/gridcoin/gridcoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ namespace GRC {
//!
//! \brief Initialize Gridcoin-specific components and services.
//!
//! \param threads Used to start Gridcoin threads.
//! \param pindexBest Block index for the tip of the chain.
//!
//! \return \c false if a problem occurs during initialization.
//!
bool Initialize(ThreadHandlerPtr threads, CBlockIndex* pindexBest);
bool Initialize(CBlockIndex* pindexBest);

//!
//! \brief Set up Gridcoin-specific background jobs.
Expand Down
4 changes: 2 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ void Shutdown(void* parg)
bitdb.Flush(false);
StopNode();
bitdb.Flush(true);

StopRPCThreads();

boost::filesystem::remove(GetPidFile());
UnregisterWallet(pwalletMain);
delete pwalletMain;
Expand Down Expand Up @@ -1080,8 +1082,6 @@ bool AppInit2(ThreadHandlerPtr threads)

RandAddSeedPerfmon();

GRC::Initialize(threads, pindexBest);

//// debug print
if (LogInstance().WillLogCategory(BCLog::LogFlags::VERBOSE))
{
Expand Down
4 changes: 4 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "init.h"
#include "ui_interface.h"
#include "util.h"
#include "gridcoin/gridcoin.h"

#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
#include <boost/thread.hpp>
Expand Down Expand Up @@ -2318,6 +2319,9 @@ void StartNode(void* parg)
else
if (!netThreads->createThread(ThreadStakeMiner,pwalletMain,"ThreadStakeMiner"))
LogPrintf("Error: createThread(ThreadStakeMiner) failed");

// Initialize GRC services.
GRC::Initialize(pindexBest);
}

bool StopNode()
Expand Down
28 changes: 27 additions & 1 deletion src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
extern CWallet* pwalletMain;
extern std::string FromQString(QString qs);

void GetGlobalStatus();

BitcoinGUI::BitcoinGUI(QWidget *parent):
QMainWindow(parent),
clientModel(0),
Expand Down Expand Up @@ -177,12 +179,18 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):

diagnosticsDialog = new DiagnosticsDialog(this);


// Clicking on "Verify Message" in the address book sends you to the verify message tab
connect(addressBookPage, SIGNAL(verifyMessage(QString)), this, SLOT(gotoVerifyMessageTab(QString)));
// Clicking on "Sign Message" in the receive coins page sends you to the sign message tab
connect(receiveCoinsPage, SIGNAL(signMessage(QString)), this, SLOT(gotoSignMessageTab(QString)));

QTimer *overview_update_timer = new QTimer(this);

// Update every 5 seconds.
overview_update_timer->start(5 * 1000);

QObject::connect(overview_update_timer, SIGNAL(timeout()), this, SLOT(updateGlobalStatus()));

gotoOverviewPage();
}

Expand Down Expand Up @@ -1264,6 +1272,24 @@ void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
hide();
}

void BitcoinGUI::updateGlobalStatus()
{
// This is needed to prevent segfaulting due to early GUI initialization compared to core.
if (miner_first_pass_complete)
{
try
{
GetGlobalStatus();
overviewPage->updateglobalstatus();
setNumConnections(clientModel->getNumConnections());
}
catch(std::runtime_error &e)
{
LogPrintf("GENERAL RUNTIME ERROR!");
}
}
}
Comment on lines +1275 to +1291
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I finally removed the ridiculous GlobalStatusStruct and related code for an upcoming PR. Should be fine to merge this in the meantime, though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. This probably creates more work for you in the interim, but it was pretty simple to get it to work again.


void BitcoinGUI::toggleHidden()
{
showNormalIfMinimized(true);
Expand Down
2 changes: 2 additions & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ private slots:
void updateBeaconIcon();

QString GetEstimatedStakingFrequency(unsigned int nEstimateTime);

void updateGlobalStatus();
};

#endif