Disable BIP152
This commit is contained in:
78
src/main.cpp
78
src/main.cpp
@@ -7,7 +7,10 @@
|
||||
|
||||
#include "addrman.h"
|
||||
#include "arith_uint256.h"
|
||||
/*
|
||||
// Disable BIP152
|
||||
#include "blockencodings.h"
|
||||
*/
|
||||
#include "chainparams.h"
|
||||
#include "checkpoints.h"
|
||||
#include "checkqueue.h"
|
||||
@@ -219,12 +222,18 @@ namespace {
|
||||
uint256 hash;
|
||||
CBlockIndex* pindex; //!< Optional.
|
||||
bool fValidatedHeaders; //!< Whether this block has validated headers at the time of request.
|
||||
/*
|
||||
// Disable BIP152
|
||||
std::unique_ptr<PartiallyDownloadedBlock> partialBlock; //!< Optional, used for CMPCTBLOCK downloads
|
||||
*/
|
||||
};
|
||||
map<uint256, pair<NodeId, list<QueuedBlock>::iterator> > mapBlocksInFlight;
|
||||
|
||||
/** Stack of nodes which we have set to announce using compact blocks */
|
||||
/*
|
||||
// Disable BIP152
|
||||
list<NodeId> lNodesAnnouncingHeaderAndIDs;
|
||||
*/
|
||||
|
||||
/** Number of preferable block download peers. */
|
||||
int nPreferredDownload = 0;
|
||||
@@ -300,10 +309,13 @@ struct CNodeState {
|
||||
bool fPreferredDownload;
|
||||
//! Whether this peer wants invs or headers (when possible) for block announcements.
|
||||
bool fPreferHeaders;
|
||||
/*
|
||||
// Disable BIP152
|
||||
//! Whether this peer wants invs or cmpctblocks (when possible) for block announcements.
|
||||
bool fPreferHeaderAndIDs;
|
||||
//! Whether this peer will send us cmpctblocks if we request them
|
||||
bool fProvidesHeaderAndIDs;
|
||||
*/
|
||||
|
||||
CNodeState() {
|
||||
fCurrentlyConnected = false;
|
||||
@@ -321,8 +333,11 @@ struct CNodeState {
|
||||
nBlocksInFlightValidHeaders = 0;
|
||||
fPreferredDownload = false;
|
||||
fPreferHeaders = false;
|
||||
/*
|
||||
// Disable BIP152
|
||||
fPreferHeaderAndIDs = false;
|
||||
fProvidesHeaderAndIDs = false;
|
||||
*/
|
||||
}
|
||||
};
|
||||
|
||||
@@ -431,8 +446,13 @@ bool MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, const Consensus::Pa
|
||||
// Make sure it's not listed somewhere already.
|
||||
MarkBlockAsReceived(hash);
|
||||
|
||||
/*
|
||||
// Disable BIP152
|
||||
list<QueuedBlock>::iterator it = state->vBlocksInFlight.insert(state->vBlocksInFlight.end(),
|
||||
{hash, pindex, pindex != NULL, std::unique_ptr<PartiallyDownloadedBlock>(pit ? new PartiallyDownloadedBlock(&mempool) : NULL)});
|
||||
*/
|
||||
list<QueuedBlock>::iterator it = state->vBlocksInFlight.insert(state->vBlocksInFlight.end(),
|
||||
{hash, pindex, pindex != NULL});
|
||||
state->nBlocksInFlight++;
|
||||
state->nBlocksInFlightValidHeaders += it->fValidatedHeaders;
|
||||
if (state->nBlocksInFlight == 1) {
|
||||
@@ -483,6 +503,8 @@ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// Disable BIP152
|
||||
void MaybeSetPeerAsAnnouncingHeaderAndIDs(const CNodeState* nodestate, CNode* pfrom) {
|
||||
if (nodestate->fProvidesHeaderAndIDs) {
|
||||
for (std::list<NodeId>::iterator it = lNodesAnnouncingHeaderAndIDs.begin(); it != lNodesAnnouncingHeaderAndIDs.end(); it++) {
|
||||
@@ -508,6 +530,7 @@ void MaybeSetPeerAsAnnouncingHeaderAndIDs(const CNodeState* nodestate, CNode* pf
|
||||
lNodesAnnouncingHeaderAndIDs.push_back(pfrom->GetId());
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Requires cs_main
|
||||
bool CanDirectFetch(const Consensus::Params &consensusParams)
|
||||
@@ -4855,7 +4878,11 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
|
||||
boost::this_thread::interruption_point();
|
||||
it++;
|
||||
|
||||
/*
|
||||
// Disable BIP152
|
||||
if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK || inv.type == MSG_CMPCT_BLOCK)
|
||||
*/
|
||||
if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK)
|
||||
{
|
||||
bool send = false;
|
||||
BlockMap::iterator mi = mapBlockIndex.find(inv.hash);
|
||||
@@ -4895,7 +4922,11 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
|
||||
assert(!"cannot load block from disk");
|
||||
if (inv.type == MSG_BLOCK)
|
||||
pfrom->PushMessage(NetMsgType::BLOCK, block);
|
||||
/*
|
||||
// Disable BIP152
|
||||
else if (inv.type == MSG_FILTERED_BLOCK)
|
||||
*/
|
||||
else // MSG_FILTERED_BLOCK
|
||||
{
|
||||
bool send = false;
|
||||
CMerkleBlock merkleBlock;
|
||||
@@ -4921,6 +4952,8 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
|
||||
// else
|
||||
// no response
|
||||
}
|
||||
/*
|
||||
// Disable BIP152
|
||||
else if (inv.type == MSG_CMPCT_BLOCK)
|
||||
{
|
||||
// If a peer is asking for old blocks, we're almost guaranteed
|
||||
@@ -4933,6 +4966,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
|
||||
} else
|
||||
pfrom->PushMessage(NetMsgType::BLOCK, block);
|
||||
}
|
||||
*/
|
||||
|
||||
// Trigger the peer node to send a getblocks request for the next batch of inventory
|
||||
if (inv.hash == pfrom->hashContinue)
|
||||
@@ -4972,7 +5006,11 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
|
||||
// Track requests for our stuff.
|
||||
GetMainSignals().Inventory(inv.hash);
|
||||
|
||||
/*
|
||||
// Disable BIP152
|
||||
if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK || inv.type == MSG_CMPCT_BLOCK)
|
||||
*/
|
||||
if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK)
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -5183,6 +5221,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
// nodes)
|
||||
pfrom->PushMessage(NetMsgType::SENDHEADERS);
|
||||
}
|
||||
/*
|
||||
// Disable BIP152
|
||||
if (pfrom->nVersion >= SHORT_IDS_BLOCKS_VERSION) {
|
||||
// Tell our peer we are willing to provide version-1 cmpctblocks
|
||||
// However, we do not request new block announcements using
|
||||
@@ -5193,6 +5233,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
uint64_t nCMPCTBLOCKVersion = 1;
|
||||
pfrom->PushMessage(NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -5267,6 +5308,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
State(pfrom->GetId())->fPreferHeaders = true;
|
||||
}
|
||||
|
||||
/*
|
||||
// Disable BIP152
|
||||
else if (strCommand == NetMsgType::SENDCMPCT)
|
||||
{
|
||||
bool fAnnounceUsingCMPCTBLOCK = false;
|
||||
@@ -5286,6 +5329,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
else if (strCommand == NetMsgType::INV)
|
||||
@@ -5333,10 +5377,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
CNodeState *nodestate = State(pfrom->GetId());
|
||||
if (CanDirectFetch(chainparams.GetConsensus()) &&
|
||||
nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
|
||||
/*
|
||||
// Disable BIP152
|
||||
if (nodestate->fProvidesHeaderAndIDs)
|
||||
vToFetch.push_back(CInv(MSG_CMPCT_BLOCK, inv.hash));
|
||||
else
|
||||
vToFetch.push_back(inv);
|
||||
*/
|
||||
vToFetch.push_back(inv);
|
||||
// Mark block as in flight already, even though the actual "getdata" message only goes out
|
||||
// later (within the same cs_main lock, though).
|
||||
MarkBlockAsInFlight(pfrom->GetId(), inv.hash, chainparams.GetConsensus());
|
||||
@@ -5433,6 +5481,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// Disable BIP152
|
||||
else if (strCommand == NetMsgType::GETBLOCKTXN)
|
||||
{
|
||||
BlockTransactionsRequest req;
|
||||
@@ -5477,6 +5527,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
}
|
||||
pfrom->PushMessage(NetMsgType::BLOCKTXN, resp);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
else if (strCommand == NetMsgType::GETHEADERS)
|
||||
@@ -5694,7 +5745,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
FlushStateToDisk(state, FLUSH_STATE_PERIODIC);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// Disable BIP152
|
||||
else if (strCommand == NetMsgType::CMPCTBLOCK && !fImporting && !fReindex) // Ignore blocks received while importing
|
||||
{
|
||||
CBlockHeaderAndShortTxIDs cmpctblock;
|
||||
@@ -5932,6 +5984,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
else if (strCommand == NetMsgType::HEADERS && !fImporting && !fReindex) // Ignore headers received while importing
|
||||
@@ -6063,6 +6116,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
pindexLast->GetBlockHash().ToString(), pindexLast->nHeight);
|
||||
}
|
||||
if (vGetData.size() > 0) {
|
||||
/*
|
||||
// Disable BIP152
|
||||
if (nodestate->fProvidesHeaderAndIDs && vGetData.size() == 1 && mapBlocksInFlight.size() == 1 && pindexLast->pprev->IsValid(BLOCK_VALID_CHAIN)) {
|
||||
// We seem to be rather well-synced, so it appears pfrom was the first to provide us
|
||||
// with this block! Let's get them to announce using compact blocks in the future.
|
||||
@@ -6070,6 +6125,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
// In any case, we want to download using a compact block, not a regular one
|
||||
vGetData[0] = CInv(MSG_CMPCT_BLOCK, vGetData[0].hash);
|
||||
}
|
||||
*/
|
||||
pfrom->PushMessage(NetMsgType::GETDATA, vGetData);
|
||||
}
|
||||
}
|
||||
@@ -6627,9 +6683,13 @@ bool SendMessages(CNode* pto)
|
||||
// add all to the inv queue.
|
||||
LOCK(pto->cs_inventory);
|
||||
vector<CBlock> vHeaders;
|
||||
/*
|
||||
// Disable BIP152
|
||||
bool fRevertToInv = ((!state.fPreferHeaders &&
|
||||
(!state.fPreferHeaderAndIDs || pto->vBlockHashesToAnnounce.size() > 1)) ||
|
||||
pto->vBlockHashesToAnnounce.size() > MAX_BLOCKS_TO_ANNOUNCE);
|
||||
*/
|
||||
bool fRevertToInv = (!state.fPreferHeaders || pto->vBlockHashesToAnnounce.size() > MAX_BLOCKS_TO_ANNOUNCE);
|
||||
CBlockIndex *pBestIndex = NULL; // last header queued for delivery
|
||||
ProcessBlockAvailability(pto->id); // ensure pindexBestKnownBlock is up-to-date
|
||||
|
||||
@@ -6681,6 +6741,8 @@ bool SendMessages(CNode* pto)
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
// Disable BIP152
|
||||
if (!fRevertToInv && !vHeaders.empty()) {
|
||||
if (vHeaders.size() == 1 && state.fPreferHeaderAndIDs) {
|
||||
// We only send up to 1 block as header-and-ids, as otherwise
|
||||
@@ -6708,6 +6770,7 @@ bool SendMessages(CNode* pto)
|
||||
} else
|
||||
fRevertToInv = true;
|
||||
}
|
||||
*/
|
||||
if (fRevertToInv) {
|
||||
// If falling back to using an inv, just try to inv the tip.
|
||||
// The last entry in vBlockHashesToAnnounce was our tip at some point
|
||||
@@ -6733,6 +6796,19 @@ bool SendMessages(CNode* pto)
|
||||
pto->id, hashToAnnounce.ToString());
|
||||
}
|
||||
}
|
||||
// Disable BIP152
|
||||
} else if (!vHeaders.empty()) {
|
||||
if (vHeaders.size() > 1) {
|
||||
LogPrint("net", "%s: %u headers, range (%s, %s), to peer=%d\n", __func__,
|
||||
vHeaders.size(),
|
||||
vHeaders.front().GetHash().ToString(),
|
||||
vHeaders.back().GetHash().ToString(), pto->id);
|
||||
} else {
|
||||
LogPrint("net", "%s: sending header %s to peer=%d\n", __func__,
|
||||
vHeaders.front().GetHash().ToString(), pto->id);
|
||||
}
|
||||
pto->PushMessage(NetMsgType::HEADERS, vHeaders);
|
||||
state.pindexBestHeaderSent = pBestIndex;
|
||||
}
|
||||
pto->vBlockHashesToAnnounce.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user