fixed restart issues, ditched metadata column

This commit is contained in:
Brannon King 2019-12-10 17:17:22 -07:00
parent 19300d269e
commit 737ee8c641
11 changed files with 92 additions and 104 deletions

View file

@ -11,43 +11,39 @@ CClaimScriptAddOp::CClaimScriptAddOp(const COutPoint& point, CAmount nValue, int
{
}
bool CClaimScriptAddOp::claimName(CClaimTrieCache& trieCache, const std::string& name,
const std::vector<unsigned char>& metadata)
bool CClaimScriptAddOp::claimName(CClaimTrieCache& trieCache, const std::string& name)
{
auto claimId = ClaimIdHash(point.hash, point.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);
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,
const std::vector<unsigned char>& metadata)
bool CClaimScriptAddOp::updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
{
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);
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,
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,
const std::vector<unsigned char>& metadata)
bool CClaimScriptAddOp::supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
{
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);
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)
{
}
bool CClaimScriptUndoAddOp::claimName(CClaimTrieCache& trieCache, const std::string& name,
const std::vector<unsigned char>& metadata)
bool CClaimScriptUndoAddOp::claimName(CClaimTrieCache& trieCache, const std::string& name)
{
auto claimId = ClaimIdHash(point.hash, point.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);
}
bool CClaimScriptUndoAddOp::updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
const std::vector<unsigned char>& metadata)
bool CClaimScriptUndoAddOp::updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
{
LogPrint(BCLog::CLAIMS, "--- Undoing claim update: %s, c: %.6s, t: %.6s:%d, h: %.6d\n",
name, claimId.GetHex(), point.hash.GetHex(), point.n, nHeight);
@ -73,8 +68,7 @@ bool CClaimScriptUndoAddOp::undoAddClaim(CClaimTrieCache& trieCache, const std::
return res;
}
bool CClaimScriptUndoAddOp::supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
const std::vector<unsigned char>& metadata)
bool CClaimScriptUndoAddOp::supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
{
LogPrint(BCLog::CLAIMS, "--- Undoing support add: %s, c: %.6s, t: %.6s:%d, h: %.6d\n",
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,
const std::vector<unsigned char>& metadata)
bool CClaimScriptSpendOp::claimName(CClaimTrieCache& trieCache, const std::string& name)
{
auto claimId = ClaimIdHash(point.hash, point.n);
auto ret = spendClaim(trieCache, name, claimId);
@ -101,8 +94,7 @@ bool CClaimScriptSpendOp::claimName(CClaimTrieCache& trieCache, const std::strin
return ret;
}
bool CClaimScriptSpendOp::updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
const std::vector<unsigned char>& metadata)
bool CClaimScriptSpendOp::updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
{
auto ret = spendClaim(trieCache, name, claimId);
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;
}
bool CClaimScriptSpendOp::supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
const std::vector<unsigned char>& metadata)
bool CClaimScriptSpendOp::supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
{
std::string nodeName;
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,
const std::vector<unsigned char>& metadata)
bool CClaimScriptUndoSpendOp::claimName(CClaimTrieCache& trieCache, const std::string& name)
{
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",
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,
const std::vector<unsigned char>& metadata)
bool CClaimScriptUndoSpendOp::updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
{
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);
return undoSpendClaim(trieCache, name, claimId, metadata);
return undoSpendClaim(trieCache, name, claimId);
}
bool CClaimScriptUndoSpendOp::undoSpendClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
const std::vector<unsigned char>& metadata)
bool CClaimScriptUndoSpendOp::undoSpendClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
{
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,
const std::vector<unsigned char>& metadata)
bool CClaimScriptUndoSpendOp::supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
{
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);
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)
@ -181,13 +168,11 @@ bool ProcessClaim(CClaimScriptOp& claimOp, CClaimTrieCache& trieCache, const CSc
switch (op) {
case OP_CLAIM_NAME:
return claimOp.claimName(trieCache, vchToString(vvchParams[0]), vvchParams[1]);
return claimOp.claimName(trieCache, vchToString(vvchParams[0]));
case OP_SUPPORT_CLAIM:
return claimOp.supportClaim(trieCache, vchToString(vvchParams[0]), uint160(vvchParams[1]),
vvchParams.size() > 2 ? vvchParams[2] : std::vector<unsigned char>());
return claimOp.supportClaim(trieCache, vchToString(vvchParams[0]), uint160(vvchParams[1]));
case OP_UPDATE_CLAIM:
return claimOp.updateClaim(trieCache, vchToString(vvchParams[0]), uint160(vvchParams[1]),
vvchParams[2]);
return claimOp.updateClaim(trieCache, vchToString(vvchParams[0]), uint160(vvchParams[1]));
default:
throw std::runtime_error("Unimplemented OP handler.");
}
@ -243,11 +228,10 @@ void UpdateCache(const CTransaction& tx, CClaimTrieCache& trieCache, const CCoin
public:
using CClaimScriptAddOp::CClaimScriptAddOp;
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
const std::vector<unsigned char>& metadata) override
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override
{
if (callback(name, claimId))
return CClaimScriptAddOp::updateClaim(trieCache, name, claimId, metadata);
return CClaimScriptAddOp::updateClaim(trieCache, name, claimId);
return false;
}
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] name name of the claim
*/
virtual bool claimName(CClaimTrieCache& trieCache, const std::string& name,
const std::vector<unsigned char>& metadata) = 0;
virtual bool claimName(CClaimTrieCache& trieCache, const std::string& name) = 0;
/**
* Pure virtual, OP_UPDATE_CLAIM handler
* @param[in] trieCache trie to operate on
* @param[in] name name of the claim
* @param[in] claimId id of the claim
*/
virtual bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
const std::vector<unsigned char>& metadata) = 0;
virtual bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) = 0;
/**
* Pure virtual, OP_SUPPORT_CLAIM handler
* @param[in] trieCache trie to operate on
* @param[in] name name of the claim
* @param[in] claimId id of the claim
*/
virtual bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
const std::vector<unsigned char>& metadata) = 0;
virtual bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) = 0;
};
/**
@ -65,20 +62,17 @@ public:
* Implementation of OP_CLAIM_NAME handler
* @see CClaimScriptOp::claimName
*/
bool claimName(CClaimTrieCache& trieCache, const std::string& name,
const std::vector<unsigned char>& metadata) override;
bool claimName(CClaimTrieCache& trieCache, const std::string& name) override;
/**
* Implementation of OP_UPDATE_CLAIM handler
* @see CClaimScriptOp::updateClaim
*/
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
const std::vector<unsigned char>& metadata) override;
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
/**
* Implementation of OP_SUPPORT_CLAIM handler
* @see CClaimScriptOp::supportClaim
*/
bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
const std::vector<unsigned char>& metadata) override;
bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
protected:
/**
@ -87,8 +81,7 @@ protected:
* @param[in] name name of the claim
* @param[in] claimId id of the claim
*/
virtual bool addClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
int takeoverHeight, const std::vector<unsigned char>& metadata);
virtual bool addClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId, int takeoverHeight);
const COutPoint point;
const CAmount nValue;
const int nHeight;
@ -110,20 +103,17 @@ public:
* Implementation of OP_CLAIM_NAME handler
* @see CClaimScriptOp::claimName
*/
bool claimName(CClaimTrieCache& trieCache, const std::string& name,
const std::vector<unsigned char>& metadata) override;
bool claimName(CClaimTrieCache& trieCache, const std::string& name) override;
/**
* Implementation of OP_UPDATE_CLAIM handler
* @see CClaimScriptOp::updateClaim
*/
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
const std::vector<unsigned char>& metadata) override;
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
/**
* Implementation of OP_SUPPORT_CLAIM handler
* @see CClaimScriptOp::supportClaim
*/
bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
const std::vector<unsigned char>& metadata) override;
bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
protected:
/**
@ -154,20 +144,17 @@ public:
* Implementation of OP_CLAIM_NAME handler
* @see CClaimScriptOp::claimName
*/
bool claimName(CClaimTrieCache& trieCache, const std::string& name,
const std::vector<unsigned char>& metadata) override;
bool claimName(CClaimTrieCache& trieCache, const std::string& name) override;
/**
* Implementation of OP_UPDATE_CLAIM handler
* @see CClaimScriptOp::updateClaim
*/
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
const std::vector<unsigned char>& metadata) override;
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
/**
* Implementation of OP_SUPPORT_CLAIM handler
* @see CClaimScriptOp::supportClaim
*/
bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
const std::vector<unsigned char>& metadata) override;
bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
protected:
/**
@ -200,20 +187,17 @@ public:
* Implementation of OP_CLAIM_NAME handler
* @see CClaimScriptOp::claimName
*/
bool claimName(CClaimTrieCache& trieCache, const std::string& name,
const std::vector<unsigned char>& metadata) override;
bool claimName(CClaimTrieCache& trieCache, const std::string& name) override;
/**
* Implementation of OP_UPDATE_CLAIM handler
* @see CClaimScriptOp::updateClaim
*/
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
const std::vector<unsigned char>& metadata) override;
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
/**
* Implementation of OP_SUPPORT_CLAIM handler
* @see CClaimScriptOp::supportClaim
*/
bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
const std::vector<unsigned char>& metadata) override;
bool supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override;
protected:
/**
@ -222,8 +206,7 @@ protected:
* @param[in] name name of the claim
* @param[in] claimId id of the claim
*/
virtual bool undoSpendClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId,
const std::vector<unsigned char>& metadata);
virtual bool undoSpendClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId);
const COutPoint point;
const CAmount nValue;
const int nHeight;

