Use fully static linkage #364

Closed
bvbfan wants to merge 78 commits from static_link into master
11 changed files with 92 additions and 104 deletions
Showing only changes of commit 737ee8c641 - Show all commits

View file

@ -11,43 +11,39 @@ CClaimScriptAddOp::CClaimScriptAddOp(const COutPoint& point, CAmount nValue, int
{ {
} }
bool CClaimScriptAddOp::claimName(CClaimTrieCache& trieCache, const std::string& name, bool CClaimScriptAddOp::claimName(CClaimTrieCache& trieCache, const std::string& name)
const std::vector<unsigned char>& metadata)
{ {
auto claimId = ClaimIdHash(point.hash, point.n); auto claimId = ClaimIdHash(point.hash, point.n);
LogPrint(BCLog::CLAIMS, "+++ Claim added: %s, c: %.6s, t: %.6s:%d, h: %.6d, a: %d\n", LogPrint(BCLog::CLAIMS, "+++ Claim added: %s, c: %.6s, t: %.6s:%d, h: %.6d, a: %d\n",
name, claimId.GetHex(), point.hash.GetHex(), point.n, nHeight, nValue); name, claimId.GetHex(), point.hash.GetHex(), point.n, nHeight, nValue);
return addClaim(trieCache, name, claimId, -1, metadata); return addClaim(trieCache, name, claimId, -1);
} }
bool CClaimScriptAddOp::updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool CClaimScriptAddOp::updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
const std::vector<unsigned char>& metadata)
{ {
LogPrint(BCLog::CLAIMS, "+++ Claim updated: %s, c: %.6s, t: %.6s:%d, h: %.6d, a: %d\n", LogPrint(BCLog::CLAIMS, "+++ Claim updated: %s, c: %.6s, t: %.6s:%d, h: %.6d, a: %d\n",
name, claimId.GetHex(), point.hash.GetHex(), point.n, nHeight, nValue); name, claimId.GetHex(), point.hash.GetHex(), point.n, nHeight, nValue);
return addClaim(trieCache, name, claimId, -1, metadata); return addClaim(trieCache, name, claimId, -1);
} }
bool CClaimScriptAddOp::addClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool CClaimScriptAddOp::addClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
int takeoverHeight, const std::vector<unsigned char>& metadata) int takeoverHeight)
{ {
return trieCache.addClaim(name, point, claimId, nValue, nHeight, takeoverHeight, metadata); return trieCache.addClaim(name, point, claimId, nValue, nHeight, takeoverHeight);
} }
bool CClaimScriptAddOp::supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool CClaimScriptAddOp::supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
const std::vector<unsigned char>& metadata)
{ {
LogPrint(BCLog::CLAIMS, "+++ Support added: %s, c: %.6s, t: %.6s:%d, h: %.6d, a: %d\n", LogPrint(BCLog::CLAIMS, "+++ Support added: %s, c: %.6s, t: %.6s:%d, h: %.6d, a: %d\n",
name, claimId.GetHex(), point.hash.GetHex(), point.n, nHeight, nValue); name, claimId.GetHex(), point.hash.GetHex(), point.n, nHeight, nValue);
return trieCache.addSupport(name, point, claimId, nValue, nHeight, -1, metadata); return trieCache.addSupport(name, point, claimId, nValue, nHeight, -1);
} }
CClaimScriptUndoAddOp::CClaimScriptUndoAddOp(const COutPoint& point, int nHeight) : point(point), nHeight(nHeight) CClaimScriptUndoAddOp::CClaimScriptUndoAddOp(const COutPoint& point, int nHeight) : point(point), nHeight(nHeight)
{ {
} }
bool CClaimScriptUndoAddOp::claimName(CClaimTrieCache& trieCache, const std::string& name, bool CClaimScriptUndoAddOp::claimName(CClaimTrieCache& trieCache, const std::string& name)
const std::vector<unsigned char>& metadata)
{ {
auto claimId = ClaimIdHash(point.hash, point.n); auto claimId = ClaimIdHash(point.hash, point.n);
LogPrint(BCLog::CLAIMS, "--- Undoing claim add: %s, c: %.6s, t: %.6s:%d, h: %.6d\n", LogPrint(BCLog::CLAIMS, "--- Undoing claim add: %s, c: %.6s, t: %.6s:%d, h: %.6d\n",
@ -55,8 +51,7 @@ bool CClaimScriptUndoAddOp::claimName(CClaimTrieCache& trieCache, const std::str
return undoAddClaim(trieCache, name, claimId); return undoAddClaim(trieCache, name, claimId);
} }
bool CClaimScriptUndoAddOp::updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool CClaimScriptUndoAddOp::updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
const std::vector<unsigned char>& metadata)
{ {
LogPrint(BCLog::CLAIMS, "--- Undoing claim update: %s, c: %.6s, t: %.6s:%d, h: %.6d\n", LogPrint(BCLog::CLAIMS, "--- Undoing claim update: %s, c: %.6s, t: %.6s:%d, h: %.6d\n",
name, claimId.GetHex(), point.hash.GetHex(), point.n, nHeight); name, claimId.GetHex(), point.hash.GetHex(), point.n, nHeight);
@ -73,8 +68,7 @@ bool CClaimScriptUndoAddOp::undoAddClaim(CClaimTrieCache& trieCache, const std::
return res; return res;
} }
bool CClaimScriptUndoAddOp::supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool CClaimScriptUndoAddOp::supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
const std::vector<unsigned char>& metadata)
{ {
LogPrint(BCLog::CLAIMS, "--- Undoing support add: %s, c: %.6s, t: %.6s:%d, h: %.6d\n", LogPrint(BCLog::CLAIMS, "--- Undoing support add: %s, c: %.6s, t: %.6s:%d, h: %.6d\n",
name, claimId.GetHex(), point.hash.GetHex(), point.n, nHeight); name, claimId.GetHex(), point.hash.GetHex(), point.n, nHeight);
@ -91,8 +85,7 @@ CClaimScriptSpendOp::CClaimScriptSpendOp(const COutPoint& point, int nHeight, in
{ {
} }
bool CClaimScriptSpendOp::claimName(CClaimTrieCache& trieCache, const std::string& name, bool CClaimScriptSpendOp::claimName(CClaimTrieCache& trieCache, const std::string& name)
const std::vector<unsigned char>& metadata)
{ {
auto claimId = ClaimIdHash(point.hash, point.n); auto claimId = ClaimIdHash(point.hash, point.n);
auto ret = spendClaim(trieCache, name, claimId); auto ret = spendClaim(trieCache, name, claimId);
@ -101,8 +94,7 @@ bool CClaimScriptSpendOp::claimName(CClaimTrieCache& trieCache, const std::strin
return ret; return ret;
} }
bool CClaimScriptSpendOp::updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool CClaimScriptSpendOp::updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
const std::vector<unsigned char>& metadata)
{ {
auto ret = spendClaim(trieCache, name, claimId); auto ret = spendClaim(trieCache, name, claimId);
LogPrint(BCLog::CLAIMS, "--- Spent updated claim: %s, c: %.6s, t: %.6s:%d, h: %.6d, vh: %d\n", LogPrint(BCLog::CLAIMS, "--- Spent updated claim: %s, c: %.6s, t: %.6s:%d, h: %.6d, vh: %d\n",
@ -119,8 +111,7 @@ bool CClaimScriptSpendOp::spendClaim(CClaimTrieCache& trieCache, const std::stri
return res; return res;
} }
bool CClaimScriptSpendOp::supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool CClaimScriptSpendOp::supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
const std::vector<unsigned char>& metadata)
{ {
std::string nodeName; std::string nodeName;
bool res = trieCache.removeSupport(point, nodeName, nValidHeight); bool res = trieCache.removeSupport(point, nodeName, nValidHeight);
@ -136,35 +127,31 @@ CClaimScriptUndoSpendOp::CClaimScriptUndoSpendOp(const COutPoint& point, CAmount
{ {
} }
bool CClaimScriptUndoSpendOp::claimName(CClaimTrieCache& trieCache, const std::string& name, bool CClaimScriptUndoSpendOp::claimName(CClaimTrieCache& trieCache, const std::string& name)
const std::vector<unsigned char>& metadata)
{ {
auto claimId = ClaimIdHash(point.hash, point.n); auto claimId = ClaimIdHash(point.hash, point.n);
LogPrint(BCLog::CLAIMS, "+++ Undoing original claim spend: %s, c: %.6s, t: %.6s:%d, h: %.6d, vh: %d\n", LogPrint(BCLog::CLAIMS, "+++ Undoing original claim spend: %s, c: %.6s, t: %.6s:%d, h: %.6d, vh: %d\n",
name, claimId.GetHex(), point.hash.GetHex(), point.n, nHeight, nValidHeight); name, claimId.GetHex(), point.hash.GetHex(), point.n, nHeight, nValidHeight);
return undoSpendClaim(trieCache, name, claimId, metadata); return undoSpendClaim(trieCache, name, claimId);
} }
bool CClaimScriptUndoSpendOp::updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool CClaimScriptUndoSpendOp::updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
const std::vector<unsigned char>& metadata)
{ {
LogPrint(BCLog::CLAIMS, "+++ Undoing updated claim spend: %s, c: %.6s, t: %.6s:%d, h: %.6d, vh: %d\n", LogPrint(BCLog::CLAIMS, "+++ Undoing updated claim spend: %s, c: %.6s, t: %.6s:%d, h: %.6d, vh: %d\n",
name, claimId.GetHex(), point.hash.GetHex(), point.n, nHeight, nValidHeight); name, claimId.GetHex(), point.hash.GetHex(), point.n, nHeight, nValidHeight);
return undoSpendClaim(trieCache, name, claimId, metadata); return undoSpendClaim(trieCache, name, claimId);
} }
bool CClaimScriptUndoSpendOp::undoSpendClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool CClaimScriptUndoSpendOp::undoSpendClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
const std::vector<unsigned char>& metadata)
{ {
return trieCache.addClaim(name, point, claimId, nValue, nHeight, nValidHeight, metadata); return trieCache.addClaim(name, point, claimId, nValue, nHeight, nValidHeight);
} }
bool CClaimScriptUndoSpendOp::supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool CClaimScriptUndoSpendOp::supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
const std::vector<unsigned char>& metadata)
{ {
LogPrint(BCLog::CLAIMS, "+++ Undoing support spend: %s, c: %.6s, t: %.6s:%d, h: %.6d, vh: %d\n", LogPrint(BCLog::CLAIMS, "+++ Undoing support spend: %s, c: %.6s, t: %.6s:%d, h: %.6d, vh: %d\n",
name, claimId.GetHex(), point.hash.GetHex(), point.n, nHeight, nValidHeight); name, claimId.GetHex(), point.hash.GetHex(), point.n, nHeight, nValidHeight);
return trieCache.addSupport(name, point, claimId, nValue, nHeight, nValidHeight, metadata); return trieCache.addSupport(name, point, claimId, nValue, nHeight, nValidHeight);
} }
static std::string vchToString(const std::vector<unsigned char>& name) static std::string vchToString(const std::vector<unsigned char>& name)
@ -181,13 +168,11 @@ bool ProcessClaim(CClaimScriptOp& claimOp, CClaimTrieCache& trieCache, const CSc
switch (op) { switch (op) {
case OP_CLAIM_NAME: case OP_CLAIM_NAME:
return claimOp.claimName(trieCache, vchToString(vvchParams[0]), vvchParams[1]); return claimOp.claimName(trieCache, vchToString(vvchParams[0]));
case OP_SUPPORT_CLAIM: case OP_SUPPORT_CLAIM:
return claimOp.supportClaim(trieCache, vchToString(vvchParams[0]), uint160(vvchParams[1]), return claimOp.supportClaim(trieCache, vchToString(vvchParams[0]), uint160(vvchParams[1]));
vvchParams.size() > 2 ? vvchParams[2] : std::vector<unsigned char>());
case OP_UPDATE_CLAIM: case OP_UPDATE_CLAIM:
return claimOp.updateClaim(trieCache, vchToString(vvchParams[0]), uint160(vvchParams[1]), return claimOp.updateClaim(trieCache, vchToString(vvchParams[0]), uint160(vvchParams[1]));
vvchParams[2]);
default: default:
throw std::runtime_error("Unimplemented OP handler."); throw std::runtime_error("Unimplemented OP handler.");
} }
@ -243,11 +228,10 @@ void UpdateCache(const CTransaction& tx, CClaimTrieCache& trieCache, const CCoin
public: public:
using CClaimScriptAddOp::CClaimScriptAddOp; using CClaimScriptAddOp::CClaimScriptAddOp;
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override
const std::vector<unsigned char>& metadata) override
{ {
if (callback(name, claimId)) if (callback(name, claimId))
return CClaimScriptAddOp::updateClaim(trieCache, name, claimId, metadata); return CClaimScriptAddOp::updateClaim(trieCache, name, claimId);
return false; return false;
} }
std::function<bool(const std::string& name, const uint160& claimId)> callback; std::function<bool(const std::string& name, const uint160& claimId)> callback;

View file

@ -28,24 +28,21 @@ public:
* @param[in] trieCache trie to operate on * @param[in] trieCache trie to operate on
* @param[in] name name of the claim * @param[in] name name of the claim
*/ */
virtual bool claimName(CClaimTrieCache& trieCache, const std::string& name, virtual bool claimName(CClaimTrieCache& trieCache, const std::string& name) = 0;
const std::vector<unsigned char>& metadata) = 0;
/** /**
* Pure virtual, OP_UPDATE_CLAIM handler * Pure virtual, OP_UPDATE_CLAIM handler
* @param[in] trieCache trie to operate on * @param[in] trieCache trie to operate on
* @param[in] name name of the claim * @param[in] name name of the claim
* @param[in] claimId id of the claim * @param[in] claimId id of the claim
*/ */
virtual bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, virtual bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) = 0;
const std::vector<unsigned char>& metadata) = 0;
/** /**
* Pure virtual, OP_SUPPORT_CLAIM handler * Pure virtual, OP_SUPPORT_CLAIM handler
* @param[in] trieCache trie to operate on * @param[in] trieCache trie to operate on
* @param[in] name name of the claim * @param[in] name name of the claim
* @param[in] claimId id of the claim * @param[in] claimId id of the claim
*/ */
virtual bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, virtual bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) = 0;
const std::vector<unsigned char>& metadata) = 0;
}; };
/** /**
@ -65,20 +62,17 @@ public:
* Implementation of OP_CLAIM_NAME handler * Implementation of OP_CLAIM_NAME handler
* @see CClaimScriptOp::claimName * @see CClaimScriptOp::claimName
*/ */
bool claimName(CClaimTrieCache& trieCache, const std::string& name, bool claimName(CClaimTrieCache& trieCache, const std::string& name) override;
const std::vector<unsigned char>& metadata) override;
/** /**
* Implementation of OP_UPDATE_CLAIM handler * Implementation of OP_UPDATE_CLAIM handler
* @see CClaimScriptOp::updateClaim * @see CClaimScriptOp::updateClaim
*/ */
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
const std::vector<unsigned char>& metadata) override;
/** /**
* Implementation of OP_SUPPORT_CLAIM handler * Implementation of OP_SUPPORT_CLAIM handler
* @see CClaimScriptOp::supportClaim * @see CClaimScriptOp::supportClaim
*/ */
bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
const std::vector<unsigned char>& metadata) override;
protected: protected:
/** /**
@ -87,8 +81,7 @@ protected:
* @param[in] name name of the claim * @param[in] name name of the claim
* @param[in] claimId id of the claim * @param[in] claimId id of the claim
*/ */
virtual bool addClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, virtual bool addClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, int takeoverHeight);
int takeoverHeight, const std::vector<unsigned char>& metadata);
const COutPoint point; const COutPoint point;
const CAmount nValue; const CAmount nValue;
const int nHeight; const int nHeight;
@ -110,20 +103,17 @@ public:
* Implementation of OP_CLAIM_NAME handler * Implementation of OP_CLAIM_NAME handler
* @see CClaimScriptOp::claimName * @see CClaimScriptOp::claimName
*/ */
bool claimName(CClaimTrieCache& trieCache, const std::string& name, bool claimName(CClaimTrieCache& trieCache, const std::string& name) override;
const std::vector<unsigned char>& metadata) override;
/** /**
* Implementation of OP_UPDATE_CLAIM handler * Implementation of OP_UPDATE_CLAIM handler
* @see CClaimScriptOp::updateClaim * @see CClaimScriptOp::updateClaim
*/ */
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
const std::vector<unsigned char>& metadata) override;
/** /**
* Implementation of OP_SUPPORT_CLAIM handler * Implementation of OP_SUPPORT_CLAIM handler
* @see CClaimScriptOp::supportClaim * @see CClaimScriptOp::supportClaim
*/ */
bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
const std::vector<unsigned char>& metadata) override;
protected: protected:
/** /**
@ -154,20 +144,17 @@ public:
* Implementation of OP_CLAIM_NAME handler * Implementation of OP_CLAIM_NAME handler
* @see CClaimScriptOp::claimName * @see CClaimScriptOp::claimName
*/ */
bool claimName(CClaimTrieCache& trieCache, const std::string& name, bool claimName(CClaimTrieCache& trieCache, const std::string& name) override;
const std::vector<unsigned char>& metadata) override;
/** /**
* Implementation of OP_UPDATE_CLAIM handler * Implementation of OP_UPDATE_CLAIM handler
* @see CClaimScriptOp::updateClaim * @see CClaimScriptOp::updateClaim
*/ */
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
const std::vector<unsigned char>& metadata) override;
/** /**
* Implementation of OP_SUPPORT_CLAIM handler * Implementation of OP_SUPPORT_CLAIM handler
* @see CClaimScriptOp::supportClaim * @see CClaimScriptOp::supportClaim
*/ */
bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
const std::vector<unsigned char>& metadata) override;
protected: protected:
/** /**
@ -200,20 +187,17 @@ public:
* Implementation of OP_CLAIM_NAME handler * Implementation of OP_CLAIM_NAME handler
* @see CClaimScriptOp::claimName * @see CClaimScriptOp::claimName
*/ */
bool claimName(CClaimTrieCache& trieCache, const std::string& name, bool claimName(CClaimTrieCache& trieCache, const std::string& name) override;
const std::vector<unsigned char>& metadata) override;
/** /**
* Implementation of OP_UPDATE_CLAIM handler * Implementation of OP_UPDATE_CLAIM handler
* @see CClaimScriptOp::updateClaim * @see CClaimScriptOp::updateClaim
*/ */
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
const std::vector<unsigned char>& metadata) override;
/** /**
* Implementation of OP_SUPPORT_CLAIM handler * Implementation of OP_SUPPORT_CLAIM handler
* @see CClaimScriptOp::supportClaim * @see CClaimScriptOp::supportClaim
*/ */
bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
const std::vector<unsigned char>& metadata) override;
protected: protected:
/** /**
@ -222,8 +206,7 @@ protected:
* @param[in] name name of the claim * @param[in] name name of the claim
* @param[in] claimId id of the claim * @param[in] claimId id of the claim
*/ */
virtual bool undoSpendClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, virtual bool undoSpendClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId);
const std::vector<unsigned char>& metadata);
const COutPoint point; const COutPoint point;
const CAmount nValue; const CAmount nValue;
const int nHeight; const int nHeight;

