Skip to content

Commit 4f44530

Browse files
committed
Merge pull request #6680
d76a8ac use CBlockIndex* insted of uint256 for UpdatedBlockTip signal (Jonas Schnelli)
2 parents 3f74cd2 + d76a8ac commit 4f44530

File tree

8 files changed

+21
-17
lines changed

8 files changed

+21
-17
lines changed

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2320,7 +2320,7 @@ bool ActivateBestChain(CValidationState &state, const CBlock *pblock) {
23202320
pnode->PushInventory(CInv(MSG_BLOCK, hashNewTip));
23212321
}
23222322
// Notify external listeners about the new tip.
2323-
GetMainSignals().UpdatedBlockTip(hashNewTip);
2323+
GetMainSignals().UpdatedBlockTip(pindexNewTip);
23242324
uiInterface.NotifyBlockTip(hashNewTip);
23252325
}
23262326
} while(pindexMostWork != chainActive.Tip());

src/validationinterface.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
class CBlock;
1313
struct CBlockLocator;
14+
class CBlockIndex;
1415
class CReserveScript;
1516
class CTransaction;
1617
class CValidationInterface;
@@ -30,7 +31,7 @@ void SyncWithWallets(const CTransaction& tx, const CBlock* pblock = NULL);
3031

3132
class CValidationInterface {
3233
protected:
33-
virtual void UpdatedBlockTip(const uint256 &newHashTip) {}
34+
virtual void UpdatedBlockTip(const CBlockIndex *pindex) {}
3435
virtual void SyncTransaction(const CTransaction &tx, const CBlock *pblock) {}
3536
virtual void SetBestChain(const CBlockLocator &locator) {}
3637
virtual void UpdatedTransaction(const uint256 &hash) {}
@@ -46,7 +47,7 @@ class CValidationInterface {
4647

4748
struct CMainSignals {
4849
/** Notifies listeners of updated block chain tip */
49-
boost::signals2::signal<void (const uint256 &)> UpdatedBlockTip;
50+
boost::signals2::signal<void (const CBlockIndex *)> UpdatedBlockTip;
5051
/** Notifies listeners of updated transaction data (transaction, and optionally the block it is found in. */
5152
boost::signals2::signal<void (const CTransaction &, const CBlock *)> SyncTransaction;
5253
/** Notifies listeners of an updated transaction without new data (for now: a coinbase potentially becoming visible). */

src/zmq/zmqabstractnotifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ CZMQAbstractNotifier::~CZMQAbstractNotifier()
1111
assert(!psocket);
1212
}
1313

14-
bool CZMQAbstractNotifier::NotifyBlock(const uint256 &/*hash*/)
14+
bool CZMQAbstractNotifier::NotifyBlock(const CBlockIndex * /*CBlockIndex*/)
1515
{
1616
return true;
1717
}

src/zmq/zmqabstractnotifier.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
#include "zmqconfig.h"
99

10+
class CBlockIndex;
1011
class CZMQAbstractNotifier;
12+
1113
typedef CZMQAbstractNotifier* (*CZMQNotifierFactory)();
1214

1315
class CZMQAbstractNotifier
@@ -30,7 +32,7 @@ class CZMQAbstractNotifier
3032
virtual bool Initialize(void *pcontext) = 0;
3133
virtual void Shutdown() = 0;
3234

33-
virtual bool NotifyBlock(const uint256 &hash);
35+
virtual bool NotifyBlock(const CBlockIndex *pindex);
3436
virtual bool NotifyTransaction(const CTransaction &transaction);
3537

3638
protected:

src/zmq/zmqnotificationinterface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ void CZMQNotificationInterface::Shutdown()
120120
}
121121
}
122122

123-
void CZMQNotificationInterface::UpdatedBlockTip(const uint256 &hash)
123+
void CZMQNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindex)
124124
{
125125
for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i!=notifiers.end(); )
126126
{
127127
CZMQAbstractNotifier *notifier = *i;
128-
if (notifier->NotifyBlock(hash))
128+
if (notifier->NotifyBlock(pindex))
129129
{
130130
i++;
131131
}

src/zmq/zmqnotificationinterface.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <string>
1010
#include <map>
1111

12+
class CBlockIndex;
1213
class CZMQAbstractNotifier;
1314

1415
class CZMQNotificationInterface : public CValidationInterface
@@ -23,7 +24,7 @@ class CZMQNotificationInterface : public CValidationInterface
2324

2425
protected: // CValidationInterface
2526
void SyncTransaction(const CTransaction &tx, const CBlock *pblock);
26-
void UpdatedBlockTip(const uint256 &newHashTip);
27+
void UpdatedBlockTip(const CBlockIndex *pindex);
2728

2829
private:
2930
CZMQNotificationInterface();

src/zmq/zmqpublishnotifier.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ void CZMQAbstractPublishNotifier::Shutdown()
116116
psocket = 0;
117117
}
118118

119-
bool CZMQPublishHashBlockNotifier::NotifyBlock(const uint256 &hash)
119+
bool CZMQPublishHashBlockNotifier::NotifyBlock(const CBlockIndex *pindex)
120120
{
121+
uint256 hash = pindex->GetBlockHash();
121122
LogPrint("zmq", "Publish hash block %s\n", hash.GetHex());
122123
char data[32];
123124
for (unsigned int i = 0; i < 32; i++)
@@ -137,18 +138,15 @@ bool CZMQPublishHashTransactionNotifier::NotifyTransaction(const CTransaction &t
137138
return rc == 0;
138139
}
139140

140-
bool CZMQPublishRawBlockNotifier::NotifyBlock(const uint256 &hash)
141+
bool CZMQPublishRawBlockNotifier::NotifyBlock(const CBlockIndex *pindex)
141142
{
142-
LogPrint("zmq", "Publish raw block %s\n", hash.GetHex());
143+
LogPrint("zmq", "Publish raw block %s\n", pindex->GetBlockHash().GetHex());
143144

144145
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
145146
{
146147
LOCK(cs_main);
147-
148148
CBlock block;
149-
CBlockIndex* pblockindex = mapBlockIndex[hash];
150-
151-
if(!ReadBlockFromDisk(block, pblockindex))
149+
if(!ReadBlockFromDisk(block, pindex))
152150
{
153151
zmqError("Can't read block from disk");
154152
return false;

src/zmq/zmqpublishnotifier.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "zmqabstractnotifier.h"
99

10+
class CBlockIndex;
11+
1012
class CZMQAbstractPublishNotifier : public CZMQAbstractNotifier
1113
{
1214
public:
@@ -17,7 +19,7 @@ class CZMQAbstractPublishNotifier : public CZMQAbstractNotifier
1719
class CZMQPublishHashBlockNotifier : public CZMQAbstractPublishNotifier
1820
{
1921
public:
20-
bool NotifyBlock(const uint256 &hash);
22+
bool NotifyBlock(const CBlockIndex *pindex);
2123
};
2224

2325
class CZMQPublishHashTransactionNotifier : public CZMQAbstractPublishNotifier
@@ -29,7 +31,7 @@ class CZMQPublishHashTransactionNotifier : public CZMQAbstractPublishNotifier
2931
class CZMQPublishRawBlockNotifier : public CZMQAbstractPublishNotifier
3032
{
3133
public:
32-
bool NotifyBlock(const uint256 &hash);
34+
bool NotifyBlock(const CBlockIndex *pindex);
3335
};
3436

3537
class CZMQPublishRawTransactionNotifier : public CZMQAbstractPublishNotifier

0 commit comments

Comments
 (0)