Skip to content

Commit 2bbac8f

Browse files
committed
Introduce NotifyChainLock signal and invoke it when CLSIGs get processed
1 parent e47af29 commit 2bbac8f

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

src/llmq/quorums_chainlocks.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ void CChainLocksHandler::ProcessNewChainLock(NodeId from, const llmq::CChainLock
149149

150150
LogPrintf("CChainLocksHandler::%s -- processed new CLSIG (%s), peer=%d\n",
151151
__func__, clsig.ToString(), from);
152+
153+
if (lastNotifyChainLockBlockIndex != bestChainLockBlockIndex) {
154+
lastNotifyChainLockBlockIndex = bestChainLockBlockIndex;
155+
GetMainSignals().NotifyChainLock(bestChainLockBlockIndex);
156+
}
152157
}
153158

154159
void CChainLocksHandler::AcceptedBlockHeader(const CBlockIndex* pindexNew)
@@ -204,6 +209,11 @@ void CChainLocksHandler::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBl
204209
if (bestChainLockBlockIndex == pindexNew) {
205210
// we first got the CLSIG, then the header, and then the block was connected.
206211
// In this case there is no need to continue here.
212+
// However, NotifyChainLock might not have been called yet, so call it now if needed
213+
if (lastNotifyChainLockBlockIndex != bestChainLockBlockIndex) {
214+
lastNotifyChainLockBlockIndex = bestChainLockBlockIndex;
215+
GetMainSignals().NotifyChainLock(bestChainLockBlockIndex);
216+
}
207217
return;
208218
}
209219

src/llmq/quorums_chainlocks.h

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class CChainLocksHandler : public CRecoveredSigsListener
5555

5656
CChainLockSig bestChainLockWithKnownBlock;
5757
const CBlockIndex* bestChainLockBlockIndex{nullptr};
58+
const CBlockIndex* lastNotifyChainLockBlockIndex{nullptr};
5859

5960
int32_t lastSignedHeight{-1};
6061
uint256 lastSignedRequestId;

src/validationinterface.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) {
1818
g_signals.UpdatedBlockTip.connect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1, _2, _3));
1919
g_signals.SyncTransaction.connect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2, _3));
2020
g_signals.NotifyTransactionLock.connect(boost::bind(&CValidationInterface::NotifyTransactionLock, pwalletIn, _1));
21+
g_signals.NotifyChainLock.connect(boost::bind(&CValidationInterface::NotifyChainLock, pwalletIn, _1));
2122
g_signals.UpdatedTransaction.connect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
2223
g_signals.SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
2324
g_signals.Inventory.connect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
@@ -40,6 +41,7 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
4041
g_signals.Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
4142
g_signals.SetBestChain.disconnect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
4243
g_signals.UpdatedTransaction.disconnect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
44+
g_signals.NotifyChainLock.disconnect(boost::bind(&CValidationInterface::NotifyChainLock, pwalletIn, _1));
4345
g_signals.NotifyTransactionLock.disconnect(boost::bind(&CValidationInterface::NotifyTransactionLock, pwalletIn, _1));
4446
g_signals.SyncTransaction.disconnect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2, _3));
4547
g_signals.UpdatedBlockTip.disconnect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1, _2, _3));
@@ -61,6 +63,7 @@ void UnregisterAllValidationInterfaces() {
6163
g_signals.SetBestChain.disconnect_all_slots();
6264
g_signals.UpdatedTransaction.disconnect_all_slots();
6365
g_signals.NotifyTransactionLock.disconnect_all_slots();
66+
g_signals.NotifyChainLock.disconnect_all_slots();
6467
g_signals.SyncTransaction.disconnect_all_slots();
6568
g_signals.UpdatedBlockTip.disconnect_all_slots();
6669
g_signals.NewPoWValidBlock.disconnect_all_slots();

src/validationinterface.h

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class CValidationInterface {
3939
virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {}
4040
virtual void SyncTransaction(const CTransaction &tx, const CBlockIndex *pindex, int posInBlock) {}
4141
virtual void NotifyTransactionLock(const CTransaction &tx) {}
42+
virtual void NotifyChainLock(const CBlockIndex* pindex) {}
4243
virtual void NotifyGovernanceVote(const CGovernanceVote &vote) {}
4344
virtual void NotifyGovernanceObject(const CGovernanceObject &object) {}
4445
virtual void NotifyInstantSendDoubleSpendAttempt(const CTransaction &currentTx, const CTransaction &previousTx) {}
@@ -76,6 +77,8 @@ struct CMainSignals {
7677
boost::signals2::signal<void (const CTransaction &, const CBlockIndex *pindex, int posInBlock)> SyncTransaction;
7778
/** Notifies listeners of an updated transaction lock without new data. */
7879
boost::signals2::signal<void (const CTransaction &)> NotifyTransactionLock;
80+
/** Notifies listeners of a ChainLock. */
81+
boost::signals2::signal<void (const CBlockIndex* pindex)> NotifyChainLock;
7982
/** Notifies listeners of a new governance vote. */
8083
boost::signals2::signal<void (const CGovernanceVote &)> NotifyGovernanceVote;
8184
/** Notifies listeners of a new governance object. */

0 commit comments

Comments
 (0)