diff --git a/src/avalanche/processor.h b/src/avalanche/processor.h --- a/src/avalanche/processor.h +++ b/src/avalanche/processor.h @@ -256,6 +256,12 @@ class NotificationsHandler; std::unique_ptr chainNotificationsHandler; + /** + * Flag indicating that the proof must be registered at first new block + * after IBD + */ + bool mustRegisterProof = false; + public: Processor(interfaces::Chain &chain, CConnman *connmanIn, NodePeerManager *nodePeerManagerIn); diff --git a/src/avalanche/processor.cpp b/src/avalanche/processor.cpp --- a/src/avalanche/processor.cpp +++ b/src/avalanche/processor.cpp @@ -149,6 +149,13 @@ void updatedBlockTip() override { LOCK(m_processor->cs_peerManager); + + if (m_processor->mustRegisterProof && + !::ChainstateActive().IsInitialBlockDownload()) { + m_processor->peerManager->getPeerId(m_processor->peerData->proof); + m_processor->mustRegisterProof = false; + } + m_processor->peerManager->updatedBlockTip(); } }; @@ -174,13 +181,8 @@ SER_NETWORK, 0); stream >> peerData->proof; - // Ensure the peer manager knows about it. - // FIXME: There is no way to register the proof at this time because - // we might not have the proper chainstate at the moment. We need to - // find a way to delay the registration of the proof until after IBD - // has finished and the chain state is settled. - // LOCK(cs_peerManager); - // peerManager->getPeerId(peerData->proof); + // Schedule proof registration at the first new block after IBD. + mustRegisterProof = true; } // Generate the delegation to the session key.