brought in the claimtrie tests, made it all compile

yanked the ICU stuff as it will come with the normalization branch
This commit is contained in:
Brannon King 2018-12-31 13:21:02 +01:00 committed by lbrynaut
parent 68a8864847
commit 11c5398c71
24 changed files with 4168 additions and 348 deletions

3
.gitignore vendored
View file

@ -116,3 +116,6 @@ test/cache/*
libbitcoinconsensus.pc
contrib/devtools/split-debug.sh
.idea
cmake-build-*/

57
CMakeLists.txt Normal file
View file

@ -0,0 +1,57 @@
cmake_minimum_required(VERSION 3.7)
project(lbrycrd_clion) # Do not use for full compile. This is for CLion syntax checking only.
set (CMAKE_CXX_STANDARD 11)
if(EXISTS "build/boost")
set(BOOST_ROOT "build/boost" CACHE PATH "Boost library path")
set(Boost_NO_SYSTEM_PATHS on CACHE BOOL "Do not search system for Boost")
endif()
find_package(Boost REQUIRED COMPONENTS filesystem program_options thread chrono locale)
file(GLOB sources
src/*.h src/*.cpp
src/wallet/*.h src/wallet/*.cpp
src/support/*.h src/support/*.cpp src/support/allocators/*.h
src/script/*.h src/script/*.cpp
src/rpc/*.h src/rpc/*.cpp
src/primitives/*.h src/primitives/*.cpp
src/policy/*.h src/policy/*.cpp
src/crypto/*.h src/crypto/*.cpp
src/consensus/*.h src/consensus/*.cpp
src/compat/*.h src/compat/*.cpp
)
list(FILTER sources EXCLUDE REGEX "src/bitcoin*.cpp$")
include_directories(${Boost_INCLUDE_DIRS}
build/bdb/include
build/libevent/include
build/openssl/include
src/support/allocators
src/support
src/rpc
src/policy
src/wallet src/script
src/leveldb/helpers/memenv
src/leveldb/include
src/config
src/crypto
src/compat
src/obj
src/univalue/include
src/secp256k1/include
src/
)
add_compile_definitions(HAVE_CONFIG_H)
add_executable(lbrycrd-cli src/bitcoin-cli.cpp ${sources})
add_executable(lbrycrd-tx src/bitcoin-tx.cpp ${sources})
add_executable(lbrycrdd src/bitcoind.cpp ${sources})
file(GLOB tests src/test/*.cpp)
foreach(test ${tests})
get_filename_component(filename ${test} NAME_WE)
add_executable(${filename} ${test} ${sources})
target_include_directories(${filename} PRIVATE src/test)
endforeach(test)

View file

@ -146,12 +146,6 @@ AC_ARG_WITH([qrencode],
[use_qr=$withval],
[use_qr=auto])
AC_ARG_WITH([icu],
[AS_HELP_STRING([--with-icu],
[Required ICU root path])],
[ICU_PREFIX=$withval],
[ICU_PREFIX=auto])
AC_ARG_ENABLE([hardening],
[AS_HELP_STRING([--disable-hardening],
[do not attempt to harden the resulting executables (default is to harden when possible)])],
@ -902,7 +896,6 @@ AX_BOOST_SYSTEM
AX_BOOST_FILESYSTEM
AX_BOOST_THREAD
AX_BOOST_CHRONO
AX_BOOST_LOCALE
dnl Boost 1.56 through 1.62 allow using std::atomic instead of its own atomic
dnl counter implementations. In 1.63 and later the std::atomic approach is default.
@ -969,7 +962,7 @@ fi
if test x$use_boost = xyes; then
BOOST_LIBS="$BOOST_LDFLAGS $BOOST_SYSTEM_LIB $BOOST_FILESYSTEM_LIB $BOOST_PROGRAM_OPTIONS_LIB $BOOST_THREAD_LIB $BOOST_CHRONO_LIB $BOOST_LOCALE_LIB"
BOOST_LIBS="$BOOST_LDFLAGS $BOOST_SYSTEM_LIB $BOOST_FILESYSTEM_LIB $BOOST_PROGRAM_OPTIONS_LIB $BOOST_THREAD_LIB $BOOST_CHRONO_LIB"
dnl If boost (prior to 1.57) was built without c++11, it emulated scoped enums
@ -1065,16 +1058,6 @@ if test x$use_pkgconfig = xyes; then
m4_ifdef(
[PKG_CHECK_MODULES],
[
ICU_CPPFLAGS="-I$ICU_PREFIX/include"
CPPFLAGS="$ICU_CPPFLAGS $CPPFLAGS"
ICU_LIBS="-L$ICU_PREFIX/lib -licui18n -licuuc -licudata -ldl"
AC_MSG_WARN([Using ICU_CPPFLAGS $ICU_CPPFLAGS])
AC_MSG_WARN([Using CPPFLAGS $CPPFLAGS])
AC_CHECK_HEADER([unicode/errorcode.h],,AC_MSG_ERROR(libicu headers missing))
AC_CHECK_LIB([icudata], [main], ICU_LIBS="-L$ICU_PREFIX/lib -licui18n -licuuc -licudata -ldl",
AC_CHECK_LIB([icu18n], [main],ICU_LIBS=$ICU_LIBS, ICU_LIBS="-L$ICU_PREFIX/lib -lsicudt -lsicuin -lsicuio -lsicule -lsiculx -lsicutest -lsicutu -lsicuuc"))
PKG_CHECK_MODULES([SSL], [libssl],, [AC_MSG_ERROR(openssl not found.)])
PKG_CHECK_MODULES([CRYPTO], [libcrypto],,[AC_MSG_ERROR(libcrypto not found.)])
BITCOIN_QT_CHECK([PKG_CHECK_MODULES([PROTOBUF], [protobuf], [have_protobuf=yes], [BITCOIN_QT_FAIL(libprotobuf not found)])])
@ -1100,18 +1083,6 @@ if test x$use_pkgconfig = xyes; then
]
)
else
ICU_CPPFLAGS="-I$ICU_PREFIX/include"
CPPFLAGS="$ICU_CPPFLAGS $CPPFLAGS"
ICU_LIBS="-L$ICU_PREFIX/lib -licui18n -licuuc -licudata -ldl"
AC_MSG_WARN([Using ICU_CPPFLAGS $ICU_CPPFLAGS])
AC_MSG_WARN([Using ICU_LIBS $ICU_LIBS])
AC_MSG_WARN([Using CPPFLAGS $CPPFLAGS])
AC_CHECK_HEADER([unicode/errorcode.h],,AC_MSG_ERROR(libicu headers missing))
AC_CHECK_LIB([icudata], [main], ICU_LIBS="-L$ICU_PREFIX/lib -licui18n -licuuc -licudata -ldl",
AC_CHECK_LIB([icu18n], [main],ICU_LIBS=$ICU_LIBS, ICU_LIBS="-L$ICU_PREFIX/lib -lsicudt -lsicuin -lsicuio -lsicule -lsiculx -lsicutest -lsicutu -lsicuuc"))
AC_CHECK_HEADER([openssl/crypto.h],,AC_MSG_ERROR(libcrypto headers missing))
AC_CHECK_LIB([crypto], [main],CRYPTO_LIBS=-lcrypto, AC_MSG_ERROR(libcrypto missing))
@ -1415,9 +1386,6 @@ AC_SUBST(LIBTOOL_APP_LDFLAGS)
AC_SUBST(USE_UPNP)
AC_SUBST(USE_QRCODE)
AC_SUBST(BOOST_LIBS)
AC_SUBST(ICU_PREFIX)
AC_SUBST(ICU_CPPFLAGS)
AC_SUBST(ICU_LIBS)
AC_SUBST(TESTDEFS)
AC_SUBST(LEVELDB_TARGET_FLAGS)
AC_SUBST(MINIUPNPC_CPPFLAGS)

View file

@ -1,6 +1,6 @@
#!/bin/bash
set -xeuo pipefail
set -euo pipefail
function HELP {
echo "Build lbrycrd"
@ -106,22 +106,24 @@ else
# this file is created when the build starts
START_TIME_FILE="$TRAVIS_BUILD_DIR/start_time"
fi
rm -f ${START_TIME_FILE}
date +%s > ${START_TIME_FILE}
if [ ! -f "${START_TIME_FILE}" ]; then
date +%s > "${START_TIME_FILE}"
fi
NEXT_TIME=60
function exit_at_60() {
function exit_at_40() {
if [ -f "${START_TIME_FILE}" ]; then
NOW=$(date +%s)
START=$(cat "${START_TIME_FILE}")
TIMEOUT_SECS=3600 # 60 * 60
TIMEOUT_SECS=2400 # 40 * 60
TIME=$((NOW - START))
if (( TIME > NEXT_TIME )); then
echo "Build has taken $((TIME / 60)) minutes: $1"
NEXT_TIME=$((TIME + 60))
fi
if [ "$TIMEOUT" = true ] && (( TIME > TIMEOUT_SECS )); then
echo 'Exiting at 60 minutes to allow the cache to populate'
echo 'Exiting at 40 minutes to allow the cache to populate'
OUTPUT_LOG=false
exit 1
fi
@ -143,7 +145,7 @@ function wait_and_echo() {
# loop until the process is no longer running
# check every $SLEEP seconds, echoing a message every minute
while (ps -p "${PID}" > /dev/null); do
exit_at_60 "$2"
exit_at_40 "$2"
sleep "${SLEEP}"
done
# restore the xtrace setting
@ -235,17 +237,15 @@ function install_apt_packages() {
if [ "${CHECK_CODE_FORMAT}" = true ]; then
$SUDO apt-get ${QUIET} install -y --no-install-recommends \
clang-format-3.4
clang-format-3.9
fi
}
function build_dependencies() {
if [ "${OS_NAME}" = "osx" ]; then
PARALLEL="-j $(sysctl -n hw.ncpu)"
install_brew_packages
else
PARALLEL="-j $(grep -c processor /proc/cpuinfo)"
install_apt_packages
fi
@ -255,14 +255,13 @@ function build_dependencies() {
fi
if [ ! -d "${LBRYCRD_DEPENDENCIES}" ]; then
git clone https://github.com/lbrynaut/lbrycrd-dependencies.git "${LBRYCRD_DEPENDENCIES}"
git clone https://github.com/lbryio/lbrycrd-dependencies.git "${LBRYCRD_DEPENDENCIES}"
fi
# TODO: if the repo exists, make sure its clean: revert to head.
mkdir -p "${LOG_DIR}"
build_dependency "${OPENSSL_PREFIX}" "${LOG_DIR}/openssl_build.log" build_openssl
build_dependency "${ICU_PREFIX}" "${LOG_DIR}/icu_build.log" build_icu
build_dependency "${BDB_PREFIX}" "${LOG_DIR}/bdb_build.log" build_bdb
build_dependency "${OPENSSL_PREFIX}" "${LOG_DIR}/openssl_build.log" build_openssl
set +u
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${OPENSSL_PREFIX}/lib/pkgconfig/"
@ -280,7 +279,7 @@ function build_bdb() {
cd db-4.8.30.NC/build_unix
echo "Building bdb. tail -f $BDB_LOG to see the details and monitor progress"
../dist/configure --prefix="${BDB_PREFIX}" --enable-cxx --disable-shared --with-pic > "${BDB_LOG}"
background "make ${PARALLEL}" "${BDB_LOG}" "Waiting for bdb to finish building"
background make "${BDB_LOG}" "Waiting for bdb to finish building"
make install >> "${BDB_LOG}" 2>&1
}
@ -298,52 +297,18 @@ function build_openssl() {
./Configure --prefix="${OPENSSL_PREFIX}" --openssldir="${OPENSSL_PREFIX}/ssl" \
${OS_ARCH} -fPIC -static no-shared no-dso > "${OPENSSL_LOG}"
fi
background "make ${PARALLEL}" "${OPENSSL_LOG}" "Waiting for openssl to finish building"
background make "${OPENSSL_LOG}" "Waiting for openssl to finish building"
make install >> "${OPENSSL_LOG}" 2>&1
}
function build_boost() {
BOOST_LOG="$1"
cd boost_1_67_0
echo "int main() { return 0; }" > libs/regex/build/has_icu_test.cpp
echo "int main() { return 0; }" > libs/locale/build/has_icu_test.cpp
export BOOST_ICU_LIBS="$(pkg-config icu-i18n --libs) -dl"
export BOOST_LDFLAGS="${BOOST_PREFIX}/lib ${ICU_PREFIX}/lib ${BOOST_ICU_LIBS}"
echo "BOOST_ICU_LIBS: $BOOST_ICU_LIBS"
echo "BOOST_LDFLAGS: $BOOST_ICU_LIBS"
cd boost_1_59_0
echo "Building Boost. tail -f ${BOOST_LOG} to see the details and monitor progress"
./bootstrap.sh --prefix="${BOOST_PREFIX}" "--with-icu=${ICU_PREFIX}" > "${BOOST_LOG}" 2>&1
b2cmd="./b2 link=static cxxflags=-fPIC install boost.locale.iconv=off boost.locale.posix=off -sICU_PATH=${ICU_PREFIX} -sICU_LINK=${BOOST_ICU_LIBS}"
background "${b2cmd}" "${BOOST_LOG}" "Waiting for boost to finish building"
}
function build_icu() {
ICU_LOG="$1"
mkdir -p "${ICU_PREFIX}/icu"
wget http://download.icu-project.org/files/icu4c/55.1/icu4c-55_1-src.tgz
tar -xf icu4c-55_1-src.tgz
rm -f icu4c-55_1-src.tgz
pushd icu/source > /dev/null
echo "Building icu. tail -f $ICU_LOG to see the details and monitor progress"
./configure --prefix="${ICU_PREFIX}" --enable-draft --enable-tools \
--enable-static --enable-shared --disable-extras --disable-icuio \
--disable-layout --disable-layoutex --disable-tests --disable-samples
if [ ! -z ${TARGET+x} ]; then
TMP_TARGET="${TARGET}"
unset TARGET
fi
set +e
background "make ${PARALLEL} VERBOSE=1" "${ICU_LOG}" "Waiting for icu to finish building"
make install >> "${ICU_LOG}" 2>&1
if [ ! -z ${TARGET+x} ]; then
TARGET="${TMP_TARGET}"
fi
set -e
popd > /dev/null
./bootstrap.sh --prefix="${BOOST_PREFIX}" > "${BOOST_LOG}" 2>&1
background "./b2 link=static cxxflags=-fPIC install" \
"${BOOST_LOG}" \
"Waiting for boost to finish building"
}
function build_libevent() {
@ -357,22 +322,23 @@ function build_libevent() {
./configure --prefix="${LIBEVENT_PREFIX}" --enable-static --disable-shared --with-pic \
LDFLAGS="-L${OPENSSL_PREFIX}/lib/" \
CPPFLAGS="-I${OPENSSL_PREFIX}/include" >> "${LIBEVENT_LOG}" 2>&1
background "make ${PARALLEL}" "${LIBEVENT_LOG}" "Waiting for libevent to finish building"
background make "${LIBEVENT_LOG}" "Waiting for libevent to finish building"
make install >> "${LIBEVENT_LOG}"
}
function build_dependency() {
pushd .
PREFIX=$1
LOG=$2
BUILD=$3
if [ ! -d "${PREFIX}" ]; then
trap 'cleanup "${PREFIX}" "${LOG}"' INT TERM EXIT
cd "${LBRYCRD_DEPENDENCIES}"
rm -rf ${PREFIX}
mkdir -p "${PREFIX}"
"${BUILD}" "${LOG}"
trap - INT TERM EXIT
fi
popd
}
function build_lbrycrd() {
@ -384,27 +350,19 @@ function build_lbrycrd() {
cd "${SOURCE_DIR}"
fi
./autogen.sh > "${LBRYCRD_LOG}" 2>&1
LDFLAGS="-L${OPENSSL_PREFIX}/lib/ -L${BDB_PREFIX}/lib/ -L${LIBEVENT_PREFIX}/lib/ -L${ICU_PREFIX}/lib/ -static-libstdc++"
LDFLAGS="-L${OPENSSL_PREFIX}/lib/ -L${BDB_PREFIX}/lib/ -L${LIBEVENT_PREFIX}/lib/ -static-libstdc++"
CPPFLAGS="-I${OPENSSL_PREFIX}/include -I${BDB_PREFIX}/include -I${LIBEVENT_PREFIX}/include/"
if [ "${OS_NAME}" = "osx" ]; then
OPTIONS="--enable-cxx --enable-static --disable-shared --with-pic"
CPPFLAGS="-I${OPENSSL_PREFIX}/include -I${BDB_PREFIX}/include -I${LIBEVENT_PREFIX}/include/ -I${ICU_PREFIX}/include"
else
OPTIONS=""
CPPFLAGS="-I${OPENSSL_PREFIX}/include -I${BDB_PREFIX}/include -I${LIBEVENT_PREFIX}/include/ -I${ICU_PREFIX}/include -Wno-unused-local-typedefs"
fi
CPPFLAGS="${CPPFLAGS}" LDFLAGS="${LDFLAGS}" \
./configure --without-gui ${OPTIONS} \
--with-boost="${BOOST_PREFIX}" \
--with-icu="${ICU_PREFIX}" >> "${LBRYCRD_LOG}" 2>&1
background "make ${PARALLEL}" "${LBRYCRD_LOG}" "Waiting for lbrycrd to finish building"
if [ "${OS_NAME}" = "linux" ]; then
LD_LIBRARY_PATH="${ICU_PREFIX}/lib" src/test/test_lbrycrd
else
DYLD_LIBRARY_PATH="${ICU_PREFIX}/lib" src/test/test_lbrycrd
fi
./configure --without-gui ${OPTIONS} \
--with-boost="${BOOST_PREFIX}" \
LDFLAGS="${LDFLAGS}" \
CPPFLAGS="${CPPFLAGS}" >> "${LBRYCRD_LOG}" 2>&1
background make "${LBRYCRD_LOG}" "Waiting for lbrycrd to finish building"
src/test/test_lbrycrd
strip src/lbrycrdd
strip src/lbrycrd-cli
strip src/lbrycrd-tx
@ -414,18 +372,13 @@ function build_lbrycrd() {
function clang_format_diff(){
# run a code formatting check on any commits not in master
# requires clang-format
if ! git config remote.origin2.url > /dev/null; then
git remote add origin2 https://github.com/lbryio/lbrycrd.git
fi
git fetch origin2
git diff -U0 origin2/master -- '*.h' '*.cpp' | ./contrib/devtools/clang-format-diff.py -p1
git diff -U0 origin/master -- '*.h' '*.cpp' | ./contrib/devtools/clang-format-diff.py -p1
}
# these variables are needed in both functions
LBRYCRD_DEPENDENCIES="$(pwd)/lbrycrd-dependencies"
OUTPUT_DIR="$(pwd)/build"
LOG_DIR="$(pwd)/logs"
ICU_PREFIX="${OUTPUT_DIR}/icu"
BDB_PREFIX="${OUTPUT_DIR}/bdb"
OPENSSL_PREFIX="${OUTPUT_DIR}/openssl"
BOOST_PREFIX="${OUTPUT_DIR}/boost"

View file

@ -55,8 +55,8 @@ if ENABLE_WALLET
bench_bench_bitcoin_SOURCES += bench/coin_selection.cpp
endif
bench_bench_bitcoin_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(ICU_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS)
bench_bench_bitcoin_LDFLAGS = -L$(ICU_PREFIX)/lib $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
bench_bench_bitcoin_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS)
bench_bench_bitcoin_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_BENCH_FILES)

View file

@ -409,9 +409,9 @@ if ENABLE_ZMQ
qt_bitcoin_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
endif
qt_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) \
$(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(PROTOBUF_LIBS) $(ICU_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \
$(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \
$(EVENT_PTHREADS_LIBS) $(EVENT_LIBS)
qt_bitcoin_qt_LDFLAGS = -L$(ICU_PREFIX)/lib $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
qt_bitcoin_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
qt_bitcoin_qt_LIBTOOLFLAGS = $(AM_LIBTOOLFLAGS) --tag CXX
#locale/foo.ts -> locale/foo.qm

View file

@ -64,9 +64,9 @@ qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
endif
qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) \
$(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \
$(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(ICU_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \
$(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \
$(EVENT_PTHREADS_LIBS) $(EVENT_LIBS)
qt_test_test_bitcoin_qt_LDFLAGS = -L$(ICU_PREFIX)/lib $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
qt_test_test_bitcoin_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
qt_test_test_bitcoin_qt_CXXFLAGS = $(AM_CXXFLAGS) $(QT_PIE_FLAGS)
CLEAN_BITCOIN_QT_TEST = $(TEST_QT_MOC_CPP) qt/test/*.gcda qt/test/*.gcno

View file

@ -120,8 +120,8 @@ test_test_bitcoin_LDADD += $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_C
$(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS)
test_test_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
test_test_bitcoin_LDADD += $(LIBBITCOIN_CONSENSUS) $(BDB_LIBS) $(ICU_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS)
test_test_bitcoin_LDFLAGS = -L$(ICU_PREFIX)/lib $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static
test_test_bitcoin_LDADD += $(LIBBITCOIN_CONSENSUS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS)
test_test_bitcoin_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static
if ENABLE_ZMQ
test_test_bitcoin_LDADD += $(ZMQ_LIBS)
@ -146,7 +146,7 @@ test_test_bitcoin_fuzzy_LDADD = \
$(LIBBITCOIN_CRYPTO_SHANI) \
$(LIBSECP256K1)
test_test_bitcoin_fuzzy_LDADD += $(BOOST_LIBS) $(CRYPTO_LIBS) $(ICU_LIBS)
test_test_bitcoin_fuzzy_LDADD += $(BOOST_LIBS) $(CRYPTO_LIBS)
#
nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)

View file

@ -41,7 +41,8 @@ static CTxIn MineBlock(const CScript& coinbase_scriptPubKey)
auto block = PrepareBlock(coinbase_scriptPubKey);
while (!CheckProofOfWork(block->GetHash(), block->nBits, Params().GetConsensus())) {
assert(++block->nNonce);
++block->nNonce;
assert(block->nNonce);
}
bool processed{ProcessNewBlock(Params(), block, true, nullptr)};

View file

@ -131,8 +131,8 @@ public:
consensus.BIP16Exception = uint256S("0x00000000000002dc756eebf4f49723ed8d30cc28a5f108eb94b1ba88ac4f9c22");
consensus.BIP34Height = 1;
consensus.BIP34Hash = uint256S("0xdecb9e2cca03a419fd9cca0cb2b1d5ad11b088f22f8f38556d93ac4358b86c24");
consensus.BIP65Height = 1;
consensus.BIP66Height = 1;
consensus.BIP65Height = 600000;
consensus.BIP66Height = 600000;
consensus.powLimit = uint256S("0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 150; //retarget every block
consensus.nPowTargetSpacing = 150;
@ -156,8 +156,8 @@ public:
// Deployment of SegWit (BIP141, BIP143, and BIP147)
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
// FIXME: Update times
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1634352575; //1479168000; // November 15th, 2016.
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1634352575; //1510704000; // November 15th, 2017.
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1547942400; // Jan 20, 2019
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1548288000; // Jan 24, 2019
// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000000000607ca7e806c4c1e9"); //400000

View file

@ -403,28 +403,6 @@ CAmount CClaimTrie::getTotalValueOfClaimsRecursive(const CClaimTrieNode* current
return value_in_subtrie;
}
bool CClaimTrie::recursiveFlattenTrie(const std::string& name, const CClaimTrieNode* current, std::vector<namedNodeType>& nodes) const
{
namedNodeType node(name, *current);
nodes.push_back(node);
for (nodeMapType::const_iterator it = current->children.begin(); it != current->children.end(); ++it)
{
std::stringstream ss;
ss << name << it->first;
if (!recursiveFlattenTrie(ss.str(), it->second, nodes))
return false;
}
return true;
}
std::vector<namedNodeType> CClaimTrie::flattenTrie() const
{
std::vector<namedNodeType> nodes;
if (!recursiveFlattenTrie("", &root, nodes))
LogPrintf("%s: Something went wrong flattening the trie", __func__);
return nodes;
}
const CClaimTrieNode* CClaimTrie::getNodeForName(const std::string& name) const
{
const CClaimTrieNode* current = &root;
@ -1300,7 +1278,7 @@ bool CClaimTrieCache::insertClaimIntoTrie(const std::string& name, CClaimValue c
currentNode = childNode->second;
continue;
}
// This next substring doesn't exist in the cache and the next
// character doesn't exist in current node's children, so check
// if the current node is in the cache, and if it's not, copy
@ -1401,7 +1379,7 @@ bool CClaimTrieCache::removeClaimFromTrie(const std::string& name, const COutPoi
bool fChanged = false;
assert(currentNode != NULL);
bool success = false;
if (currentNode->claims.empty())
{
LogPrintf("%s: Asked to remove claim from node without claims\n", __func__);
@ -1476,7 +1454,7 @@ bool CClaimTrieCache::recursivePruneName(CClaimTrieNode* tnCurrent, unsigned int
// tnCurrent isn't necessarily in the cache. If it's not, it
// has to be added to the cache, so nothing is changed in the
// trie. If the current node is added to the cache, however,
// that does not imply that the parent node must be altered to
// that does not imply that the parent node must be altered to
// reflect that its child is now in the cache, since it
// already has a character in its child map which will be used
// when calculating the merkle root.
@ -2182,7 +2160,7 @@ bool CClaimTrieCache::incrementBlock(insertUndoType& insertUndo, claimQueueRowTy
itSupportExpirationRow->second.clear();
}
// check each potentially taken over name to see if a takeover occurred.
// if it did, then check the claim and support insertion queues for
// if it did, then check the claim and support insertion queues for
// the names that have been taken over, immediately insert all claim and
// supports for those names, and stick them in the insertUndo or
// insertSupportUndo vectors, with the nValidAtHeight they had prior to
@ -2224,13 +2202,16 @@ bool CClaimTrieCache::incrementBlock(insertUndoType& insertUndo, claimQueueRowTy
{
takeoverHappened = true;
}
else if ((claimInCache != claimInTrie) && (claimInCache.claimId != claimInTrie.claimId))
else if (claimInCache != claimInTrie)
{
takeoverHappened = true;
if (claimInCache.claimId != claimInTrie.claimId)
{
takeoverHappened = true;
}
}
if (takeoverHappened)
{
// Get all claims in the queue for that name
// Get all pending claims for that name and activate them all in the case that our winner is defunct.
queueNameType::iterator itQueueNameRow = getQueueCacheNameRow(*itNamesToCheck, false);
if (itQueueNameRow != claimQueueNameCache.end())
{
@ -2270,7 +2251,7 @@ bool CClaimTrieCache::incrementBlock(insertUndoType& insertUndo, claimQueueRowTy
// remove all claims from the queue for that name
itQueueNameRow->second.clear();
}
//
//
// Then, get all supports in the queue for that name
queueNameType::iterator itSupportQueueNameRow = getSupportQueueCacheNameRow(*itNamesToCheck, false);
if (itSupportQueueNameRow != supportQueueNameCache.end())
@ -2361,6 +2342,9 @@ bool CClaimTrieCache::decrementBlock(insertUndoType& insertUndo, claimQueueRowTy
supportQueueType::iterator itSupportRow = getSupportQueueCacheRow(itSupportUndo->nHeight, true);
CSupportValue support;
assert(removeSupportFromMap(itSupportUndo->name, itSupportUndo->outPoint, support, false));
// support.nValidHeight may have been changed if this was inserted before activation height
// due to a triggered takeover, change it back to original nValidAtHeight
support.nValidAtHeight = itSupportUndo->nHeight;
queueNameType::iterator itSupportNameRow = getSupportQueueCacheNameRow(itSupportUndo->name, true);
itSupportRow->second.push_back(std::make_pair(itSupportUndo->name, support));
itSupportNameRow->second.push_back(outPointHeightType(support.outPoint, support.nValidAtHeight));
@ -2383,9 +2367,12 @@ bool CClaimTrieCache::decrementBlock(insertUndoType& insertUndo, claimQueueRowTy
claimQueueType::iterator itQueueRow = getQueueCacheRow(itInsertUndo->nHeight, true);
CClaimValue claim;
assert(removeClaimFromTrie(itInsertUndo->name, itInsertUndo->outPoint, claim, false));
// claim.nValidHeight may have been changed if this was inserted before activation height
// due to a triggered takeover, change it back to original nValidAtHeight
claim.nValidAtHeight = itInsertUndo->nHeight;
queueNameType::iterator itQueueNameRow = getQueueCacheNameRow(itInsertUndo->name, true);
itQueueRow->second.push_back(std::make_pair(itInsertUndo->name, claim));
itQueueNameRow->second.push_back(outPointHeightType(itInsertUndo->outPoint, itInsertUndo->nHeight));
itQueueNameRow->second.push_back(outPointHeightType(itInsertUndo->outPoint, claim.nValidAtHeight));
}
for (std::vector<std::pair<std::string, int> >::iterator itTakeoverHeightUndo = takeoverHeightUndo.begin(); itTakeoverHeightUndo != takeoverHeightUndo.end(); ++itTakeoverHeightUndo)
@ -2524,25 +2511,32 @@ uint256 CClaimTrieCache::getLeafHashForProof(const std::string& currentPosition,
return (cachedHash != cacheHashes.end()) ? cachedHash->second : currentNode->hash;
}
void CClaimTrieCache::recursiveFlattenTrie(const std::string& name, const CClaimTrieNode* current, std::vector<namedNodeType>& nodes) const
void CClaimTrieCache::recursiveIterateTrie(std::string& name, const CClaimTrieNode* current, CNodeCallback& callback) const
{
nodes.push_back(std::make_pair(name, *current));
callback.visit(name, current);
nodeCacheType::const_iterator cachedNode;
for (nodeMapType::const_iterator it = current->children.begin(); it != current->children.end(); ++it) {
const std::string str = name + char(it->first);
cachedNode = cache.find(str);
name.push_back(it->first);
cachedNode = cache.find(name);
if (cachedNode != cache.end())
recursiveFlattenTrie(str, cachedNode->second, nodes);
recursiveIterateTrie(name, cachedNode->second, callback);
else
recursiveFlattenTrie(str, it->second, nodes);
recursiveIterateTrie(name, it->second, callback);
name.erase(name.end() - 1);
}
}
std::vector<namedNodeType> CClaimTrieCache::flattenTrie() const
bool CClaimTrieCache::iterateTrie(CNodeCallback& callback) const
{
std::vector<namedNodeType> nodes;
recursiveFlattenTrie("", getRoot(), nodes);
return nodes;
try {
std::string name;
recursiveIterateTrie(name, getRoot(), callback);
assert(name.empty());
} catch (const CNodeCallback::CRecursionInterruptionException& ex) {
return ex.success;
}
return true;
}
claimsForNameType CClaimTrieCache::getClaimsForName(const std::string& name) const

View file

@ -332,7 +332,6 @@ public:
bool WriteToDisk();
bool ReadFromDisk(bool check = false);
std::vector<namedNodeType> flattenTrie() const;
bool getInfoForName(const std::string& name, CClaimValue& claim) const;
bool getLastTakeoverForName(const std::string& name, int& lastTakeoverHeight) const;
@ -407,9 +406,6 @@ private:
unsigned int getTotalClaimsRecursive(const CClaimTrieNode* current) const;
CAmount getTotalValueOfClaimsRecursive(const CClaimTrieNode* current,
bool fControllingOnly) const;
bool recursiveFlattenTrie(const std::string& name,
const CClaimTrieNode* current,
std::vector<namedNodeType>& nodes) const;
void markNodeDirty(const std::string& name, CClaimTrieNode* node);
void updateQueueRow(int nHeight, claimQueueRowType& row);
@ -474,6 +470,27 @@ public:
int nHeightOfLastTakeover;
};
struct CNodeCallback {
struct CRecursionInterruptionException : public std::exception {
const bool success;
explicit CRecursionInterruptionException(bool success) : success(success) {}
};
virtual ~CNodeCallback()
{
}
/**
* Callback to be called on every trie node
* @param[in] name full name of the node
* @param[in] node pointer to node itself
*
* To breakout early throw an exception.
* Throwing CRecursionInterruptionException will allow you to set the return value of iterateTrie.
*/
virtual void visit(const std::string& name, const CClaimTrieNode* node) = 0;
};
class CClaimTrieCache
{
public:
@ -548,7 +565,7 @@ public:
bool forkForExpirationChange(bool increment) const;
std::vector<namedNodeType> flattenTrie() const;
bool iterateTrie(CNodeCallback& callback) const;
claimsForNameType getClaimsForName(const std::string& name) const;
@ -572,7 +589,7 @@ protected:
mutable queueNameType supportQueueNameCache;
mutable expirationQueueType supportExpirationQueueCache;
mutable std::set<std::string> namesToCheckForTakeover;
mutable std::map<std::string, int> cacheTakeoverHeights;
mutable std::map<std::string, int> cacheTakeoverHeights;
mutable int nCurrentHeight; // Height of the block that is being worked on, which is
// one greater than the height of the chain's tip
mutable claimIndexElementListType claimsToAdd;
@ -647,7 +664,7 @@ protected:
int getNumBlocksOfContinuousOwnership(const std::string& name) const;
void recursiveFlattenTrie(const std::string& name, const CClaimTrieNode* current, std::vector<namedNodeType>& nodes) const;
void recursiveIterateTrie(std::string& name, const CClaimTrieNode* current, CNodeCallback& callback) const;
const CClaimTrieNode* getNodeForName(const std::string& name) const;
};