View file

@ -77,7 +77,7 @@ class TestClaimTrieTypes(unittest.TestCase):
uint160 = self.uint160 uint160 = self.uint160
claim = CClaimValue(txp, uint160, 20, 0, 0) claim = CClaimValue(txp, uint160, 20, 0, 0)
wipe = True; height = 1; data_dir = "." wipe = True; height = 1; data_dir = "."
trie = CClaimTrie(wipe, height, data_dir) trie = CClaimTrie(10*1024*1024, wipe, height, data_dir)
cache = CClaimTrieCache(trie) cache = CClaimTrieCache(trie)
self.assertTrue(trie.empty(), "incorrect CClaimtrieCache::empty") self.assertTrue(trie.empty(), "incorrect CClaimtrieCache::empty")
self.assertTrue(cache.addClaim("test", txp, uint160, 20, 0, 0), "incorrect CClaimtrieCache::addClaim") self.assertTrue(cache.addClaim("test", txp, uint160, 20, 0, 0), "incorrect CClaimtrieCache::addClaim")

View file

@ -39,7 +39,7 @@ namespace sqlite
auto ptr = sqlite3_column_blob(stmt, inx); auto ptr = sqlite3_column_blob(stmt, inx);
if (!ptr) return ret; if (!ptr) return ret;
int bytes = sqlite3_column_bytes(stmt, inx); int bytes = sqlite3_column_bytes(stmt, inx);
assert(bytes == ret.size()); assert(bytes <= ret.size());
std::memcpy(ret.begin(), ptr, bytes); std::memcpy(ret.begin(), ptr, bytes);
return ret; return ret;
} }
@ -49,7 +49,7 @@ namespace sqlite
auto ptr = sqlite3_column_blob(stmt, inx); auto ptr = sqlite3_column_blob(stmt, inx);
if (!ptr) return ret; if (!ptr) return ret;
int bytes = sqlite3_column_bytes(stmt, inx); int bytes = sqlite3_column_bytes(stmt, inx);
assert(bytes == ret.size()); assert(bytes <= ret.size());
std::memcpy(ret.begin(), ptr, bytes); std::memcpy(ret.begin(), ptr, bytes);
return ret; return ret;
} }

