Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
873c597ba6 | ||
|
|
1804bba558 | ||
|
|
a8555a5515 | ||
|
|
f92e12511b | ||
|
|
45064b6b7b | ||
|
|
776da644eb | ||
|
|
76e68b04d0 | ||
|
|
043e17d85d | ||
|
|
e9f2f4be9e | ||
|
|
39e2f3e5bc | ||
|
|
b18091f63c | ||
|
|
55730549af | ||
|
|
7af6e43bb5 |
No files matched your search
@@ -24,11 +24,13 @@ jobs:
|
||||
- mkdir -p ${HOME}/ccache
|
||||
- docker pull $DOCKER_BUILD_IMAGE
|
||||
script:
|
||||
- echo "build..."
|
||||
- docker run -v "$(pwd):/lbrycrd" -v "${HOME}/ccache:/ccache" -w /lbrycrd -e CCACHE_DIR=/ccache ${DOCKER_IMAGE} packaging/build_${NAME}_64bit.sh
|
||||
before_deploy:
|
||||
- mkdir -p dist
|
||||
- sudo zip -Xj dist/lbrycrd-${NAME}.zip src/lbrycrdd${EXT} src/lbrycrd-cli${EXT} src/lbrycrd-tx${EXT}
|
||||
- sudo zip -Xj dist/lbrycrd-${NAME}-test.zip src/test/test_lbrycrd${EXT} src/test/test_lbrycrd_fuzzy${EXT}
|
||||
- sudo cp dist/lbrycrd-${NAME}.zip packaging/docker-for-binary/lbrycrd-${NAME}.zip
|
||||
- sha256sum dist/lbrycrd-${NAME}.zip
|
||||
- sha256sum dist/lbrycrd-${NAME}-test.zip
|
||||
deploy:
|
||||
@@ -44,6 +46,13 @@ jobs:
|
||||
on:
|
||||
repo: lbryio/lbrycrd
|
||||
all_branches: true
|
||||
- provider: script
|
||||
script: bash packaging/docker-for-binary/auto_deploy.sh ${TRAVIS_BRANCH}
|
||||
skip_cleanup: true
|
||||
on:
|
||||
repo: lbryio/lbrycrd
|
||||
all_branches: true
|
||||
condition: $NAME = linux
|
||||
|
||||
- <<: *build-template
|
||||
name: windows
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-2019 LBRY Inc
|
||||
Copyright (c) 2015-2020 LBRY Inc
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ AC_PREREQ([2.60])
|
||||
define(_CLIENT_VERSION_MAJOR, 0)
|
||||
define(_CLIENT_VERSION_MINOR, 17)
|
||||
define(_CLIENT_VERSION_REVISION, 4)
|
||||
define(_CLIENT_VERSION_BUILD, 1)
|
||||
define(_CLIENT_VERSION_BUILD, 2)
|
||||
define(_CLIENT_VERSION_IS_RELEASE, true)
|
||||
define(_COPYRIGHT_YEAR, 2019)
|
||||
define(_COPYRIGHT_HOLDERS,[The %s developers])
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
FROM ubuntu:18.04 as prep
|
||||
LABEL MAINTAINER="leopere [at] nixc [dot] us"
|
||||
## TODO: Implement version pinning. `apt-get install curl=<version>`
|
||||
RUN apt-get update && \
|
||||
apt-get -y install unzip curl build-essential && \
|
||||
apt-get autoclean -y && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
WORKDIR /
|
||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||
COPY ./stuff/start.sh start
|
||||
COPY ./stuff/healthcheck.sh healthcheck
|
||||
COPY ./stuff/advance_blocks.sh advance
|
||||
COPY ./stuff/fix-permissions.c fix-permissions.c
|
||||
COPY ./lbrycrd-linux.zip lbrycrd-linux.zip
|
||||
|
||||
RUN unzip ./lbrycrd-linux.zip && \
|
||||
gcc fix-permissions.c -o fix-permissions && \
|
||||
chmod +x ./lbrycrdd ./lbrycrd-cli ./lbrycrd-tx ./start ./healthcheck ./fix-permissions ./advance
|
||||
|
||||
FROM ubuntu:18.04 as app
|
||||
COPY --from=prep /lbrycrdd /lbrycrd-cli /lbrycrd-tx /start /healthcheck /fix-permissions /advance /usr/bin/
|
||||
RUN addgroup --gid 1000 lbrycrd && \
|
||||
adduser lbrycrd --uid 1000 --gid 1000 --gecos GECOS --shell /bin/bash --disabled-password --home /data && \
|
||||
mkdir /etc/lbry && \
|
||||
chown lbrycrd /etc/lbry && \
|
||||
chmod a+s /usr/bin/fix-permissions
|
||||
RUN apt-get update && apt-get -y install wget && apt-get autoclean -y && rm -rf /var/lib/apt/lists/*
|
||||
VOLUME ["/data"]
|
||||
WORKDIR /data
|
||||
HEALTHCHECK CMD /usr/bin/healthcheck
|
||||
EXPOSE 9246 9245 11337 29245
|
||||
|
||||
USER lbrycrd
|
||||
CMD ["start"]
|
||||
@@ -1,5 +1,36 @@
|
||||
# lbrycrd Docker image
|
||||
`
|
||||
|
||||
## Scripts
|
||||
|
||||
There are two scripts `deploy.sh` and `auto_deploy.sh` These are used to create
|
||||
docker images to push to lbry's Docker Hub.
|
||||
|
||||
### `auto_deploy.sh`
|
||||
|
||||
This script is used by the LBRYcrd's CI. When a branch or tag is built
|
||||
it will create a docker image for it and push it to DockerHub. This should
|
||||
not be used outside of the CI environment. In addition to this, the
|
||||
`Dockerfile.Auto` is associated with this script. This will only run on the
|
||||
Linux build job.
|
||||
|
||||
#### Requirements
|
||||
|
||||
- You would need to build lbrycrd with the Docker image for reproducible
|
||||
builds. https://hub.docker.com/repository/docker/lbry/build_lbrycrd
|
||||
- You will need DockerHub credentials to run this locally.
|
||||
- When the script is executed you will need the parameter as
|
||||
`./auto_deploy.sh ${tag_name}`
|
||||
|
||||
### `deploy.sh`
|
||||
|
||||
This can be used locally to manually create a docker image based on a
|
||||
release. `release_url` is requested as a parameter to the script when
|
||||
run locally. This will grab the binary from github releases inside the
|
||||
image build.
|
||||
|
||||
#### Requirements
|
||||
|
||||
- You will need DockerHub credentials to run this locally.
|
||||
|
||||
## Configuration
|
||||
|
||||
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
set -euo pipefail
|
||||
hash docker 2>/dev/null || { echo >&2 'Make sure Docker is installed'; exit 1; }
|
||||
|
||||
set +eo pipefail
|
||||
docker version | grep -q Server
|
||||
ret=$?
|
||||
set -eo pipefail
|
||||
|
||||
if [ $ret -ne 0 ]; then
|
||||
echo "Cannot connect to Docker server. Is it running? Do you have the right user permissions?"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "Docker tag parameter cannot be empty"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd packaging/docker-for-binary
|
||||
docker build --tag "lbry/lbrycrd:$1" -f Dockerfile.Auto "$DIR"
|
||||
echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin
|
||||
docker push "lbry/lbrycrd:$1"
|
||||
@@ -254,14 +254,14 @@ uint256 CClaimTrieCacheHashFork::computeNodeHash(const std::string& name, int ta
|
||||
childHashQuery++;
|
||||
|
||||
std::vector<uint256> claimHashes;
|
||||
//if (takeoverHeight > 0) {
|
||||
if (takeoverHeight > 0) {
|
||||
COutPoint p;
|
||||
for (auto &&row: claimHashQuery << nNextHeight << name) {
|
||||
row >> p.hash >> p.n;
|
||||
claimHashes.push_back(getValueHash(p, takeoverHeight));
|
||||
}
|
||||
claimHashQuery++;
|
||||
//}
|
||||
}
|
||||
|
||||
auto left = childHashes.empty() ? leafHash : ComputeMerkleRoot(std::move(childHashes));
|
||||
auto right = claimHashes.empty() ? emptyHash : ComputeMerkleRoot(std::move(claimHashes));
|
||||
|
||||
@@ -88,6 +88,21 @@ namespace sqlite
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
inline int sync(database& db, std::size_t attempts = 200)
|
||||
{
|
||||
int code = SQLITE_OK;
|
||||
for (auto i = 0u; i < attempts; ++i) {
|
||||
code = sqlite3_wal_checkpoint_v2(db.connection().get(), nullptr, SQLITE_CHECKPOINT_FULL, nullptr, nullptr);
|
||||
if (code != SQLITE_OK) {
|
||||
using namespace std::chrono_literals;
|
||||
std::this_thread::sleep_for(100ms);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SQLITE_H
|
||||
+34
-22
@@ -40,10 +40,11 @@ static const sqlite::sqlite_config sharedConfig {
|
||||
void applyPragmas(sqlite::database& db, std::size_t cache)
|
||||
{
|
||||
db << "PRAGMA cache_size=-" + std::to_string(cache); // in -KB
|
||||
db << "PRAGMA synchronous=OFF"; // don't disk sync after transaction commit
|
||||
db << "PRAGMA journal_mode=WAL";
|
||||
db << "PRAGMA temp_store=MEMORY";
|
||||
db << "PRAGMA case_sensitive_like=true";
|
||||
db << "PRAGMA journal_mode=WAL";
|
||||
db << "PRAGMA synchronous=OFF"; // don't disk sync after transaction commit; we handle that elsewhere
|
||||
db << "PRAGMA wal_autocheckpoint=4000"; // 4k page size * 4000 = 16MB
|
||||
|
||||
db.define("POPS", [](std::string s) -> std::string { if (!s.empty()) s.pop_back(); return s; });
|
||||
db.define("REVERSE", [](std::vector<uint8_t> s) -> std::vector<uint8_t> { std::reverse(s.begin(), s.end()); return s; });
|
||||
@@ -71,7 +72,7 @@ CClaimTrie::CClaimTrie(std::size_t cacheBytes, bool fWipe, int height,
|
||||
nExtendedClaimExpirationForkHeight(nExtendedClaimExpirationForkHeight),
|
||||
nAllClaimsInMerkleForkHeight(nAllClaimsInMerkleForkHeight)
|
||||
{
|
||||
applyPragmas(db, 5U * 1024U); // in KB
|
||||
applyPragmas(db, cacheBytes >> 10U); // in KB
|
||||
|
||||
db << "CREATE TABLE IF NOT EXISTS node (name BLOB NOT NULL PRIMARY KEY, "
|
||||
"parent BLOB REFERENCES node(name) DEFERRABLE INITIALLY DEFERRED, "
|
||||
@@ -130,14 +131,15 @@ CClaimTrieCacheBase::~CClaimTrieCacheBase()
|
||||
bool CClaimTrie::SyncToDisk()
|
||||
{
|
||||
// alternatively, switch to full sync after we are caught up on the chain
|
||||
auto rc = sqlite3_wal_checkpoint_v2(db.connection().get(), nullptr, SQLITE_CHECKPOINT_FULL, nullptr, nullptr);
|
||||
return rc == SQLITE_OK;
|
||||
return sqlite::sync(db) == SQLITE_OK;
|
||||
}
|
||||
|
||||
bool CClaimTrie::empty()
|
||||
bool CClaimTrie::empty() // only used for testing
|
||||
{
|
||||
sqlite::database local(dbFile, sharedConfig);
|
||||
applyPragmas(local, 100);
|
||||
int64_t count;
|
||||
db << "SELECT COUNT(*) FROM (SELECT 1 FROM claim WHERE activationHeight < ?1 AND expirationHeight >= ?1 LIMIT 1)" << nNextHeight >> count;
|
||||
local << "SELECT COUNT(*) FROM (SELECT 1 FROM claim WHERE activationHeight < ?1 AND expirationHeight >= ?1 LIMIT 1)" << nNextHeight >> count;
|
||||
return count == 0;
|
||||
}
|
||||
|
||||
@@ -425,10 +427,12 @@ uint256 CClaimTrieCacheBase::computeNodeHash(const std::string& name, int takeov
|
||||
};
|
||||
childHashQuery++;
|
||||
|
||||
CClaimValue claim;
|
||||
if (getInfoForName(name, claim)) {
|
||||
auto valueHash = getValueHash(claim.outPoint, takeoverHeight);
|
||||
vchToHash.insert(vchToHash.end(), valueHash.begin(), valueHash.end());
|
||||
if (takeoverHeight > 0) {
|
||||
CClaimValue claim;
|
||||
if (getInfoForName(name, claim)) {
|
||||
auto valueHash = getValueHash(claim.outPoint, takeoverHeight);
|
||||
vchToHash.insert(vchToHash.end(), valueHash.begin(), valueHash.end());
|
||||
}
|
||||
}
|
||||
|
||||
return vchToHash.empty() ? one : Hash(vchToHash.begin(), vchToHash.end());
|
||||
@@ -450,15 +454,17 @@ bool CClaimTrieCacheBase::checkConsistency()
|
||||
auto query = db << "SELECT n.name, n.hash, "
|
||||
"IFNULL((SELECT CASE WHEN t.claimID IS NULL THEN 0 ELSE t.height END "
|
||||
"FROM takeover t WHERE t.name = n.name ORDER BY t.height DESC LIMIT 1), 0) FROM node n "
|
||||
"WHERE n.name IN (SELECT r.name FROM node r ORDER BY RANDOM() LIMIT 56789) OR LENGTH(n.parent) < 2";
|
||||
"WHERE n.name IN (SELECT r.name FROM node r ORDER BY RANDOM() LIMIT 100000) OR n.parent = x''";
|
||||
for (auto&& row: query) {
|
||||
std::string name;
|
||||
uint256 hash;
|
||||
int takeoverHeight;
|
||||
row >> name >> hash >> takeoverHeight;
|
||||
auto computedHash = computeNodeHash(name, takeoverHeight);
|
||||
if (computedHash != hash)
|
||||
if (computedHash != hash) {
|
||||
logPrint << "Invalid hash at " << name << Clog::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -517,21 +523,21 @@ extern const std::string proofClaimQuery_s =
|
||||
"ORDER BY n.name";
|
||||
|
||||
CClaimTrieCacheBase::CClaimTrieCacheBase(CClaimTrie* base)
|
||||
: base(base), db(base->dbFile, sharedConfig), transacting(false),
|
||||
: base(base), db(base->db.connection()), transacting(false),
|
||||
childHashQuery(db << childHashQuery_s),
|
||||
claimHashQuery(db << claimHashQuery_s),
|
||||
claimHashQueryLimit(db << claimHashQueryLimit_s)
|
||||
{
|
||||
assert(base);
|
||||
nNextHeight = base->nNextHeight;
|
||||
|
||||
applyPragmas(db, base->dbCacheBytes >> 10U); // in KB
|
||||
}
|
||||
|
||||
void CClaimTrieCacheBase::ensureTransacting()
|
||||
{
|
||||
if (!transacting) {
|
||||
transacting = true;
|
||||
int isNotInTransaction = sqlite3_get_autocommit(db.connection().get());
|
||||
assert(isNotInTransaction);
|
||||
db << "BEGIN";
|
||||
}
|
||||
}
|
||||
@@ -730,11 +736,20 @@ bool CClaimTrieCacheBase::incrementBlock()
|
||||
"UNION SELECT nodeName FROM support WHERE expirationHeight = ?1 OR activationHeight = ?1)"
|
||||
<< nNextHeight;
|
||||
|
||||
auto insertTakeoverQuery = db << "INSERT INTO takeover(name, height, claimID) VALUES(?, ?, ?)";
|
||||
insertTakeovers();
|
||||
|
||||
nNextHeight++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CClaimTrieCacheBase::insertTakeovers(bool allowReplace) {
|
||||
auto insertTakeoverQuery = allowReplace ?
|
||||
db << "INSERT OR REPLACE INTO takeover(name, height, claimID) VALUES(?, ?, ?)" :
|
||||
db << "INSERT INTO takeover(name, height, claimID) VALUES(?, ?, ?)";
|
||||
|
||||
// takeover handling:
|
||||
db << "SELECT name FROM node WHERE hash IS NULL"
|
||||
>> [this, &insertTakeoverQuery](const std::string& nameWithTakeover) {
|
||||
db << "SELECT name FROM node WHERE hash IS NULL"
|
||||
>> [this, &insertTakeoverQuery](const std::string& nameWithTakeover) {
|
||||
// if somebody activates on this block and they are the new best, then everybody activates on this block
|
||||
CClaimValue candidateValue;
|
||||
auto hasCandidate = getInfoForName(nameWithTakeover, candidateValue, 1);
|
||||
@@ -768,9 +783,6 @@ bool CClaimTrieCacheBase::incrementBlock()
|
||||
};
|
||||
|
||||
insertTakeoverQuery.used(true);
|
||||
|
||||
nNextHeight++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CClaimTrieCacheBase::activateAllFor(const std::string& name)
|
||||
|
||||
@@ -127,6 +127,7 @@ protected:
|
||||
bool deleteNodeIfPossible(const std::string& name, std::string& parent, int64_t& claims);
|
||||
void ensureTreeStructureIsUpToDate();
|
||||
void ensureTransacting();
|
||||
void insertTakeovers(bool allowReplace=false);
|
||||
|
||||
private:
|
||||
bool transacting;
|
||||
|
||||
@@ -30,26 +30,40 @@
|
||||
#endif // !defined(bswap_16)
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/endian/detail/intrinsic.hpp>
|
||||
|
||||
// Non-Mac OS X / non-Darwin
|
||||
|
||||
#if HAVE_DECL_BSWAP_16 == 0
|
||||
inline uint16_t bswap_16(uint16_t x)
|
||||
{
|
||||
#ifdef BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2
|
||||
return BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2(x);
|
||||
#else
|
||||
return (x >> 8) | (x << 8);
|
||||
#endif
|
||||
}
|
||||
#endif // HAVE_DECL_BSWAP16 == 0
|
||||
|
||||
#if HAVE_DECL_BSWAP_32 == 0
|
||||
inline uint32_t bswap_32(uint32_t x)
|
||||
{
|
||||
#ifdef BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4
|
||||
return BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4(x);
|
||||
#else
|
||||
return (((x & 0xff000000U) >> 24) | ((x & 0x00ff0000U) >> 8) |
|
||||
((x & 0x0000ff00U) << 8) | ((x & 0x000000ffU) << 24));
|
||||
#endif
|
||||
}
|
||||
#endif // HAVE_DECL_BSWAP32 == 0
|
||||
|
||||
#if HAVE_DECL_BSWAP_64 == 0
|
||||
inline uint64_t bswap_64(uint64_t x)
|
||||
{
|
||||
#ifdef BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8
|
||||
return BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8(x);
|
||||
#else
|
||||
return (((x & 0xff00000000000000ull) >> 56)
|
||||
| ((x & 0x00ff000000000000ull) >> 40)
|
||||
| ((x & 0x0000ff0000000000ull) >> 24)
|
||||
@@ -58,6 +72,7 @@ inline uint64_t bswap_64(uint64_t x)
|
||||
| ((x & 0x0000000000ff0000ull) << 24)
|
||||
| ((x & 0x000000000000ff00ull) << 40)
|
||||
| ((x & 0x00000000000000ffull) << 56));
|
||||
#endif
|
||||
}
|
||||
#endif // HAVE_DECL_BSWAP64 == 0
|
||||
|
||||
|
||||
+1
-1
@@ -1621,7 +1621,7 @@ bool AppInitMain()
|
||||
if (fReindex) {
|
||||
// remove old LevelDB indexes
|
||||
boost::system::error_code ec;
|
||||
fs::remove_all(GetDataDir() / "blocks" / "index", ec);
|
||||
fs::remove_all(GetBlocksDir() / "index", ec);
|
||||
fs::remove_all(GetDataDir() / "chainstate", ec);
|
||||
fs::remove_all(GetDataDir() / "claimtrie", ec);
|
||||
}
|
||||
|
||||
+9
-6
@@ -172,7 +172,7 @@ CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
|
||||
static int GetnScore(const CService& addr)
|
||||
{
|
||||
LOCK(cs_mapLocalHost);
|
||||
if (mapLocalHost.count(addr) == LOCAL_NONE)
|
||||
if (mapLocalHost.count(addr) == 0)
|
||||
return 0;
|
||||
return mapLocalHost[addr].nScore;
|
||||
}
|
||||
@@ -926,7 +926,8 @@ size_t CConnman::SocketSendData(CNode *pnode) const
|
||||
int nErr = WSAGetLastError();
|
||||
if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS)
|
||||
{
|
||||
LogPrintf("socket send error %s\n", NetworkErrorString(nErr));
|
||||
LogPrintf("socket send error: %s%s\n", NetworkErrorString(nErr),
|
||||
fLogIPs ? (", peeraddr=" + pnode->addrName) : std::string());
|
||||
pnode->CloseSocketDisconnect();
|
||||
}
|
||||
}
|
||||
@@ -1325,6 +1326,9 @@ void CConnman::ThreadSocketHandler()
|
||||
}
|
||||
}
|
||||
|
||||
if (interruptNet)
|
||||
return;
|
||||
|
||||
#ifdef USE_POLL
|
||||
std::vector<struct pollfd> vpollfds;
|
||||
vpollfds.reserve(pollfds.size());
|
||||
@@ -1359,8 +1363,6 @@ void CConnman::ThreadSocketHandler()
|
||||
}
|
||||
#endif
|
||||
|
||||
if (interruptNet)
|
||||
return;
|
||||
//
|
||||
// Accept new connections
|
||||
//
|
||||
@@ -1385,7 +1387,7 @@ void CConnman::ThreadSocketHandler()
|
||||
for (CNode* pnode : vNodesCopy)
|
||||
{
|
||||
if (interruptNet)
|
||||
return;
|
||||
break;
|
||||
|
||||
//
|
||||
// Receive
|
||||
@@ -1450,7 +1452,8 @@ void CConnman::ThreadSocketHandler()
|
||||
if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS)
|
||||
{
|
||||
if (!pnode->fDisconnect)
|
||||
LogPrintf("socket recv error %s\n", NetworkErrorString(nErr));
|
||||
LogPrintf("socket recv error: %s%s\n", NetworkErrorString(nErr),
|
||||
fLogIPs ? (", peeraddr=" + pnode->addrName) : std::string());
|
||||
pnode->CloseSocketDisconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1981,7 +1981,9 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||
{
|
||||
pfrom->AddInventoryKnown(inv);
|
||||
if (fBlocksOnly) {
|
||||
LogPrint(BCLog::NET, "transaction (%s) inv sent in violation of protocol peer=%d\n", inv.hash.ToString(), pfrom->GetId());
|
||||
LogPrint(BCLog::NET, "transaction (%s) inv sent in violation of protocol, disconnecting peer=%d\n", inv.hash.ToString(), pfrom->GetId());
|
||||
pfrom->fDisconnect = true;
|
||||
return true;
|
||||
} else if (!fAlreadyHave && !fImporting && !fReindex && !IsInitialBlockDownload()) {
|
||||
pfrom->AskFor(inv);
|
||||
}
|
||||
@@ -2206,6 +2208,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||
if (!fRelayTxes && (!pfrom->fWhitelisted || !gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)))
|
||||
{
|
||||
LogPrint(BCLog::NET, "transaction sent in violation of protocol peer=%d\n", pfrom->GetId());
|
||||
pfrom->fDisconnect = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class CClaimTrieCacheTest : public CClaimTrieCacheBase
|
||||
public:
|
||||
explicit CClaimTrieCacheTest(CClaimTrie* base): CClaimTrieCacheBase(base)
|
||||
{
|
||||
nNextHeight = 2;
|
||||
nNextHeight = std::max(2, nNextHeight);
|
||||
}
|
||||
|
||||
bool insertClaimIntoTrie(const std::string& key, const CClaimValue& value)
|
||||
@@ -63,6 +63,10 @@ public:
|
||||
assert(!ret || nodeName == key);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void processTakeovers() {
|
||||
insertTakeovers(true);
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(claimtriecache_tests, RegTestingSetup)
|
||||
@@ -97,110 +101,122 @@ BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
|
||||
COutPoint tx6OutPoint(tx6.GetHash(), 0);
|
||||
|
||||
uint256 hash1;
|
||||
hash1.SetHex("71c7b8d35b9a3d7ad9a1272b68972979bbd18589f1efe6f27b0bf260a6ba78fa");
|
||||
hash1.SetHex("917106c2e4a5d454c6463e366ec2c70fde57a3deacb36f566fc0c8568e4523d5");
|
||||
|
||||
uint256 hash2;
|
||||
hash2.SetHex("c4fc0e2ad56562a636a0a237a96a5f250ef53495c2cb5edd531f087a8de83722");
|
||||
hash2.SetHex("79d0482510cb3da12b31096d459f8221cd094d268c03d96d897c932716e130e5");
|
||||
|
||||
uint256 hash3;
|
||||
hash3.SetHex("baf52472bd7da19fe1e35116cfb3bd180d8770ffbe3ae9243df1fb58a14b0975");
|
||||
hash3.SetHex("14ba954095acc42e8a5c1c3c1ca1203a1f1fb44d66b4141272cbb5a16837e3e6");
|
||||
|
||||
uint256 hash4;
|
||||
hash4.SetHex("c73232a755bf015f22eaa611b283ff38100f2a23fb6222e86eca363452ba0c51");
|
||||
hash4.SetHex("446b9dd04a1ff062c984cbbf0d5ab5aaea4ee3db1a9b65c5d06be0cb2090dbcf");
|
||||
|
||||
auto dataDir = GetDataDir() / "merkle_test";
|
||||
fs::create_directories(dataDir);
|
||||
CClaimTrie trie(10*1024*1024, true, 3, dataDir.string(), 1000, 1000, -1, 1000, 1000, 1000, 1000, 1);
|
||||
{
|
||||
CClaimTrieCacheTest ntState(pclaimTrie);
|
||||
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, {}, 50, 0, 0));
|
||||
ntState.insertClaimIntoTrie(std::string("test2"), CClaimValue(tx2OutPoint, {}, 50, 0, 0));
|
||||
CClaimTrieCacheTest ntState(&trie);
|
||||
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, {}, 50, 2, 2));
|
||||
ntState.insertClaimIntoTrie(std::string("test2"), CClaimValue(tx2OutPoint, {}, 50, 2, 2));
|
||||
|
||||
BOOST_CHECK(pclaimTrie->empty());
|
||||
BOOST_CHECK(trie.empty());
|
||||
BOOST_CHECK_EQUAL(ntState.getTotalClaimsInTrie(), 2U);
|
||||
ntState.processTakeovers();
|
||||
BOOST_CHECK_EQUAL(ntState.getMerkleHash(), hash1);
|
||||
|
||||
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3OutPoint, {}, 50, 1, 1));
|
||||
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3OutPoint, {}, 50, 3, 3));
|
||||
ntState.processTakeovers();
|
||||
BOOST_CHECK_EQUAL(ntState.getMerkleHash(), hash1);
|
||||
ntState.insertClaimIntoTrie(std::string("tes"), CClaimValue(tx4OutPoint, {}, 50, 0, 0));
|
||||
ntState.insertClaimIntoTrie(std::string("tes"), CClaimValue(tx4OutPoint, {}, 50, 2, 2));
|
||||
ntState.processTakeovers();
|
||||
BOOST_CHECK_EQUAL(ntState.getMerkleHash(), hash2);
|
||||
ntState.insertClaimIntoTrie(std::string("testtesttesttest"),
|
||||
CClaimValue(tx5OutPoint, {}, 50, 0, 0));
|
||||
CClaimValue(tx5OutPoint, {}, 50, 2, 2));
|
||||
ntState.removeClaimFromTrie(std::string("testtesttesttest"), tx5OutPoint);
|
||||
ntState.processTakeovers();
|
||||
BOOST_CHECK_EQUAL(ntState.getMerkleHash(), hash2);
|
||||
ntState.flush();
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(!trie.empty());
|
||||
BOOST_CHECK_EQUAL(ntState.getMerkleHash(), hash2);
|
||||
BOOST_CHECK(ntState.checkConsistency());
|
||||
}
|
||||
{
|
||||
CClaimTrieCacheTest ntState1(pclaimTrie);
|
||||
CClaimTrieCacheTest ntState1(&trie);
|
||||
ntState1.removeClaimFromTrie(std::string("test"), tx1OutPoint);
|
||||
ntState1.removeClaimFromTrie(std::string("test2"), tx2OutPoint);
|
||||
ntState1.removeClaimFromTrie(std::string("test"), tx3OutPoint);
|
||||
ntState1.removeClaimFromTrie(std::string("tes"), tx4OutPoint);
|
||||
|
||||
ntState1.processTakeovers();
|
||||
BOOST_CHECK_EQUAL(ntState1.getMerkleHash(), hash0);
|
||||
}
|
||||
{
|
||||
CClaimTrieCacheTest ntState2(pclaimTrie);
|
||||
ntState2.insertClaimIntoTrie(std::string("abab"), CClaimValue(tx6OutPoint, {}, 50, 0, 200));
|
||||
CClaimTrieCacheTest ntState2(&trie);
|
||||
ntState2.insertClaimIntoTrie(std::string("abab"), CClaimValue(tx6OutPoint, {}, 50, 2, 200));
|
||||
ntState2.removeClaimFromTrie(std::string("test"), tx1OutPoint);
|
||||
|
||||
ntState2.processTakeovers();
|
||||
BOOST_CHECK_EQUAL(ntState2.getMerkleHash(), hash3);
|
||||
|
||||
ntState2.flush();
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(!trie.empty());
|
||||
BOOST_CHECK_EQUAL(ntState2.getMerkleHash(), hash3);
|
||||
BOOST_CHECK(ntState2.checkConsistency());
|
||||
}
|
||||
{
|
||||
CClaimTrieCacheTest ntState3(pclaimTrie);
|
||||
ntState3.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, {}, 50, 0, 0));
|
||||
CClaimTrieCacheTest ntState3(&trie);
|
||||
ntState3.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, {}, 50, 2, 2));
|
||||
ntState3.processTakeovers();
|
||||
BOOST_CHECK_EQUAL(ntState3.getMerkleHash(), hash4);
|
||||
ntState3.flush();
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(!trie.empty());
|
||||
BOOST_CHECK_EQUAL(ntState3.getMerkleHash(), hash4);
|
||||
BOOST_CHECK(ntState3.checkConsistency());
|
||||
}
|
||||
{
|
||||
CClaimTrieCacheTest ntState4(pclaimTrie);
|
||||
CClaimTrieCacheTest ntState4(&trie);
|
||||
ntState4.removeClaimFromTrie(std::string("abab"), tx6OutPoint);
|
||||
ntState4.processTakeovers();
|
||||
BOOST_CHECK_EQUAL(ntState4.getMerkleHash(), hash2);
|
||||
ntState4.flush();
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(!trie.empty());
|
||||
BOOST_CHECK_EQUAL(ntState4.getMerkleHash(), hash2);
|
||||
BOOST_CHECK(ntState4.checkConsistency());
|
||||
}
|
||||
{
|
||||
CClaimTrieCacheTest ntState5(pclaimTrie);
|
||||
CClaimTrieCacheTest ntState5(&trie);
|
||||
ntState5.removeClaimFromTrie(std::string("test"), tx3OutPoint);
|
||||
|
||||
ntState5.processTakeovers();
|
||||
BOOST_CHECK_EQUAL(ntState5.getMerkleHash(), hash2);
|
||||
ntState5.flush();
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(!trie.empty());
|
||||
BOOST_CHECK_EQUAL(ntState5.getMerkleHash(), hash2);
|
||||
BOOST_CHECK(ntState5.checkConsistency());
|
||||
}
|
||||
{
|
||||
CClaimTrieCacheTest ntState6(pclaimTrie);
|
||||
ntState6.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3OutPoint, {}, 50, 1, 1));
|
||||
|
||||
CClaimTrieCacheTest ntState6(&trie);
|
||||
ntState6.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3OutPoint, {}, 50, 3, 3));
|
||||
ntState6.processTakeovers();
|
||||
BOOST_CHECK_EQUAL(ntState6.getMerkleHash(), hash2);
|
||||
ntState6.flush();
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(!trie.empty());
|
||||
BOOST_CHECK_EQUAL(ntState6.getMerkleHash(), hash2);
|
||||
BOOST_CHECK(ntState6.checkConsistency());
|
||||
}
|
||||
{
|
||||
CClaimTrieCacheTest ntState7(pclaimTrie);
|
||||
CClaimTrieCacheTest ntState7(&trie);
|
||||
ntState7.removeClaimFromTrie(std::string("test"), tx3OutPoint);
|
||||
ntState7.removeClaimFromTrie(std::string("test"), tx1OutPoint);
|
||||
ntState7.removeClaimFromTrie(std::string("tes"), tx4OutPoint);
|
||||
ntState7.removeClaimFromTrie(std::string("test2"), tx2OutPoint);
|
||||
|
||||
ntState7.processTakeovers();
|
||||
BOOST_CHECK_EQUAL(ntState7.getMerkleHash(), hash0);
|
||||
ntState7.flush();
|
||||
BOOST_CHECK(pclaimTrie->empty());
|
||||
BOOST_CHECK(trie.empty());
|
||||
BOOST_CHECK_EQUAL(ntState7.getMerkleHash(), hash0);
|
||||
BOOST_CHECK(ntState7.checkConsistency());
|
||||
}
|
||||
|
||||
+23
-15
@@ -30,10 +30,11 @@ CCoinsViewDB::CCoinsViewDB(size_t nCacheSize, bool fMemory, bool fWipe)
|
||||
: db(fMemory ? ":memory:" : (GetDataDir() / "coins.sqlite").string(), sharedConfig)
|
||||
{
|
||||
db << "PRAGMA cache_size=-" + std::to_string(nCacheSize >> 10); // in -KB
|
||||
db << "PRAGMA synchronous=OFF"; // don't disk sync after transaction commit
|
||||
db << "PRAGMA journal_mode=WAL";
|
||||
db << "PRAGMA temp_store=MEMORY";
|
||||
db << "PRAGMA case_sensitive_like=true";
|
||||
db << "PRAGMA journal_mode=WAL";
|
||||
db << "PRAGMA synchronous=OFF"; // don't disk sync after transaction commit; we handle that elsewhere
|
||||
db << "PRAGMA wal_autocheckpoint=4000"; // 4k page size * 4000 = 16MB
|
||||
|
||||
db << "CREATE TABLE IF NOT EXISTS unspent (txID BLOB NOT NULL COLLATE BINARY, txN INTEGER NOT NULL, "
|
||||
"isCoinbase INTEGER NOT NULL, blockHeight INTEGER NOT NULL, amount INTEGER NOT NULL, "
|
||||
@@ -157,8 +158,11 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, boo
|
||||
}
|
||||
LogPrint(BCLog::COINDB, "Committed %u changed transaction outputs (out of %u) to coin database...\n", (unsigned int)changed, (unsigned int)count);
|
||||
if (sync) {
|
||||
auto rc = sqlite3_wal_checkpoint_v2(db.connection().get(), nullptr, SQLITE_CHECKPOINT_FULL, nullptr, nullptr);
|
||||
return rc == SQLITE_OK;
|
||||
auto code = sqlite::sync(db);
|
||||
if (code != SQLITE_OK) {
|
||||
LogPrint(BCLog::COINDB, "Error syncing coin database. SQLite error: %d\n", code);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -174,10 +178,11 @@ CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe)
|
||||
: db(fMemory ? ":memory:" : (GetDataDir() / "block_index.sqlite").string(), sharedConfig)
|
||||
{
|
||||
db << "PRAGMA cache_size=-" + std::to_string(nCacheSize >> 10); // in -KB
|
||||
db << "PRAGMA synchronous=OFF"; // don't disk sync after transaction commit
|
||||
db << "PRAGMA journal_mode=WAL";
|
||||
db << "PRAGMA temp_store=MEMORY";
|
||||
db << "PRAGMA case_sensitive_like=true";
|
||||
db << "PRAGMA journal_mode=WAL";
|
||||
db << "PRAGMA synchronous=OFF"; // don't disk sync after transaction commit; we handle that elsewhere
|
||||
db << "PRAGMA wal_autocheckpoint=4000"; // 4k page size * 4000 = 16MB
|
||||
|
||||
db << "CREATE TABLE IF NOT EXISTS block_file ("
|
||||
"file INTEGER NOT NULL PRIMARY KEY, "
|
||||
@@ -335,8 +340,11 @@ bool CBlockTreeDB::BatchWrite(const std::vector<std::pair<int, const CBlockFileI
|
||||
}
|
||||
// by Sync they mean disk sync:
|
||||
if (sync) {
|
||||
auto rc = sqlite3_wal_checkpoint_v2(db.connection().get(), nullptr, SQLITE_CHECKPOINT_FULL, nullptr, nullptr);
|
||||
return rc == SQLITE_OK;
|
||||
auto code = sqlite::sync(db);
|
||||
if (code != SQLITE_OK) {
|
||||
LogPrintf("%s: Error syncing block database. SQLite error: %d\n", __func__, code);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -383,13 +391,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
|
||||
>> pindexNew->nNonce
|
||||
>> pindexNew->nStatus;
|
||||
|
||||
if ((pindexNew->nHeight & 0x3ff) == 0x3ff) { // don't check for shutdown on every single block
|
||||
boost::this_thread::interruption_point();
|
||||
if (ShutdownRequested())
|
||||
return false;
|
||||
}
|
||||
|
||||
pindexNew->nChainTx = pindexNew->pprev ? pindexNew->pprev->nChainTx + pindexNew->nTx : pindexNew->nTx;
|
||||
// nChainTx gets set later; don't set it here or you'll mess up the Unlinked list
|
||||
|
||||
if (!CheckProofOfWork(pindexNew->GetBlockPoWHash(), pindexNew->nBits, consensusParams))
|
||||
{
|
||||
@@ -397,6 +399,12 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
|
||||
LogPrintf("%s: CheckProofOfWorkFailed: %s (hash %s, nBits=%x, nTime=%d)\n", __func__, pindexNew->GetBlockPoWHash().GetHex(), pindexNew->GetBlockHash().GetHex(), pindexNew->nBits, pindexNew->nTime);
|
||||
return error("%s: CheckProofOfWork failed: %s", __func__, pindexNew->ToString());
|
||||
}
|
||||
|
||||
if ((pindexNew->nHeight & 0x3ff) == 0x3ff) { // don't check for shutdown on every single block
|
||||
boost::this_thread::interruption_point();
|
||||
if (ShutdownRequested())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
+18
-11
@@ -703,17 +703,22 @@ const fs::path &GetBlocksDir(bool fNetSpecific)
|
||||
|
||||
if (gArgs.IsArgSet("-blocksdir")) {
|
||||
path = fs::system_complete(gArgs.GetArg("-blocksdir", ""));
|
||||
if (!fs::is_directory(path)) {
|
||||
path = "";
|
||||
return path;
|
||||
if (fs::exists(path) && !fs::is_directory(path)) {
|
||||
LogPrintf("%s: %s is not a directory, falling back to GetDataDir\n", __func__, path);
|
||||
path.clear();
|
||||
}
|
||||
} else {
|
||||
path = GetDataDir(false);
|
||||
}
|
||||
|
||||
bool usingDataDir = path.empty();
|
||||
if (usingDataDir)
|
||||
path = GetDataDir(false);
|
||||
|
||||
if (fNetSpecific)
|
||||
path /= BaseParams().DataDir();
|
||||
|
||||
path /= "blocks";
|
||||
if (usingDataDir)
|
||||
path /= "blocks";
|
||||
|
||||
fs::create_directories(path);
|
||||
return path;
|
||||
}
|
||||
@@ -732,13 +737,15 @@ const fs::path &GetDataDir(bool fNetSpecific)
|
||||
|
||||
if (gArgs.IsArgSet("-datadir")) {
|
||||
path = fs::system_complete(gArgs.GetArg("-datadir", ""));
|
||||
if (!fs::is_directory(path)) {
|
||||
path = "";
|
||||
return path;
|
||||
if (fs::exists(path) && !fs::is_directory(path)) {
|
||||
LogPrintf("%s: %s is not a directory, falling back to GetDefaultDataDir\n", __func__, path);
|
||||
path.clear();
|
||||
}
|
||||
} else {
|
||||
path = GetDefaultDataDir();
|
||||
}
|
||||
|
||||
if (path.empty())
|
||||
path = GetDefaultDataDir();
|
||||
|
||||
if (fNetSpecific)
|
||||
path /= BaseParams().DataDir();
|
||||
|
||||
|
||||
+2
-2
@@ -2531,7 +2531,7 @@ CBlockIndex* CChainState::FindMostWorkChain() {
|
||||
|
||||
// Find the best candidate header.
|
||||
{
|
||||
std::set<CBlockIndex*, CBlockIndexWorkComparator>::reverse_iterator it = setBlockIndexCandidates.rbegin();
|
||||
auto it = setBlockIndexCandidates.rbegin();
|
||||
if (it == setBlockIndexCandidates.rend())
|
||||
return nullptr;
|
||||
pindexNew = *it;
|
||||
@@ -4362,7 +4362,7 @@ bool LoadBlockIndex(const CChainParams& chainparams)
|
||||
needs_init = g_chainstate.mapBlockIndex.empty();
|
||||
|
||||
if (needs_init) {
|
||||
auto blockDir = GetDataDir() / "blocks";
|
||||
auto& blockDir = GetBlocksDir();
|
||||
for (auto it: fs::directory_iterator(blockDir)) {
|
||||
boost::system::error_code ec;
|
||||
if (fs::file_size(it, ec) > 100000000) {
|
||||
|
||||
Reference in new issue
Block a user