Skip to content

Commit c602f23

Browse files
committed
Fixed CInv::IsKnownType()
1 parent 0f9efb0 commit c602f23

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/protocol.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ bool operator<(const CInv& a, const CInv& b)
184184

185185
bool CInv::IsKnownType() const
186186
{
187-
return (type >= 1 && type < (int)ARRAYLEN(ppszTypeName));
187+
int masked = type & MSG_TYPE_MASK;
188+
return (masked >= 1 && masked <= MSG_TYPE_MAX);
188189
}
189190

190191
const char* CInv::GetCommand() const

src/protocol.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,17 @@ class CInv
315315
uint256 hash;
316316
};
317317

318+
const uint32_t MSG_WITNESS_FLAG = 1 << 30;
319+
const uint32_t MSG_TYPE_MASK = 0xffffffff >> 2;
318320
enum {
319321
MSG_TX = 1,
320322
MSG_BLOCK,
321323
// The following can only occur in getdata. Invs always use TX or BLOCK.
322324
MSG_FILTERED_BLOCK,
323-
MSG_WITNESS_BLOCK = MSG_BLOCK | 0x40000000,
324-
MSG_WITNESS_TX = MSG_TX | 0x40000000,
325+
MSG_WITNESS_BLOCK = MSG_BLOCK | MSG_WITNESS_FLAG,
326+
MSG_WITNESS_TX = MSG_TX | MSG_WITNESS_FLAG,
325327
};
326328

329+
const int MSG_TYPE_MAX = MSG_FILTERED_BLOCK;
330+
327331
#endif // BITCOIN_PROTOCOL_H

0 commit comments

Comments
 (0)