View file

@ -48,7 +48,7 @@ void applyPragmas(sqlite::database& db, std::size_t cache)
db << "PRAGMA case_sensitive_like=true"; db << "PRAGMA case_sensitive_like=true";
} }
CClaimTrie::CClaimTrie(int64_t cacheBytes, bool fWipe, int height, CClaimTrie::CClaimTrie(std::size_t cacheBytes, bool fWipe, int height,
const std::string& dataDir, const std::string& dataDir,
int nNormalizedNameForkHeight, int nNormalizedNameForkHeight,
int64_t nOriginalClaimExpirationTime, int64_t nOriginalClaimExpirationTime,
@ -57,6 +57,7 @@ CClaimTrie::CClaimTrie(int64_t cacheBytes, bool fWipe, int height,
int64_t nAllClaimsInMerkleForkHeight, int64_t nAllClaimsInMerkleForkHeight,
int proportionalDelayFactor) : int proportionalDelayFactor) :
nNextHeight(height), nNextHeight(height),
dbCacheBytes(cacheBytes),
dbFile(dataDir + "/claims.sqlite"), db(dbFile, sharedConfig), dbFile(dataDir + "/claims.sqlite"), db(dbFile, sharedConfig),
nProportionalDelayFactor(proportionalDelayFactor), nProportionalDelayFactor(proportionalDelayFactor),
nNormalizedNameForkHeight(nNormalizedNameForkHeight), nNormalizedNameForkHeight(nNormalizedNameForkHeight),
@ -65,6 +66,8 @@ CClaimTrie::CClaimTrie(int64_t cacheBytes, bool fWipe, int height,
nExtendedClaimExpirationForkHeight(nExtendedClaimExpirationForkHeight), nExtendedClaimExpirationForkHeight(nExtendedClaimExpirationForkHeight),
nAllClaimsInMerkleForkHeight(nAllClaimsInMerkleForkHeight) nAllClaimsInMerkleForkHeight(nAllClaimsInMerkleForkHeight)
{ {
applyPragmas(db, 5U * 1024U); // in KB
db << "CREATE TABLE IF NOT EXISTS nodes (name TEXT NOT NULL PRIMARY KEY, " db << "CREATE TABLE IF NOT EXISTS nodes (name TEXT NOT NULL PRIMARY KEY, "
"parent TEXT REFERENCES nodes(name) DEFERRABLE INITIALLY DEFERRED, " "parent TEXT REFERENCES nodes(name) DEFERRABLE INITIALLY DEFERRED, "
"hash BLOB COLLATE BINARY)"; "hash BLOB COLLATE BINARY)";
@ -81,7 +84,7 @@ CClaimTrie::CClaimTrie(int64_t cacheBytes, bool fWipe, int height,
"nodeName TEXT NOT NULL REFERENCES nodes(name) DEFERRABLE INITIALLY DEFERRED, " "nodeName TEXT NOT NULL REFERENCES nodes(name) DEFERRABLE INITIALLY DEFERRED, "
"txID BLOB NOT NULL COLLATE BINARY, txN INTEGER NOT NULL, blockHeight INTEGER NOT NULL, " "txID BLOB NOT NULL COLLATE BINARY, txN INTEGER NOT NULL, blockHeight INTEGER NOT NULL, "
"validHeight INTEGER NOT NULL, activationHeight INTEGER NOT NULL, " "validHeight INTEGER NOT NULL, activationHeight INTEGER NOT NULL, "
"expirationHeight INTEGER NOT NULL, amount INTEGER NOT NULL, metadata BLOB COLLATE BINARY);"; "expirationHeight INTEGER NOT NULL, amount INTEGER NOT NULL);";
db << "CREATE INDEX IF NOT EXISTS claims_activationHeight ON claims (activationHeight)"; db << "CREATE INDEX IF NOT EXISTS claims_activationHeight ON claims (activationHeight)";
db << "CREATE INDEX IF NOT EXISTS claims_expirationHeight ON claims (expirationHeight)"; db << "CREATE INDEX IF NOT EXISTS claims_expirationHeight ON claims (expirationHeight)";
@ -90,15 +93,13 @@ CClaimTrie::CClaimTrie(int64_t cacheBytes, bool fWipe, int height,
db << "CREATE TABLE IF NOT EXISTS supports (txID BLOB NOT NULL COLLATE BINARY, txN INTEGER NOT NULL, " db << "CREATE TABLE IF NOT EXISTS supports (txID BLOB NOT NULL COLLATE BINARY, txN INTEGER NOT NULL, "
"supportedClaimID BLOB NOT NULL COLLATE BINARY, name TEXT NOT NULL, nodeName TEXT NOT NULL, " "supportedClaimID BLOB NOT NULL COLLATE BINARY, name TEXT NOT NULL, nodeName TEXT NOT NULL, "
"blockHeight INTEGER NOT NULL, validHeight INTEGER NOT NULL, activationHeight INTEGER NOT NULL, " "blockHeight INTEGER NOT NULL, validHeight INTEGER NOT NULL, activationHeight INTEGER NOT NULL, "
"expirationHeight INTEGER NOT NULL, amount INTEGER NOT NULL, metadata BLOB COLLATE BINARY, PRIMARY KEY(txID, txN));"; "expirationHeight INTEGER NOT NULL, amount INTEGER NOT NULL, PRIMARY KEY(txID, txN));";
db << "CREATE INDEX IF NOT EXISTS supports_supportedClaimID ON supports (supportedClaimID)"; db << "CREATE INDEX IF NOT EXISTS supports_supportedClaimID ON supports (supportedClaimID)";
db << "CREATE INDEX IF NOT EXISTS supports_activationHeight ON supports (activationHeight)"; db << "CREATE INDEX IF NOT EXISTS supports_activationHeight ON supports (activationHeight)";
db << "CREATE INDEX IF NOT EXISTS supports_expirationHeight ON supports (expirationHeight)"; db << "CREATE INDEX IF NOT EXISTS supports_expirationHeight ON supports (expirationHeight)";
db << "CREATE INDEX IF NOT EXISTS supports_nodeName ON supports (nodeName)"; db << "CREATE INDEX IF NOT EXISTS supports_nodeName ON supports (nodeName)";
applyPragmas(db, std::size_t(5) * 1024); // in -KB
if (fWipe) { if (fWipe) {
db << "DELETE FROM nodes"; db << "DELETE FROM nodes";
db << "DELETE FROM claims"; db << "DELETE FROM claims";
@ -518,7 +519,7 @@ CClaimTrieCacheBase::CClaimTrieCacheBase(CClaimTrie* base)
assert(base); assert(base);
nNextHeight = base->nNextHeight; nNextHeight = base->nNextHeight;
applyPragmas(db, std::size_t(200) * 1024); // in -KB applyPragmas(db, base->dbCacheBytes >> 10U); // in KB
db.define("SIZE", [](const std::string& s) -> int { return s.size(); }); db.define("SIZE", [](const std::string& s) -> int { return s.size(); });
db.define("POPS", [](std::string s) -> std::string { if (!s.empty()) s.pop_back(); return s; }); db.define("POPS", [](std::string s) -> std::string { if (!s.empty()) s.pop_back(); return s; });
@ -578,7 +579,7 @@ bool CClaimTrieCacheBase::getLastTakeoverForName(const std::string& name, CUint1
} }
bool CClaimTrieCacheBase::addClaim(const std::string& name, const CTxOutPoint& outPoint, const CUint160& claimId, bool CClaimTrieCacheBase::addClaim(const std::string& name, const CTxOutPoint& outPoint, const CUint160& claimId,
int64_t nAmount, int nHeight, int nValidHeight, const std::vector<unsigned char>& metadata) int64_t nAmount, int nHeight, int nValidHeight)
{ {
ensureTransacting(); ensureTransacting();
@ -599,9 +600,9 @@ bool CClaimTrieCacheBase::addClaim(const std::string& name, const CTxOutPoint& o
auto nodeName = adjustNameForValidHeight(name, nValidHeight); auto nodeName = adjustNameForValidHeight(name, nValidHeight);
auto expires = expirationTime() + nHeight; auto expires = expirationTime() + nHeight;
db << "INSERT INTO claims(claimID, name, nodeName, txID, txN, amount, blockHeight, validHeight, activationHeight, expirationHeight, metadata) " db << "INSERT INTO claims(claimID, name, nodeName, txID, txN, amount, blockHeight, validHeight, activationHeight, expirationHeight) "
"VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
<< claimId << name << nodeName << outPoint.hash << outPoint.n << nAmount << nHeight << nValidHeight << nValidHeight << expires << metadata; << claimId << name << nodeName << outPoint.hash << outPoint.n << nAmount << nHeight << nValidHeight << nValidHeight << expires;
if (nValidHeight < nNextHeight) if (nValidHeight < nNextHeight)
db << "INSERT INTO nodes(name) VALUES(?) ON CONFLICT(name) DO UPDATE SET hash = NULL" << nodeName; db << "INSERT INTO nodes(name) VALUES(?) ON CONFLICT(name) DO UPDATE SET hash = NULL" << nodeName;
@ -610,7 +611,7 @@ bool CClaimTrieCacheBase::addClaim(const std::string& name, const CTxOutPoint& o
} }
bool CClaimTrieCacheBase::addSupport(const std::string& name, const CTxOutPoint& outPoint, const CUint160& supportedClaimId, bool CClaimTrieCacheBase::addSupport(const std::string& name, const CTxOutPoint& outPoint, const CUint160& supportedClaimId,
int64_t nAmount, int nHeight, int nValidHeight, const std::vector<unsigned char>& metadata) int64_t nAmount, int nHeight, int nValidHeight)
{ {
ensureTransacting(); ensureTransacting();
@ -620,9 +621,9 @@ bool CClaimTrieCacheBase::addSupport(const std::string& name, const CTxOutPoint&
auto nodeName = adjustNameForValidHeight(name, nValidHeight); auto nodeName = adjustNameForValidHeight(name, nValidHeight);
auto expires = expirationTime() + nHeight; auto expires = expirationTime() + nHeight;
db << "INSERT INTO supports(supportedClaimID, name, nodeName, txID, txN, amount, blockHeight, validHeight, activationHeight, expirationHeight, metadata) " db << "INSERT INTO supports(supportedClaimID, name, nodeName, txID, txN, amount, blockHeight, validHeight, activationHeight, expirationHeight) "
"VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
<< supportedClaimId << name << nodeName << outPoint.hash << outPoint.n << nAmount << nHeight << nValidHeight << nValidHeight << expires << metadata; << supportedClaimId << name << nodeName << outPoint.hash << outPoint.n << nAmount << nHeight << nValidHeight << nValidHeight << expires;
if (nValidHeight < nNextHeight) if (nValidHeight < nNextHeight)
db << "UPDATE nodes SET hash = NULL WHERE name = ?" << nodeName; db << "UPDATE nodes SET hash = NULL WHERE name = ?" << nodeName;

View file

@ -27,7 +27,7 @@ public:
CClaimTrie() = delete; CClaimTrie() = delete;
CClaimTrie(CClaimTrie&&) = delete; CClaimTrie(CClaimTrie&&) = delete;
CClaimTrie(const CClaimTrie&) = delete; CClaimTrie(const CClaimTrie&) = delete;
CClaimTrie(int64_t cacheBytes, bool fWipe, int height = 0, CClaimTrie(std::size_t cacheBytes, bool fWipe, int height = 0,
const std::string& dataDir = ".", const std::string& dataDir = ".",
int nNormalizedNameForkHeight = 1, int nNormalizedNameForkHeight = 1,
int64_t nOriginalClaimExpirationTime = 1, int64_t nOriginalClaimExpirationTime = 1,
@ -44,6 +44,7 @@ public:
protected: protected:
int nNextHeight; int nNextHeight;
std::size_t dbCacheBytes;
const std::string dbFile; const std::string dbFile;
sqlite::database db; sqlite::database db;
const int nProportionalDelayFactor; const int nProportionalDelayFactor;
@ -77,10 +78,10 @@ public:
bool haveSupportInQueue(const std::string& name, const CTxOutPoint& outPoint, int& nValidAtHeight) const; bool haveSupportInQueue(const std::string& name, const CTxOutPoint& outPoint, int& nValidAtHeight) const;
bool addClaim(const std::string& name, const CTxOutPoint& outPoint, const CUint160& claimId, int64_t nAmount, bool addClaim(const std::string& name, const CTxOutPoint& outPoint, const CUint160& claimId, int64_t nAmount,
int nHeight, int nValidHeight = -1, const std::vector<unsigned char>& metadata = {}); int nHeight, int nValidHeight = -1);
bool addSupport(const std::string& name, const CTxOutPoint& outPoint, const CUint160& supportedClaimId, int64_t nAmount, bool addSupport(const std::string& name, const CTxOutPoint& outPoint, const CUint160& supportedClaimId, int64_t nAmount,
int nHeight, int nValidHeight = -1, const std::vector<unsigned char>& metadata = {}); int nHeight, int nValidHeight = -1);
bool removeClaim(const CUint160& claimId, const CTxOutPoint& outPoint, std::string& nodeName, int& validHeight); bool removeClaim(const CUint160& claimId, const CTxOutPoint& outPoint, std::string& nodeName, int& validHeight);
bool removeSupport(const CTxOutPoint& outPoint, std::string& nodeName, int& validHeight); bool removeSupport(const CTxOutPoint& outPoint, std::string& nodeName, int& validHeight);

View file

@ -390,6 +390,7 @@ void SetupServerArgs()
#else #else
hidden_args.emplace_back("-sysperms"); hidden_args.emplace_back("-sysperms");
#endif #endif
gArgs.AddArg("-txindex", "Deprecated", false, OptionsCategory::HIDDEN);
gArgs.AddArg("-addnode=<ip>", "Add a node to connect to and attempt to keep the connection open (see the `addnode` RPC command help for more info). This option can be specified multiple times to add multiple nodes.", false, OptionsCategory::CONNECTION); gArgs.AddArg("-addnode=<ip>", "Add a node to connect to and attempt to keep the connection open (see the `addnode` RPC command help for more info). This option can be specified multiple times to add multiple nodes.", false, OptionsCategory::CONNECTION);
gArgs.AddArg("-banscore=<n>", strprintf("Threshold for disconnecting misbehaving peers (default: %u)", DEFAULT_BANSCORE_THRESHOLD), false, OptionsCategory::CONNECTION); gArgs.AddArg("-banscore=<n>", strprintf("Threshold for disconnecting misbehaving peers (default: %u)", DEFAULT_BANSCORE_THRESHOLD), false, OptionsCategory::CONNECTION);
gArgs.AddArg("-bantime=<n>", strprintf("Number of seconds to keep misbehaving peers from reconnecting (default: %u)", DEFAULT_MISBEHAVING_BANTIME), false, OptionsCategory::CONNECTION); gArgs.AddArg("-bantime=<n>", strprintf("Number of seconds to keep misbehaving peers from reconnecting (default: %u)", DEFAULT_MISBEHAVING_BANTIME), false, OptionsCategory::CONNECTION);
@ -1606,6 +1607,11 @@ bool AppInitMain()
::feeEstimator.Read(est_filein); ::feeEstimator.Read(est_filein);
fFeeEstimatesInitialized = true; fFeeEstimatesInitialized = true;
// ********************************************************* Step 8: start indexers
if (gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
LogPrintf("The txindex parameter is no longer necessary. It is always on.\n");
}
// ********************************************************* Step 9: load wallet // ********************************************************* Step 9: load wallet
if (!g_wallet_init_interface.Open()) return false; if (!g_wallet_init_interface.Open()) return false;

View file

@ -5,6 +5,7 @@
#include <test/test_bitcoin.h> #include <test/test_bitcoin.h>
#include <chainparams.h> #include <chainparams.h>
#include <claimtrie/forks.h>
#include <consensus/consensus.h> #include <consensus/consensus.h>
#include <consensus/validation.h> #include <consensus/validation.h>
#include <crypto/sha256.h> #include <crypto/sha256.h>
@ -148,7 +149,7 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
pcoinsdbview.reset(new CCoinsViewDB(1 << 23, true)); pcoinsdbview.reset(new CCoinsViewDB(1 << 23, true));
pcoinsTip.reset(new CCoinsViewCache(pcoinsdbview.get())); pcoinsTip.reset(new CCoinsViewCache(pcoinsdbview.get()));
auto &consensus = chainparams.GetConsensus(); auto &consensus = chainparams.GetConsensus();
pclaimTrie = new CClaimTrie(20000000, true, 0, GetDataDir().string(), pclaimTrie = new CClaimTrie(20000000U, true, 0, GetDataDir().string(),
consensus.nNormalizedNameForkHeight, consensus.nNormalizedNameForkHeight,
consensus.nOriginalClaimExpirationTime, consensus.nOriginalClaimExpirationTime,
consensus.nExtendedClaimExpirationTime, consensus.nExtendedClaimExpirationTime,

View file

@ -6,7 +6,6 @@
#define BITCOIN_TEST_TEST_BITCOIN_H #define BITCOIN_TEST_TEST_BITCOIN_H
#include <chainparamsbase.h> #include <chainparamsbase.h>
#include <claimtrie/forks.h>
#include <fs.h> #include <fs.h>
#include <key.h> #include <key.h>
#include <pubkey.h> #include <pubkey.h>
@ -138,6 +137,9 @@ std::ostream& operator<<(std::ostream& os, const COutPoint& point);
std::ostream& operator<<(std::ostream& os, const CUint256& num); std::ostream& operator<<(std::ostream& os, const CUint256& num);
std::ostream& operator<<(std::ostream& os, const CUint160& num); std::ostream& operator<<(std::ostream& os, const CUint160& num);
std::ostream& operator<<(std::ostream& os, const CTxOutPoint& point); std::ostream& operator<<(std::ostream& os, const CTxOutPoint& point);
class CClaimValue;
class CSupportValue;
std::ostream& operator<<(std::ostream& os, const CClaimValue& claim); std::ostream& operator<<(std::ostream& os, const CClaimValue& claim);
std::ostream& operator<<(std::ostream& os, const CSupportValue& support); std::ostream& operator<<(std::ostream& os, const CSupportValue& support);
#endif #endif

View file

@ -53,7 +53,7 @@ bool CCoinsViewDB::GetCoin(const COutPoint &outpoint, Coin &coin) const {
uint32_t coinbase = 0, height = 0; uint32_t coinbase = 0, height = 0;
row >> coinbase >> height >> coin.out.nValue >> coin.out.scriptPubKey; row >> coinbase >> height >> coin.out.nValue >> coin.out.scriptPubKey;
coin.fCoinBase = coinbase; coin.fCoinBase = coinbase;
coin.nHeight = coin.nHeight; coin.nHeight = height;
return true; return true;
} }
return false; return false;
@ -291,6 +291,7 @@ bool CBlockTreeDB::BatchWrite(const std::vector<std::pair<int, const CBlockFileI
<< kvp.second->nHeightFirst << kvp.second->nHeightLast << kvp.second->nTimeFirst << kvp.second->nTimeLast; << kvp.second->nHeightFirst << kvp.second->nHeightLast << kvp.second->nTimeFirst << kvp.second->nTimeLast;
ibf++; ibf++;
} }
ibf.used(true);
db << "INSERT OR REPLACE INTO flag VALUES('last_block', ?)" << nLastFile; // TODO: is this always max(file column)? db << "INSERT OR REPLACE INTO flag VALUES('last_block', ?)" << nLastFile; // TODO: is this always max(file column)?
auto ibi = db << "INSERT OR REPLACE INTO block_info(hash, prevHash, height, file, dataPos, undoPos, " auto ibi = db << "INSERT OR REPLACE INTO block_info(hash, prevHash, height, file, dataPos, undoPos, "
@ -303,6 +304,7 @@ bool CBlockTreeDB::BatchWrite(const std::vector<std::pair<int, const CBlockFileI
<< bi->nTime << bi->nBits << bi->nNonce; << bi->nTime << bi->nBits << bi->nNonce;
ibi++; ibi++;
} }
ibi.used(true);
db << "commit"; db << "commit";
// by Sync they mean disk sync: // by Sync they mean disk sync:
if (sync) { if (sync) {
@ -331,8 +333,8 @@ bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) {
bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex) bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex)
{ {
auto query = db << "SELECT hash, prevHash, height, file, dataPos, undoPos, txCount, " auto query = db << "SELECT hash, prevHash, height, file, dataPos, undoPos, txCount, "
"status, version, rootTxHash, rootTrieHash, time, bits, nonce " "version, rootTxHash, rootTrieHash, time, bits, nonce, status "
"FROM block_info ORDER BY height"; "FROM block_info"; // insertBlockIndex puts them in order
// Load mapBlockIndex // Load mapBlockIndex
for (auto&& row: query) { for (auto&& row: query) {
@ -376,6 +378,7 @@ bool CBlockTreeDB::WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos>
query << kvp.first << kvp.second.nFile << kvp.second.nPos << kvp.second.nTxOffset; query << kvp.first << kvp.second.nFile << kvp.second.nPos << kvp.second.nTxOffset;
query++; query++;
} }
query.used(true);
db << "commit"; db << "commit";
return true; return true;
} }

View file

@ -51,11 +51,18 @@ namespace sqlite {
struct has_sqlite_type<uint256, SQLITE_BLOB, void> : std::true_type {}; struct has_sqlite_type<uint256, SQLITE_BLOB, void> : std::true_type {};
inline uint256 get_col_from_db(sqlite3_stmt* stmt, int inx, result_type<uint256>) { inline uint256 get_col_from_db(sqlite3_stmt* stmt, int inx, result_type<uint256>) {
uint256 ret; auto type = sqlite3_column_type(stmt, inx);
if (type == SQLITE_NULL)
return {};
if (type == SQLITE_INTEGER)
return ArithToUint256(arith_uint256(sqlite3_column_int64(stmt, inx)));
assert(type == SQLITE_BLOB);
auto ptr = sqlite3_column_blob(stmt, inx); auto ptr = sqlite3_column_blob(stmt, inx);
uint256 ret;
if (!ptr) return ret; if (!ptr) return ret;
int bytes = sqlite3_column_bytes(stmt, inx); int bytes = sqlite3_column_bytes(stmt, inx);
assert(bytes == ret.size()); assert(bytes <= ret.size());
std::memcpy(ret.begin(), ptr, bytes); std::memcpy(ret.begin(), ptr, bytes);
return ret; return ret;
} }