Skip to content

Commit

Permalink
Added Service Bit bitcoin#4 for Xtreme Thinblocks
Browse files Browse the repository at this point in the history
Xtreme Thinblocks service enabled

NODE_XTHIN = (1 << 4),

Conflicts:
	src/main.cpp
  • Loading branch information
Peter Tschipper authored and rusty-loy committed Mar 24, 2016
1 parent 216ed6e commit 537f771
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4475,7 +4475,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
if (IsThinBlocksEnabled() && IsChainNearlySyncd()) {
if (HaveConnectThinblockNodes() || (HaveThinblockNodes() && CheckThinblockTimer(inv.hash))) {
// Must download a block from a ThinBlock peer
if (pfrom->mapThinBlocksInFlight.size() < 1 && pfrom->nVersion >= THINBLOCKS_VERSION) { // We can only send one thinblock per peer at a time
if (pfrom->mapThinBlocksInFlight.size() < 1 && pfrom->ThinBlockCapable()) { // We can only send one thinblock per peer at a time
pfrom->mapThinBlocksInFlight[inv2.hash] = GetTime();
inv2.type = MSG_XTHINBLOCK;
std::vector<uint256> vOrphanHashes;
Expand All @@ -4491,7 +4491,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
}
else {
// Try to download a thinblock if possible otherwise just download a regular block
if (pfrom->mapThinBlocksInFlight.size() < 1 && pfrom->nVersion >= THINBLOCKS_VERSION) { // We can only send one thinblock per peer at a time
if (pfrom->mapThinBlocksInFlight.size() < 1 && pfrom->ThinBlockCapable()) { // We can only send one thinblock per peer at a time
pfrom->mapThinBlocksInFlight[inv2.hash] = GetTime();
inv2.type = MSG_XTHINBLOCK;
std::vector<uint256> vOrphanHashes;
Expand Down Expand Up @@ -5922,7 +5922,7 @@ bool SendMessages(CNode* pto)
CBloomFilter filterMemPool;
if (HaveConnectThinblockNodes() || (HaveThinblockNodes() && CheckThinblockTimer(pindex->GetBlockHash()))) {
// Must download a block from a ThinBlock peer
if (pto->mapThinBlocksInFlight.size() < 1 && pto->nVersion >= THINBLOCKS_VERSION) { // We can only send one thinblock per peer at a time
if (pto->mapThinBlocksInFlight.size() < 1 && pto->ThinBlockCapable()) { // We can only send one thinblock per peer at a time
pto->mapThinBlocksInFlight[pindex->GetBlockHash()] = GetTime();
std::vector<uint256> vOrphanHashes;
for (map<uint256, COrphanTx>::iterator mi = mapOrphanTransactions.begin(); mi != mapOrphanTransactions.end(); ++mi)
Expand All @@ -5938,7 +5938,7 @@ bool SendMessages(CNode* pto)
}
else {
// Try to download a thinblock if possible otherwise just download a regular block
if (pto->mapThinBlocksInFlight.size() < 1 && pto->nVersion >= THINBLOCKS_VERSION) { // We can only send one thinblock per peer at a time
if (pto->mapThinBlocksInFlight.size() < 1 && pto->ThinBlockCapable()) { // We can only send one thinblock per peer at a time
pto->mapThinBlocksInFlight[pindex->GetBlockHash()] = GetTime();
std::vector<uint256> vOrphanHashes;
for (map<uint256, COrphanTx>::iterator mi = mapOrphanTransactions.begin(); mi != mapOrphanTransactions.end(); ++mi)
Expand Down
3 changes: 1 addition & 2 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,9 @@ class CNode
// BUIP010:
bool ThinBlockCapable()
{
if(nVersion >= THINBLOCKS_VERSION) return true;
if (nServices & NODE_XTHIN) return true;
return false;
}



void AddAddressKnown(const CAddress& addr)
Expand Down
7 changes: 7 additions & 0 deletions src/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ enum {
// but no longer do as of protocol version 70011 (= NO_BLOOM_VERSION)
NODE_BLOOM = (1 << 2),

// BUIP010 - Xtreme Thinblocks - begin section
// NODE_XTHIN means the node supports Xtreme Thinblocks
// If this is turned off then the node will not service xthin requests nor
// make xthin requests
NODE_XTHIN = (1 << 4),
// BUIP010 - Xtreme Thinblocks - end section

// Bits 24-31 are reserved for temporary experiments. Just pick a bit that
// isn't getting used, or one not being used much, and notify the
// bitcoin-development mailing list. Remember that service bits are just
Expand Down
3 changes: 3 additions & 0 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,9 @@ QString formatServicesStr(quint64 mask)
case NODE_BLOOM:
strList.append("BLOOM");
break;
case NODE_XTHIN:
strList.append("XTHIN");
break;
default:
strList.append(QString("%1[%2]").arg("UNKNOWN").arg(check));
}
Expand Down
25 changes: 17 additions & 8 deletions src/unlimited.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ bool HaveThinblockNodes()
{
LOCK(cs_vNodes);
BOOST_FOREACH (CNode* pnode, vNodes)
if (pnode->nVersion >= THINBLOCKS_VERSION)
if (pnode->ThinBlockCapable())
return true;
}
return false;
Expand Down Expand Up @@ -122,7 +122,14 @@ void ClearThinBlockTimer(uint256 hash)

bool IsThinBlocksEnabled()
{
return GetBoolArg("-use-thinblocks", true);
bool fThinblocksEnabled = GetBoolArg("-use-thinblocks", true);

// Enabling the XTHIN service should really be in init.cpp but because
// we want to avoid possile future merge conflicts with Core we can enable
// it here as it has little performance impact.
if (fThinblocksEnabled)
nLocalServices |= NODE_XTHIN;
return fThinblocksEnabled;
}

bool IsChainNearlySyncd()
Expand Down Expand Up @@ -271,12 +278,14 @@ void ConnectToThinBlockNodes()

void CheckNodeSupportForThinBlocks()
{
// Check that a nodes pointed to with connect-thinblock actually supports thinblocks
BOOST_FOREACH(string& strAddr, mapMultiArgs["-connect-thinblock"]) {
if(CNode* pnode = FindNode(strAddr)) {
if(pnode->nVersion < THINBLOCKS_VERSION && pnode->nVersion > 0) {
LogPrintf("ERROR: You are trying to use connect-thinblocks but to a node that does not support it - Protocol Version: %d peer=%d\n",
pnode->nVersion, pnode->id);
if(IsThinBlocksEnabled()) {
// Check that a nodes pointed to with connect-thinblock actually supports thinblocks
BOOST_FOREACH(string& strAddr, mapMultiArgs["-connect-thinblock"]) {
if(CNode* pnode = FindNode(strAddr)) {
if(!pnode->ThinBlockCapable()) {
LogPrintf("ERROR: You are trying to use connect-thinblocks but to a node that does not support it - Protocol Version: %d peer=%d\n",
pnode->nVersion, pnode->id);
}
}
}
}
Expand Down

0 comments on commit 537f771

Please sign in to comment.