Skip to content

Commit

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

NODE_XTHIN = (1 << 4),
  • Loading branch information
Peter Tschipper committed Mar 8, 2016
1 parent e63d83c commit f4984cd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
11 changes: 5 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ uint64_t nPruneTarget = 0;
bool fAlerts = DEFAULT_ALERTS;
bool fEnableReplacement = DEFAULT_ENABLE_REPLACEMENT;


/** Fees smaller than this (in satoshi) are considered zero fee (for relaying, mining and transaction creation) */
CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);

Expand Down Expand Up @@ -1057,7 +1056,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState &state, const C
// -limitfreerelay unit is thousand-bytes-per-minute
// At default rate it would take over a month to fill 1GB
LogPrint("mempool", "Rate limit dFreeCount: %g => %g\n", dFreeCount, dFreeCount+nSize);
if ((dFreeCount + nSize) >= nFreeLimit*10*1000)
if ((dFreeCount + nSize) >= (nFreeLimit*10*1000 * nLargestBlockSeen / BLOCKSTREAM_CORE_MAX_BLOCK_SIZE))
return state.DoS(0,
error("AcceptToMemoryPool : free transaction rejected by rate limiter"),
REJECT_INSUFFICIENTFEE, "rate limited free transaction");
Expand Down Expand Up @@ -4673,7 +4672,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 @@ -4689,7 +4688,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 @@ -6127,7 +6126,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 @@ -6143,7 +6142,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 @@ -493,10 +493,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 @@ -478,7 +478,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 @@ -513,7 +513,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 @@ -667,12 +674,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 f4984cd

Please sign in to comment.