|
|
|
@ -1991,7 +1991,7 @@ void static ProcessOrphanTx(CConnman* connman, CTxMemPool& mempool, std::set<uin
|
|
|
|
|
*
|
|
|
|
|
* May disconnect from the peer in the case of a bad request.
|
|
|
|
|
*
|
|
|
|
|
* @param[in] pfrom The peer that we received the request from
|
|
|
|
|
* @param[in] peer The peer that we received the request from
|
|
|
|
|
* @param[in] chain_params Chain parameters
|
|
|
|
|
* @param[in] filter_type The filter type the request is for. Must be basic filters.
|
|
|
|
|
* @param[in] start_height The start height for the request
|
|
|
|
@ -2001,7 +2001,7 @@ void static ProcessOrphanTx(CConnman* connman, CTxMemPool& mempool, std::set<uin
|
|
|
|
|
* @param[out] filter_index The filter index, if the request can be serviced.
|
|
|
|
|
* @return True if the request can be serviced.
|
|
|
|
|
*/
|
|
|
|
|
static bool PrepareBlockFilterRequest(CNode& pfrom, const CChainParams& chain_params,
|
|
|
|
|
static bool PrepareBlockFilterRequest(CNode& peer, const CChainParams& chain_params,
|
|
|
|
|
BlockFilterType filter_type, uint32_t start_height,
|
|
|
|
|
const uint256& stop_hash, uint32_t max_height_diff,
|
|
|
|
|
const CBlockIndex*& stop_index,
|
|
|
|
@ -2012,8 +2012,8 @@ static bool PrepareBlockFilterRequest(CNode& pfrom, const CChainParams& chain_pa
|
|
|
|
|
gArgs.GetBoolArg("-peerblockfilters", DEFAULT_PEERBLOCKFILTERS));
|
|
|
|
|
if (!supported_filter_type) {
|
|
|
|
|
LogPrint(BCLog::NET, "peer %d requested unsupported block filter type: %d\n",
|
|
|
|
|
pfrom.GetId(), static_cast<uint8_t>(filter_type));
|
|
|
|
|
pfrom.fDisconnect = true;
|
|
|
|
|
peer.GetId(), static_cast<uint8_t>(filter_type));
|
|
|
|
|
peer.fDisconnect = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2024,8 +2024,8 @@ static bool PrepareBlockFilterRequest(CNode& pfrom, const CChainParams& chain_pa
|
|
|
|
|
// Check that the stop block exists and the peer would be allowed to fetch it.
|
|
|
|
|
if (!stop_index || !BlockRequestAllowed(stop_index, chain_params.GetConsensus())) {
|
|
|
|
|
LogPrint(BCLog::NET, "peer %d requested invalid block hash: %s\n",
|
|
|
|
|
pfrom.GetId(), stop_hash.ToString());
|
|
|
|
|
pfrom.fDisconnect = true;
|
|
|
|
|
peer.GetId(), stop_hash.ToString());
|
|
|
|
|
peer.fDisconnect = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -2034,14 +2034,14 @@ static bool PrepareBlockFilterRequest(CNode& pfrom, const CChainParams& chain_pa
|
|
|
|
|
if (start_height > stop_height) {
|
|
|
|
|
LogPrint(BCLog::NET, "peer %d sent invalid getcfilters/getcfheaders with " /* Continued */
|
|
|
|
|
"start height %d and stop height %d\n",
|
|
|
|
|
pfrom.GetId(), start_height, stop_height);
|
|
|
|
|
pfrom.fDisconnect = true;
|
|
|
|
|
peer.GetId(), start_height, stop_height);
|
|
|
|
|
peer.fDisconnect = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (stop_height - start_height >= max_height_diff) {
|
|
|
|
|
LogPrint(BCLog::NET, "peer %d requested too many cfilters/cfheaders: %d / %d\n",
|
|
|
|
|
pfrom.GetId(), stop_height - start_height + 1, max_height_diff);
|
|
|
|
|
pfrom.fDisconnect = true;
|
|
|
|
|
peer.GetId(), stop_height - start_height + 1, max_height_diff);
|
|
|
|
|
peer.fDisconnect = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2059,12 +2059,12 @@ static bool PrepareBlockFilterRequest(CNode& pfrom, const CChainParams& chain_pa
|
|
|
|
|
*
|
|
|
|
|
* May disconnect from the peer in the case of a bad request.
|
|
|
|
|
*
|
|
|
|
|
* @param[in] pfrom The peer that we received the request from
|
|
|
|
|
* @param[in] peer The peer that we received the request from
|
|
|
|
|
* @param[in] vRecv The raw message received
|
|
|
|
|
* @param[in] chain_params Chain parameters
|
|
|
|
|
* @param[in] connman Pointer to the connection manager
|
|
|
|
|
*/
|
|
|
|
|
static void ProcessGetCFilters(CNode& pfrom, CDataStream& vRecv, const CChainParams& chain_params,
|
|
|
|
|
static void ProcessGetCFilters(CNode& peer, CDataStream& vRecv, const CChainParams& chain_params,
|
|
|
|
|
CConnman& connman)
|
|
|
|
|
{
|
|
|
|
|
uint8_t filter_type_ser;
|
|
|
|
@ -2077,13 +2077,12 @@ static void ProcessGetCFilters(CNode& pfrom, CDataStream& vRecv, const CChainPar
|
|
|
|
|
|
|
|
|
|
const CBlockIndex* stop_index;
|
|
|
|
|
BlockFilterIndex* filter_index;
|
|
|
|
|
if (!PrepareBlockFilterRequest(pfrom, chain_params, filter_type, start_height, stop_hash,
|
|
|
|
|
if (!PrepareBlockFilterRequest(peer, chain_params, filter_type, start_height, stop_hash,
|
|
|
|
|
MAX_GETCFILTERS_SIZE, stop_index, filter_index)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<BlockFilter> filters;
|
|
|
|
|
|
|
|
|
|
if (!filter_index->LookupFilterRange(start_height, stop_index, filters)) {
|
|
|
|
|
LogPrint(BCLog::NET, "Failed to find block filter in index: filter_type=%s, start_height=%d, stop_hash=%s\n",
|
|
|
|
|
BlockFilterTypeName(filter_type), start_height, stop_hash.ToString());
|
|
|
|
@ -2091,9 +2090,9 @@ static void ProcessGetCFilters(CNode& pfrom, CDataStream& vRecv, const CChainPar
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const auto& filter : filters) {
|
|
|
|
|
CSerializedNetMsg msg = CNetMsgMaker(pfrom.GetSendVersion())
|
|
|
|
|
CSerializedNetMsg msg = CNetMsgMaker(peer.GetSendVersion())
|
|
|
|
|
.Make(NetMsgType::CFILTER, filter);
|
|
|
|
|
connman.PushMessage(&pfrom, std::move(msg));
|
|
|
|
|
connman.PushMessage(&peer, std::move(msg));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2102,12 +2101,12 @@ static void ProcessGetCFilters(CNode& pfrom, CDataStream& vRecv, const CChainPar
|
|
|
|
|
*
|
|
|
|
|
* May disconnect from the peer in the case of a bad request.
|
|
|
|
|
*
|
|
|
|
|
* @param[in] pfrom The peer that we received the request from
|
|
|
|
|
* @param[in] peer The peer that we received the request from
|
|
|
|
|
* @param[in] vRecv The raw message received
|
|
|
|
|
* @param[in] chain_params Chain parameters
|
|
|
|
|
* @param[in] connman Pointer to the connection manager
|
|
|
|
|
*/
|
|
|
|
|
static void ProcessGetCFHeaders(CNode& pfrom, CDataStream& vRecv, const CChainParams& chain_params,
|
|
|
|
|
static void ProcessGetCFHeaders(CNode& peer, CDataStream& vRecv, const CChainParams& chain_params,
|
|
|
|
|
CConnman& connman)
|
|
|
|
|
{
|
|
|
|
|
uint8_t filter_type_ser;
|
|
|
|
@ -2120,7 +2119,7 @@ static void ProcessGetCFHeaders(CNode& pfrom, CDataStream& vRecv, const CChainPa
|
|
|
|
|
|
|
|
|
|
const CBlockIndex* stop_index;
|
|
|
|
|
BlockFilterIndex* filter_index;
|
|
|
|
|
if (!PrepareBlockFilterRequest(pfrom, chain_params, filter_type, start_height, stop_hash,
|
|
|
|
|
if (!PrepareBlockFilterRequest(peer, chain_params, filter_type, start_height, stop_hash,
|
|
|
|
|
MAX_GETCFHEADERS_SIZE, stop_index, filter_index)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -2143,13 +2142,13 @@ static void ProcessGetCFHeaders(CNode& pfrom, CDataStream& vRecv, const CChainPa
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSerializedNetMsg msg = CNetMsgMaker(pfrom.GetSendVersion())
|
|
|
|
|
CSerializedNetMsg msg = CNetMsgMaker(peer.GetSendVersion())
|
|
|
|
|
.Make(NetMsgType::CFHEADERS,
|
|
|
|
|
filter_type_ser,
|
|
|
|
|
stop_index->GetBlockHash(),
|
|
|
|
|
prev_header,
|
|
|
|
|
filter_hashes);
|
|
|
|
|
connman.PushMessage(&pfrom, std::move(msg));
|
|
|
|
|
connman.PushMessage(&peer, std::move(msg));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -2157,12 +2156,12 @@ static void ProcessGetCFHeaders(CNode& pfrom, CDataStream& vRecv, const CChainPa
|
|
|
|
|
*
|
|
|
|
|
* May disconnect from the peer in the case of a bad request.
|
|
|
|
|
*
|
|
|
|
|
* @param[in] pfrom The peer that we received the request from
|
|
|
|
|
* @param[in] peer The peer that we received the request from
|
|
|
|
|
* @param[in] vRecv The raw message received
|
|
|
|
|
* @param[in] chain_params Chain parameters
|
|
|
|
|
* @param[in] connman Pointer to the connection manager
|
|
|
|
|
*/
|
|
|
|
|
static void ProcessGetCFCheckPt(CNode& pfrom, CDataStream& vRecv, const CChainParams& chain_params,
|
|
|
|
|
static void ProcessGetCFCheckPt(CNode& peer, CDataStream& vRecv, const CChainParams& chain_params,
|
|
|
|
|
CConnman& connman)
|
|
|
|
|
{
|
|
|
|
|
uint8_t filter_type_ser;
|
|
|
|
@ -2174,7 +2173,7 @@ static void ProcessGetCFCheckPt(CNode& pfrom, CDataStream& vRecv, const CChainPa
|
|
|
|
|
|
|
|
|
|
const CBlockIndex* stop_index;
|
|
|
|
|
BlockFilterIndex* filter_index;
|
|
|
|
|
if (!PrepareBlockFilterRequest(pfrom, chain_params, filter_type, /*start_height=*/0, stop_hash,
|
|
|
|
|
if (!PrepareBlockFilterRequest(peer, chain_params, filter_type, /*start_height=*/0, stop_hash,
|
|
|
|
|
/*max_height_diff=*/std::numeric_limits<uint32_t>::max(),
|
|
|
|
|
stop_index, filter_index)) {
|
|
|
|
|
return;
|
|
|
|
@ -2195,12 +2194,12 @@ static void ProcessGetCFCheckPt(CNode& pfrom, CDataStream& vRecv, const CChainPa
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSerializedNetMsg msg = CNetMsgMaker(pfrom.GetSendVersion())
|
|
|
|
|
CSerializedNetMsg msg = CNetMsgMaker(peer.GetSendVersion())
|
|
|
|
|
.Make(NetMsgType::CFCHECKPT,
|
|
|
|
|
filter_type_ser,
|
|
|
|
|
stop_index->GetBlockHash(),
|
|
|
|
|
headers);
|
|
|
|
|
connman.PushMessage(&pfrom, std::move(msg));
|
|
|
|
|
connman.PushMessage(&peer, std::move(msg));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams, ChainstateManager& chainman, CTxMemPool& mempool, CConnman* connman, BanMan* banman, const std::atomic<bool>& interruptMsgProc)
|
|
|
|
|