Compare commits

...
Author SHA1 Message Date
Jack Robison 3a7e7adfe3 bump version to 0.12.0.4 2017-04-13 18:43:48 -04:00
Jack Robison 2b1d07fee4 Merge pull request #60 from lbryio/include-claimid-in-getclaimsintrie
include the claimid in the response for getclaimsintrie
2017-04-13 18:38:26 -04:00
Jack Robison dd8638dba8 include the claimid in the response for getclaimsintrie 2017-04-13 15:10:22 -04:00
Alex Grintsvayg 4ec3516045 bump version to 0.12.0.3 2017-04-03 17:27:03 -04:00
Jack Robison 5913a70f7e Merge pull request #58 from lbryio/add-claimid-to-getvalueforname
add claimId to return from getvalueforname
2017-03-22 21:12:10 -04:00
Jack Robison e6629319a5 add claimId to return from getvalueforname 2017-03-22 15:06:20 -04:00
Kay Kurokawa 4a8e372720 bump version to 12.0.1.2 2017-02-01 11:16:28 -05:00
Umpei Kay Kurokawa 1b896ae75b Merge pull request #56 from lbryio/change_block_decrements
Change max block decrement amount to 50
2017-01-13 10:35:23 -05:00
Umpei Kay Kurokawa ffad0154c1 Merge pull request #55 from lbryio/new_effective_amount
Adding effective amount function to CClaimTrie
2017-01-11 13:46:33 -05:00
Kay Kurokawa 61664b027b change max block decrement amount to 50 2017-01-04 17:52:07 -05:00
Kay Kurokawa 86592934cb Adding effective amount function to CClaimTrie 2017-01-04 13:57:28 -05:00
Umpei Kay Kurokawa 6542b53b36 Merge pull request #53 from kaykurokawa/fix_removesupport_bug_2
Fix remove support bug
2016-11-10 20:18:10 -05:00
Umpei Kay Kurokawa e20f6785ad Merge pull request #52 from kaykurokawa/claimtrie_branching_tests
Claimtrie branching tests with test for remove suppport bug
2016-11-10 20:17:37 -05:00
kkurokawa 51d6b690cb fixing removesupport bug 2016-11-10 20:15:23 -05:00
kkurokawa 03b3828a65 adding test to check for spend of support where i in of txin[i] is not 0 2016-11-01 15:46:32 -04:00
kkurokawa 34f61bbbf0 adding new claimtrie branching tests 2016-10-28 14:28:11 -04:00
Umpei Kay Kurokawa cddeccd2b9 Merge pull request #50 from kaykurokawa/add_claimscript_encode
Adding claimtrie script generation functions
2016-10-28 12:26:43 -04:00
Umpei Kay Kurokawa af860d89cf Merge pull request #49 from kaykurokawa/set_release_true
Set client version as release
2016-10-27 11:06:18 -04:00
kkurokawa 65505b3d55 Adding claimtrie script generation functions 2016-10-27 11:02:21 -04:00
kkurokawa b6d9e4e591 setting client version as release 2016-10-26 11:32:02 -04:00
Job Evers‐Meltzer b89ff5f456 Merge pull request #34 from kaykurokawa/check_dust
Re-enable dust threshold checks
2016-10-18 11:27:20 -05:00
Alex Grintsvayg f288fac940 Bump version: 0.3.15 → 0.3.16 2016-10-13 16:07:25 -04:00
Alex Grintsvayg 7308f24663 get bumpversion back on track 2016-10-13 16:07:17 -04:00
Alex Grin 5a83924245 Merge pull request #47 from lbryio/new_seed_nodes
update fixed seed nodes
2016-10-13 16:05:28 -04:00
Alex Grintsvayg df5f764d52 add testnet dns seeds 2016-10-13 15:46:14 -04:00
Alex Grintsvayg c8199b158d update fixed seed nodes 2016-10-12 20:25:21 -04:00
Alex Grintsvayg 270307a290 license 2016-09-13 22:10:35 -04:00
James Kiselak 0d0d7c5320 Merge pull request #37 from kaykurokawa/bump_version
update version
2016-08-26 18:38:25 -04:00
Alex Grintsvayg e7eaf46f3c bumpversion 2016-08-25 19:14:44 -04:00
James Kiselak fa505b789a Merge pull request #38 from kaykurokawa/new_basic_tests
New basic tests
2016-08-17 21:09:47 -04:00
kkurokawa 1b80858a44 adding test to check the POW algorithm 2016-08-10 21:04:04 -04:00
kkurokawa e0089d19f2 adding test for block with bogus claim trie hash 2016-08-10 16:45:36 -04:00
kkurokawa 50c2ed0fee lowering dust threshold to 1 , in order to not break lbrynet 2016-08-08 20:49:40 -04:00
kkurokawa e4481fc213 update version 2016-08-08 19:12:30 -04:00
Job Evers-Meltzer 083a4a1b88 Change build timeout to 40 minutes 2016-08-08 10:58:58 -05:00
Job Evers-Meltzer cbb6acd75c travis fix: only output last 1000 lines on error 2016-08-08 10:02:46 -05:00
kkurokawa b51444fd5c Re-enable dust threshold checks 2016-08-07 18:58:14 -04:00
Jack Robison 774246d16f Merge pull request #15 from jimmykiselak/claimid_rpc_updates
Claimid rpc updates
2016-08-06 21:25:33 -04:00
Job Evers‐Meltzer 3e26b5f342 Merge pull request #31 from lbryio/build-windows
add windows build to travis
2016-08-03 14:58:25 -05:00
James Kiselak 93eb2e3c47 Merge pull request #1 from kaykurokawa/claimid_rpc_updates_fix
patch for https://github.com/lbryio/lbrycrd/pull/15
2016-08-01 21:47:25 -04:00
kkurokawa ec3801f07a fixing listclaimnames not showing supports, updating help messages for rpc commands 2016-08-01 21:31:20 -04:00
Job Evers 2df151e325 add windows build to travis
Compiles lbrycrdd using mingw to produce a windows executable
2016-07-29 15:12:46 -05:00
Jimmy Kiselak a186aaa073 put useful documentation, also report the last takeover height 2016-07-18 23:29:41 -04:00
Jimmy Kiselak 80bb42c912 make getclaimsforname show useful info and group together supports 2016-07-18 22:37:30 -04:00
Jimmy Kiselak e713501a5d start making getclaimsforname rpc command 2016-07-14 23:11:31 -04:00
Jimmy Kiselak 0551e881f5 fix supports and fix printing of claimid and value for updates 2016-07-11 23:37:17 -04:00
Jimmy Kiselak 31008a84b2 begin updating wallet rpc to use claimids 2016-07-11 00:08:01 -04:00
27 changed files with 1267 additions and 88 deletions

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
[bumpversion]
current_version = 0.3.16
commit = True
tag = True
+25 -4
View File
@@ -4,14 +4,23 @@ matrix:
sudo: required
dist: trusty
language: c
env: TARGET=linux
- os: linux
sudo: required
dist: trusty
language: c
env: TARGET=windows
- os: osx
language: c
osx_image: xcode7.3
env: TARGET=osx
cache:
apt: true
ccache: true
directories:
- build
- depends/built
before_install:
- date +%s > "${TRAVIS_BUILD_DIR}/start_time"
@@ -20,8 +29,12 @@ before_install:
install: true
script:
- ./reproducible_build.sh -t -o -c
- zip -j "lbrycrd-${TRAVIS_OS_NAME}.zip" src/lbrycrdd src/lbrycrd-cli src/lbrycrd-tx
- if [[ "${TARGET}" == "osx" ]]; then ./reproducible_build.sh -t -o -c; fi
- if [[ "${TARGET}" == "linux" ]]; then ./reproducible_build.sh -t -o -c; fi
- if [[ "${TARGET}" == "windows" ]]; then ./packaging/build_windows.sh; fi
- if [[ "${TARGET}" == "osx" ]]; then zip -j "lbrycrd-${TARGET}.zip" src/lbrycrdd src/lbrycrd-cli src/lbrycrd-tx; fi
- if [[ "${TARGET}" == "linux" ]]; then zip -j "lbrycrd-${TARGET}.zip" src/lbrycrdd src/lbrycrd-cli src/lbrycrd-tx; fi
- if [[ "${TARGET}" == "windows" ]]; then zip -j "lbrycrd-${TARGET}.zip" src/lbrycrdd.exe src/lbrycrd-cli.exe src/lbrycrd-tx.exe; fi
before_cache:
- ls -lh build
@@ -33,7 +46,7 @@ deploy:
skip_cleanup: true
on:
tags: true
condition: "$TRAVIS_OS_NAME = linux"
condition: "$TARGET = linux"
api_key:
secure: "ibN+PQg84f0tgJLV3KaHjkHmgFNOPqBLIrSU42moen22xxT2VIn0j7DkFaLLts1fs/+/gxmrvhOQ0vUFJqmflZ3kCeyedP/CVgZz7D7HRVK0cYUMJ2F9VWMZAFIX6A67OUlypqZqzKAKrZHx3HXky6Z8NBU23JgWqDm8PcrbbgMLvB2lvWVASjJVKreaL9BOxFOOOrAj6xAIm9ogTOnFVI/AhufNOKOTZaiprcbqMngwHeaILbwEJVqv5P2YUurC6Sq+QaH26tX00DtsYOW+n8AA3Fe48+L6rqa6Q8ru+dhPuR/Apr2+DTZ+npzY8leV3A7mYUeLo4JLaEH6n1TLVt65cX7nuesS7KsSKBSxs7q7bsqeapDcMskZz5JR4EK4S96CuHZEnn6+efpH8IrxWpbeO3EibJfyT8tMJKw7Zym5mPr+sz6xSlVMoBVcCm+7z9e7Zcqukdvdy8jM7sGP9qusqEhpojh0o+gPgr9p13SfR+6OCpj9gwxPCnZO8RBfh1cbz9vFSVlDyUYcpI2CCCpPazA1glTsEDk+VtznnUMmWksXWfxBFV81jQB2SnoZKlnsiEuNMwhiMCMEkRFo74+AsUr2UjmKJ5KC8ACwsn475PoLZBh2J6fyXBHMdbrGfK+Zt5K2IHRRtDaZVT4eHqYzxh8KhalsuBNxCo3FygI="
- provider: releases
@@ -41,7 +54,15 @@ deploy:
skip_cleanup: true
on:
tags: true
condition: "$TRAVIS_OS_NAME = osx"
condition: "$TARGET = osx"
api_key:
secure: "ibN+PQg84f0tgJLV3KaHjkHmgFNOPqBLIrSU42moen22xxT2VIn0j7DkFaLLts1fs/+/gxmrvhOQ0vUFJqmflZ3kCeyedP/CVgZz7D7HRVK0cYUMJ2F9VWMZAFIX6A67OUlypqZqzKAKrZHx3HXky6Z8NBU23JgWqDm8PcrbbgMLvB2lvWVASjJVKreaL9BOxFOOOrAj6xAIm9ogTOnFVI/AhufNOKOTZaiprcbqMngwHeaILbwEJVqv5P2YUurC6Sq+QaH26tX00DtsYOW+n8AA3Fe48+L6rqa6Q8ru+dhPuR/Apr2+DTZ+npzY8leV3A7mYUeLo4JLaEH6n1TLVt65cX7nuesS7KsSKBSxs7q7bsqeapDcMskZz5JR4EK4S96CuHZEnn6+efpH8IrxWpbeO3EibJfyT8tMJKw7Zym5mPr+sz6xSlVMoBVcCm+7z9e7Zcqukdvdy8jM7sGP9qusqEhpojh0o+gPgr9p13SfR+6OCpj9gwxPCnZO8RBfh1cbz9vFSVlDyUYcpI2CCCpPazA1glTsEDk+VtznnUMmWksXWfxBFV81jQB2SnoZKlnsiEuNMwhiMCMEkRFo74+AsUr2UjmKJ5KC8ACwsn475PoLZBh2J6fyXBHMdbrGfK+Zt5K2IHRRtDaZVT4eHqYzxh8KhalsuBNxCo3FygI="
- provider: releases
file: lbrycrd-windows.zip
skip_cleanup: true
on:
tags: true
condition: "$TARGET = windows"
api_key:
secure: "ibN+PQg84f0tgJLV3KaHjkHmgFNOPqBLIrSU42moen22xxT2VIn0j7DkFaLLts1fs/+/gxmrvhOQ0vUFJqmflZ3kCeyedP/CVgZz7D7HRVK0cYUMJ2F9VWMZAFIX6A67OUlypqZqzKAKrZHx3HXky6Z8NBU23JgWqDm8PcrbbgMLvB2lvWVASjJVKreaL9BOxFOOOrAj6xAIm9ogTOnFVI/AhufNOKOTZaiprcbqMngwHeaILbwEJVqv5P2YUurC6Sq+QaH26tX00DtsYOW+n8AA3Fe48+L6rqa6Q8ru+dhPuR/Apr2+DTZ+npzY8leV3A7mYUeLo4JLaEH6n1TLVt65cX7nuesS7KsSKBSxs7q7bsqeapDcMskZz5JR4EK4S96CuHZEnn6+efpH8IrxWpbeO3EibJfyT8tMJKw7Zym5mPr+sz6xSlVMoBVcCm+7z9e7Zcqukdvdy8jM7sGP9qusqEhpojh0o+gPgr9p13SfR+6OCpj9gwxPCnZO8RBfh1cbz9vFSVlDyUYcpI2CCCpPazA1glTsEDk+VtznnUMmWksXWfxBFV81jQB2SnoZKlnsiEuNMwhiMCMEkRFo74+AsUr2UjmKJ5KC8ACwsn475PoLZBh2J6fyXBHMdbrGfK+Zt5K2IHRRtDaZVT4eHqYzxh8KhalsuBNxCo3FygI="
+15
View File
@@ -0,0 +1,15 @@
The MIT License (MIT)
Copyright (c) 2015-2016 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,
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+2 -2
View File
@@ -1,2 +1,2 @@
45.32.39.241:9246
45.32.40.180:9246
138.68.198.142:9246
138.197.224.252:9246
+1 -1
View File
@@ -1,6 +1,6 @@
# List of fixed seed nodes for testnet
45.32.39.241:19246
159.203.154.219:19246
# Onion nodes
#thfsmmn2jbitcoin.onion
+1
View File
@@ -95,6 +95,7 @@ wallet_packages_$(NO_WALLET) = $(wallet_packages)
upnp_packages_$(NO_UPNP) = $(upnp_packages)
packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages) $(qt_packages_) $(wallet_packages_) $(upnp_packages_)
$(info $$packages is [${packages}])
native_packages += $($(host_arch)_$(host_os)_native_packages) $($(host_os)_native_packages) $(qt_native_packages_)
all_packages = $(packages) $(native_packages)
+18
View File
@@ -0,0 +1,18 @@
#! /bin/bash
set -euo pipefail
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
g++-mingw-w64-i686 mingw-w64-i686-dev g++-mingw-w64-x86-64 \
mingw-w64-x86-64-dev build-essential libtool autotools-dev automake pkg-config \
libssl-dev libevent-dev bsdmainutils curl ca-certificates
cd depends
make HOST=i686-w64-mingw32 NO_QT=1
cd ..
patch -p1 < packaging/remove_consensus.patch
./autogen.sh
./configure --prefix=`pwd`/depends/i686-w64-mingw32 --without-gui
make
+23
View File
@@ -0,0 +1,23 @@
diff --git a/src/Makefile.am b/src/Makefile.am
index a9f0a94..d71bfeb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -64,12 +64,12 @@ if ENABLE_ZMQ
EXTRA_LIBRARIES += libbitcoin_zmq.a
endif
-if BUILD_BITCOIN_LIBS
-lib_LTLIBRARIES = libbitcoinconsensus.la
-LIBBITCOINCONSENSUS=libbitcoinconsensus.la
-else
-LIBBITCOINCONSENSUS=
-endif
+# if BUILD_BITCOIN_LIBS
+# lib_LTLIBRARIES = libbitcoinconsensus.la
+# LIBBITCOINCONSENSUS=libbitcoinconsensus.la
+# else
+# LIBBITCOINCONSENSUS=
+# endif
bin_PROGRAMS =
TESTS =
+16 -11
View File
@@ -19,7 +19,7 @@ function HELP {
echo "-r: remove intermediate files."
echo "-l: build only lbrycrd"
echo "-d: build only the dependencies"
echo "-o: timeout build after 45 minutes"
echo "-o: timeout build after 40 minutes"
echo "-t: turn trace on"
echo "-h: show help"
exit 1
@@ -31,6 +31,9 @@ BUILD_DEPENDENCIES=true
BUILD_LBRYCRD=true
TIMEOUT=false
THREE_MB=3145728
# this flag gets set to False if
# the script exits due to a timeout
OUTPUT_LOG=true
while getopts :crldoth:w:d: FLAG; do
case $FLAG in
@@ -104,18 +107,19 @@ fi
NEXT_TIME=60
function exit_at_45() {
function exit_at_40() {
if [ -f "${START_TIME_FILE}" ]; then
NOW=$(date +%s)
START=$(cat "${START_TIME_FILE}")
TIMEOUT_SECS=2700 # 45 * 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 45 minutes to allow the cache to populate'
echo 'Exiting at 40 minutes to allow the cache to populate'
OUTPUT_LOG=false
exit 1
fi
fi
@@ -136,7 +140,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_45 "$2"
exit_at_40 "$2"
sleep "${SLEEP}"
done
# restore the xtrace setting
@@ -159,11 +163,11 @@ function background() {
function cleanup() {
rv=$?
# cat the log file if it exists
if [ -f "$2" ]; then
if [ -f "$2" ] && [ "${OUTPUT_LOG}" = true ]; then
echo
echo "Output of log file $2"
echo
tail -c $THREE_MB "$1"
tail -n 1000 "$2"
echo
fi
# delete the build directory
@@ -175,14 +179,15 @@ function cleanup() {
function cat_and_exit() {
rv=$?
# cat the log file if it exists
if [ -f "$1" ]; then
if [ -f "$1" ] && [ "${OUTPUT_LOG}" = true ]; then
echo
echo "Output of log file $1"
echo
# log size is limited to 4MB on travis
# so hopefully the last 3MB is enough
# This used to be the last 3MB but outputing that
# caused problems on travis.
# Hopefully the last 1000 lines is enough
# to debug whatever went wrong
tail -c $THREE_MB "$1"
tail -n 1000 "$1"
echo
fi
exit $rv
+2 -2
View File
@@ -50,9 +50,9 @@ Var StartMenuGroup
# Installer attributes
OutFile @abs_top_srcdir@/@PACKAGE_TARNAME@-${VERSION}-win@WINDOWS_BITS@-setup.exe
!if "@WINDOWS_BITS@" == "64"
InstallDir $PROGRAMFILES64\Bitcoin
InstallDir $PROGRAMFILES64\Lbrycrd
!else
InstallDir $PROGRAMFILES\Bitcoin
InstallDir $PROGRAMFILES\Lbrycrd
!endif
CRCCheck on
XPStyle on
+1 -1
View File
@@ -357,7 +357,7 @@ lbrycrdd_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
lbrycrdd_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
if TARGET_WINDOWS
lbrycrdd_SOURCES += lbrycrdd-res.rc
lbrycrdd_SOURCES += bitcoin-cli-res.rc
endif
lbrycrdd_LDADD = \
+1
View File
@@ -61,6 +61,7 @@ BITCOIN_TESTS =\
test/miner_tests.cpp \
test/multisig_tests.cpp \
test/claimtrie_tests.cpp \
test/claimtriebranching_tests.cpp \
test/netbase_tests.cpp \
test/pmt_tests.cpp \
test/policyestimator_tests.cpp \
+4 -5
View File
@@ -126,8 +126,8 @@ public:
consensus.nMajorityEnforceBlockUpgrade = 750;
consensus.nMajorityRejectBlockOutdated = 950;
consensus.nMajorityWindow = 1000;
consensus.BIP34Height = 1;
consensus.BIP34Hash = uint256S("0xdecb9e2cca03a419fd9cca0cb2b1d5ad11b088f22f8f38556d93ac4358b86c24");
consensus.BIP34Height = 1;
consensus.BIP34Hash = uint256S("0xdecb9e2cca03a419fd9cca0cb2b1d5ad11b088f22f8f38556d93ac4358b86c24");
consensus.powLimit = uint256S("0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 150; //retarget every block
consensus.nPowTargetSpacing = 150;
@@ -247,9 +247,8 @@ public:
vFixedSeeds.clear();
vSeeds.clear();
//vSeeds.push_back(CDNSSeedData("bitcoin.petertodd.org", "testnet-seed.bitcoin.petertodd.org"));
//vSeeds.push_back(CDNSSeedData("bluematt.me", "testnet-seed.bluematt.me"));
//vSeeds.push_back(CDNSSeedData("bitcoin.schildbach.de", "testnet-seed.bitcoin.schildbach.de"));
vSeeds.push_back(CDNSSeedData("lbry.io", "testdnsseed1.lbry.io"));
vSeeds.push_back(CDNSSeedData("lbry.io", "testdnsseed2.lbry.io"));
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
+3 -3
View File
@@ -8,11 +8,11 @@
* IPv4 as well as onion addresses are wrapped inside a IPv6 address accordingly.
*/
static SeedSpec6 pnSeed6_main[] = {
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x2d,0x20,0x27,0xf1}, 9246},
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x2d,0x20,0x28,0xb4}, 9246}
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x8a,0x44,0xc6,0x8e}, 9246},
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x8a,0xc5,0xe0,0xfc}, 9246}
};
static SeedSpec6 pnSeed6_test[] = {
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x2d,0x20,0x27,0xf1}, 19246}
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x9f,0xcb,0x9a,0xdb}, 19246}
};
#endif // BITCOIN_CHAINPARAMSSEEDS_H
+92
View File
@@ -458,6 +458,98 @@ bool CClaimTrie::getLastTakeoverForName(const std::string& name, int& lastTakeov
return false;
}
claimsForNameType CClaimTrie::getClaimsForName(const std::string& name) const
{
std::vector<CClaimValue> claims;
std::vector<CSupportValue> supports;
int nLastTakeoverHeight = 0;
const CClaimTrieNode* current = getNodeForName(name);
if (current)
{
if (!current->claims.empty())
{
nLastTakeoverHeight = current->nHeightOfLastTakeover;
}
for (std::vector<CClaimValue>::const_iterator itClaims = current->claims.begin(); itClaims != current->claims.end(); ++itClaims)
{
claims.push_back(*itClaims);
}
}
supportMapEntryType supportNode;
if (getSupportNode(name, supportNode))
{
for (std::vector<CSupportValue>::const_iterator itSupports = supportNode.begin(); itSupports != supportNode.end(); ++itSupports)
{
supports.push_back(*itSupports);
}
}
queueNameRowType namedClaimRow;
if (getQueueNameRow(name, namedClaimRow))
{
for (queueNameRowType::const_iterator itClaimsForName = namedClaimRow.begin(); itClaimsForName != namedClaimRow.end(); ++itClaimsForName)
{
claimQueueRowType claimRow;
if (getQueueRow(itClaimsForName->nHeight, claimRow))
{
for (claimQueueRowType::const_iterator itClaimRow = claimRow.begin(); itClaimRow != claimRow.end(); ++itClaimRow)
{
if (itClaimRow->first == name && itClaimRow->second.outPoint == itClaimsForName->outPoint)
{
claims.push_back(itClaimRow->second);
break;
}
}
}
}
}
queueNameRowType namedSupportRow;
if (getSupportQueueNameRow(name, namedSupportRow))
{
for (queueNameRowType::const_iterator itSupportsForName = namedSupportRow.begin(); itSupportsForName != namedSupportRow.end(); ++itSupportsForName)
{
supportQueueRowType supportRow;
if (getSupportQueueRow(itSupportsForName->nHeight, supportRow))
{
for (supportQueueRowType::const_iterator itSupportRow = supportRow.begin(); itSupportRow != supportRow.end(); ++itSupportRow)
{
if (itSupportRow->first == name && itSupportRow->second.outPoint == itSupportsForName->outPoint)
{
supports.push_back(itSupportRow->second);
break;
}
}
}
}
}
claimsForNameType allClaims(claims, supports, nLastTakeoverHeight);
return allClaims;
}
//return effective amount form claim, retuns 0 if claim is not found
CAmount CClaimTrie::getEffectiveAmountForClaim(const std::string& name, uint160 claimId) const
{
claimsForNameType claims = getClaimsForName(name);
CAmount effectiveAmount = 0;
bool claim_found = false;
for (std::vector<CClaimValue>::iterator it=claims.claims.begin(); it!=claims.claims.end(); ++it)
{
if (it->claimId == claimId && it->nValidAtHeight < nCurrentHeight)
effectiveAmount += it->nAmount;
claim_found = true;
break;
}
if (!claim_found)
return effectiveAmount;
for (std::vector<CSupportValue>::iterator it=claims.supports.begin(); it!=claims.supports.end(); ++it)
{
if (it->supportedClaimId == claimId && it->nValidAtHeight < nCurrentHeight)
effectiveAmount += it->nAmount;
}
return effectiveAmount;
}
bool CClaimTrie::checkConsistency() const
{
if (empty())
+14 -1
View File
@@ -265,6 +265,16 @@ typedef std::map<std::string, CClaimTrieNode*, nodenamecompare> nodeCacheType;
typedef std::map<std::string, uint256> hashMapType;
struct claimsForNameType
{
std::vector<CClaimValue> claims;
std::vector<CSupportValue> supports;
int nLastTakeoverHeight;
claimsForNameType(std::vector<CClaimValue> claims, std::vector<CSupportValue> supports, int nLastTakeoverHeight)
: claims(claims), supports(supports), nLastTakeoverHeight(nLastTakeoverHeight) {}
};
class CClaimTrieCache;
class CClaimTrie
@@ -290,7 +300,10 @@ public:
std::vector<namedNodeType> flattenTrie() const;
bool getInfoForName(const std::string& name, CClaimValue& claim) const;
bool getLastTakeoverForName(const std::string& name, int& lastTakeoverHeight) const;
claimsForNameType getClaimsForName(const std::string& name) const;
CAmount getEffectiveAmountForClaim(const std::string& name, uint160 claimId) const;
bool queueEmpty() const;
bool supportEmpty() const;
bool supportQueueEmpty() const;
+3 -3
View File
@@ -16,11 +16,11 @@
//! These need to be macros, as clientversion.cpp's and bitcoin*-res.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 0
#define CLIENT_VERSION_MINOR 12
#define CLIENT_VERSION_REVISION 99
#define CLIENT_VERSION_BUILD 0
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_BUILD 4
//! Set to true for release, false for prerelease or test build
#define CLIENT_VERSION_IS_RELEASE false
#define CLIENT_VERSION_IS_RELEASE true
/**
* Copyright year (2009-this)
+2 -2
View File
@@ -2588,10 +2588,10 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
std::string name(vvchParams[0].begin(), vvchParams[0].end());
uint160 supportedClaimId(vvchParams[1]);
int nValidAtHeight;
LogPrintf("%s: Removing support for %s in %s. Tx: %s, nOut: %d\n", __func__, supportedClaimId.ToString(), name, txin.prevout.hash.ToString(), txin.prevout.n);
LogPrintf("%s: Removing support for %s in %s. Tx: %s, nOut: %d, removed txid: %s\n", __func__, supportedClaimId.ToString(), name, txin.prevout.hash.ToString(), txin.prevout.n,tx.GetHash().ToString());
if (trieCache.spendSupport(name, COutPoint(txin.prevout.hash, txin.prevout.n), coins->nHeight, nValidAtHeight))
{
mClaimUndoHeights[0] = nValidAtHeight;
mClaimUndoHeights[i] = nValidAtHeight;
}
}
}
+23
View File
@@ -25,6 +25,29 @@ uint32_t vch_to_uint32_t(std::vector<unsigned char>& vchN)
return n;
}
CScript ClaimNameScript(std::string name, std::string value)
{
std::vector<unsigned char> vchName(name.begin(), name.end());
std::vector<unsigned char> vchValue(value.begin(), value.end());
return CScript() << OP_CLAIM_NAME << vchName << vchValue << OP_2DROP << OP_DROP << OP_TRUE;
}
CScript SupportClaimScript(std::string name, uint160 claimId)
{
std::vector<unsigned char> vchName(name.begin(), name.end());
std::vector<unsigned char> vchClaimId(claimId.begin(),claimId.end());
return CScript() << OP_SUPPORT_CLAIM << vchName << vchClaimId << OP_2DROP << OP_DROP << OP_TRUE;
}
CScript UpdateClaimScript(std::string name, uint160 claimId, std::string value)
{
std::vector<unsigned char> vchName(name.begin(), name.end());
std::vector<unsigned char> vchClaimId(claimId.begin(),claimId.end());
std::vector<unsigned char> vchValue(value.begin(), value.end());
return CScript() << OP_UPDATE_CLAIM << vchName << vchClaimId << vchValue << OP_2DROP << OP_2DROP << OP_TRUE;
}
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams)
{
CScript::const_iterator pc = scriptIn.begin();
+4
View File
@@ -14,6 +14,9 @@
// Scripts exceeding this size are rejected in CheckTransaction in main.cpp
#define MAX_CLAIM_NAME_SIZE 255
CScript ClaimNameScript(std::string name, std::string value);
CScript SupportClaimScript(std::string name, uint160 claimId);
CScript UpdateClaimScript(std::string name, uint160 claimId, std::string value);
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams);
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams, CScript::const_iterator& pc);
CScript StripClaimScriptPrefix(const CScript& scriptIn);
@@ -26,4 +29,5 @@ size_t ClaimScriptSize(const CScript& scriptIn);
// get size of the name in a claim script, returns 0 if scriptin is not a claimetrie transaction
size_t ClaimNameSize(const CScript& scriptIn);
#endif // BITCOIN_NAMECLAIM_H
+9 -5
View File
@@ -170,15 +170,19 @@ public:
// 546*minRelayTxFee/1000 (in satoshis)
if (scriptPubKey.IsUnspendable())
return 0;
size_t nSize = GetSerializeSize(SER_DISK,0)+148u;
return 3*minRelayTxFee.GetFee(nSize);
// for lbrycrd this is mainly to prevent 0 value claims
// and some spam protection without limiting small
// lbrynet transactions
return 1;
// below is original bitcoin core code
//size_t nSize = GetSerializeSize(SER_DISK,0)+dd148u;
//return 3*minRelayTxFee.GetFee(nSize);
}
bool IsDust(const CFeeRate &minRelayTxFee) const
{
return false;
// return (nValue < GetDustThreshold(minRelayTxFee));
return (nValue < GetDustThreshold(minRelayTxFee));
}
friend bool operator==(const CTxOut& a, const CTxOut& b)
+198 -22
View File
@@ -4,6 +4,8 @@
#include "univalue.h"
#include "txmempool.h"
// Maximum block decrement that is allowed from rpc calls
const int MAX_RPC_BLOCK_DECREMENTS = 50;
UniValue getclaimsintrie(const UniValue& params, bool fHelp)
{
@@ -19,6 +21,7 @@ UniValue getclaimsintrie(const UniValue& params, bool fHelp)
" \"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"
@@ -46,6 +49,7 @@ UniValue getclaimsintrie(const UniValue& params, bool fHelp)
for (std::vector<CClaimValue>::iterator itClaims = it->second.claims.begin(); itClaims != it->second.claims.end(); ++itClaims)
{
UniValue claim(UniValue::VOBJ);
claim.push_back(Pair("claimId", itClaims->claimId.GetHex()));
claim.push_back(Pair("txid", itClaims->outPoint.hash.GetHex()));
claim.push_back(Pair("n", (int)itClaims->outPoint.n));
claim.push_back(Pair("amount", ValueFromAmount(itClaims->nAmount)));
@@ -123,6 +127,41 @@ UniValue getclaimtrie(const UniValue& params, bool fHelp)
return ret;
}
bool getValueForClaim(const COutPoint& out, std::string& sValue)
{
CCoinsViewCache view(pcoinsTip);
const CCoins* coin = view.AccessCoins(out.hash);
if (!coin)
{
LogPrintf("%s: %s does not exist in the coins view, despite being associated with a name\n",
__func__, out.hash.GetHex());
return true;
}
if (coin->vout.size() < out.n || coin->vout[out.n].IsNull())
{
LogPrintf("%s: the specified txout of %s appears to have been spent\n", __func__, out.hash.GetHex());
return true;
}
int op;
std::vector<std::vector<unsigned char> > vvchParams;
if (!DecodeClaimScript(coin->vout[out.n].scriptPubKey, op, vvchParams))
{
LogPrintf("%s: the specified txout of %s does not have a name claim command\n", __func__, out.hash.GetHex());
return false;
}
if (op == OP_CLAIM_NAME)
{
sValue = std::string(vvchParams[1].begin(), vvchParams[1].end());
}
else if (op == OP_UPDATE_CLAIM)
{
sValue = std::string(vvchParams[2].begin(), vvchParams[2].end());
}
return true;
}
UniValue getvalueforname(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
@@ -133,6 +172,7 @@ UniValue getvalueforname(const UniValue& params, bool fHelp)
"1. \"name\" (string) the name to look up\n"
"Result: \n"
"\"value\" (string) the value of the name, if it exists\n"
"\"claimId\" (string) the claimId for this name claim\n"
"\"txid\" (string) the hash of the transaction which successfully claimed the name\n"
"\"n\" (numeric) vout value\n"
"\"amount\" (numeric) txout amount\n"
@@ -145,36 +185,171 @@ UniValue getvalueforname(const UniValue& params, bool fHelp)
UniValue ret(UniValue::VOBJ);
if (!pclaimTrie->getInfoForName(name, claim))
return ret;
CCoinsViewCache view(pcoinsTip);
const CCoins* coin = view.AccessCoins(claim.outPoint.hash);
if (!coin)
{
LogPrintf("%s: %s does not exist in the coins view, despite being associated with a name\n",
__func__, claim.outPoint.hash.GetHex());
std::string sValue;
if (!getValueForClaim(claim.outPoint, sValue))
return ret;
}
if (coin->vout.size() < claim.outPoint.n || coin->vout[claim.outPoint.n].IsNull())
{
LogPrintf("%s: the specified txout of %s appears to have been spent\n", __func__, claim.outPoint.hash.GetHex());
return ret;
}
int op;
std::vector<std::vector<unsigned char> > vvchParams;
if (!DecodeClaimScript(coin->vout[claim.outPoint.n].scriptPubKey, op, vvchParams))
{
LogPrintf("%s: the specified txout of %s does not have a name claim command\n", __func__, claim.outPoint.hash.GetHex());
}
std::string sValue(vvchParams[1].begin(), vvchParams[1].end());
ret.push_back(Pair("value", sValue));
ret.push_back(Pair("claimId", claim.claimId.GetHex()));
ret.push_back(Pair("txid", claim.outPoint.hash.GetHex()));
ret.push_back(Pair("n", (int)claim.outPoint.n));
ret.push_back(Pair("amount", claim.nAmount));
ret.push_back(Pair("effective amount", claim.nEffectiveAmount));
ret.push_back(Pair("effective amount", pclaimTrie->getEffectiveAmountForClaim(name, claim.claimId)));
ret.push_back(Pair("height", claim.nHeight));
return ret;
}
typedef std::pair<CClaimValue, std::vector<CSupportValue> > claimAndSupportsType;
typedef std::map<uint160, claimAndSupportsType> claimSupportMapType;
typedef std::map<uint160, std::vector<CSupportValue> > supportsWithoutClaimsMapType;
UniValue claimsAndSupportsToJSON(claimSupportMapType::const_iterator itClaimsAndSupports, int nCurrentHeight)
{
UniValue ret(UniValue::VOBJ);
const CClaimValue claim = itClaimsAndSupports->second.first;
const std::vector<CSupportValue> supports = itClaimsAndSupports->second.second;
CAmount nEffectiveAmount = 0;
UniValue supportObjs(UniValue::VARR);
for (std::vector<CSupportValue>::const_iterator itSupports = supports.begin(); itSupports != supports.end(); ++itSupports)
{
UniValue supportObj(UniValue::VOBJ);
supportObj.push_back(Pair("txid", itSupports->outPoint.hash.GetHex()));
supportObj.push_back(Pair("n", (int)itSupports->outPoint.n));
supportObj.push_back(Pair("nHeight", itSupports->nHeight));
supportObj.push_back(Pair("nValidAtHeight", itSupports->nValidAtHeight));
if (itSupports->nValidAtHeight < nCurrentHeight)
{
nEffectiveAmount += itSupports->nAmount;
}
supportObj.push_back(Pair("nAmount", itSupports->nAmount));
supportObjs.push_back(supportObj);
}
ret.push_back(Pair("claimId", itClaimsAndSupports->first.GetHex()));
ret.push_back(Pair("txid", claim.outPoint.hash.GetHex()));
ret.push_back(Pair("n", (int)claim.outPoint.n));
ret.push_back(Pair("nHeight", claim.nHeight));
ret.push_back(Pair("nValidAtHeight", claim.nValidAtHeight));
if (claim.nValidAtHeight < nCurrentHeight)
{
nEffectiveAmount += claim.nAmount;
}
ret.push_back(Pair("nAmount", claim.nAmount));
std::string sValue;
if (getValueForClaim(claim.outPoint, sValue))
{
ret.push_back(Pair("value", sValue));
}
ret.push_back(Pair("nEffectiveAmount", nEffectiveAmount));
ret.push_back(Pair("supports", supportObjs));
return ret;
}
UniValue supportsWithoutClaimsToJSON(supportsWithoutClaimsMapType::const_iterator itSupportsWithoutClaims, int nCurrentHeight)
{
const std::vector<CSupportValue> supports = itSupportsWithoutClaims->second;
UniValue ret(UniValue::VOBJ);
UniValue supportObjs(UniValue::VARR);
ret.push_back(Pair("claimId (no matching claim)", itSupportsWithoutClaims->first.GetHex()));
for (std::vector<CSupportValue>::const_iterator itSupports = supports.begin(); itSupports != supports.end(); ++itSupports)
{
UniValue supportObj(UniValue::VOBJ);
supportObj.push_back(Pair("txid", itSupports->outPoint.hash.GetHex()));
supportObj.push_back(Pair("n", (int)itSupports->outPoint.n));
supportObj.push_back(Pair("nHeight", itSupports->nHeight));
supportObj.push_back(Pair("nValidAtHeight", itSupports->nValidAtHeight));
supportObj.push_back(Pair("nAmount", itSupports->nAmount));
supportObjs.push_back(supportObj);
}
ret.push_back(Pair("supports", supportObjs));
return ret;
}
UniValue getclaimsforname(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
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"
"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"
" {\n"
" \"claimId\" (string) the claimId of this claim\n"
" \"txid\" (string) the txid of this claim\n"
" \"n\" (numeric) the index of the claim in the transaction's list of outputs\n"
" \"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"
" \"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"
" \"n\" (numeric) the index of the support in the transaction's list of outputs\n"
" \"nHeight\" (numeric) the height at which the support was included in the blockchain\n"
" \"nValidAtHeight\" (numeric) the height at which the support became/becomes valid\n"
" \"nAmount\" (numeric) the amount of the support\n"
" ]\n"
" }\n"
" ],\n"
" \"unmatched supports\": [ (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"
" \"nHeight\" (numeric) the height at which the support was included in the blockchain\n"
" \"nValidAtHeight\" (numeric) the height at which the support became/becomes valid\n"
" \"nAmount\" (numeric) the amount of the support\n"
" }\n"
" ]\n"
"}\n"
);
LOCK(cs_main);
std::string name = params[0].get_str();
claimsForNameType claimsForName = pclaimTrie->getClaimsForName(name);
int nCurrentHeight = chainActive.Height();
claimSupportMapType claimSupportMap;
supportsWithoutClaimsMapType supportsWithoutClaims;
for (std::vector<CClaimValue>::const_iterator itClaims = claimsForName.claims.begin(); itClaims != claimsForName.claims.end(); ++itClaims)
{
claimAndSupportsType claimAndSupports = std::make_pair(*itClaims, std::vector<CSupportValue>());
claimSupportMap.insert(std::pair<uint160, claimAndSupportsType>(itClaims->claimId, claimAndSupports));
}
for (std::vector<CSupportValue>::const_iterator itSupports = claimsForName.supports.begin(); itSupports != claimsForName.supports.end(); ++itSupports)
{
claimSupportMapType::iterator itClaimAndSupports = claimSupportMap.find(itSupports->supportedClaimId);
if (itClaimAndSupports == claimSupportMap.end())
{
std::pair<supportsWithoutClaimsMapType::iterator, bool> ret = supportsWithoutClaims.insert(std::pair<uint160, std::vector<CSupportValue> >(itSupports->supportedClaimId, std::vector<CSupportValue>()));
ret.first->second.push_back(*itSupports);
}
else
{
itClaimAndSupports->second.second.push_back(*itSupports);
}
}
UniValue ret(UniValue::VOBJ);
UniValue claimObjs(UniValue::VARR);
ret.push_back(Pair("nLastTakeoverHeight", claimsForName.nLastTakeoverHeight));
for (claimSupportMapType::const_iterator itClaimsAndSupports = claimSupportMap.begin(); itClaimsAndSupports != claimSupportMap.end(); ++itClaimsAndSupports)
{
UniValue claimAndSupportsObj = claimsAndSupportsToJSON(itClaimsAndSupports, nCurrentHeight);
claimObjs.push_back(claimAndSupportsObj);
}
ret.push_back(Pair("claims", claimObjs));
UniValue unmatchedSupports(UniValue::VARR);
for (supportsWithoutClaimsMapType::const_iterator itSupportsWithoutClaims = supportsWithoutClaims.begin(); itSupportsWithoutClaims != supportsWithoutClaims.end(); ++itSupportsWithoutClaims)
{
UniValue supportsObj = supportsWithoutClaimsToJSON(itSupportsWithoutClaims, nCurrentHeight);
unmatchedSupports.push_back(supportsObj);
}
ret.push_back(Pair("supports without claims", unmatchedSupports));
return ret;
}
UniValue gettotalclaimednames(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 0)
@@ -513,7 +688,7 @@ UniValue getnameproof(const UniValue& params, bool fHelp)
if (!chainActive.Contains(pblockIndex))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not in main chain");
if (chainActive.Tip()->nHeight > (pblockIndex->nHeight + 20))
if (chainActive.Tip()->nHeight > (pblockIndex->nHeight + MAX_RPC_BLOCK_DECREMENTS))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block too deep to generate proof");
CClaimTrieProof proof;
@@ -529,6 +704,7 @@ static const CRPCCommand commands[] =
{ "Claimtrie", "getclaimsintrie", &getclaimsintrie, true },
{ "Claimtrie", "getclaimtrie", &getclaimtrie, true },
{ "Claimtrie", "getvalueforname", &getvalueforname, true },
{ "Claimtrie", "getclaimsforname", &getclaimsforname, true },
{ "Claimtrie", "gettotalclaimednames", &gettotalclaimednames, true },
{ "Claimtrie", "gettotalclaims", &gettotalclaims, true },
{ "Claimtrie", "gettotalvalueofclaims", &gettotalvalueofclaims, true },
+59
View File
@@ -2768,5 +2768,64 @@ BOOST_AUTO_TEST_CASE(claimtrievalue_proof)
}
// Check that blocks with bogus calimtrie hash is rejected
BOOST_AUTO_TEST_CASE(bogus_claimtrie_hash)
{
fRequireStandard = false;
BOOST_CHECK(pclaimTrie->nCurrentHeight = chainActive.Height() + 1);
LOCK(cs_main);
std::string sName("test");
std::string sValue1("test");
std::vector<unsigned char> vchName(sName.begin(), sName.end());
std::vector<unsigned char> vchValue1(sValue1.begin(), sValue1.end());
std::vector<CTransaction> coinbases;
BOOST_CHECK(CreateCoinbases(3, coinbases));
int orig_chain_height = chainActive.Height();
CMutableTransaction tx1 = BuildTransaction(coinbases[0]);
tx1.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue1 << OP_2DROP << OP_DROP << OP_TRUE;
tx1.vout[0].nValue = 1;
COutPoint tx1OutPoint(tx1.GetHash(), 0);
AddToMempool(tx1);
CBlockTemplate *pblockTemp;
BOOST_CHECK(pblockTemp = CreateNewBlock(Params(), scriptPubKey));
pblockTemp->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
pblockTemp->block.nVersion = 1;
pblockTemp->block.nTime = chainActive.Tip()->GetBlockTime()+Params().GetConsensus().nPowTargetSpacing;
CMutableTransaction txCoinbase(pblockTemp->block.vtx[0]);
txCoinbase.vin[0].scriptSig = CScript() << CScriptNum(chainActive.Height());
txCoinbase.vout[0].nValue = GetBlockSubsidy(chainActive.Height() + 1, Params().GetConsensus());
pblockTemp->block.vtx[0] = CTransaction(txCoinbase);
pblockTemp->block.hashMerkleRoot = BlockMerkleRoot(pblockTemp->block);
//create bogus hash
uint256 bogusHashClaimTrie;
bogusHashClaimTrie.SetHex("aaa");
pblockTemp->block.hashClaimTrie = bogusHashClaimTrie;
for (int i = 0; ; ++i)
{
pblockTemp->block.nNonce = i;
if (CheckProofOfWork(pblockTemp->block.GetPoWHash(), pblockTemp->block.nBits, Params().GetConsensus()))
{
break;
}
}
CValidationState state;
bool success = ProcessNewBlock(state, Params(), NULL, &pblockTemp->block, true, NULL);
// will process , but will not be connected
BOOST_CHECK(success);
BOOST_CHECK(state.IsValid());
BOOST_CHECK(pblockTemp->block.GetHash() != chainActive.Tip()->GetBlockHash());
BOOST_CHECK_EQUAL(orig_chain_height,chainActive.Height());
delete pblockTemp;
}
BOOST_AUTO_TEST_SUITE_END()
+670
View File
@@ -0,0 +1,670 @@
// Copyright (c) 2015 The LBRY Foundation
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://opensource.org/licenses/mit-license.php
#include "main.h"
#include "consensus/validation.h"
#include "consensus/merkle.h"
#include "primitives/transaction.h"
#include "miner.h"
#include "txmempool.h"
#include "claimtrie.h"
#include "nameclaim.h"
#include "coins.h"
#include "streams.h"
#include "chainparams.h"
#include "policy/policy.h"
#include <boost/test/unit_test.hpp>
#include <iostream>
#include "test/test_bitcoin.h"
using namespace std;
BOOST_FIXTURE_TEST_SUITE(claimtriebranching_tests, RegTestingSetup)
//is a claim in queue
boost::test_tools::predicate_result
is_claim_in_queue(std::string name, const CTransaction &tx)
{
CClaimValue val;
COutPoint outPoint(tx.GetHash(), 0);
int validAtHeight;
bool have_claim = pclaimTrie->haveClaimInQueue(name,outPoint,validAtHeight);
if (have_claim){
return true;
}
else{
boost::test_tools::predicate_result res(false);
res.message()<<"Is not a claim in queue.";
return res;
}
}
// check if tx is best claim based on outpoint
boost::test_tools::predicate_result
is_best_claim(std::string name, const CTransaction &tx)
{
CClaimValue val;
COutPoint outPoint(tx.GetHash(), 0);
bool have_claim = pclaimTrie->haveClaim(name,outPoint);
bool have_info = pclaimTrie->getInfoForName(name, val);
if (have_claim && have_info && val.outPoint == outPoint){
return true;
}
else{
boost::test_tools::predicate_result res(false);
res.message()<<"Is not best claim";
return res;
}
}
// check effective quantity of best claim
boost::test_tools::predicate_result
best_claim_effective_amount_equals(std::string name, CAmount amount)
{
CClaimValue val;
bool have_info = pclaimTrie->getInfoForName(name, val);
if (!have_info)
{
boost::test_tools::predicate_result res(false);
res.message()<<"No claim found";
return res;
}
else
{
CAmount effective_amount = pclaimTrie->getEffectiveAmountForClaim(name, val.claimId);
if (val.nEffectiveAmount != amount)
{
boost::test_tools::predicate_result res(false);
res.message()<<amount<<" != "<<effective_amount;
return res;
}
else
{
return true;
}
}
}
CMutableTransaction BuildTransaction(const CMutableTransaction& prev, uint32_t prevout=0, unsigned int numOutputs=1)
{
CMutableTransaction tx;
tx.nVersion = 1;
tx.nLockTime = 0;
tx.vin.resize(1);
tx.vout.resize(numOutputs);
tx.vin[0].prevout.hash = prev.GetHash();
tx.vin[0].prevout.n = prevout;
tx.vin[0].scriptSig = CScript();
tx.vin[0].nSequence = std::numeric_limits<unsigned int>::max();
CAmount valuePerOutput = prev.vout[prevout].nValue;
unsigned int numOutputsCopy = numOutputs;
while ((numOutputsCopy = numOutputsCopy >> 1) > 0)
{
valuePerOutput = valuePerOutput >> 1;
}
for (unsigned int i = 0; i < numOutputs; ++i)
{
tx.vout[i].scriptPubKey = CScript();
tx.vout[i].nValue = valuePerOutput;
}
return tx;
}
bool CreateBlock(CBlockTemplate* pblocktemplate)
{
static int unique_block_counter = 0;
CBlock* pblock = &pblocktemplate->block;
pblock->nVersion = 1;
pblock->nTime = chainActive.Tip()->GetBlockTime()+Params().GetConsensus().nPowTargetSpacing;
CMutableTransaction txCoinbase(pblock->vtx[0]);
txCoinbase.vin[0].scriptSig = CScript() << CScriptNum(unique_block_counter++) << CScriptNum(chainActive.Height());
txCoinbase.vout[0].nValue = GetBlockSubsidy(chainActive.Height() + 1, Params().GetConsensus());
pblock->vtx[0] = CTransaction(txCoinbase);
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
for (int i = 0; ; ++i)
{
pblock->nNonce = i;
if (CheckProofOfWork(pblock->GetPoWHash(), pblock->nBits, Params().GetConsensus()))
{
break;
}
}
CValidationState state;
bool success = (ProcessNewBlock(state, Params(), NULL, pblock, true, NULL) && state.IsValid() && pblock->GetHash() == chainActive.Tip()->GetBlockHash());
pblock->hashPrevBlock = pblock->GetHash();
return success;
}
bool CreateCoinbases(unsigned int num_coinbases, std::vector<CTransaction>& coinbases)
{
CBlockTemplate *pblocktemplate;
coinbases.clear();
BOOST_CHECK(pblocktemplate = CreateNewBlock(Params(), CScript()<<OP_TRUE ));
BOOST_CHECK(pblocktemplate->block.vtx.size() == 1);
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
for (unsigned int i = 0; i < 100 + num_coinbases; ++i)
{
BOOST_CHECK(CreateBlock(pblocktemplate));
if (coinbases.size() < num_coinbases)
coinbases.push_back(CTransaction(pblocktemplate->block.vtx[0]));
}
delete pblocktemplate;
return true;
}
// Test Fixtures
struct ClaimTrieChainFixture{
std::vector<CTransaction> coinbase_txs;
int coinbase_txs_used;
unsigned int num_txs;
unsigned int num_txs_for_next_block;
ClaimTrieChainFixture()
{
fRequireStandard = false;
BOOST_CHECK(pclaimTrie->nCurrentHeight == chainActive.Height() + 1);
LOCK(cs_main);
num_txs_for_next_block = 0;
num_txs = 0;
coinbase_txs_used = 0;
// generate coinbases to spend
CreateCoinbases(20,coinbase_txs);
}
~ClaimTrieChainFixture()
{
DecrementBlocks(chainActive.Height());
}
void CommitTx(CMutableTransaction &tx){
num_txs_for_next_block++;
num_txs++;
if(num_txs > coinbase_txs.size())
{
//ran out of coinbases to spend
assert(0);
}
CValidationState state;
bool *fMissingInputs;
CFeeRate txFeeRate = CFeeRate(0);
BOOST_CHECK(AcceptToMemoryPool(mempool, state, tx, false, fMissingInputs, &txFeeRate));
}
//spend a bid into some non claimtrie related unspent
CMutableTransaction Spend(const CTransaction &prev){
uint32_t prevout = 0;
CMutableTransaction tx = BuildTransaction(prev,prevout);
tx.vout[0].scriptPubKey = CScript() << OP_TRUE;
tx.vout[0].nValue = 1;
CommitTx(tx);
return tx;
}
//make claim at the current block
CMutableTransaction MakeClaim(const CTransaction &prev, std::string name, std::string value,
CAmount quantity)
{
uint32_t prevout = 0;
CMutableTransaction tx = BuildTransaction(prev,prevout);
tx.vout[0].scriptPubKey = ClaimNameScript(name,value);
tx.vout[0].nValue = quantity;
CommitTx(tx);
return tx;
}
//make support at the current block
CMutableTransaction MakeSupport(const CTransaction &prev, const CTransaction &claimtx, std::string name, CAmount quantity)
{
uint160 claimId = ClaimIdHash(claimtx.GetHash(), 0);
uint32_t prevout = 0;
CMutableTransaction tx = BuildTransaction(prev,prevout);
tx.vout[0].scriptPubKey = SupportClaimScript(name,claimId);
tx.vout[0].nValue = quantity;
CommitTx(tx);
return tx;
}
//make update at the current block
CMutableTransaction MakeUpdate(const CTransaction &prev, std::string name, std::string value,
uint160 claimId, CAmount quantity)
{
uint32_t prevout = 0;
CMutableTransaction tx = BuildTransaction(prev,prevout);
tx.vout[0].scriptPubKey = UpdateClaimScript(name,claimId,value);
tx.vout[0].nValue = quantity;
CommitTx(tx);
return tx;
}
CMutableTransaction GetCoinbase()
{
CMutableTransaction tx = coinbase_txs[coinbase_txs_used];
coinbase_txs_used++;
return tx;
}
//create i blocks
void IncrementBlocks(int num_blocks)
{
for (int i = 0; i < num_blocks; ++i)
{
CBlockTemplate *pblocktemplate;
CScript coinbase_scriptpubkey;
coinbase_scriptpubkey << CScriptNum(chainActive.Height());
BOOST_CHECK(pblocktemplate = CreateNewBlock(Params(), coinbase_scriptpubkey));
BOOST_CHECK(pblocktemplate->block.vtx.size() == num_txs_for_next_block+1);
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
BOOST_CHECK(CreateBlock(pblocktemplate));
delete pblocktemplate;
num_txs_for_next_block = 0 ;
}
}
//disconnect i blocks from tip
void DecrementBlocks(int num_blocks)
{
for(int i = 0; i< num_blocks; i++){
CValidationState state;
CBlockIndex* pblockindex = chainActive.Tip();
InvalidateBlock(state, Params().GetConsensus(), pblockindex);
if (state.IsValid())
{
ActivateBestChain(state, Params());
}
else
{
BOOST_FAIL("removing block failed");
}
}
mempool.clear();
num_txs_for_next_block = 0;
}
};
/*
claims
no competing bids
there is a competing bid inserted same height
check the greater one wins
- quantity is same, check outpoint greater wins
there is an existing competing bid
check that rules for delays are observed
check that a greater amount wins
check that a smaller amount does not win
*/
BOOST_AUTO_TEST_CASE(claimtriebranching_claim)
{
// no competing bids
ClaimTrieChainFixture fixture;
CMutableTransaction tx1 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",1);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx1));
fixture.DecrementBlocks(1);
BOOST_CHECK(!is_best_claim("test",tx1));
// there is a competing bid inserted same height
CMutableTransaction tx2 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",1);
CMutableTransaction tx3 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",2);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx3));
fixture.DecrementBlocks(1);
BOOST_CHECK(!is_best_claim("test",tx2));
BOOST_CHECK(!is_best_claim("test",tx3));
// make two claims , one older
CMutableTransaction tx4 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",1);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx4));
CMutableTransaction tx5 = fixture.MakeClaim(fixture.GetCoinbase(),"test","two",1);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_claim_in_queue("test",tx5));
BOOST_CHECK(is_best_claim("test",tx4));
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx4));
fixture.DecrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx4));
BOOST_CHECK(is_claim_in_queue("test",tx5));
fixture.DecrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx4));
fixture.DecrementBlocks(1);
// check claim takeover
CMutableTransaction tx6 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",1);
fixture.IncrementBlocks(10);
BOOST_CHECK(is_best_claim("test",tx6));
CMutableTransaction tx7 = fixture.MakeClaim(fixture.GetCoinbase(),"test","two",2);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_claim_in_queue("test",tx7));
BOOST_CHECK(is_best_claim("test",tx6));
fixture.IncrementBlocks(10);
BOOST_CHECK(is_best_claim("test",tx7));
fixture.DecrementBlocks(10);
BOOST_CHECK(is_claim_in_queue("test",tx7));
BOOST_CHECK(is_best_claim("test",tx6));
fixture.DecrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx6));
fixture.DecrementBlocks(10);
}
/*
spent claims
spending winning claim will make losing active claim winner
spending winning claim will make inactive claim winner
spending winning claim will empty out claim trie
*/
BOOST_AUTO_TEST_CASE(claimtriebranching_spend_claim)
{
ClaimTrieChainFixture fixture;
// spending winning claim will make losing active claim winner
CMutableTransaction tx1 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",2);
CMutableTransaction tx2 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",1);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx1));
fixture.Spend(tx1);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx2));
fixture.DecrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx1));
fixture.DecrementBlocks(1);
// spending winning claim will make inactive claim winner
CMutableTransaction tx3 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",2);
fixture.IncrementBlocks(10);
BOOST_CHECK(is_best_claim("test",tx3));
CMutableTransaction tx4 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",2);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx3));
fixture.Spend(tx3);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx4));
fixture.DecrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx3));
fixture.DecrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx3));
fixture.DecrementBlocks(10);
//spending winning claim will empty out claim trie
CMutableTransaction tx5 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",2);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx5));
fixture.Spend(tx5);
fixture.IncrementBlocks(1);
BOOST_CHECK(!is_best_claim("test",tx5));
BOOST_CHECK(pclaimTrie->empty());
fixture.DecrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx5));
fixture.DecrementBlocks(1);
}
/*
supports
check support with wrong name does not work
check claim with more support wins
check support delay
*/
BOOST_AUTO_TEST_CASE(claimtriebranching_support)
{
ClaimTrieChainFixture fixture;
// check claim with more support wins
CMutableTransaction tx1 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",2);
CMutableTransaction tx2 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",1);
CMutableTransaction s1 = fixture.MakeSupport(fixture.GetCoinbase(),tx1,"test",1);
CMutableTransaction s2 = fixture.MakeSupport(fixture.GetCoinbase(),tx2,"test",10);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx2));
BOOST_CHECK(best_claim_effective_amount_equals("test",11));
fixture.DecrementBlocks(1);
// check support delay
CMutableTransaction tx3 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",1);
CMutableTransaction tx4 = fixture.MakeClaim(fixture.GetCoinbase(),"test","two",2);
fixture.IncrementBlocks(10);
BOOST_CHECK(is_best_claim("test",tx4));
BOOST_CHECK(best_claim_effective_amount_equals("test",2));
CMutableTransaction s4 = fixture.MakeSupport(fixture.GetCoinbase(),tx3,"test",10); //10 delay
fixture.IncrementBlocks(10);
BOOST_CHECK(is_best_claim("test",tx4));
BOOST_CHECK(best_claim_effective_amount_equals("test",2));
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx3));
BOOST_CHECK(best_claim_effective_amount_equals("test",11));
fixture.DecrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx4));
BOOST_CHECK(best_claim_effective_amount_equals("test",2));
fixture.DecrementBlocks(10);
BOOST_CHECK(is_best_claim("test",tx4));
BOOST_CHECK(best_claim_effective_amount_equals("test",2));
fixture.DecrementBlocks(10);
}
/*
support spend
spending suport on winning claim will cause it to lose
spending a support on txin[i] where i is not 0
*/
BOOST_AUTO_TEST_CASE(claimtriebranching_support_spend)
{
ClaimTrieChainFixture fixture;
CMutableTransaction tx1 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",1);
CMutableTransaction tx2 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",2);
CMutableTransaction s1 = fixture.MakeSupport(fixture.GetCoinbase(),tx1,"test",2);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx1));
CMutableTransaction sp1 = fixture.Spend(s1);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx2));
fixture.DecrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx1));
fixture.DecrementBlocks(1);
// spend a support on txin[i] where i is not 0
CMutableTransaction tx3 = fixture.MakeClaim(fixture.GetCoinbase(),"x","one",3);
CMutableTransaction tx4 = fixture.MakeClaim(fixture.GetCoinbase(),"test","two",2);
CMutableTransaction tx5 = fixture.MakeClaim(fixture.GetCoinbase(),"test","three",1);
CMutableTransaction s2 = fixture.MakeSupport(fixture.GetCoinbase(),tx5,"test",2);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx5));
// build the spend where s2 is sppent on txin[1] and tx3 is spent on txin[0]
uint32_t prevout = 0;
CMutableTransaction tx;
tx.nVersion = 1;
tx.nLockTime = 0;
tx.vin.resize(2);
tx.vout.resize(1);
tx.vin[0].prevout.hash = tx3.GetHash();
tx.vin[0].prevout.n = prevout;
tx.vin[0].scriptSig = CScript();
tx.vin[0].nSequence = std::numeric_limits<unsigned int>::max();
tx.vin[1].prevout.hash = s2.GetHash();
tx.vin[1].prevout.n = prevout;
tx.vin[1].scriptSig = CScript();
tx.vin[1].nSequence = std::numeric_limits<unsigned int>::max();
tx.vout[0].scriptPubKey = CScript() << OP_TRUE;
tx.vout[0].nValue = 1;
fixture.CommitTx(tx);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx4));
fixture.DecrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx5));
}
/*
update
update preserves claim id
update preserves supports
winning update on winning claim happens without delay
losing update on winning claim happens without delay
update on losing claim happens with delay , and wins
*/
BOOST_AUTO_TEST_CASE(claimtriebranching_update)
{
//update preserves claim id
ClaimTrieChainFixture fixture;
CMutableTransaction tx1 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",2);
CMutableTransaction u1 = fixture.MakeUpdate(tx1,"test","one",ClaimIdHash(tx1.GetHash(),0),2);
fixture.IncrementBlocks(1);
CClaimValue val;
pclaimTrie->getInfoForName("test",val);
BOOST_CHECK(val.claimId == ClaimIdHash(tx1.GetHash(),0));
BOOST_CHECK(is_best_claim("test",u1));
fixture.DecrementBlocks(1);
// update preserves supports
CMutableTransaction tx2 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",1);
CMutableTransaction s1 = fixture.MakeSupport(fixture.GetCoinbase(),tx2,"test",1);
CMutableTransaction u2 = fixture.MakeUpdate(tx2,"test","one",ClaimIdHash(tx2.GetHash(),0),1);
fixture.IncrementBlocks(1);
BOOST_CHECK(best_claim_effective_amount_equals("test",2));
fixture.DecrementBlocks(1);
// winning update on winning claim happens without delay
CMutableTransaction tx3 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",2);
CMutableTransaction tx4 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",1);
fixture.IncrementBlocks(10);
CMutableTransaction u3 = fixture.MakeUpdate(tx3,"test","one",ClaimIdHash(tx3.GetHash(),0),2);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",u3));
fixture.DecrementBlocks(11);
// losing update on winning claim happens without delay
CMutableTransaction tx5 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",3);
CMutableTransaction tx6 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",2);
fixture.IncrementBlocks(10);
BOOST_CHECK(is_best_claim("test",tx5));
CMutableTransaction u4 = fixture.MakeUpdate(tx5,"test","one",ClaimIdHash(tx5.GetHash(),0),1);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx6));
fixture.DecrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx5));
fixture.DecrementBlocks(10);
// update on losing claim happens with delay , and wins
CMutableTransaction tx7 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",3);
CMutableTransaction tx8 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",2);
fixture.IncrementBlocks(10);
BOOST_CHECK(is_best_claim("test",tx7));
CMutableTransaction tx;
tx.nVersion = 1;
tx.nLockTime = 0;
tx.vin.resize(2);
tx.vout.resize(1);
tx.vin[0].prevout.hash = tx8.GetHash();
tx.vin[0].prevout.n = 0;
tx.vin[0].scriptSig = CScript();
tx.vin[0].nSequence = std::numeric_limits<unsigned int>::max();
tx.vin[1].prevout.hash = fixture.GetCoinbase().GetHash();
tx.vin[1].prevout.n = 0;
tx.vin[1].scriptSig = CScript();
tx.vin[1].nSequence = std::numeric_limits<unsigned int>::max();
tx.vout[0].scriptPubKey = UpdateClaimScript("test",ClaimIdHash(tx8.GetHash(),0),"one");
tx.vout[0].nValue = 4;
fixture.CommitTx(tx);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx7));
fixture.IncrementBlocks(10);
BOOST_CHECK(is_best_claim("test",tx));
fixture.DecrementBlocks(10);
BOOST_CHECK(is_best_claim("test",tx7));
fixture.DecrementBlocks(11);
}
/*
expiration
check claims expire and loses claim
check claims expire and is not updateable (may be changed in future soft fork)
check supports expire and can cause supported bid to lose claim
*/
BOOST_AUTO_TEST_CASE(claimtriebranching_expire)
{
ClaimTrieChainFixture fixture;
pclaimTrie->setExpirationTime(5);
// check claims expire and loses claim
CMutableTransaction tx1 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",2);
fixture.IncrementBlocks(pclaimTrie->nExpirationTime);
BOOST_CHECK(is_best_claim("test",tx1));
CMutableTransaction tx2 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",1);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx2));
fixture.DecrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx1));
fixture.DecrementBlocks(pclaimTrie->nExpirationTime);
// check claims expire and is not updateable (may be changed in future soft fork)
CMutableTransaction tx3 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",2);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx3));
fixture.IncrementBlocks(pclaimTrie->nExpirationTime);
CMutableTransaction u1 = fixture.MakeUpdate(tx3,"test","two",ClaimIdHash(tx3.GetHash(),0) ,2);
BOOST_CHECK(!is_best_claim("test",u1));
fixture.DecrementBlocks(pclaimTrie->nExpirationTime);
BOOST_CHECK(is_best_claim("test",tx3));
fixture.DecrementBlocks(1);
// check supports expire and can cause supported bid to lose claim
CMutableTransaction tx4 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",1);
CMutableTransaction tx5 = fixture.MakeClaim(fixture.GetCoinbase(),"test","one",2);
CMutableTransaction s1 = fixture.MakeSupport(fixture.GetCoinbase(),tx4,"test",2);
fixture.IncrementBlocks(1);
BOOST_CHECK(is_best_claim("test",tx4));
CMutableTransaction u2 = fixture.MakeUpdate(tx4,"test","two",ClaimIdHash(tx4.GetHash(),0) ,1);
CMutableTransaction u3 = fixture.MakeUpdate(tx5,"test","two",ClaimIdHash(tx5.GetHash(),0) ,2);
fixture.IncrementBlocks(pclaimTrie->nExpirationTime);
BOOST_CHECK(is_best_claim("test",u3));
}
BOOST_AUTO_TEST_SUITE_END()
+30
View File
@@ -3,6 +3,7 @@
#include "lbry.h"
#include "main.h"
#include "test/test_bitcoin.h"
#include "hash.h"
#include <cstdio>
#include <boost/test/unit_test.hpp>
@@ -95,6 +96,35 @@ BOOST_AUTO_TEST_CASE(pow_limit_check)
}
boost::test_tools::predicate_result
check_powhash_equals(std::string test_string,std::string expected_hash_hex)
{
std::vector<unsigned char> test_vect(test_string.begin(),test_string.end());
uint256 expected;
expected.SetHex(expected_hash_hex);
uint256 hash = PoWHash(test_vect);
//std::cout<<"hash :"<<hash.ToString()<<"\n";
if (hash == expected){
return true;
}
else
{
boost::test_tools::predicate_result res( false );
res.message() << "Hash of " << test_string << " != " << expected_hash_hex;
return res;
}
}
BOOST_AUTO_TEST_CASE(lbry_pow_test)
{
BOOST_CHECK(check_powhash_equals("test string","485f3920d48a0448034b0852d1489cfa475341176838c7d36896765221be35ce"));
BOOST_CHECK(check_powhash_equals(std::string(70,'a'),"eb44af2f41e7c6522fb8be4773661be5baa430b8b2c3a670247e9ab060608b75"));
BOOST_CHECK(check_powhash_equals(std::string(140,'d'),"74044747b7c1ff867eb09a84d026b02d8dc539fb6adcec3536f3dfa9266495d9"));
}
+7 -4
View File
@@ -337,11 +337,14 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
BOOST_CHECK(IsStandardTx(t, reason));
// Check dust with default relay fee:
CAmount nDustThreshold = 182 * minRelayTxFee.GetFeePerK()/1000 * 3;
BOOST_CHECK_EQUAL(nDustThreshold, 546);
//CAmount nDustThreshold = 182 * minRelayTxFee.GetFeePerK()/1000 * 3;
//BOOST_CHECK_EQUAL(nDustThreshold, 546);
// lbry dust is set to 1, regardless of minRelayTxfee
CAmount nDustThreshold = 1;
// dust:
//t.vout[0].nValue = nDustThreshold - 1;
//BOOST_CHECK(!IsStandardTx(t, reason));
t.vout[0].nValue = nDustThreshold - 1;
BOOST_CHECK(!IsStandardTx(t, reason));
// not dust:
t.vout[0].nValue = nDustThreshold;
BOOST_CHECK(IsStandardTx(t, reason));
+39 -22
View File
@@ -442,7 +442,7 @@ UniValue claimname(const UniValue& params, bool fHelp)
}
void UpdateName(const std::vector<unsigned char> vchName, const std::vector<unsigned char> vchValue, CAmount nAmount, CWalletTx& wtxNew, CWalletTx wtxIn, unsigned int nTxOut)
void UpdateName(const std::vector<unsigned char> vchName, const uint160 claimId, const std::vector<unsigned char> vchValue, CAmount nAmount, CWalletTx& wtxNew, CWalletTx wtxIn, unsigned int nTxOut)
{
// Check amount
if (nAmount <= 0)
@@ -464,8 +464,9 @@ void UpdateName(const std::vector<unsigned char> vchName, const std::vector<unsi
if (!pwalletMain->GetKeyFromPool(newKey))
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
std::vector<unsigned char> vchClaimId(claimId.begin(), claimId.end());
CScript scriptPubKey = GetScriptForDestination(CTxDestination(newKey.GetID()));
CScript claimScript = CScript() << OP_CLAIM_NAME << vchName << vchValue << OP_2DROP << OP_DROP;
CScript claimScript = CScript() << OP_UPDATE_CLAIM << vchName << vchClaimId << vchValue << OP_2DROP << OP_2DROP;
claimScript = claimScript + scriptPubKey;
vector<CRecipient> vecSend;
@@ -501,7 +502,7 @@ UniValue updateclaim(const UniValue& params, bool fHelp)
"\nArguments:\n"
"1. \"txid\" (string, required) The transaction containing the unspent txout which should be spent.\n"
"2. \"value\" (string, required) The value to assign to the name.\n"
"3. \"amount\" (numeric, required) The amount in LBRYcrd to send. eg 0.1\n"
"3. \"amount\" (numeric, required) The amount in LBRYcrd to use to bid for the name. eg 0.1\n"
"\nResult:\n"
"\"transactionid\" (string) The new transaction id.\n"
);
@@ -523,6 +524,7 @@ UniValue updateclaim(const UniValue& params, bool fHelp)
const CWalletTx& wtx = pwalletMain->mapWallet[hash];
int op;
std::vector<std::vector<unsigned char> > vvchParams;
uint160 claimId;
CWalletTx wtxNew;
bool fFound = false;
for (unsigned int i = 0; !fFound && i < wtx.vout.size(); i++)
@@ -533,7 +535,15 @@ UniValue updateclaim(const UniValue& params, bool fHelp)
{
vchName = vvchParams[0];
EnsureWalletIsUnlocked();
UpdateName(vchName, vchValue, nAmount, wtxNew, wtx, i);
if (op == OP_CLAIM_NAME)
{
claimId = ClaimIdHash(wtx.GetHash(), i);
}
else if (op == OP_UPDATE_CLAIM)
{
claimId = uint160(vvchParams[1]);
}
UpdateName(vchName, claimId, vchValue, nAmount, wtxNew, wtx, i);
fFound = true;
}
}
@@ -668,7 +678,8 @@ void ListNameClaims(const CWalletTx& wtx, const string& strAccount, int nMinDept
LogPrintf("%s(): Txout classified as name claim could not be decoded. Txid: %s", __func__, wtx.GetHash().ToString());
continue;
}
else if (((op == OP_CLAIM_NAME) && (vvchParams.size() != 2)) || ((op == OP_SUPPORT_CLAIM) && (vvchParams.size() != 3)))
else if (((op == OP_CLAIM_NAME || op == OP_SUPPORT_CLAIM) && (vvchParams.size() != 2)) ||
((op == OP_UPDATE_CLAIM) && (vvchParams.size() != 3)))
{
LogPrintf("%s(): Wrong number of params to name claim script. Got %d, expected %d. Txid: %s", __func__, vvchParams.size(), ((op == OP_CLAIM_NAME) ? 2 : 3), wtx.GetHash().ToString());
continue;
@@ -677,15 +688,22 @@ void ListNameClaims(const CWalletTx& wtx, const string& strAccount, int nMinDept
entry.push_back(Pair("name", sName));
if (op == OP_CLAIM_NAME)
{
uint160 claimId = ClaimIdHash(wtx.GetHash(), s.vout);
entry.push_back(Pair("claimId", claimId.GetHex()));
string sValue (vvchParams[1].begin(), vvchParams[1].end());
entry.push_back(Pair("value", sValue));
}
else if (op == OP_UPDATE_CLAIM)
{
uint160 claimId(vvchParams[1]);
entry.push_back(Pair("claimId", claimId.GetHex()));
string sValue(vvchParams[2].begin(), vvchParams[2].end());
entry.push_back(Pair("value", sValue));
}
else if (op == OP_SUPPORT_CLAIM)
{
uint256 txhash(vvchParams[1]);
entry.push_back(Pair("supported_txid", txhash.GetHex()));
int32_t nOut = vch_to_uint32_t(vvchParams[2]);
entry.push_back(Pair("supported_nOut", nOut));
uint160 claimId(vvchParams[1]);
entry.push_back(Pair("supported_claimid", claimId.GetHex()));
}
entry.push_back(Pair("txid", wtx.GetHash().ToString()));
entry.push_back(Pair("account", strSentAccount));
@@ -737,7 +755,7 @@ UniValue listnameclaims(const UniValue& params, bool fHelp)
if (fHelp || params.size() > 3)
throw runtime_error(
"listnameclaims activeonly minconf\n"
"listnameclaims includesuppports activeonly minconf\n"
"Return a list of all transactions claiming names.\n"
"\nArguments\n"
"1. includesupports (bool, optional) Whether to also include claim supports. Default is true.\n"
@@ -748,6 +766,7 @@ UniValue listnameclaims(const UniValue& params, bool fHelp)
" {\n"
" \"name\":\"claimedname\", (string) The name that is claimed.\n"
" \"claimtype\":\"claimtype\", (string) CLAIM or SUPPORT.\n"
" \"claimId\":\"claimId\", (string) The claimId of the claim.\n"
" \"value\":\"value\" (string) The value assigned to the name, if claimtype is CLAIM.\n"
" \"account\":\"accountname\", (string) The account name associated with the transaction. \n"
" It will be \"\" for the default account.\n"
@@ -813,34 +832,32 @@ UniValue supportclaim(const UniValue& params, bool fHelp)
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (fHelp || params.size() != 4)
if (fHelp || params.size() != 3)
throw runtime_error(
"supportclaim \"name\" \"txid\" nout amount\n"
"supportclaim \"name\" \"claimid\" \"amount\"\n"
"Increase the value of a claim. Whichever claim has the greatest value, including all support values, will be the authoritative claim, according to the rest of the rules. The name is the name which is claimed by the claim that will be supported, the txid is the txid of the claim that will be supported, nout is the transaction output which contains the claim to be supported, and amount is the amount which will be added to the value of the claim. If the claim is currently the authoritative claim, this support will go into effect immediately. Otherwise, it will go into effect after 100 blocks. The support will be in effect until it is spent, and will lose its effect when the claim is spent or expires. The amount is a real and is rounded to the nearest .00000001\n"
+ HelpRequiringPassphrase() +
"\nArguments:\n"
"1. \"name\" (string, required) The name claimed by the claim to support.\n"
"2. \"txid\" (string, required) The transaction id of the claim to support.\n"
"3. \"nout\" (integer, required) The transaction output of the transaction which contains the claim to be supported.\n"
"4. \"amount\" (numeric, required) The amount in LBC to use to support the claim.\n"
"2. \"claimid\" (string, required) The claimid of the claim to support. This can be obtained by TODO PUT IN PLACE THAT SHOWS THIS.\n"
"3. \"amount\" (numeric, required) The amount in LBC to use to support the claim.\n"
"\nResult:\n"
"\"transactionid\" (string) The transaction id of the support.\n"
);
string sName = params[0].get_str();
string sTxid = params[1].get_str();
uint256 txid;
txid.SetHex(sTxid);
string sClaimId = params[1].get_str();
uint160 claimId;
claimId.SetHex(sClaimId);
std::vector<unsigned char> vchName (sName.begin(), sName.end());
std::vector<unsigned char> vchTxid (txid.begin(), txid.end());
std::vector<unsigned char> vchnOut = uint32_t_to_vch(params[2].get_int());
CAmount nAmount = AmountFromValue(params[3]);
std::vector<unsigned char> vchClaimId (claimId.begin(), claimId.end());
CAmount nAmount = AmountFromValue(params[2]);
CWalletTx wtx;
EnsureWalletIsUnlocked();
CScript supportScript = CScript() << OP_SUPPORT_CLAIM << vchName << vchTxid << vchnOut << OP_2DROP << OP_2DROP;
CScript supportScript = CScript() << OP_SUPPORT_CLAIM << vchName << vchClaimId << OP_2DROP << OP_DROP;
CreateClaim(supportScript, nAmount, wtx);