Skip to content

Commit 6987219

Browse files
committed
Add a CValidationInterface::NewPoWValidBlock callback
1 parent 180586f commit 6987219

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/validation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3096,6 +3096,11 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation
30963096
return error("%s: %s", __func__, FormatStateMessage(state));
30973097
}
30983098

3099+
// Header is valid/has work, merkle tree and segwit merkle tree are good...RELAY NOW
3100+
// (but if it does not build on our best tip, let the SendMessages loop relay it)
3101+
if (!IsInitialBlockDownload() && chainActive.Tip() == pindex->pprev)
3102+
GetMainSignals().NewPoWValidBlock(pindex, pblock);
3103+
30993104
int nHeight = pindex->nHeight;
31003105

31013106
// Write block to history file

src/validationinterface.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) {
2222
g_signals.BlockChecked.connect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
2323
g_signals.ScriptForMining.connect(boost::bind(&CValidationInterface::GetScriptForMining, pwalletIn, _1));
2424
g_signals.BlockFound.connect(boost::bind(&CValidationInterface::ResetRequestCount, pwalletIn, _1));
25+
g_signals.NewPoWValidBlock.connect(boost::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, _1, _2));
2526
}
2627

2728
void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
@@ -34,6 +35,7 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
3435
g_signals.UpdatedTransaction.disconnect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
3536
g_signals.SyncTransaction.disconnect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2, _3));
3637
g_signals.UpdatedBlockTip.disconnect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1, _2, _3));
38+
g_signals.NewPoWValidBlock.disconnect(boost::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, _1, _2));
3739
}
3840

3941
void UnregisterAllValidationInterfaces() {
@@ -46,4 +48,5 @@ void UnregisterAllValidationInterfaces() {
4648
g_signals.UpdatedTransaction.disconnect_all_slots();
4749
g_signals.SyncTransaction.disconnect_all_slots();
4850
g_signals.UpdatedBlockTip.disconnect_all_slots();
51+
g_signals.NewPoWValidBlock.disconnect_all_slots();
4952
}

src/validationinterface.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <boost/signals2/signal.hpp>
1010
#include <boost/shared_ptr.hpp>
11+
#include <memory>
1112

1213
class CBlock;
1314
class CBlockIndex;
@@ -40,6 +41,7 @@ class CValidationInterface {
4041
virtual void BlockChecked(const CBlock&, const CValidationState&) {}
4142
virtual void GetScriptForMining(boost::shared_ptr<CReserveScript>&) {};
4243
virtual void ResetRequestCount(const uint256 &hash) {};
44+
virtual void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& block) {};
4345
friend void ::RegisterValidationInterface(CValidationInterface*);
4446
friend void ::UnregisterValidationInterface(CValidationInterface*);
4547
friend void ::UnregisterAllValidationInterfaces();
@@ -66,6 +68,10 @@ struct CMainSignals {
6668
boost::signals2::signal<void (boost::shared_ptr<CReserveScript>&)> ScriptForMining;
6769
/** Notifies listeners that a block has been successfully mined */
6870
boost::signals2::signal<void (const uint256 &)> BlockFound;
71+
/**
72+
* Notifies listeners that a block which builds directly on our current tip
73+
* has been received and connected to the headers tree, though not validated yet */
74+
boost::signals2::signal<void (const CBlockIndex *, const std::shared_ptr<const CBlock>&)> NewPoWValidBlock;
6975
};
7076

7177
CMainSignals& GetMainSignals();

0 commit comments

Comments
 (0)