aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorMatt Corallo <git@bluematt.me>2017-01-05 10:31:39 -0500
committerMatt Corallo <git@bluematt.me>2017-01-05 10:32:07 -0500
commitc80209214208621b84da10895427e1e5f381d1b8 (patch)
tree76d664bf1f5edd8709440c09c93c4e2846ccf5a5 /src/net_processing.cpp
parent69872195773870de8ee6521c9f555d60395a5ad9 (diff)
downloadbitcoin-c80209214208621b84da10895427e1e5f381d1b8.tar.xz
Relay compact block messages prior to full block connection
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 4374b5be3e..15bdef86fa 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -752,6 +752,39 @@ void PeerLogicValidation::SyncTransaction(const CTransaction& tx, const CBlockIn
}
}
+void PeerLogicValidation::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) {
+ CBlockHeaderAndShortTxIDs cmpctblock(*pblock, true);
+ CNetMsgMaker msgMaker(PROTOCOL_VERSION);
+
+ LOCK(cs_main);
+
+ static int nHighestFastAnnounce = 0;
+ if (pindex->nHeight <= nHighestFastAnnounce)
+ return;
+ nHighestFastAnnounce = pindex->nHeight;
+
+ bool fWitnessEnabled = IsWitnessEnabled(pindex->pprev, Params().GetConsensus());
+ uint256 hashBlock(pblock->GetHash());
+
+ connman->ForEachNode([this, &cmpctblock, pindex, &msgMaker, fWitnessEnabled, &hashBlock](CNode* pnode) {
+ // TODO: Avoid the repeated-serialization here
+ if (pnode->nVersion < INVALID_CB_NO_BAN_VERSION || pnode->fDisconnect)
+ return;
+ ProcessBlockAvailability(pnode->GetId());
+ CNodeState &state = *State(pnode->GetId());
+ // If the peer has, or we announced to them the previous block already,
+ // but we don't think they have this one, go ahead and announce it
+ if (state.fPreferHeaderAndIDs && (!fWitnessEnabled || state.fWantsCmpctWitness) &&
+ !PeerHasHeader(&state, pindex) && PeerHasHeader(&state, pindex->pprev)) {
+
+ LogPrint("net", "%s sending header-and-ids %s to peer %d\n", "PeerLogicValidation::NewPoWValidBlock",
+ hashBlock.ToString(), pnode->id);
+ connman->PushMessage(pnode, msgMaker.Make(NetMsgType::CMPCTBLOCK, cmpctblock));
+ state.pindexBestHeaderSent = pindex;
+ }
+ });
+}
+
void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
const int nNewHeight = pindexNew->nHeight;
connman->SetBestHeight(nNewHeight);