@@ -775,6 +775,7 @@ static CCriticalSection cs_most_recent_block;
775
775
static std::shared_ptr<const CBlock> most_recent_block;
776
776
static std::shared_ptr<const CBlockHeaderAndShortTxIDs> most_recent_compact_block;
777
777
static uint256 most_recent_block_hash;
778
+ static bool fWitnessesPresentInMostRecentCompactBlock ;
778
779
779
780
void PeerLogicValidation::NewPoWValidBlock (const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) {
780
781
std::shared_ptr<const CBlockHeaderAndShortTxIDs> pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs> (*pblock, true );
@@ -795,6 +796,7 @@ void PeerLogicValidation::NewPoWValidBlock(const CBlockIndex *pindex, const std:
795
796
most_recent_block_hash = hashBlock;
796
797
most_recent_block = pblock;
797
798
most_recent_compact_block = pcmpctblock;
799
+ fWitnessesPresentInMostRecentCompactBlock = fWitnessEnabled ;
798
800
}
799
801
800
802
connman->ForEachNode ([this , &pcmpctblock, pindex, &msgMaker, fWitnessEnabled , &hashBlock](CNode* pnode) {
@@ -981,10 +983,12 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
981
983
BlockMap::iterator mi = mapBlockIndex.find (inv.hash );
982
984
std::shared_ptr<const CBlock> a_recent_block;
983
985
std::shared_ptr<const CBlockHeaderAndShortTxIDs> a_recent_compact_block;
986
+ bool fWitnessesPresentInARecentCompactBlock ;
984
987
{
985
988
LOCK (cs_most_recent_block);
986
989
a_recent_block = most_recent_block;
987
990
a_recent_compact_block = most_recent_compact_block;
991
+ fWitnessesPresentInARecentCompactBlock = fWitnessesPresentInMostRecentCompactBlock ;
988
992
}
989
993
if (mi != mapBlockIndex.end ())
990
994
{
@@ -1077,7 +1081,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
1077
1081
bool fPeerWantsWitness = State (pfrom->GetId ())->fWantsCmpctWitness ;
1078
1082
int nSendFlags = fPeerWantsWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
1079
1083
if (CanDirectFetch (consensusParams) && mi->second ->nHeight >= chainActive.Height () - MAX_CMPCTBLOCK_DEPTH) {
1080
- if (fPeerWantsWitness && a_recent_compact_block && a_recent_compact_block->header .GetHash () == mi->second ->GetBlockHash ()) {
1084
+ if (( fPeerWantsWitness || ! fWitnessesPresentInARecentCompactBlock ) && a_recent_compact_block && a_recent_compact_block->header .GetHash () == mi->second ->GetBlockHash ()) {
1081
1085
connman.PushMessage (pfrom, msgMaker.Make (nSendFlags, NetMsgType::CMPCTBLOCK, *a_recent_compact_block));
1082
1086
} else {
1083
1087
CBlockHeaderAndShortTxIDs cmpctblock (*pblock, fPeerWantsWitness );
@@ -2941,7 +2945,7 @@ bool SendMessages(CNode* pto, CConnman& connman, std::atomic<bool>& interruptMsg
2941
2945
{
2942
2946
LOCK (cs_most_recent_block);
2943
2947
if (most_recent_block_hash == pBestIndex->GetBlockHash ()) {
2944
- if (state.fWantsCmpctWitness )
2948
+ if (state.fWantsCmpctWitness || ! fWitnessesPresentInMostRecentCompactBlock )
2945
2949
connman.PushMessage (pto, msgMaker.Make (nSendFlags, NetMsgType::CMPCTBLOCK, *most_recent_compact_block));
2946
2950
else {
2947
2951
CBlockHeaderAndShortTxIDs cmpctblock (*most_recent_block, state.fWantsCmpctWitness );
0 commit comments