Skip to content

Commit 82564e2

Browse files
committed
Merge pull request #4134
aa250f0 Remove NumBlocksOfPeers (Wladimir J. van der Laan)
2 parents e443ed2 + aa250f0 commit 82564e2

File tree

9 files changed

+19
-75
lines changed

9 files changed

+19
-75
lines changed

src/main.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ int64_t CTransaction::nMinTxFee = 10000; // Override with -mintxfee
5454
/** Fees smaller than this (in satoshi) are considered zero fee (for relaying and mining) */
5555
int64_t CTransaction::nMinRelayTxFee = 1000;
5656

57-
static CMedianFilter<int> cPeerBlockCounts(8, 0); // Amount of blocks that other nodes claim to have
58-
5957
struct COrphanBlock {
6058
uint256 hashBlock;
6159
uint256 hashPrev;
@@ -1307,12 +1305,6 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits)
13071305
return true;
13081306
}
13091307

1310-
// Return maximum amount of blocks that other nodes claim to have
1311-
int GetNumBlocksOfPeers()
1312-
{
1313-
return std::max(cPeerBlockCounts.median(), Checkpoints::GetTotalBlocksEstimate());
1314-
}
1315-
13161308
bool IsInitialBlockDownload()
13171309
{
13181310
LOCK(cs_main);
@@ -3583,9 +3575,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
35833575
LogPrintf("receive version message: %s: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", pfrom->cleanSubVer, pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString(), addrFrom.ToString(), pfrom->addr.ToString());
35843576

35853577
AddTimeData(pfrom->addr, nTime);
3586-
3587-
LOCK(cs_main);
3588-
cPeerBlockCounts.input(pfrom->nStartingHeight);
35893578
}
35903579

35913580

src/main.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ void ThreadScriptCheck();
160160
bool CheckProofOfWork(uint256 hash, unsigned int nBits);
161161
/** Calculate the minimum amount of work a received block needs, without knowing its direct parent */
162162
unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime);
163-
/** Get the number of active peers */
164-
int GetNumBlocksOfPeers();
165163
/** Check whether we are doing an initial block download (synchronizing from disk or network) */
166164
bool IsInitialBlockDownload();
167165
/** Format a string that describes several potential problems detected by the core */

src/qt/bitcoingui.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
403403
setNumConnections(clientModel->getNumConnections());
404404
connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
405405

406-
setNumBlocks(clientModel->getNumBlocks(), clientModel->getNumBlocksOfPeers());
407-
connect(clientModel, SIGNAL(numBlocksChanged(int,int)), this, SLOT(setNumBlocks(int,int)));
406+
setNumBlocks(clientModel->getNumBlocks());
407+
connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
408408

409409
// Receive and report messages from client model
410410
connect(clientModel, SIGNAL(message(QString,QString,unsigned int)), this, SLOT(message(QString,QString,unsigned int)));
@@ -617,7 +617,7 @@ void BitcoinGUI::setNumConnections(int count)
617617
labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
618618
}
619619

620-
void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
620+
void BitcoinGUI::setNumBlocks(int count)
621621
{
622622
// Prevent orphan statusbar messages (e.g. hover Quit in main menu, wait until chain-sync starts -> garbelled text)
623623
statusBar()->clearMessage();
@@ -646,17 +646,10 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
646646
QDateTime currentDate = QDateTime::currentDateTime();
647647
int secs = lastBlockDate.secsTo(currentDate);
648648

649-
if(count < nTotalBlocks)
650-
{
651-
tooltip = tr("Processed %1 of %2 (estimated) blocks of transaction history.").arg(count).arg(nTotalBlocks);
652-
}
653-
else
654-
{
655-
tooltip = tr("Processed %1 blocks of transaction history.").arg(count);
656-
}
649+
tooltip = tr("Processed %1 blocks of transaction history.").arg(count);
657650

658651
// Set icon state: spinning if catching up, tick otherwise
659-
if(secs < 90*60 && count >= nTotalBlocks)
652+
if(secs < 90*60)
660653
{
661654
tooltip = tr("Up to date") + QString(".<br>") + tooltip;
662655
labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));