View file

@ -77,7 +77,7 @@ class TestClaimTrieTypes(unittest.TestCase):
uint160 = self.uint160
claim = CClaimValue(txp, uint160, 20, 0, 0)
wipe = True; height = 1; data_dir = "."
trie = CClaimTrie(wipe, height, data_dir)
trie = CClaimTrie(10*1024*1024, wipe, height, data_dir)
cache = CClaimTrieCache(trie)
self.assertTrue(trie.empty(), "incorrect CClaimtrieCache::empty")
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);
if (!ptr) return ret;
int bytes = sqlite3_column_bytes(stmt, inx);
assert(bytes == ret.size());
assert(bytes <= ret.size());
std::memcpy(ret.begin(), ptr, bytes);
return ret;
}
@ -49,7 +49,7 @@ namespace sqlite
auto ptr = sqlite3_column_blob(stmt, inx);
if (!ptr) return ret;
int bytes = sqlite3_column_bytes(stmt, inx);
assert(bytes == ret.size());
assert(bytes <= ret.size());
std::memcpy(ret.begin(), ptr, bytes);
return ret;
}

View file

@ -48,7 +48,7 @@ void applyPragmas(sqlite::database& db, std::size_t cache)
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,
int nNormalizedNameForkHeight,
int64_t nOriginalClaimExpirationTime,
@ -57,6 +57,7 @@ CClaimTrie::CClaimTrie(int64_t cacheBytes, bool fWipe, int height,
int64_t nAllClaimsInMerkleForkHeight,
int proportionalDelayFactor) :
nNextHeight(height),
dbCacheBytes(cacheBytes),
dbFile(dataDir + "/claims.sqlite"), db(dbFile, sharedConfig),
nProportionalDelayFactor(proportionalDelayFactor),
nNormalizedNameForkHeight(nNormalizedNameForkHeight),
@ -65,6 +66,8 @@ CClaimTrie::CClaimTrie(int64_t cacheBytes, bool fWipe, int height,
nExtendedClaimExpirationForkHeight(nExtendedClaimExpirationForkHeight),
nAllClaimsInMerkleForkHeight(nAllClaimsInMerkleForkHeight)
{
applyPragmas(db, 5U * 1024U); // in KB
db << "CREATE TABLE IF NOT EXISTS nodes (name TEXT NOT NULL PRIMARY KEY, "
"parent TEXT REFERENCES nodes(name) DEFERRABLE INITIALLY DEFERRED, "
"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, "
"txID BLOB NOT NULL COLLATE BINARY, txN 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);";
"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_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, "
"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, "
"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_activationHeight ON supports (activationHeight)";
db << "CREATE INDEX IF NOT EXISTS supports_expirationHeight ON supports (expirationHeight)";
db << "CREATE INDEX IF NOT EXISTS supports_nodeName ON supports (nodeName)";
applyPragmas(db, std::size_t(5) * 1024); // in -KB
if (fWipe) {
db << "DELETE FROM nodes";
db << "DELETE FROM claims";
@ -518,7 +519,7 @@ CClaimTrieCacheBase::CClaimTrieCacheBase(CClaimTrie* base)
assert(base);
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("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,
int64_t nAmount, int nHeight, int nValidHeight, const std::vector<unsigned char>& metadata)
int64_t nAmount, int nHeight, int nValidHeight)
{
ensureTransacting();
@ -599,9 +600,9 @@ bool CClaimTrieCacheBase::addClaim(const std::string& name, const CTxOutPoint& o
auto nodeName = adjustNameForValidHeight(name, nValidHeight);
auto expires = expirationTime() + nHeight;
db << "INSERT INTO claims(claimID, name, nodeName, txID, txN, amount, blockHeight, validHeight, activationHeight, expirationHeight, metadata) "
"VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
<< claimId << name << nodeName << outPoint.hash << outPoint.n << nAmount << nHeight << nValidHeight << nValidHeight << expires << metadata;
db << "INSERT INTO claims(claimID, name, nodeName, txID, txN, amount, blockHeight, validHeight, activationHeight, expirationHeight) "
"VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
<< claimId << name << nodeName << outPoint.hash << outPoint.n << nAmount << nHeight << nValidHeight << nValidHeight << expires;
if (nValidHeight < nNextHeight)
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,
int64_t nAmount, int nHeight, int nValidHeight, const std::vector<unsigned char>& metadata)
int64_t nAmount, int nHeight, int nValidHeight)
{
ensureTransacting();
@ -620,9 +621,9 @@ bool CClaimTrieCacheBase::addSupport(const std::string& name, const CTxOutPoint&
auto nodeName = adjustNameForValidHeight(name, nValidHeight);
auto expires = expirationTime() + nHeight;
db << "INSERT INTO supports(supportedClaimID, name, nodeName, txID, txN, amount, blockHeight, validHeight, activationHeight, expirationHeight, metadata) "
"VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
<< supportedClaimId << name << nodeName << outPoint.hash << outPoint.n << nAmount << nHeight << nValidHeight << nValidHeight << expires << metadata;
db << "INSERT INTO supports(supportedClaimID, name, nodeName, txID, txN, amount, blockHeight, validHeight, activationHeight, expirationHeight) "
"VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
<< supportedClaimId << name << nodeName << outPoint.hash << outPoint.n << nAmount << nHeight << nValidHeight << nValidHeight << expires;
if (nValidHeight < nNextHeight)
db << "UPDATE nodes SET hash = NULL WHERE name = ?" << nodeName;

View file

@ -27,7 +27,7 @@ public:
CClaimTrie() = delete;
CClaimTrie(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 = ".",
int nNormalizedNameForkHeight = 1,
int64_t nOriginalClaimExpirationTime = 1,
@ -44,6 +44,7 @@ public:
protected:
int nNextHeight;
std::size_t dbCacheBytes;
const std::string dbFile;
sqlite::database db;
const int nProportionalDelayFactor;
@ -77,10 +78,10 @@ public:
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,
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,
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 removeSupport(const CTxOutPoint& outPoint, std::string& nodeName, int& validHeight);

View file

@ -390,6 +390,7 @@ void SetupServerArgs()
#else
hidden_args.emplace_back("-sysperms");
#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("-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);
@ -1606,6 +1607,11 @@ bool AppInitMain()
::feeEstimator.Read(est_filein);
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
if (!g_wallet_init_interface.Open()) return false;

View file

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

View file

@ -6,7 +6,6 @@
#define BITCOIN_TEST_TEST_BITCOIN_H
#include <chainparamsbase.h>
#include <claimtrie/forks.h>
#include <fs.h>
#include <key.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 CUint160& num);
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 CSupportValue& support);
#endif

View file

@ -53,7 +53,7 @@ bool CCoinsViewDB::GetCoin(const COutPoint &outpoint, Coin &coin) const {
uint32_t coinbase = 0, height = 0;
row >> coinbase >> height >> coin.out.nValue >> coin.out.scriptPubKey;
coin.fCoinBase = coinbase;
coin.nHeight = coin.nHeight;
coin.nHeight = height;
return true;
}
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;
ibf++;
}
ibf.used(true);
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, "
@ -303,6 +304,7 @@ bool CBlockTreeDB::BatchWrite(const std::vector<std::pair<int, const CBlockFileI
<< bi->nTime << bi->nBits << bi->nNonce;
ibi++;
}
ibi.used(true);
db << "commit";
// by Sync they mean disk 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)
{
auto query = db << "SELECT hash, prevHash, height, file, dataPos, undoPos, txCount, "
"status, version, rootTxHash, rootTrieHash, time, bits, nonce "
"FROM block_info ORDER BY height";
"version, rootTxHash, rootTrieHash, time, bits, nonce, status "
"FROM block_info"; // insertBlockIndex puts them in order
// Load mapBlockIndex
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++;
}
query.used(true);
db << "commit";
return true;
}

View file

@ -51,11 +51,18 @@ namespace sqlite {
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>) {
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);
uint256 ret;
if (!ptr) return ret;
int bytes = sqlite3_column_bytes(stmt, inx);
assert(bytes == ret.size());
assert(bytes <= ret.size());
std::memcpy(ret.begin(), ptr, bytes);
return ret;
}