View file

@ -218,7 +218,7 @@ static bool InitRPCAuthentication()
LogPrintf("No rpcpassword set - using random cookie authentication.\n");
if (!GenerateAuthCookie(&strRPCUserColonPass)) {
uiInterface.ThreadSafeMessageBox(
_("Error: A fatal internal error occurred, see debug.log for details"), // Same message as AbortNode
_("Error: A fatal internal error occurred generating the cookie, see debug.log for details"), // Same message as AbortNode
"", CClientUIInterface::MSG_ERROR);
return false;
}

View file

@ -3,15 +3,16 @@
#include <core_io.h>
#include <nameclaim.h>
#include <rpc/server.h>
#include <shutdown.h>
#include <txdb.h>
#include <txmempool.h>
#include <univalue.h>
#include <validation.h>
// Maximum block decrement that is allowed from rpc calls
const int MAX_RPC_BLOCK_DECREMENTS = 50;
#include <boost/thread.hpp>
#include <cmath>
static uint160 ParseClaimtrieId(const UniValue& v, const std::string& strName)
uint160 ParseClaimtrieId(const UniValue& v, const std::string& strName)
{
static constexpr size_t claimIdHexLength = 40;
@ -39,43 +40,70 @@ static CBlockIndex* BlockHashIndex(const uint256& blockHash)
if (!chainActive.Contains(pblockIndex))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not in main chain");
if (chainActive.Tip()->nHeight > (pblockIndex->nHeight + MAX_RPC_BLOCK_DECREMENTS))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block is too deep");
return pblockIndex;
}
static std::string encodeValue(const std::string& value)
#define MAX_RPC_BLOCK_DECREMENTS 500
extern CChainState g_chainstate;
void RollBackTo(const CBlockIndex* targetIndex, CCoinsViewCache& coinsCache, CClaimTrieCache& trieCache)
{
// FIXME: match old encoding??
return SanitizeString(value);
AssertLockHeld(cs_main);
const CBlockIndex* activeIndex = chainActive.Tip();
if (activeIndex->nHeight > (targetIndex->nHeight + MAX_RPC_BLOCK_DECREMENTS))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block is too deep");
const size_t currentMemoryUsage = pcoinsTip->DynamicMemoryUsage();
for (; activeIndex && activeIndex != targetIndex; activeIndex = activeIndex->pprev) {
boost::this_thread::interruption_point();
CBlock block;
if (!ReadBlockFromDisk(block, activeIndex, Params().GetConsensus()))
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Failed to read %s", activeIndex->ToString()));
if (coinsCache.DynamicMemoryUsage() + currentMemoryUsage > nCoinCacheUsage)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Out of memory, you may want to increase dbcache size");
if (ShutdownRequested())
throw JSONRPCError(RPC_INTERNAL_ERROR, "Shutdown requested");
if (g_chainstate.DisconnectBlock(block, activeIndex, coinsCache, trieCache) != DisconnectResult::DISCONNECT_OK)
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Failed to disconnect %s", block.ToString()));
}
}
static UniValue getclaimsintrie(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() > 0)
if (request.fHelp || request.params.size() > 1)
throw std::runtime_error(
"getclaimsintrie\n"
"Return all claims in the name trie.\n"
"Arguments:\n"
"None\n"
"1. \"blockhash\" (string, optional) get claims in the trie\n"
" at the block specified\n"
" by this block hash.\n"
" If none is given,\n"
" the latest active\n"
" block will be used.\n"
"Result: \n"
"[\n"
" {\n"
" \"name\" (string) the name claimed\n"
" \"claims\": [ (array of object) the claims for this name\n"
" \"name\" (string) the name claimed\n"
" \"claims\": [ (array of object) the claims for this name\n"
" {\n"
" \"claimId\" (string) the claimId of the claim\n"
" \"txid\" (string) the txid of the claim\n"
" \"n\" (numeric) the vout value of the claim\n"
" \"amount\" (numeric) txout amount\n"
" \"height\" (numeric) the height of the block in which this transaction is located\n"
" \"value\" (string) the value of this claim\n"
" \"claimId\" (string) the claimId of the claim\n"
" \"txid\" (string) the txid of the claim\n"
" \"n\" (numeric) the vout value of the claim\n"
" \"amount\" (numeric) txout amount\n"
" \"height\" (numeric) the height of the block in which this transaction is located\n"
" \"value\" (string) the value of this claim\n"
" }\n"
" ]\n"
" }\n"
"]\n"
);
"]\n");
LOCK(cs_main);
@ -84,21 +112,28 @@ static UniValue getclaimsintrie(const JSONRPCRequest& request)
if (!request.params.empty()) {
CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(request.params[0], "blockhash (optional parameter 1)"));
if (!RollBackTo(blockIndex, coinsCache, trieCache))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Rollback failure");
RollBackTo(blockIndex, coinsCache, trieCache);
}
UniValue ret(UniValue::VARR);
std::vector<namedNodeType> nodes = pclaimTrie->flattenTrie();
for (std::vector<namedNodeType>::iterator it = nodes.begin(); it != nodes.end(); ++it)
class CClaimsCallback : public CNodeCallback
{
if (!it->second.claims.empty())
public:
CClaimsCallback(UniValue& ret, const CCoinsViewCache& coinsCache) : nodes(ret), coinsCache(coinsCache)
{
UniValue node(UniValue::VOBJ);
node.pushKV("name", encodeValue(it->first));
}
void visit(const std::string& name, const CClaimTrieNode* node)
{
if (ShutdownRequested())
throw JSONRPCError(RPC_INTERNAL_ERROR, "Shutdown requested");
boost::this_thread::interruption_point();
if (node->claims.empty())
return;
UniValue claims(UniValue::VARR);
for (std::vector<CClaimValue>::iterator itClaims = it->second.claims.begin(); itClaims != it->second.claims.end(); ++itClaims)
{
for (std::vector<CClaimValue>::const_iterator itClaims = node->claims.begin(); itClaims != node->claims.end(); ++itClaims) {
UniValue claim(UniValue::VOBJ);
claim.pushKV("claimId", itClaims->claimId.GetHex());
claim.pushKV("txid", itClaims->outPoint.hash.GetHex());
@ -120,55 +155,97 @@ static UniValue getclaimsintrie(const JSONRPCRequest& request)
LogPrintf("%s: the specified txout of %s does not have an claim command\n", __func__, itClaims->outPoint.hash.GetHex());
}
std::string sValue(vvchParams[1].begin(), vvchParams[1].end());
claim.pushKV("value", encodeValue(sValue));
claim.pushKV("value", sValue);
}
claims.push_back(claim);
}
node.pushKV("claims", claims);
ret.push_back(node);
UniValue nodeObj(UniValue::VOBJ);
nodeObj.pushKV("name", name);
nodeObj.pushKV("claims", claims);
nodes.push_back(nodeObj);
}
}
private:
UniValue& nodes;
const CCoinsViewCache& coinsCache;
};
UniValue ret(UniValue::VARR);
CClaimsCallback claimsCallback(ret, coinsCache);
trieCache.iterateTrie(claimsCallback);
return ret;
}
static UniValue getclaimtrie(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() > 0)
if (request.fHelp || request.params.size() > 1)
throw std::runtime_error(
"getclaimtrie\n"
"Return the entire claim trie.\n"
"DEPRECATED. Return the entire claim trie.\n"
"Arguments:\n"
"None\n"
"1. \"blockhash\" (string, optional) get claim in the trie\n"
" at the block specified\n"
" by this block hash.\n"
" If none is given,\n"
" the latest active\n"
" block will be used.\n"
"Result: \n"
"{\n"
"[\n"
" {\n"
" \"name\" (string) the name of the node\n"
" \"hash\" (string) the hash of the node\n"
" \"txid\" (string) (if value exists) the hash of the transaction which has successfully claimed this name\n"
" \"n\" (numeric) (if value exists) vout value\n"
" \"value\" (numeric) (if value exists) txout value\n"
" \"height\" (numeric) (if value exists) the height of the block in which this transaction is located\n"
"}\n"
);
" }\n"
"]\n");
LOCK(cs_main);
UniValue ret(UniValue::VARR);
std::vector<namedNodeType> nodes = pclaimTrie->flattenTrie();
for (std::vector<namedNodeType>::iterator it = nodes.begin(); it != nodes.end(); ++it)
{
UniValue node(UniValue::VOBJ);
node.pushKV("name", encodeValue(it->first));
node.pushKV("hash", it->second.hash.GetHex());
CClaimValue claim;
if (it->second.getBestClaim(claim))
{
node.pushKV("txid", claim.outPoint.hash.GetHex());
node.pushKV("n", (int)claim.outPoint.n);
node.pushKV("value", ValueFromAmount(claim.nAmount));
node.pushKV("height", claim.nHeight);
}
ret.push_back(node);
CCoinsViewCache coinsCache(pcoinsTip.get());
CClaimTrieCache trieCache(pclaimTrie);
if (!request.params.empty()) {
CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(request.params[0], "blockhash (optional parameter 1)"));
RollBackTo(blockIndex, coinsCache, trieCache);
}
class CClaimCallback : public CNodeCallback
{
public:
CClaimCallback(UniValue& ret) : nodes(ret)
{
}
void visit(const std::string& name, const CClaimTrieNode* node)
{
if (ShutdownRequested())
throw JSONRPCError(RPC_INTERNAL_ERROR, "Shutdown requested");
boost::this_thread::interruption_point();
UniValue nodeObj(UniValue::VOBJ);
nodeObj.pushKV("name", name);
nodeObj.pushKV("hash", node->hash.GetHex());
CClaimValue claim;
if (node->getBestClaim(claim)) {
nodeObj.pushKV("txid", claim.outPoint.hash.GetHex());
nodeObj.pushKV("n", (int)claim.outPoint.n);
nodeObj.pushKV("value", ::ValueFromAmount(claim.nAmount));
nodeObj.pushKV("height", claim.nHeight);
}
nodes.push_back(nodeObj);
}
private:
UniValue& nodes;
};
UniValue ret(UniValue::VARR);
CClaimCallback claimCallback(ret);
trieCache.iterateTrie(claimCallback);
return ret;
}
@ -202,7 +279,7 @@ static bool getValueForClaim(const CCoinsViewCache& coinsCache, const COutPoint&
static UniValue getvalueforname(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 1)
if (request.fHelp || request.params.size() > 2)
throw std::runtime_error(
"getvalueforname \"name\"\n"
"Return the value associated with a name, if one exists\n"
@ -231,8 +308,7 @@ static UniValue getvalueforname(const JSONRPCRequest& request)
if (request.params.size() > 1) {
CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(request.params[1], "blockhash (optional parameter 2)"));
if (!RollBackTo(blockIndex, coinsCache, trieCache))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Rollback failure");
RollBackTo(blockIndex, coinsCache, trieCache);
}
const auto& name = request.params[0].get_str();
@ -248,7 +324,7 @@ static UniValue getvalueforname(const JSONRPCRequest& request)
const auto nEffectiveAmount = trieCache.getEffectiveAmountForClaim(name, claim.claimId);
ret.pushKV("value", encodeValue(sValue));
ret.pushKV("value", sValue);
ret.pushKV("claimId", claim.claimId.GetHex());
ret.pushKV("txid", claim.outPoint.hash.GetHex());
ret.pushKV("n", (int)claim.outPoint.n);
@ -272,7 +348,7 @@ UniValue supportToJSON(const CSupportValue& support)
return ret;
}
UniValue claimAndSupportsToJSON(CAmount nEffectiveAmount, claimSupportMapType::const_iterator itClaimsAndSupports)
UniValue claimAndSupportsToJSON(const CCoinsViewCache& coinsCache, CAmount nEffectiveAmount, claimSupportMapType::const_iterator itClaimsAndSupports)
{
const CClaimValue& claim = itClaimsAndSupports->second.first;
const std::vector<CSupportValue>& supports = itClaimsAndSupports->second.second;
@ -288,6 +364,9 @@ UniValue claimAndSupportsToJSON(CAmount nEffectiveAmount, claimSupportMapType::c
result.pushKV("nHeight", claim.nHeight);
result.pushKV("nValidAtHeight", claim.nValidAtHeight);
result.pushKV("nAmount", claim.nAmount);
std::string sValue;
if (getValueForClaim(coinsCache, claim.outPoint, sValue))
result.pushKV("value", sValue);
result.pushKV("nEffectiveAmount", nEffectiveAmount);
result.pushKV("supports", supportObjs);
return result;
@ -295,16 +374,22 @@ UniValue claimAndSupportsToJSON(CAmount nEffectiveAmount, claimSupportMapType::c
UniValue getclaimsforname(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 1)
if (request.fHelp || request.params.size() > 2)
throw std::runtime_error(
"getclaimsforname\n"
"Return all claims and supports for a name\n"
"Arguments: \n"
"1. \"name\" (string) the name for which to get claims and supports\n"
"1. \"name\" (string) the name for which to get claims and supports\n"
"2. \"blockhash\" (string, optional) get claims for name\n"
" at the block specified\n"
" by this block hash.\n"
" If none is given,\n"
" the latest active\n"
" block will be used.\n"
"Result:\n"
"{\n"
" \"nLastTakeoverheight\" (numeric) the last height at which ownership of the name changed\n"
" \"claims\": [ (array of object) claims for this name\n"
" \"nLastTakeoverHeight\" (numeric) the last height at which ownership of the name changed\n"
" \"claims\": [ (array of object) claims for this name\n"
" {\n"
" \"claimId\" (string) the claimId of this claim\n"
" \"txid\" (string) the txid of this claim\n"
@ -312,6 +397,7 @@ UniValue getclaimsforname(const JSONRPCRequest& request)
" \"nHeight\" (numeric) the height at which the claim was included in the blockchain\n"
" \"nValidAtHeight\" (numeric) the height at which the claim became/becomes valid\n"
" \"nAmount\" (numeric) the amount of the claim\n"
" \"value\" (string) the value of the name, if it exists\n"
" \"nEffectiveAmount\" (numeric) the total effective amount of the claim, taking into effect whether the claim or support has reached its nValidAtHeight\n"
" \"supports\" : [ (array of object) supports for this claim\n"
" \"txid\" (string) the txid of the support\n"
@ -322,7 +408,7 @@ UniValue getclaimsforname(const JSONRPCRequest& request)
" ]\n"
" }\n"
" ],\n"
" \"unmatched supports\": [ (array of object) supports that did not match a claim for this name\n"
" \"supports without claims\": [ (array of object) supports that did not match a claim for this name\n"
" {\n"
" \"txid\" (string) the txid of the support\n"
" \"n\" (numeric) the index of the support in the transaction's list of outputs\n"
@ -331,8 +417,7 @@ UniValue getclaimsforname(const JSONRPCRequest& request)
" \"nAmount\" (numeric) the amount of the support\n"
" }\n"
" ]\n"
"}\n"
);
"}\n");
LOCK(cs_main);
@ -341,13 +426,11 @@ UniValue getclaimsforname(const JSONRPCRequest& request)
if (request.params.size() > 1) {
CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(request.params[1], "blockhash (optional parameter 2)"));
if (!RollBackTo(blockIndex, coinsCache, trieCache))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Rollback failure");
RollBackTo(blockIndex, coinsCache, trieCache);
}
std::string name = request.params[0].get_str();
claimsForNameType claimsForName = pclaimTrie->getClaimsForName(name);
claimsForNameType claimsForName = trieCache.getClaimsForName(name);
UniValue claimObjs(UniValue::VARR);
claimSupportMapType claimSupportMap;
@ -374,11 +457,12 @@ UniValue getclaimsforname(const JSONRPCRequest& request)
for (claimSupportMapType::const_iterator itClaimsAndSupports = claimSupportMap.begin(); itClaimsAndSupports != claimSupportMap.end(); ++itClaimsAndSupports)
{
const auto nEffectiveAmount = trieCache.getEffectiveAmountForClaim(claimsForName, itClaimsAndSupports->first);
claimObjs.push_back(claimAndSupportsToJSON(nEffectiveAmount, itClaimsAndSupports));
UniValue claimObj = claimAndSupportsToJSON(coinsCache, nEffectiveAmount, itClaimsAndSupports);
claimObjs.push_back(claimObj);
}
result.pushKV("claims", claimObjs);
result.pushKV("unmatched supports", unmatchedSupports);
result.pushKV("supports without claims", unmatchedSupports);
return result;
}
@ -426,7 +510,7 @@ UniValue getclaimbyid(const JSONRPCRequest& request)
claim.pushKV("name", name);
CCoinsViewCache coinsCache(pcoinsTip.get());
if (getValueForClaim(coinsCache, claimValue.outPoint, sValue))
claim.pushKV("value", encodeValue(sValue));
claim.pushKV("value", sValue);
claim.pushKV("claimId", claimValue.claimId.GetHex());
claim.pushKV("txid", claimValue.outPoint.hash.GetHex());
claim.pushKV("n", (int) claimValue.outPoint.n);
@ -465,7 +549,7 @@ UniValue gettotalclaimednames(const JSONRPCRequest& request)
if (!pclaimTrie)
{
return -1;
}
}
unsigned int num_names = pclaimTrie->getTotalNamesInTrie();
return int(num_names);
}
@ -543,16 +627,13 @@ UniValue getclaimsfortx(const JSONRPCRequest& request)
);
LOCK(cs_main);
uint256 hash;
hash.SetHex(request.params[0].get_str());
uint256 hash = ParseHashV(request.params[0], "txid (parameter 1)");
UniValue ret(UniValue::VARR);
int op;
std::vector<std::vector<unsigned char> > vvchParams;
CCoinsViewCache &view = *pcoinsTip;
CCoinsViewCache view(pcoinsTip.get());
const Coin& coin = AccessByTxid(view, hash);
std::vector<CTxOut> txouts{ coin.out };
int nHeight = coin.nHeight;
@ -574,14 +655,14 @@ UniValue getclaimsfortx(const JSONRPCRequest& request)
std::string sValue(vvchParams[1].begin(), vvchParams[1].end());
uint160 claimId = ClaimIdHash(hash, i);
o.pushKV("claimId", claimId.GetHex());
o.pushKV("value", encodeValue(sValue));
o.pushKV("value", sValue);
}
else if (op == OP_UPDATE_CLAIM)
{
uint160 claimId(vvchParams[1]);
std::string sValue(vvchParams[2].begin(), vvchParams[2].end());
o.pushKV("claimId", claimId.GetHex());
o.pushKV("value", encodeValue(sValue));
o.pushKV("value", sValue);
}
else if (op == OP_SUPPORT_CLAIM)
{
@ -733,7 +814,7 @@ UniValue getnameproof(const JSONRPCRequest& request)
" this will not\n"
" exist whether\n"
" the node has a\n"
" value or not\n"
" value or not\n"
" ]\n"
" \"txhash\" : \"hash\" (string, if exists) the txid of the\n"
" claim which controls\n"
@ -751,30 +832,18 @@ UniValue getnameproof(const JSONRPCRequest& request)
"}\n");
LOCK(cs_main);
std::string strName = request.params[0].get_str();
uint256 blockHash;
if (request.params.size() == 2)
{
std::string strBlockHash = request.params[1].get_str();
blockHash = uint256S(strBlockHash);
CCoinsViewCache coinsCache(pcoinsTip.get());
CClaimTrieCache trieCache(pclaimTrie);
if (request.params.size() == 2) {
CBlockIndex* pblockIndex = BlockHashIndex(ParseHashV(request.params[1], "blockhash (optional parameter 2)"));
RollBackTo(pblockIndex, coinsCache, trieCache);
}
else
{
blockHash = chainActive.Tip()->GetBlockHash();
}
if (mapBlockIndex.count(blockHash) == 0)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
CBlockIndex* pblockIndex = mapBlockIndex[blockHash];
if (!chainActive.Contains(pblockIndex))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not in main chain");
if (chainActive.Tip()->nHeight > (pblockIndex->nHeight + MAX_RPC_BLOCK_DECREMENTS))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block too deep to generate proof");
CClaimTrieProof proof;
if (!GetProofForName(pblockIndex, strName, proof))
std::string name = request.params[0].get_str();
if (!trieCache.getProofForName(name, proof))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Failed to generate proof");
return proofToJSON(proof);
@ -783,10 +852,10 @@ UniValue getnameproof(const JSONRPCRequest& request)
static const CRPCCommand commands[] =
{ // category name actor (function) argNames
// --------------------- ------------------------ ----------------------- ----------
{ "Claimtrie", "getclaimsintrie", &getclaimsintrie, { "" } },
{ "Claimtrie", "getclaimtrie", &getclaimtrie, { "" } },
{ "Claimtrie", "getvalueforname", &getvalueforname, { "name" } },
{ "Claimtrie", "getclaimsforname", &getclaimsforname, { "name" } },
{ "Claimtrie", "getclaimsintrie", &getclaimsintrie, { "blockhash" } },
{ "Claimtrie", "getclaimtrie", &getclaimtrie, { "blockhash" } },
{ "Claimtrie", "getvalueforname", &getvalueforname, { "name","blockhash" } },
{ "Claimtrie", "getclaimsforname", &getclaimsforname, { "name","blockhash" } },
{ "Claimtrie", "gettotalclaimednames", &gettotalclaimednames, { "" } },
{ "Claimtrie", "gettotalclaims", &gettotalclaims, { "" } },
{ "Claimtrie", "gettotalvalueofclaims", &gettotalvalueofclaims, { "controlling_only" } },

View file

@ -126,7 +126,7 @@ UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGen
LOCK(cs_main);
IncrementExtraNonce(pblock, chainActive.Tip(), nExtraNonce);
}
while (nMaxTries > 0 && pblock->nNonce < nInnerLoopCount && !CheckProofOfWork(pblock->GetHash(), pblock->nBits, Params().GetConsensus())) {
while (nMaxTries > 0 && pblock->nNonce < nInnerLoopCount && !CheckProofOfWork(pblock->GetPoWHash(), pblock->nBits, Params().GetConsensus())) {
++pblock->nNonce;
--nMaxTries;
}

View file

@ -48,7 +48,7 @@ static CBlock BuildBlockTestCase() {
bool mutated;
block.hashMerkleRoot = BlockMerkleRoot(block, &mutated);
assert(!mutated);
while (!CheckProofOfWork(block.GetHash(), block.nBits, Params().GetConsensus())) ++block.nNonce;
while (!CheckProofOfWork(block.GetPoWHash(), block.nBits, Params().GetConsensus())) ++block.nNonce;
return block;
}
@ -296,7 +296,7 @@ BOOST_AUTO_TEST_CASE(EmptyBlockRoundTripTest)
bool mutated;
block.hashMerkleRoot = BlockMerkleRoot(block, &mutated);
assert(!mutated);
while (!CheckProofOfWork(block.GetHash(), block.nBits, Params().GetConsensus())) ++block.nNonce;
while (!CheckProofOfWork(block.GetPoWHash(), block.nBits, Params().GetConsensus())) ++block.nNonce;
// Test simple header round-trip with only coinbase
{

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,331 @@
#include "claimtrie.h"
#include "nameclaim.h"
#include "uint256.h"
#include "validation.h"
#include "test/test_bitcoin.h"
#include <boost/test/unit_test.hpp>
using namespace std;
class CClaimTrieCacheTest : public CClaimTrieCache {
public:
CClaimTrieCacheTest(CClaimTrie* base):
CClaimTrieCache(base, false){}
bool recursiveComputeMerkleHash(CClaimTrieNode* tnCurrent,
std::string sPos) const
{
return CClaimTrieCache::recursiveComputeMerkleHash(tnCurrent, sPos);
}
bool recursivePruneName(CClaimTrieNode* tnCurrent, unsigned int nPos, std::string sName, bool* pfNullified) const
{
return CClaimTrieCache::recursivePruneName(tnCurrent,nPos,sName, pfNullified);
}
bool insertSupportIntoMap(const std::string& name, CSupportValue support, bool fCheckTakeover) const
{
return CClaimTrieCache::insertSupportIntoMap(name, support, fCheckTakeover);
}
int cacheSize()
{
return cache.size();
}
nodeCacheType::iterator getCache(std::string key)
{
return cache.find(key);
}
};
CMutableTransaction BuildTransaction(const uint256& prevhash)
{
CMutableTransaction tx;
tx.nVersion = 1;
tx.nLockTime = 0;
tx.vin.resize(1);
tx.vout.resize(1);
tx.vin[0].prevout.hash = prevhash;
tx.vin[0].prevout.n = 0;
tx.vin[0].scriptSig = CScript();
tx.vin[0].nSequence = std::numeric_limits<unsigned int>::max();
tx.vout[0].scriptPubKey = CScript();
tx.vout[0].nValue = 0;
return tx;
}
BOOST_FIXTURE_TEST_SUITE(claimtriecache_tests, RegTestingSetup)
BOOST_AUTO_TEST_CASE(merkle_hash_single_test)
{
// check empty trie
uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
CClaimTrieCacheTest cc(pclaimTrie);
BOOST_CHECK(one == cc.getMerkleHash());
// check trie with only root node
CClaimTrieNode base_node;
cc.recursiveComputeMerkleHash(&base_node, "");
BOOST_CHECK(one == cc.getMerkleHash());
}
BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
{
CClaimValue unused;
uint256 hash0(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
uint160 hash160;
CMutableTransaction tx1 = BuildTransaction(hash0);
COutPoint tx1OutPoint(tx1.GetHash(), 0);
CMutableTransaction tx2 = BuildTransaction(tx1.GetHash());
COutPoint tx2OutPoint(tx2.GetHash(), 0);
CMutableTransaction tx3 = BuildTransaction(tx2.GetHash());
COutPoint tx3OutPoint(tx3.GetHash(), 0);
CMutableTransaction tx4 = BuildTransaction(tx3.GetHash());
COutPoint tx4OutPoint(tx4.GetHash(), 0);
CMutableTransaction tx5 = BuildTransaction(tx4.GetHash());
COutPoint tx5OutPoint(tx5.GetHash(), 0);
CMutableTransaction tx6 = BuildTransaction(tx5.GetHash());
COutPoint tx6OutPoint(tx6.GetHash(), 0);
uint256 hash1;
hash1.SetHex("71c7b8d35b9a3d7ad9a1272b68972979bbd18589f1efe6f27b0bf260a6ba78fa");
uint256 hash2;
hash2.SetHex("c4fc0e2ad56562a636a0a237a96a5f250ef53495c2cb5edd531f087a8de83722");
uint256 hash3;
hash3.SetHex("baf52472bd7da19fe1e35116cfb3bd180d8770ffbe3ae9243df1fb58a14b0975");
uint256 hash4;
hash4.SetHex("c73232a755bf015f22eaa611b283ff38100f2a23fb6222e86eca363452ba0c51");
BOOST_CHECK(pclaimTrie->empty());
CClaimTrieCache ntState(pclaimTrie, false);
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, hash160, 50, 100, 200));
ntState.insertClaimIntoTrie(std::string("test2"), CClaimValue(tx2OutPoint, hash160, 50, 100, 200));
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(!ntState.empty());
BOOST_CHECK(ntState.getMerkleHash() == hash1);
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3OutPoint, hash160, 50, 101, 201));
BOOST_CHECK(ntState.getMerkleHash() == hash1);
ntState.insertClaimIntoTrie(std::string("tes"), CClaimValue(tx4OutPoint, hash160, 50, 100, 200));
BOOST_CHECK(ntState.getMerkleHash() == hash2);
ntState.insertClaimIntoTrie(std::string("testtesttesttest"), CClaimValue(tx5OutPoint, hash160, 50, 100, 200));
ntState.removeClaimFromTrie(std::string("testtesttesttest"), tx5OutPoint, unused);
BOOST_CHECK(ntState.getMerkleHash() == hash2);
ntState.flush();
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash2);
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState1(pclaimTrie, false);
ntState1.removeClaimFromTrie(std::string("test"), tx1OutPoint, unused);
ntState1.removeClaimFromTrie(std::string("test2"), tx2OutPoint, unused);
ntState1.removeClaimFromTrie(std::string("test"), tx3OutPoint, unused);
ntState1.removeClaimFromTrie(std::string("tes"), tx4OutPoint, unused);
BOOST_CHECK(ntState1.getMerkleHash() == hash0);
CClaimTrieCache ntState2(pclaimTrie, false);
ntState2.insertClaimIntoTrie(std::string("abab"), CClaimValue(tx6OutPoint, hash160, 50, 100, 200));
ntState2.removeClaimFromTrie(std::string("test"), tx1OutPoint, unused);
BOOST_CHECK(ntState2.getMerkleHash() == hash3);
ntState2.flush();
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash3);
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState3(pclaimTrie, false);
ntState3.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, hash160, 50, 100, 200));
BOOST_CHECK(ntState3.getMerkleHash() == hash4);
ntState3.flush();
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash4);
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState4(pclaimTrie, false);
ntState4.removeClaimFromTrie(std::string("abab"), tx6OutPoint, unused);
BOOST_CHECK(ntState4.getMerkleHash() == hash2);
ntState4.flush();
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash2);
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState5(pclaimTrie, false);
ntState5.removeClaimFromTrie(std::string("test"), tx3OutPoint, unused);
BOOST_CHECK(ntState5.getMerkleHash() == hash2);
ntState5.flush();
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash2);
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState6(pclaimTrie, false);
ntState6.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3OutPoint, hash160, 50, 101, 201));
BOOST_CHECK(ntState6.getMerkleHash() == hash2);
ntState6.flush();
BOOST_CHECK(!pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash2);
BOOST_CHECK(pclaimTrie->checkConsistency());
CClaimTrieCache ntState7(pclaimTrie, false);
ntState7.removeClaimFromTrie(std::string("test"), tx3OutPoint, unused);
ntState7.removeClaimFromTrie(std::string("test"), tx1OutPoint, unused);
ntState7.removeClaimFromTrie(std::string("tes"), tx4OutPoint, unused);
ntState7.removeClaimFromTrie(std::string("test2"), tx2OutPoint, unused);
BOOST_CHECK(ntState7.getMerkleHash() == hash0);
ntState7.flush();
BOOST_CHECK(pclaimTrie->empty());
BOOST_CHECK(pclaimTrie->getMerkleHash() == hash0);
BOOST_CHECK(pclaimTrie->checkConsistency());
}
BOOST_AUTO_TEST_CASE(basic_insertion_info_test)
{
// test basic claim insertions and that get methods retreives information properly
BOOST_CHECK(pclaimTrie->empty());
CClaimTrieCacheTest ctc(pclaimTrie);
// create and insert claim
CClaimValue unused;
uint256 hash0(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
CMutableTransaction tx1 = BuildTransaction(hash0);
uint160 claimId = ClaimIdHash(tx1.GetHash(), 0);
COutPoint claimOutPoint(tx1.GetHash(), 0);
CAmount amount(10);
int height = 0;
int validHeight = 0;
CClaimValue claimVal(claimOutPoint, claimId, amount, height, validHeight);
ctc.insertClaimIntoTrie("test", claimVal);
// try getClaimsForName, getEffectiveAmountForClaim, getInfoForName
claimsForNameType res = ctc.getClaimsForName("test");
BOOST_CHECK(res.claims.size() == 1);
BOOST_CHECK(res.claims[0] == claimVal);
BOOST_CHECK_EQUAL(10, ctc.getEffectiveAmountForClaim("test", claimId));
CClaimValue claim;
BOOST_CHECK(ctc.getInfoForName("test", claim));
BOOST_CHECK(claim == claimVal);
// insert a support
CAmount supportAmount(10);
uint256 hash1(uint256S("0000000000000000000000000000000000000000000000000000000000000002"));
CMutableTransaction tx2 = BuildTransaction(hash1);
COutPoint supportOutPoint(tx2.GetHash(), 0);
CSupportValue support(supportOutPoint, claimId, supportAmount, height, validHeight);
ctc.insertSupportIntoMap("test", support, false);
// try getEffectiveAmount
BOOST_CHECK_EQUAL(20, ctc.getEffectiveAmountForClaim("test", claimId));
}
BOOST_AUTO_TEST_CASE(recursive_prune_test)
{
CClaimTrieCacheTest cc(pclaimTrie);
BOOST_CHECK_EQUAL(0, cc.cacheSize());
COutPoint outpoint;
uint160 claimId;
CAmount amount(20);
int height = 0;
int validAtHeight = 0;
CClaimValue test_claim(outpoint, claimId, amount, height, validAtHeight);
CClaimTrieNode base_node;
// base node has a claim, so it should not be pruned
base_node.insertClaim(test_claim);
// node 1 has a claim so it should not be pruned
CClaimTrieNode node_1;
const char c = 't';
base_node.children[c] = &node_1;
node_1.insertClaim(test_claim);
// set this just to make sure we get the right CClaimTrieNode back
node_1.nHeightOfLastTakeover = 10;
//node 2 does not have a claim so it should be pruned
// thus we should find pruned node 1 in cache
CClaimTrieNode node_2;
const char c_2 = 'e';
node_1.children[c_2] = &node_2;
cc.recursivePruneName(&base_node, 0, std::string("te"), NULL);
BOOST_CHECK_EQUAL(1, cc.cacheSize());
nodeCacheType::iterator it = cc.getCache(std::string("t"));
BOOST_CHECK_EQUAL(10, it->second->nHeightOfLastTakeover);
BOOST_CHECK_EQUAL(1, it->second->claims.size());
BOOST_CHECK_EQUAL(0, it->second->children.size());
}
BOOST_AUTO_TEST_CASE(iteratetrie_test)
{
BOOST_CHECK(pclaimTrie->empty());
CClaimTrieCacheTest ctc(pclaimTrie);
uint256 hash0(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
CMutableTransaction tx1 = BuildTransaction(hash0);
const uint256 txhash = tx1.GetHash();
CClaimValue claimVal(COutPoint(txhash, 0), ClaimIdHash(txhash, 0), CAmount(10), 0, 0);
ctc.insertClaimIntoTrie("test", claimVal);
int count = 0;
struct TestCallBack : public CNodeCallback {
TestCallBack(int& count) : count(count)
{
}
void visit(const std::string& name, const CClaimTrieNode* node)
{
count++;
if (name == "test") {
BOOST_CHECK(node->claims.size() == 1);
}
}
int& count;
} testCallback(count);
BOOST_CHECK(ctc.iterateTrie(testCallback));
BOOST_CHECK(count == 5);
count = 3;
struct TestCallBack2 : public CNodeCallback {
TestCallBack2(int& count) : count(count)
{
}
void visit(const std::string& name, const CClaimTrieNode* node)
{
if (--count <= 0)
throw CRecursionInterruptionException(false);
}
int& count;
} testCallback2(count);
BOOST_CHECK(!ctc.iterateTrie(testCallback2));
BOOST_CHECK(count == 0);
}
BOOST_AUTO_TEST_SUITE_END()

View file

@ -0,0 +1,38 @@
#include "nameclaim.h"
#include "primitives/transaction.h"
#include <boost/test/unit_test.hpp>
#include "test/test_bitcoin.h"
//BOOST_FIXTURE_TEST_SUITE(nameclaim_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(calc_min_claimtrie_fee)
{
CMutableTransaction tx;
tx.vout.resize(1);
tx.vout[0].scriptPubKey = ClaimNameScript("A","test");
BOOST_CHECK_EQUAL(CalcMinClaimTrieFee(tx, MIN_FEE_PER_NAMECLAIM_CHAR), MIN_FEE_PER_NAMECLAIM_CHAR);
// check that fee is adjusted based on name length
CMutableTransaction tx2;
tx2.vout.resize(1);
tx2.vout[0].scriptPubKey = ClaimNameScript("ABCDE","test");
BOOST_CHECK_EQUAL(CalcMinClaimTrieFee(tx2,MIN_FEE_PER_NAMECLAIM_CHAR), MIN_FEE_PER_NAMECLAIM_CHAR*5);
// check that multiple OP_CLAIM_NAME outputs are counted
CMutableTransaction tx3;
tx3.vout.resize(2);
tx3.vout[0].scriptPubKey = ClaimNameScript("A","test");
tx3.vout[1].scriptPubKey = ClaimNameScript("AB","test");
BOOST_CHECK_EQUAL(CalcMinClaimTrieFee(tx3,MIN_FEE_PER_NAMECLAIM_CHAR), MIN_FEE_PER_NAMECLAIM_CHAR*3);
// if tx has no claim minimum fee is 0
CMutableTransaction tx4;
tx4.vout.resize(1);
BOOST_CHECK_EQUAL(CalcMinClaimTrieFee(tx4,MIN_FEE_PER_NAMECLAIM_CHAR), 0);
}
//BOOST_AUTO_TEST_SUITE_END()

View file

@ -164,7 +164,7 @@ TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransaction>&
IncrementExtraNonce(&block, chainActive.Tip(), extraNonce);
}
while (!CheckProofOfWork(block.GetHash(), block.nBits, chainparams.GetConsensus())) ++block.nNonce;
while (!CheckProofOfWork(block.GetPoWHash(), block.nBits, chainparams.GetConsensus())) ++block.nNonce;
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(block);
ProcessNewBlock(chainparams, shared_pblock, true, nullptr);

View file

@ -71,7 +71,7 @@ std::shared_ptr<CBlock> FinalizeBlock(std::shared_ptr<CBlock> pblock)
{
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
while (!CheckProofOfWork(pblock->GetHash(), pblock->nBits, Params().GetConsensus())) {
while (!CheckProofOfWork(pblock->GetPoWHash(), pblock->nBits, Params().GetConsensus())) {
++(pblock->nNonce);
}

View file

@ -26,7 +26,7 @@ struct CDiskTxPos;
//! No need to periodic flush if at least this much space still available.
static constexpr int MAX_BLOCK_COINSDB_USAGE = 10;
//! -dbcache default (MiB)
static const int64_t nDefaultDbCache = 450;
static const int64_t nDefaultDbCache = sizeof(void*) > 4 ? 700 : 450;
//! -dbbatchsize default (bytes)
static const int64_t nDefaultDbBatchSize = 16 << 20;
//! max. -dbcache (MiB)

View file

@ -419,44 +419,38 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
*pfMissingInputs = false;
}
std::cout << "About to check Transaction" << std::endl;
if (!CheckTransaction(tx, state))
return false; // state filled in by CheckTransaction
// Coinbase is only valid in a block, not as a loose transaction
std::cout << "About to check IsCoinbase" << std::endl;
if (tx.IsCoinBase())
return state.DoS(100, false, REJECT_INVALID, "coinbase");
// Rather not work on nonstandard transactions (unless -testnet/-regtest)
std::string reason;
std::cout << "About to check reason" << std::endl;
if (fRequireStandard && !IsStandardTx(tx, reason))
return state.DoS(0, false, REJECT_NONSTANDARD, reason);
// Do not work on transactions that are too small.
// A transaction with 1 segwit input and 1 P2WPHK output has non-witness size of 82 bytes.
// Transactions smaller than this are not relayed to reduce unnecessary malloc overhead.
std::cout << "About to check serialize size" << std::endl;
std::cout << "SIZE: " << ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) << " , comparing to " << MIN_STANDARD_TX_NONWITNESS_SIZE << std::endl;
/* if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) < MIN_STANDARD_TX_NONWITNESS_SIZE) */
/* return state.DoS(0, false, REJECT_NONSTANDARD, "tx-size-small"); */
// TODO: do we need this?
// if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) < MIN_STANDARD_TX_NONWITNESS_SIZE)
// return state.DoS(0, false, REJECT_NONSTANDARD, "tx-size-small");
// Only accept nLockTime-using transactions that can be mined in the next
// block; we don't want our mempool filled up with transactions that can't
// be mined yet.
std::cout << "About to check if final" << std::endl;
if (!CheckFinalTx(tx, STANDARD_LOCKTIME_VERIFY_FLAGS))
return state.DoS(0, false, REJECT_NONSTANDARD, "non-final");
// is it already in the memory pool?
std::cout << "About to check if already in mempool" << std::endl;
if (pool.exists(hash)) {
return state.Invalid(false, REJECT_DUPLICATE, "txn-already-in-mempool");
}
// Check for conflicts with in-memory transactions
std::cout << "About to check for conflicts" << std::endl;
std::set<uint256> setConflicts;
for (const CTxIn &txin : tx.vin)
{
@ -500,7 +494,6 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
}
std::cout << "About to check that all inputs exist" << std::endl;
{
CCoinsView dummy;
CCoinsViewCache view(&dummy);
@ -758,7 +751,6 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
// Check against previous transactions
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
std::cout << "About to check inputs" << std::endl;
PrecomputedTransactionData txdata(tx);
if (!CheckInputs(tx, state, view, true, scriptVerifyFlags, true, false, txdata)) {
// SCRIPT_VERIFY_CLEANSTACK requires SCRIPT_VERIFY_WITNESS, so we
@ -954,7 +946,6 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus:
// Check the header
if (!CheckProofOfWork(block.GetPoWHash(), block.nBits, consensusParams))
return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString());
LogPrintf("Block hash is OK! %s\n", block.GetHash().GetHex());
return true;
}
@ -1427,8 +1418,9 @@ static bool AbortNode(const std::string& strMessage, const std::string& userMess
{
SetMiscWarning(strMessage);
LogPrintf("*** %s\n", strMessage);
throw "nasty";
uiInterface.ThreadSafeMessageBox(
userMessage.empty() ? _("Error: A fatal internal error occurred, see debug.log for details") : userMessage,
userMessage.empty() ? "Error: A fatal internal error occurred, see debug.log for details. System message: " + strMessage : userMessage,
"", CClientUIInterface::MSG_ERROR);
StartShutdown();
return false;
@ -4299,42 +4291,6 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
return true;
}
bool RollBackTo(const CBlockIndex* targetIndex, CCoinsViewCache& coinsCache, CClaimTrieCache& trieCache)
{
AssertLockHeld(cs_main);
for (CBlockIndex* index = chainActive.Tip(); index && index != targetIndex; index = index->pprev) {
boost::this_thread::interruption_point();
CBlock block;
if (!ReadBlockFromDisk(block, index, Params().GetConsensus()))
return false; // return error() instead?
if ((coinsCache.DynamicMemoryUsage() + pcoinsTip->DynamicMemoryUsage()) <= nCoinCacheUsage)
return false; // don't allow a single query to chew up all our memory?
if (ShutdownRequested())
return false;
DisconnectResult res = g_chainstate.DisconnectBlock(block, index, coinsCache, trieCache);
if (res == DISCONNECT_FAILED)
return false;
}
return true;
}
bool GetProofForName(const CBlockIndex* pindexProof, const std::string& name, CClaimTrieProof& proof)
{
AssertLockHeld(cs_main);
if (!chainActive.Contains(pindexProof))
return false;
CClaimTrieCache trieCache(pclaimTrie);
CCoinsViewCache coinsCache(pcoinsTip.get());
if (RollBackTo(pindexProof, coinsCache, trieCache))
return trieCache.getProofForName(name, proof);
return false;
}
/** Apply the effects of a block on the utxo cache, ignoring that it may already have been applied. */
bool CChainState::RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& inputs, const CChainParams& params)
{
@ -4617,7 +4573,6 @@ bool CChainState::LoadGenesisBlock(const CChainParams& chainparams)
return error("%s: failed to write genesis block: %s", __func__, e.what());
}
LogPrintf("Loaded Genesis Block\n");
return true;
}

View file

@ -255,10 +255,6 @@ bool CheckDiskSpace(uint64_t nAdditionalBytes = 0, bool blocks_dir = false);
FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false);
/** Translation to a filesystem path */
fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix);
/** Utility method for going back to a previous state **/
bool RollBackTo(const CBlockIndex* targetIndex, CCoinsViewCache& coinsCache, CClaimTrieCache& trieCache);
/** Get a cryptographic proof that a name maps to a value **/
bool GetProofForName(const CBlockIndex* pindexProof, const std::string& name, CClaimTrieProof& proof);
/** Import blocks from an external file */
bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskBlockPos *dbp = nullptr);
/** Ensures we have a genesis block in the block tree, possibly writing one to disk. */
@ -360,7 +356,7 @@ bool TestLockPointValidity(const LockPoints* lp);
bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp = nullptr, bool useExistingLockPoints = false);
/************************************************************
* LBRY moved these from validation.cpp, for testcase usage
* LBRY moved these from validation.cpp, for testcase & RPC usage
* BEGIN
************************************************************/
@ -521,7 +517,7 @@ private:
};
/************************************************************
* LBRY moved these from validation.cpp, for testcase usage
* LBRY moved these from validation.cpp, for testcase & RPC usage
* END
************************************************************/