src/qt/bitcoingui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public slots:
130130
/** Set number of connections shown in the UI */
131131
void setNumConnections(int count);
132132
/** Set number of blocks shown in the UI */
133-
void setNumBlocks(int count, int nTotalBlocks);
133+
void setNumBlocks(int count);
134134

135135
/** Notify the user of an event from the core network or transaction handling code.
136136
@param[in] title the message box / notification title

src/qt/clientmodel.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static const int64_t nClientStartupTime = GetTime();
2323

2424
ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) :
2525
QObject(parent), optionsModel(optionsModel),
26-
cachedNumBlocks(0), cachedNumBlocksOfPeers(0),
26+
cachedNumBlocks(0),
2727
cachedReindexing(0), cachedImporting(0),
2828
numBlocksAtStartup(-1), pollTimer(0)
2929
{
@@ -101,19 +101,16 @@ void ClientModel::updateTimer()
101101
// Some quantities (such as number of blocks) change so fast that we don't want to be notified for each change.
102102
// Periodically check and update with a timer.
103103
int newNumBlocks = getNumBlocks();
104-
int newNumBlocksOfPeers = getNumBlocksOfPeers();
105104

106105
// check for changed number of blocks we have, number of blocks peers claim to have, reindexing state and importing state
107-
if (cachedNumBlocks != newNumBlocks || cachedNumBlocksOfPeers != newNumBlocksOfPeers ||
106+
if (cachedNumBlocks != newNumBlocks ||
108107
cachedReindexing != fReindex || cachedImporting != fImporting)
109108
{
110109
cachedNumBlocks = newNumBlocks;
111-
cachedNumBlocksOfPeers = newNumBlocksOfPeers;
112110
cachedReindexing = fReindex;
113111
cachedImporting = fImporting;
114112

115-
// ensure we return the maximum of newNumBlocksOfPeers and newNumBlocks to not create weird displays in the GUI
116-
emit numBlocksChanged(newNumBlocks, std::max(newNumBlocksOfPeers, newNumBlocks));
113+
emit numBlocksChanged(newNumBlocks);
117114
}
118115

119116
emit bytesChanged(getTotalBytesRecv(), getTotalBytesSent());
@@ -166,11 +163,6 @@ enum BlockSource ClientModel::getBlockSource() const
166163
return BLOCK_SOURCE_NONE;
167164
}
168165

169-
int ClientModel::getNumBlocksOfPeers() const
170-
{
171-
return GetNumBlocksOfPeers();
172-
}
173-
174166
QString ClientModel::getStatusBarWarnings() const
175167
{
176168
return QString::fromStdString(GetWarnings("statusbar"));

src/qt/clientmodel.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ class ClientModel : public QObject
6060
bool inInitialBlockDownload() const;
6161
//! Return true if core is importing blocks
6262
enum BlockSource getBlockSource() const;
63-
//! Return conservative estimate of total number of blocks, or 0 if unknown
64-
int getNumBlocksOfPeers() const;
6563
//! Return warnings to be displayed in status bar
6664
QString getStatusBarWarnings() const;
6765

@@ -75,7 +73,6 @@ class ClientModel : public QObject
7573
OptionsModel *optionsModel;
7674

7775
int cachedNumBlocks;
78-
int cachedNumBlocksOfPeers;
7976
bool cachedReindexing;
8077
bool cachedImporting;
8178

@@ -88,7 +85,7 @@ class ClientModel : public QObject
8885

8986
signals:
9087
void numConnectionsChanged(int count);
91-
void numBlocksChanged(int count, int countOfPeers);
88+
void numBlocksChanged(int count);
9289
void alertsChanged(const QString &warnings);
9390
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);
9491

src/qt/forms/rpcconsole.ui

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -254,36 +254,13 @@
254254
</widget>
255255
</item>
256256
<item row="11" column="0">
257-
<widget class="QLabel" name="label_4">
258-
<property name="text">
259-
<string>Estimated total blocks</string>
260-
</property>
261-
</widget>
262-
</item>
263-
<item row="11" column="1">
264-
<widget class="QLabel" name="totalBlocks">
265-
<property name="cursor">
266-
<cursorShape>IBeamCursor</cursorShape>
267-
</property>
268-
<property name="text">
269-
<string>N/A</string>
270-
</property>
271-
<property name="textFormat">
272-
<enum>Qt::PlainText</enum>
273-
</property>
274-
<property name="textInteractionFlags">
275-
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
276-
</property>
277-
</widget>
278-
</item>
279-
<item row="12" column="0">
280257
<widget class="QLabel" name="label_2">
281258
<property name="text">
282259
<string>Last block time</string>
283260
</property>
284261
</widget>
285262
</item>
286-
<item row="12" column="1">
263+
<item row="11" column="1">
287264
<widget class="QLabel" name="lastBlockTime">
288265
<property name="cursor">
289266
<cursorShape>IBeamCursor</cursorShape>
@@ -299,7 +276,7 @@
299276
</property>
300277
</widget>
301278
</item>
302-
<item row="13" column="0">
279+
<item row="12" column="0">
303280
<spacer name="verticalSpacer_2">
304281
<property name="orientation">
305282
<enum>Qt::Vertical</enum>
@@ -312,7 +289,7 @@
312289
</property>
313290
</spacer>
314291
</item>
315-
<item row="14" column="0">
292+
<item row="13" column="0">
316293
<widget class="QLabel" name="labelDebugLogfile">
317294
<property name="font">
318295
<font>
@@ -325,7 +302,7 @@
325302
</property>
326303
</widget>
327304
</item>
328-
<item row="15" column="0">
305+
<item row="14" column="0">
329306
<widget class="QPushButton" name="openDebugLogfileButton">
330307
<property name="toolTip">
331308
<string>Open the Bitcoin debug log file from the current data directory. This can take a few seconds for large log files.</string>
@@ -338,7 +315,7 @@
338315
</property>
339316
</widget>
340317
</item>
341-
<item row="16" column="0">
318+
<item row="15" column="0">
342319
<spacer name="verticalSpacer">
343320
<property name="orientation">
344321
<enum>Qt::Vertical</enum>

src/qt/rpcconsole.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ void RPCConsole::setClientModel(ClientModel *model)
271271
setNumConnections(model->getNumConnections());
272272
connect(model, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
273273

274-
setNumBlocks(model->getNumBlocks(), model->getNumBlocksOfPeers());
275-
connect(model, SIGNAL(numBlocksChanged(int,int)), this, SLOT(setNumBlocks(int,int)));
274+
setNumBlocks(model->getNumBlocks());
275+
connect(model, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
276276

277277
updateTrafficStats(model->getTotalBytesRecv(), model->getTotalBytesSent());
278278
connect(model, SIGNAL(bytesChanged(quint64,quint64)), this, SLOT(updateTrafficStats(quint64, quint64)));
@@ -366,11 +366,9 @@ void RPCConsole::setNumConnections(int count)
366366
ui->numberOfConnections->setText(connections);
367367
}
368368

369-
void RPCConsole::setNumBlocks(int count, int countOfPeers)
369+
void RPCConsole::setNumBlocks(int count)
370370
{
371371
ui->numberOfBlocks->setText(QString::number(count));
372-
// If there is no current countOfPeers available display N/A instead of 0, which can't ever be true
373-
ui->totalBlocks->setText(countOfPeers == 0 ? tr("N/A") : QString::number(countOfPeers));
374372
if(clientModel)
375373
ui->lastBlockTime->setText(clientModel->getLastBlockDate().toString());
376374
}

src/qt/rpcconsole.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public slots:
5252
/** Set number of connections shown in the UI */
5353
void setNumConnections(int count);
5454
/** Set number of blocks shown in the UI */
55-
void setNumBlocks(int count, int countOfPeers);
55+
void setNumBlocks(int count);
5656
/** Go forward or back in history */
5757
void browseHistory(int offset);
5858
/** Scroll console view to end */

0 commit comments

Comments
 (0)