Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61129e6483 |
No files matched your search
@@ -121,7 +121,3 @@ contrib/devtools/split-debug.sh
|
||||
cmake-build-*/
|
||||
|
||||
compile_commands\.json
|
||||
**/compiler*\.d
|
||||
conftest.dir/
|
||||
|
||||
confdefs.h
|
||||
+7
-16
@@ -14,7 +14,7 @@ jobs:
|
||||
- &build-template
|
||||
stage: build
|
||||
name: linux
|
||||
env: NAME=linux DOCKER_IMAGE=lbry/build_lbrycrd_gcc EXT=
|
||||
env: NAME=linux EXT=
|
||||
os: linux
|
||||
dist: xenial
|
||||
language: minimal
|
||||
@@ -22,15 +22,13 @@ jobs:
|
||||
- docker
|
||||
install:
|
||||
- mkdir -p ${HOME}/ccache
|
||||
- docker pull $DOCKER_IMAGE
|
||||
- docker pull $DOCKER_BUILD_IMAGE
|
||||
script:
|
||||
- echo "build..."
|
||||
- docker run -v "$(pwd):/lbrycrd" -v "${HOME}/ccache:/ccache" -w /lbrycrd -e CCACHE_DIR=/ccache ${DOCKER_IMAGE} packaging/build_${NAME}_64bit.sh
|
||||
before_deploy:
|
||||
- mkdir -p dist
|
||||
- sudo zip -Xj dist/lbrycrd-${NAME}.zip src/lbrycrdd${EXT} src/lbrycrd-cli${EXT} src/lbrycrd-tx${EXT}
|
||||
- sudo zip -Xj dist/lbrycrd-${NAME}-test.zip src/test/test_lbrycrd${EXT} src/test/test_lbrycrd_fuzzy${EXT}
|
||||
- sudo cp dist/lbrycrd-${NAME}.zip packaging/docker-for-binary/lbrycrd-${NAME}.zip
|
||||
- sha256sum dist/lbrycrd-${NAME}.zip
|
||||
- sha256sum dist/lbrycrd-${NAME}-test.zip
|
||||
deploy:
|
||||
@@ -46,21 +44,14 @@ jobs:
|
||||
on:
|
||||
repo: lbryio/lbrycrd
|
||||
all_branches: true
|
||||
- provider: script
|
||||
script: bash packaging/docker-for-binary/auto_deploy.sh ${TRAVIS_BRANCH}
|
||||
skip_cleanup: true
|
||||
on:
|
||||
repo: lbryio/lbrycrd
|
||||
all_branches: true
|
||||
condition: $NAME = linux
|
||||
|
||||
- <<: *build-template
|
||||
name: windows
|
||||
env: NAME=windows DOCKER_IMAGE=lbry/build_lbrycrd EXT=.exe
|
||||
env: NAME=windows EXT=.exe
|
||||
|
||||
- <<: *build-template
|
||||
name: osx
|
||||
env: NAME=darwin DOCKER_IMAGE=lbry/build_lbrycrd EXT=
|
||||
env: NAME=darwin EXT=
|
||||
before_install:
|
||||
- mkdir -p ./depends/SDKs && pushd depends/SDKs && curl -C - ${MAC_OS_SDK} | tar --skip-old-files -xJ && popd
|
||||
|
||||
@@ -71,7 +62,7 @@ jobs:
|
||||
dist: xenial
|
||||
language: minimal
|
||||
git:
|
||||
clone: false
|
||||
depth: 3
|
||||
install:
|
||||
- mkdir -p testrun && cd testrun
|
||||
- curl http://build.lbry.io/lbrycrd/${TRAVIS_BRANCH}/lbrycrd-${NAME}-test.zip -o temp.zip
|
||||
@@ -86,8 +77,8 @@ jobs:
|
||||
services:
|
||||
- docker
|
||||
script:
|
||||
- docker pull lbry/wine
|
||||
- docker run -v "$(pwd):/test" -e "WINEDEBUG=-all" -e "TRIEHASH_FUZZER_BLOCKS=1000" -it lbry/wine wine "/test/test_lbrycrd.exe"
|
||||
- docker pull $DOCKER_WINE_IMAGE
|
||||
- docker run -v "$(pwd):/test" -e "WINEDEBUG=-all" -e "TRIEHASH_FUZZER_BLOCKS=1000" -it $DOCKER_WINE_IMAGE wine "/test/test_lbrycrd.exe"
|
||||
|
||||
- <<: *test-template
|
||||
os: osx
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-2020 LBRY Inc
|
||||
Copyright (c) 2015-2019 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,
|
||||
|
||||
@@ -12,7 +12,7 @@ function HELP {
|
||||
echo "-q: compile the QT GUI (not working at present)"
|
||||
echo "-d: force a rebuild of dependencies"
|
||||
echo "-u: run the unit tests when done"
|
||||
echo "-g: compile in debug mode"
|
||||
echo "-g: include debug symbols"
|
||||
echo "-h: show help"
|
||||
exit 1
|
||||
}
|
||||
@@ -56,18 +56,16 @@ done
|
||||
|
||||
echo "Compiling with ${PARALLEL_JOBS} jobs in parallel."
|
||||
|
||||
BUILD_FLAGS=(CXXFLAGS="-O3 -march=native -g")
|
||||
DEBUG_DEPENDS=""
|
||||
BUILD_FLAGS=(CXXFLAGS="-O3 -march=native")
|
||||
if test "$COMPILE_WITH_DEBUG" = true; then
|
||||
BUILD_FLAGS=(--with-debug CXXFLAGS="-O0 -g")
|
||||
DEBUG_DEPENDS="DEBUG=1"
|
||||
BUILD_FLAGS=(--with-debug CXXFLAGS="-Og -g")
|
||||
fi
|
||||
|
||||
cd depends
|
||||
if test "$REBUILD_DEPENDENCIES" = true; then
|
||||
make clean
|
||||
fi
|
||||
make -j${PARALLEL_JOBS} ${DO_NOT_COMPILE_THE_GUI} ${DEBUG_DEPENDS} V=1
|
||||
make -j${PARALLEL_JOBS} ${DO_NOT_COMPILE_THE_GUI} V=1
|
||||
cd ..
|
||||
|
||||
LC_ALL=C autoreconf --install
|
||||
@@ -81,4 +79,4 @@ fi
|
||||
|
||||
if test $? -eq 0 && "$RUN_UNIT_TESTS" = true; then
|
||||
./src/test/test_lbrycrd
|
||||
fi
|
||||
fi
|
||||
+3
-3
@@ -2,10 +2,10 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
|
||||
AC_PREREQ([2.60])
|
||||
define(_CLIENT_VERSION_MAJOR, 0)
|
||||
define(_CLIENT_VERSION_MINOR, 17)
|
||||
define(_CLIENT_VERSION_REVISION, 4)
|
||||
define(_CLIENT_VERSION_BUILD, 6)
|
||||
define(_CLIENT_VERSION_REVISION, 3)
|
||||
define(_CLIENT_VERSION_BUILD, 2)
|
||||
define(_CLIENT_VERSION_IS_RELEASE, true)
|
||||
define(_COPYRIGHT_YEAR, 2020)
|
||||
define(_COPYRIGHT_YEAR, 2019)
|
||||
define(_COPYRIGHT_HOLDERS,[The %s developers])
|
||||
define(_COPYRIGHT_HOLDERS_SUBSTITUTION,[[LBRYcrd Core]])
|
||||
AC_INIT([LBRYcrd Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[https://github.com/lbryio/lbrycrd/issues],[lbrycrd],[https://lbry.com/])
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -9,10 +9,10 @@ darwin_CXX=clang++ -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) -isys
|
||||
darwin_CFLAGS=-pipe
|
||||
darwin_CXXFLAGS=$(darwin_CFLAGS) -std=c++11
|
||||
|
||||
darwin_release_CFLAGS=-O2 -g
|
||||
darwin_release_CFLAGS=-O2
|
||||
darwin_release_CXXFLAGS=$(darwin_release_CFLAGS)
|
||||
|
||||
darwin_debug_CFLAGS=-Og -g
|
||||
darwin_debug_CXXFLAGS=-O0 -g
|
||||
darwin_debug_CFLAGS=-Og
|
||||
darwin_debug_CXXFLAGS=$(darwin_debug_CFLAGS)
|
||||
|
||||
darwin_native_toolchain=native_cctools
|
||||
darwin_native_toolchain=native_cctools
|
||||
@@ -1,11 +1,11 @@
|
||||
linux_CFLAGS=-pipe
|
||||
linux_CXXFLAGS=$(linux_CFLAGS) -std=c++11
|
||||
|
||||
linux_release_CFLAGS=-O3 -g -include $(BASEDIR)/glibc_version_header/force_link_glibc_2.19.h
|
||||
linux_release_CFLAGS=-O2
|
||||
linux_release_CXXFLAGS=$(linux_release_CFLAGS)
|
||||
|
||||
linux_debug_CFLAGS=-O1 -g
|
||||
linux_debug_CXXFLAGS=-O0 -g
|
||||
linux_debug_CFLAGS=-Og
|
||||
linux_debug_CXXFLAGS=$(linux_debug_CFLAGS)
|
||||
|
||||
linux_debug_CPPFLAGS=-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
mingw32_CFLAGS=-pipe
|
||||
mingw32_CXXFLAGS=$(mingw32_CFLAGS) -std=c++11
|
||||
|
||||
mingw32_release_CFLAGS=-O2 -g
|
||||
mingw32_release_CFLAGS=-O2
|
||||
mingw32_release_CXXFLAGS=$(mingw32_release_CFLAGS)
|
||||
|
||||
mingw32_debug_CFLAGS=-O1 -g
|
||||
mingw32_debug_CXXFLAGS=-O0 -g
|
||||
mingw32_debug_CFLAGS=-O1
|
||||
mingw32_debug_CXXFLAGS=$(mingw32_debug_CFLAGS)
|
||||
|
||||
mingw32_debug_CPPFLAGS=-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
|
||||
@@ -1,6 +1,6 @@
|
||||
package=bdb
|
||||
$(package)_version=4.8.30
|
||||
$(package)_download_path=https://download.oracle.com/berkeley-db
|
||||
$(package)_download_path=http://download.oracle.com/berkeley-db
|
||||
$(package)_file_name=db-$($(package)_version).NC.tar.gz
|
||||
$(package)_sha256_hash=12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef
|
||||
$(package)_build_subdir=build_unix
|
||||
@@ -9,7 +9,6 @@ define $(package)_set_vars
|
||||
$(package)_config_opts=--disable-shared --enable-cxx --disable-replication
|
||||
$(package)_config_opts_mingw32=--enable-mingw
|
||||
$(package)_config_opts_linux=--with-pic
|
||||
$(package)_cppflags_mingw32=-DUNICODE -D_UNICODE
|
||||
endef
|
||||
|
||||
define $(package)_preprocess_cmds
|
||||
|
||||
@@ -21,6 +21,7 @@ define $(package)_preprocess_cmds
|
||||
PKG_CONFIG_SYSROOT_DIR=/ \
|
||||
PKG_CONFIG_LIBDIR=$(host_prefix)/lib/pkgconfig \
|
||||
PKG_CONFIG_PATH=$(host_prefix)/share/pkgconfig \
|
||||
sed -i.old 's/^GEN_DEPS.cc.*/& $(CXXFLAGS)/' source/config/mh-mingw* && \
|
||||
mkdir -p build && cd build && \
|
||||
../source/runConfigureICU Linux $($(package)_standard_opts) CXXFLAGS=-std=c++11 && \
|
||||
$(MAKE) && cd ..
|
||||
@@ -30,8 +31,6 @@ define $(package)_config_cmds
|
||||
PKG_CONFIG_SYSROOT_DIR=/ \
|
||||
PKG_CONFIG_LIBDIR=$(host_prefix)/lib/pkgconfig \
|
||||
PKG_CONFIG_PATH=$(host_prefix)/share/pkgconfig \
|
||||
sed -i.old 's|^GEN_DEPS.c=.*|& $($(package)_cflags)|' config/mh-mingw* && \
|
||||
sed -i.old 's|^GEN_DEPS.cc=.*|& $($(package)_cxxflags)|' config/mh-mingw* && \
|
||||
$($(package)_autoconf)
|
||||
endef
|
||||
|
||||
|
||||
@@ -27,5 +27,4 @@ define $(package)_stage_cmds
|
||||
endef
|
||||
|
||||
define $(package)_postprocess_cmds
|
||||
rm lib/*.la
|
||||
endef
|
||||
@@ -5,7 +5,7 @@ $(package)_file_name=$(package)-$($(package)_version).tar.gz
|
||||
$(package)_sha256_hash=8f9faeaebad088e772f4ef5e38252d472be4d878c6b3a2718c10a4fcebe7a41c
|
||||
|
||||
define $(package)_set_vars
|
||||
$(package)_config_env=AR="$($(package)_ar)" RANLIB="$($(package)_ranlib)" CC="$($(package)_cc) $($(package)_cflags) $($(package)_cppflags)"
|
||||
$(package)_config_env=AR="$($(package)_ar)" RANLIB="$($(package)_ranlib)" CC="$($(package)_cc)"
|
||||
$(package)_config_opts=--prefix=$(host_prefix) --openssldir=$(host_prefix)/etc/openssl
|
||||
$(package)_config_opts+=no-camellia
|
||||
$(package)_config_opts+=no-capieng
|
||||
@@ -42,6 +42,7 @@ $(package)_config_opts+=no-weak-ssl-ciphers
|
||||
$(package)_config_opts+=no-whirlpool
|
||||
$(package)_config_opts+=no-zlib
|
||||
$(package)_config_opts+=no-zlib-dynamic
|
||||
$(package)_config_opts+=$($(package)_cflags) $($(package)_cppflags)
|
||||
$(package)_config_opts_linux=-fPIC -Wa,--noexecstack
|
||||
$(package)_config_opts_x86_64_linux=linux-x86_64
|
||||
$(package)_config_opts_i686_linux=linux-generic32
|
||||
|
||||
@@ -6,9 +6,7 @@ $(package)_sha256_hash=bcbabe1e2c7d0eec4ed612e10b94b112dd5f06fcefa994a0c79a45d83
|
||||
$(package)_patches=0001-fix-build-with-older-mingw64.patch 0002-disable-pthread_set_name_np.patch
|
||||
|
||||
define $(package)_set_vars
|
||||
$(package)_config_opts=--without-docs --disable-shared --without-libsodium --disable-curve --disable-curve-keygen --disable-perf --disable-Werror --disable-drafts
|
||||
$(package)_config_opts += --without-libsodium --without-libgssapi_krb5 --without-pgm --without-norm --without-vmci
|
||||
$(package)_config_opts += --disable-libunwind --disable-radix-tree --without-gcov
|
||||
$(package)_config_opts=--without-docs --disable-shared --without-libsodium --disable-curve --disable-curve-keygen --disable-perf --disable-Werror
|
||||
$(package)_config_opts_linux=--with-pic
|
||||
endef
|
||||
|
||||
@@ -32,5 +30,5 @@ endef
|
||||
|
||||
define $(package)_postprocess_cmds
|
||||
sed -i.old "s/ -lstdc++//" lib/pkgconfig/libzmq.pc && \
|
||||
rm -rf bin share lib/*.la
|
||||
rm -rf bin share
|
||||
endef
|
||||
+10
-5
@@ -1,12 +1,17 @@
|
||||
FROM ubuntu:18.04
|
||||
FROM ubuntu:16.04
|
||||
ENV LANG C.UTF-8
|
||||
|
||||
RUN set -xe; \
|
||||
apt-get update; \
|
||||
apt-get install --no-install-recommends -y build-essential libtool autotools-dev automake pkg-config git wget apt-utils \
|
||||
librsvg2-bin libtiff-tools cmake imagemagick libcap-dev libz-dev libbz2-dev python-setuptools python3-setuptools xz-utils ccache g++-multilib \
|
||||
g++-mingw-w64-i686 mingw-w64-i686-dev bsdmainutils curl ca-certificates g++-mingw-w64-x86-64 mingw-w64-x86-64-dev \
|
||||
clang-8 lldb-8 lld-8 libc++-8-dev; \
|
||||
librsvg2-bin libtiff-tools cmake imagemagick libcap-dev libz-dev libbz2-dev python-setuptools xz-utils ccache g++-multilib \
|
||||
g++-mingw-w64-i686 mingw-w64-i686-dev bsdmainutils curl ca-certificates g++-mingw-w64-x86-64 mingw-w64-x86-64-dev; \
|
||||
rm -rf /var/lib/apt/lists/*;
|
||||
|
||||
RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -; \
|
||||
echo 'deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main' >> /etc/apt/sources.list; \
|
||||
apt-get update; \
|
||||
apt-get install --no-install-recommends -y clang-8 lldb-8 lld-8 libc++-8-dev; \
|
||||
rm -rf /var/lib/apt/lists/*;
|
||||
|
||||
RUN update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang-cpp-8 80; \
|
||||
@@ -23,7 +28,7 @@ ARG VCS_REF
|
||||
ARG BUILD_DATE
|
||||
LABEL maintainer="blockchain@lbry.com" \
|
||||
decription="build_lbrycrd" \
|
||||
version="1.2" \
|
||||
version="1.1" \
|
||||
org.label-schema.name="build_lbrycrd" \
|
||||
org.label-schema.description="Use this to generate a reproducible build of LBRYcrd" \
|
||||
org.label-schema.build-date=$BUILD_DATE \
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
FROM ubuntu:18.04 as prep
|
||||
LABEL MAINTAINER="leopere [at] nixc [dot] us"
|
||||
## TODO: Implement version pinning. `apt-get install curl=<version>`
|
||||
RUN apt-get update && \
|
||||
apt-get -y install unzip curl build-essential && \
|
||||
apt-get autoclean -y && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
WORKDIR /
|
||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||
COPY ./stuff/start.sh start
|
||||
COPY ./stuff/healthcheck.sh healthcheck
|
||||
COPY ./stuff/advance_blocks.sh advance
|
||||
COPY ./stuff/fix-permissions.c fix-permissions.c
|
||||
COPY ./lbrycrd-linux.zip lbrycrd-linux.zip
|
||||
|
||||
RUN unzip ./lbrycrd-linux.zip && \
|
||||
gcc fix-permissions.c -o fix-permissions && \
|
||||
chmod +x ./lbrycrdd ./lbrycrd-cli ./lbrycrd-tx ./start ./healthcheck ./fix-permissions ./advance
|
||||
|
||||
FROM ubuntu:18.04 as app
|
||||
COPY --from=prep /lbrycrdd /lbrycrd-cli /lbrycrd-tx /start /healthcheck /fix-permissions /advance /usr/bin/
|
||||
RUN addgroup --gid 1000 lbrycrd && \
|
||||
adduser lbrycrd --uid 1000 --gid 1000 --gecos GECOS --shell /bin/bash --disabled-password --home /data && \
|
||||
mkdir /etc/lbry && \
|
||||
chown lbrycrd /etc/lbry && \
|
||||
chmod a+s /usr/bin/fix-permissions
|
||||
RUN apt-get update && apt-get -y install wget && apt-get autoclean -y && rm -rf /var/lib/apt/lists/*
|
||||
VOLUME ["/data"]
|
||||
WORKDIR /data
|
||||
HEALTHCHECK CMD /usr/bin/healthcheck
|
||||
EXPOSE 9246 9245 11337 29245
|
||||
|
||||
USER lbrycrd
|
||||
CMD ["start"]
|
||||
@@ -1,36 +1,5 @@
|
||||
# lbrycrd Docker image
|
||||
|
||||
## Scripts
|
||||
|
||||
There are two scripts `deploy.sh` and `auto_deploy.sh` These are used to create
|
||||
docker images to push to lbry's Docker Hub.
|
||||
|
||||
### `auto_deploy.sh`
|
||||
|
||||
This script is used by the LBRYcrd's CI. When a branch or tag is built
|
||||
it will create a docker image for it and push it to DockerHub. This should
|
||||
not be used outside of the CI environment. In addition to this, the
|
||||
`Dockerfile.Auto` is associated with this script. This will only run on the
|
||||
Linux build job.
|
||||
|
||||
#### Requirements
|
||||
|
||||
- You would need to build lbrycrd with the Docker image for reproducible
|
||||
builds. https://hub.docker.com/repository/docker/lbry/build_lbrycrd
|
||||
- You will need DockerHub credentials to run this locally.
|
||||
- When the script is executed you will need the parameter as
|
||||
`./auto_deploy.sh ${tag_name}`
|
||||
|
||||
### `deploy.sh`
|
||||
|
||||
This can be used locally to manually create a docker image based on a
|
||||
release. `release_url` is requested as a parameter to the script when
|
||||
run locally. This will grab the binary from github releases inside the
|
||||
image build.
|
||||
|
||||
#### Requirements
|
||||
|
||||
- You will need DockerHub credentials to run this locally.
|
||||
`
|
||||
|
||||
## Configuration
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
set -euo pipefail
|
||||
hash docker 2>/dev/null || { echo >&2 'Make sure Docker is installed'; exit 1; }
|
||||
|
||||
set +eo pipefail
|
||||
docker version | grep -q Server
|
||||
ret=$?
|
||||
set -eo pipefail
|
||||
|
||||
if [ $ret -ne 0 ]; then
|
||||
echo "Cannot connect to Docker server. Is it running? Do you have the right user permissions?"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "Docker tag parameter cannot be empty"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd packaging/docker-for-binary
|
||||
docker build --tag "lbry/lbrycrd:$1" -f Dockerfile.Auto "$DIR"
|
||||
echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin
|
||||
docker push "lbry/lbrycrd:$1"
|
||||
@@ -35,6 +35,7 @@ function set_config() {
|
||||
override_config_option RPC_ALLOW_IP rpcallowip $MERGED_CONFIG
|
||||
override_config_option RPC_PORT rpcport $MERGED_CONFIG
|
||||
override_config_option RPC_BIND rpcbind $MERGED_CONFIG
|
||||
override_config_option TX_INDEX txindex $MERGED_CONFIG
|
||||
override_config_option MAX_TX_FEE maxtxfee $MERGED_CONFIG
|
||||
override_config_option DUST_RELAY_FEE dustrelayfee $MERGED_CONFIG
|
||||
# Make the new merged config file the new CONFIG_PATH
|
||||
@@ -49,12 +50,11 @@ printtoconsole=1
|
||||
port=${PORT:-9246}
|
||||
rpcuser=${RPC_USER:-lbry}
|
||||
rpcpassword=${RPC_PASSWORD:-lbry}
|
||||
## Be careful what you set this to when running mainnet. By default it only allows RPC connections from localhost
|
||||
## if running inside a composition of services Then pass the environment variable `RPC_ALLOW_IP=0.0.0.0/0`
|
||||
rpcallowip=${RPC_ALLOW_IP:-127.0.0.1}
|
||||
rpcport=${RPC_PORT:-9245}
|
||||
rpcbind=${RPC_BIND:-"0.0.0.0"}
|
||||
|
||||
txindex=${TX_INDEX:-"1"}
|
||||
maxtxfee=${MAX_TX_FEE:-"0.5"}
|
||||
dustrelayfee=${DUST_RELAY_FEE:-"0.00000001"}
|
||||
EOF
|
||||
@@ -88,15 +88,15 @@ case $RUN_MODE in
|
||||
download_snapshot
|
||||
exec lbrycrdd -conf=$CONFIG_PATH
|
||||
;;
|
||||
## If for some reason one is told to reindex their blockchain this run mode will launch lbrycrd with the reindex parameter.
|
||||
## Don't forget to change it back to default once complete ( you will need to remove the container to re-apply the run mode).
|
||||
## If it's a first run you need to do a full index including all transactions
|
||||
## tx index creates an index of every single transaction in the block history if
|
||||
## not specified it will only create an index for transactions that are related to the wallet or have unspent outputs.
|
||||
## This is generally specific to chainquery.
|
||||
reindex )
|
||||
## Apply this RUN_MODE in the case you need to update a dataset. NOTE: you do not need to use `RUN_MODE reindex` for more than one complete run.
|
||||
set_config
|
||||
exec lbrycrdd -conf=$CONFIG_PATH -reindex
|
||||
;;
|
||||
## Regtest requires ports to be the port listed below. It is hardcoded to be this port for regtest when using a config.
|
||||
## Only way to override it is to run lbrycrd from the commandline and set the port there.
|
||||
regtest )
|
||||
## Set config params
|
||||
## TODO: Make this more automagic in the future.
|
||||
@@ -107,6 +107,7 @@ case $RUN_MODE in
|
||||
echo "rpcbind=0.0.0.0" >> $CONFIG_PATH
|
||||
echo "rpcallowip=0.0.0.0/0" >> $CONFIG_PATH
|
||||
echo "regtest=1" >> $CONFIG_PATH
|
||||
echo "txindex=1" >> $CONFIG_PATH
|
||||
echo "server=1" >> $CONFIG_PATH
|
||||
echo "printtoconsole=1" >> $CONFIG_PATH
|
||||
|
||||
@@ -124,6 +125,7 @@ case $RUN_MODE in
|
||||
echo "rpcbind=0.0.0.0" >> $CONFIG_PATH
|
||||
echo "rpcallowip=0.0.0.0/0" >> $CONFIG_PATH
|
||||
echo "testnet=1" >> $CONFIG_PATH
|
||||
echo "txindex=1" >> $CONFIG_PATH
|
||||
echo "server=1" >> $CONFIG_PATH
|
||||
echo "printtoconsole=1" >> $CONFIG_PATH
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
FROM ubuntu:18.04
|
||||
ENV LANG C.UTF-8
|
||||
|
||||
RUN set -xe; \
|
||||
apt-get update; \
|
||||
apt-get install --no-install-recommends -y build-essential libtool autotools-dev automake pkg-config git wget apt-utils \
|
||||
librsvg2-bin cmake libcap-dev libz-dev libbz2-dev python-setuptools python3-setuptools xz-utils ccache \
|
||||
bsdmainutils curl ca-certificates; \
|
||||
rm -rf /var/lib/apt/lists/*; \
|
||||
/usr/sbin/update-ccache-symlinks;
|
||||
|
||||
ARG VCS_REF
|
||||
ARG BUILD_DATE
|
||||
LABEL maintainer="blockchain@lbry.com" \
|
||||
decription="build_lbrycrd_gcc" \
|
||||
version="1.2" \
|
||||
org.label-schema.name="build_lbrycrd_gcc" \
|
||||
org.label-schema.description="Use this to generate a reproducible build of LBRYcrd for Linux" \
|
||||
org.label-schema.build-date=$BUILD_DATE \
|
||||
org.label-schema.vcs-ref=$VCS_REF \
|
||||
org.label-schema.vcs-url="https://github.com/lbryio/lbrycrd" \
|
||||
org.label-schema.schema-version="1.0.0-rc1" \
|
||||
org.label-schema.vendor="LBRY" \
|
||||
org.label-schema.docker.cmd="docker build --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` --build-arg VCS_REF=`git rev-parse --short HEAD` -t lbry/build_lbrycrd_gcc packaging"
|
||||
|
||||
ENV PATH "/usr/lib/ccache:$PATH"
|
||||
WORKDIR /home
|
||||
CMD ["/bin/bash"]
|
||||
@@ -148,7 +148,6 @@ BITCOIN_CORE_H = \
|
||||
policy/fees.h \
|
||||
policy/policy.h \
|
||||
policy/rbf.h \
|
||||
primitives/robin_hood.h \
|
||||
pow.h \
|
||||
protocol.h \
|
||||
random.h \
|
||||
|
||||
+6
-5
@@ -171,7 +171,7 @@ class CBlockIndex
|
||||
{
|
||||
public:
|
||||
//! pointer to the hash of the block, if any. Memory is owned by this CBlockIndex
|
||||
const uint256 hash;
|
||||
const uint256* phashBlock;
|
||||
|
||||
//! pointer to the index of the predecessor of this block
|
||||
CBlockIndex* pprev;
|
||||
@@ -222,6 +222,7 @@ public:
|
||||
|
||||
void SetNull()
|
||||
{
|
||||
phashBlock = nullptr;
|
||||
pprev = nullptr;
|
||||
pskip = nullptr;
|
||||
nHeight = 0;
|
||||
@@ -243,12 +244,12 @@ public:
|
||||
nNonce = 0;
|
||||
}
|
||||
|
||||
CBlockIndex(const uint256& blockHash) : hash(blockHash)
|
||||
CBlockIndex()
|
||||
{
|
||||
SetNull();
|
||||
}
|
||||
|
||||
explicit CBlockIndex(const CBlockHeader& block) : hash(block.GetHash())
|
||||
explicit CBlockIndex(const CBlockHeader& block)
|
||||
{
|
||||
SetNull();
|
||||
|
||||
@@ -292,9 +293,9 @@ public:
|
||||
return block;
|
||||
}
|
||||
|
||||
const uint256& GetBlockHash() const
|
||||
uint256 GetBlockHash() const
|
||||
{
|
||||
return hash;
|
||||
return *phashBlock;
|
||||
}
|
||||
|
||||
uint256 GetBlockPoWHash() const
|
||||
|
||||
+21
-24
@@ -144,7 +144,7 @@ public:
|
||||
consensus.nAllowMinDiffMaxHeight = -1;
|
||||
consensus.nNormalizedNameForkHeight = 539940; // targeting 21 March 2019
|
||||
consensus.nMinRemovalWorkaroundHeight = 297706;
|
||||
consensus.nMaxRemovalWorkaroundHeight = 658300;
|
||||
consensus.nMaxRemovalWorkaroundHeight = 100000000;
|
||||
consensus.nWitnessForkHeight = 680770; // targeting 11 Dec 2019
|
||||
consensus.nAllClaimsInMerkleForkHeight = 658310; // targeting 30 Oct 2019
|
||||
consensus.fPowAllowMinDifficultyBlocks = false;
|
||||
@@ -166,10 +166,10 @@ public:
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1548288000; // Jan 24, 2019
|
||||
|
||||
// The best chain should have at least this much work.
|
||||
consensus.nMinimumChainWork = uint256S("0000000000000000000000000000000000000000000003253077412df5b49766"); //749k
|
||||
consensus.nMinimumChainWork = uint256S("00000000000000000000000000000000000000000000024108e3204a44a57a5a"); //621000
|
||||
|
||||
// By default assume that the signatures in ancestors of this block are valid.
|
||||
consensus.defaultAssumeValid = uint256S("b9676f45be594438a2011407c93bb530d817fa365846e7a6ecdf2790e4a0ad6b"); //749k
|
||||
consensus.defaultAssumeValid = uint256S("7899464514d0d8854919e87eb234fd5f0c35d06418bd5fd3c1a8f7092b2a9317"); //620000
|
||||
|
||||
/**
|
||||
* The message start string is designed to be unlikely to occur in normal data.
|
||||
@@ -247,27 +247,24 @@ public:
|
||||
consensus.nMajorityRejectBlockOutdated = 75;
|
||||
consensus.nMajorityWindow = 100;
|
||||
consensus.BIP16Exception = uint256S("0x00000000dd30457c001f4095d208cc1296b0eed002427aa599874af7a432b105");
|
||||
consensus.BIP34Height = 14;
|
||||
consensus.BIP34Hash = uint256S("0x079557d16edcd640c4057c9fddb81257263014fe384c4aa348c5b9d190650a46");
|
||||
consensus.BIP34Height = 21111;
|
||||
consensus.BIP34Hash = uint256S("0x0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8");
|
||||
// FIXME: adjust heights
|
||||
consensus.BIP65Height = 120;
|
||||
consensus.BIP66Height = 120;
|
||||
consensus.BIP65Height = 1200000;
|
||||
consensus.BIP66Height = 1200000;
|
||||
consensus.powLimit = uint256S("0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
consensus.nPowTargetTimespan = 150;
|
||||
// consensus.CSVHeight = 0;
|
||||
// consensus.SegwitHeight = 120;
|
||||
// consensus.MinBIP9WarningHeight = 2136; // segwit activation height + miner confirmation window
|
||||
consensus.nPowTargetSpacing = 150;
|
||||
consensus.nOriginalClaimExpirationTime = 262974;
|
||||
consensus.nExtendedClaimExpirationTime = 2102400;
|
||||
consensus.nExtendedClaimExpirationForkHeight = 1;
|
||||
consensus.nAllowMinDiffMinHeight = 1;
|
||||
consensus.nAllowMinDiffMaxHeight = 2;
|
||||
consensus.nNormalizedNameForkHeight = 1; // targeting, 21 Feb 2019
|
||||
consensus.nExtendedClaimExpirationForkHeight = 278160;
|
||||
consensus.nAllowMinDiffMinHeight = 277299;
|
||||
consensus.nAllowMinDiffMaxHeight = 1100000;
|
||||
consensus.nNormalizedNameForkHeight = 993380; // targeting, 21 Feb 2019
|
||||
consensus.nMinRemovalWorkaroundHeight = 99;
|
||||
consensus.nMaxRemovalWorkaroundHeight = 100;
|
||||
consensus.nWitnessForkHeight = 120;
|
||||
consensus.nAllClaimsInMerkleForkHeight = 110; // targeting 30 Sep 2019
|
||||
consensus.nMaxRemovalWorkaroundHeight = 100000000;
|
||||
consensus.nWitnessForkHeight = 1198600;
|
||||
consensus.nAllClaimsInMerkleForkHeight = 1198560; // targeting 30 Sep 2019
|
||||
consensus.fPowAllowMinDifficultyBlocks = true;
|
||||
consensus.fPowNoRetargeting = false;
|
||||
consensus.nRuleChangeActivationThreshold = 1512; // 75% for testchains
|
||||
@@ -278,19 +275,19 @@ public:
|
||||
|
||||
// Deployment of BIP68, BIP112, and BIP113.
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].bit = 0;
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = Consensus::BIP9Deployment::ALWAYS_ACTIVE;
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nStartTime = 1456790400; // March 1st, 2016
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = 1493596800; // May 1st, 2017
|
||||
|
||||
// Deployment of SegWit (BIP141, BIP143, and BIP147) -- Unused (see nWitnessForkHeight).
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = 1462060800; // May 1st 2016
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1585849000; // Apr 2nd 2020
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1493596800; // May 1st 2017
|
||||
|
||||
// The best chain should have at least this much work.
|
||||
consensus.nMinimumChainWork = uint256S("00000000000000000000000000000000000000000000000000000054b7d280af"); // 8400
|
||||
consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000000000000a0c3931735170");
|
||||
|
||||
// By default assume that the signatures in ancestors of this block are valid.
|
||||
consensus.defaultAssumeValid = uint256S("50b68b892f4e0f2ef649df37ef10b702e826c8913cc785c5e8ec16dd6be83f8b"); // 8400
|
||||
consensus.defaultAssumeValid = uint256S("9812b0bcb7e889e58d999c897e9eaddb2dab98122ff1cfb238ebeef5351bd48c"); // 1
|
||||
|
||||
pchMessageStart[0] = 0xfa;
|
||||
pchMessageStart[1] = 0xe4;
|
||||
@@ -311,8 +308,8 @@ public:
|
||||
|
||||
vFixedSeeds.clear();
|
||||
vSeeds.clear();
|
||||
vSeeds.emplace_back("testdnsseed1.lbry.com");
|
||||
vSeeds.emplace_back("testdnsseed2.lbry.com");
|
||||
vSeeds.emplace_back("testdnsseed1.lbry.io");
|
||||
vSeeds.emplace_back("testdnsseed2.lbry.io");
|
||||
|
||||
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
|
||||
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
|
||||
|
||||
+11
-9
@@ -9,8 +9,9 @@
|
||||
|
||||
/** Template base class for fixed-sized opaque blobs. */
|
||||
template<uint32_t BITS>
|
||||
CBaseBlob<BITS>::CBaseBlob() noexcept : data{}
|
||||
CBaseBlob<BITS>::CBaseBlob()
|
||||
{
|
||||
SetNull();
|
||||
}
|
||||
|
||||
template<uint32_t BITS>
|
||||
@@ -21,15 +22,16 @@ CBaseBlob<BITS>::CBaseBlob(const std::vector<uint8_t>& vec)
|
||||
}
|
||||
|
||||
template<uint32_t BITS>
|
||||
CBaseBlob<BITS>::CBaseBlob(const CBaseBlob& o) noexcept
|
||||
CBaseBlob<BITS>::CBaseBlob(const CBaseBlob& o)
|
||||
{
|
||||
*this = o;
|
||||
}
|
||||
|
||||
template<uint32_t BITS>
|
||||
CBaseBlob<BITS>& CBaseBlob<BITS>::operator=(const CBaseBlob& o) noexcept
|
||||
CBaseBlob<BITS>& CBaseBlob<BITS>::operator=(const CBaseBlob& o)
|
||||
{
|
||||
data = o.data;
|
||||
if (this != &o)
|
||||
std::copy(o.begin(), o.end(), begin());
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -54,7 +56,7 @@ bool CBaseBlob<BITS>::operator==(const CBaseBlob& b) const
|
||||
template<uint32_t BITS>
|
||||
bool CBaseBlob<BITS>::operator!=(const CBaseBlob& b) const
|
||||
{
|
||||
return Compare(b) != 0;
|
||||
return !(*this == b);
|
||||
}
|
||||
|
||||
template<uint32_t BITS>
|
||||
@@ -139,25 +141,25 @@ std::string CBaseBlob<BITS>::ToString() const
|
||||
template<uint32_t BITS>
|
||||
uint8_t* CBaseBlob<BITS>::begin() noexcept
|
||||
{
|
||||
return data.data();
|
||||
return data.begin();
|
||||
}
|
||||
|
||||
template<uint32_t BITS>
|
||||
const uint8_t* CBaseBlob<BITS>::begin() const noexcept
|
||||
{
|
||||
return data.data();
|
||||
return data.begin();
|
||||
}
|
||||
|
||||
template<uint32_t BITS>
|
||||
uint8_t* CBaseBlob<BITS>::end() noexcept
|
||||
{
|
||||
return data.data() + data.size();
|
||||
return data.end();
|
||||
}
|
||||
|
||||
template<uint32_t BITS>
|
||||
const uint8_t* CBaseBlob<BITS>::end() const noexcept
|
||||
{
|
||||
return data.data() + data.size();
|
||||
return data.end();
|
||||
}
|
||||
|
||||
template<uint32_t BITS>
|
||||
|
||||
@@ -12,15 +12,15 @@ class CBaseBlob
|
||||
{
|
||||
std::array<uint8_t, BITS / 8> data;
|
||||
public:
|
||||
CBaseBlob() noexcept;
|
||||
CBaseBlob();
|
||||
|
||||
explicit CBaseBlob(const std::vector<uint8_t>& vec);
|
||||
|
||||
CBaseBlob(CBaseBlob&&) = default;
|
||||
CBaseBlob& operator=(CBaseBlob&&) = default;
|
||||
|
||||
CBaseBlob(const CBaseBlob& o) noexcept;
|
||||
CBaseBlob& operator=(const CBaseBlob& o) noexcept;
|
||||
CBaseBlob(const CBaseBlob& o);
|
||||
CBaseBlob& operator=(const CBaseBlob& o);
|
||||
|
||||
int Compare(const CBaseBlob& b) const;
|
||||
bool operator<(const CBaseBlob& b) const;
|
||||
|
||||
+21
-25
@@ -139,10 +139,10 @@ bool CClaimTrieCacheNormalizationFork::normalizeAllNamesInTrieIfNecessary()
|
||||
|
||||
// make the new nodes
|
||||
db << "INSERT INTO node(name) SELECT NORMALIZED(name) AS nn FROM claim WHERE nn != nodeName "
|
||||
"AND activationHeight <= ?1 AND expirationHeight > ?1 ON CONFLICT(name) DO UPDATE SET hash = NULL, claimsHash = NULL" << nNextHeight;
|
||||
"AND activationHeight <= ?1 AND expirationHeight > ?1 ON CONFLICT(name) DO UPDATE SET hash = NULL" << nNextHeight;
|
||||
|
||||
// there's a subtlety here: names in supports don't make new nodes
|
||||
db << "UPDATE node SET hash = NULL, claimsHash = NULL WHERE name IN "
|
||||
db << "UPDATE node SET hash = NULL WHERE name IN "
|
||||
"(SELECT NORMALIZED(name) AS nn FROM support WHERE nn != nodeName "
|
||||
"AND activationHeight <= ?1 AND expirationHeight > ?1)" << nNextHeight;
|
||||
|
||||
@@ -151,7 +151,7 @@ bool CClaimTrieCacheNormalizationFork::normalizeAllNamesInTrieIfNecessary()
|
||||
db << "UPDATE support SET nodeName = NORMALIZED(name) WHERE activationHeight <= ?1 AND expirationHeight > ?1" << nNextHeight;
|
||||
|
||||
// remove the old nodes
|
||||
db << "UPDATE node SET hash = NULL, claimsHash = NULL WHERE name NOT IN "
|
||||
db << "UPDATE node SET hash = NULL WHERE name NOT IN "
|
||||
"(SELECT nodeName FROM claim WHERE activationHeight <= ?1 AND expirationHeight > ?1 "
|
||||
"UNION SELECT nodeName FROM support WHERE activationHeight <= ?1 AND expirationHeight > ?1)" << nNextHeight;
|
||||
|
||||
@@ -167,9 +167,9 @@ bool CClaimTrieCacheNormalizationFork::unnormalizeAllNamesInTrieIfNecessary()
|
||||
ensureTransacting();
|
||||
|
||||
db << "INSERT INTO node(name) SELECT name FROM claim WHERE name != nodeName "
|
||||
"AND activationHeight < ?1 AND expirationHeight > ?1 ON CONFLICT(name) DO UPDATE SET hash = NULL, claimsHash = NULL" << nNextHeight;
|
||||
"AND activationHeight < ?1 AND expirationHeight > ?1 ON CONFLICT(name) DO UPDATE SET hash = NULL" << nNextHeight;
|
||||
|
||||
db << "UPDATE node SET hash = NULL, claimsHash = NULL WHERE name IN "
|
||||
db << "UPDATE node SET hash = NULL WHERE name IN "
|
||||
"(SELECT nodeName FROM support WHERE name != nodeName "
|
||||
"UNION SELECT nodeName FROM claim WHERE name != nodeName)";
|
||||
|
||||
@@ -177,7 +177,7 @@ bool CClaimTrieCacheNormalizationFork::unnormalizeAllNamesInTrieIfNecessary()
|
||||
db << "UPDATE support SET nodeName = name";
|
||||
|
||||
// we need to let the tree structure method do the actual node delete
|
||||
db << "UPDATE node SET hash = NULL, claimsHash = NULL WHERE name NOT IN "
|
||||
db << "UPDATE node SET hash = NULL WHERE name NOT IN "
|
||||
"(SELECT DISTINCT name FROM claim)";
|
||||
|
||||
return true;
|
||||
@@ -242,10 +242,10 @@ uint256 ComputeMerkleRoot(std::vector<uint256> hashes)
|
||||
return hashes.empty() ? uint256{} : hashes[0];
|
||||
}
|
||||
|
||||
uint256 CClaimTrieCacheHashFork::computeNodeHash(const std::string& name, uint256& claimsHash, int takeoverHeight)
|
||||
uint256 CClaimTrieCacheHashFork::computeNodeHash(const std::string& name, int takeoverHeight)
|
||||
{
|
||||
if (nNextHeight < base->nAllClaimsInMerkleForkHeight)
|
||||
return CClaimTrieCacheNormalizationFork::computeNodeHash(name, claimsHash, takeoverHeight);
|
||||
return CClaimTrieCacheNormalizationFork::computeNodeHash(name, takeoverHeight);
|
||||
|
||||
std::vector<uint256> childHashes;
|
||||
childHashQuery << name >> [&childHashes](std::string, uint256 hash) {
|
||||
@@ -253,24 +253,20 @@ uint256 CClaimTrieCacheHashFork::computeNodeHash(const std::string& name, uint25
|
||||
};
|
||||
childHashQuery++;
|
||||
|
||||
if (takeoverHeight > 0) {
|
||||
if (claimsHash.IsNull()) {
|
||||
COutPoint p;
|
||||
std::vector<uint256> hashes;
|
||||
for (auto&& row: claimHashQuery << nNextHeight << name) {
|
||||
row >> p.hash >> p.n;
|
||||
hashes.push_back(getValueHash(p, takeoverHeight));
|
||||
}
|
||||
claimHashQuery++;
|
||||
claimsHash = hashes.empty() ? emptyHash : ComputeMerkleRoot(std::move(hashes));
|
||||
std::vector<uint256> claimHashes;
|
||||
//if (takeoverHeight > 0) {
|
||||
COutPoint p;
|
||||
for (auto &&row: claimHashQuery << nNextHeight << name) {
|
||||
row >> p.hash >> p.n;
|
||||
claimHashes.push_back(getValueHash(p, takeoverHeight));
|
||||
}
|
||||
} else {
|
||||
claimsHash = emptyHash;
|
||||
}
|
||||
claimHashQuery++;
|
||||
//}
|
||||
|
||||
const auto& childrenHash = childHashes.empty() ? leafHash : ComputeMerkleRoot(std::move(childHashes));
|
||||
auto left = childHashes.empty() ? leafHash : ComputeMerkleRoot(std::move(childHashes));
|
||||
auto right = claimHashes.empty() ? emptyHash : ComputeMerkleRoot(std::move(claimHashes));
|
||||
|
||||
return Hash(childrenHash.begin(), childrenHash.end(), claimsHash.begin(), claimsHash.end());
|
||||
return Hash(left.begin(), left.end(), right.begin(), right.end());
|
||||
}
|
||||
|
||||
std::vector<uint256> ComputeMerklePath(const std::vector<uint256>& hashes, uint32_t idx)
|
||||
@@ -401,7 +397,7 @@ void CClaimTrieCacheHashFork::initializeIncrement()
|
||||
// we could do this in the constructor, but that would not allow for multiple increments in a row (as done in unit tests)
|
||||
if (nNextHeight == base->nAllClaimsInMerkleForkHeight - 1) {
|
||||
ensureTransacting();
|
||||
db << "UPDATE node SET hash = NULL, claimsHash = NULL";
|
||||
db << "UPDATE node SET hash = NULL";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,7 +406,7 @@ bool CClaimTrieCacheHashFork::finalizeDecrement()
|
||||
auto ret = CClaimTrieCacheNormalizationFork::finalizeDecrement();
|
||||
if (ret && nNextHeight == base->nAllClaimsInMerkleForkHeight - 1) {
|
||||
ensureTransacting();
|
||||
db << "UPDATE node SET hash = NULL, claimsHash = NULL";
|
||||
db << "UPDATE node SET hash = NULL";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
bool allowSupportMetadata() const;
|
||||
|
||||
protected:
|
||||
uint256 computeNodeHash(const std::string& name, uint256& claimsHash, int takeoverHeight) override;
|
||||
uint256 computeNodeHash(const std::string& name, int takeoverHeight) override;
|
||||
};
|
||||
|
||||
typedef CClaimTrieCacheHashFork CClaimTrieCache;
|
||||
|
||||
@@ -14,31 +14,15 @@
|
||||
return sqlite3_bind_blob(stmt, inx, val.begin(), int(val.size()), SQLITE_STATIC);
|
||||
}
|
||||
|
||||
inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, uint160&& val) {
|
||||
return sqlite3_bind_blob(stmt, inx, val.begin(), int(val.size()), SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, const uint256& val) {
|
||||
return sqlite3_bind_blob(stmt, inx, val.begin(), int(val.size()), SQLITE_STATIC);
|
||||
}
|
||||
|
||||
inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, uint256&& val) {
|
||||
return sqlite3_bind_blob(stmt, inx, val.begin(), int(val.size()), SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
inline void store_result_in_db(sqlite3_context* db, const uint160& val) {
|
||||
sqlite3_result_blob(db, val.begin(), int(val.size()), SQLITE_STATIC);
|
||||
}
|
||||
|
||||
inline void store_result_in_db(sqlite3_context* db, uint160&& val) {
|
||||
sqlite3_result_blob(db, val.begin(), int(val.size()), SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
inline void store_result_in_db(sqlite3_context* db, const uint256& val) {
|
||||
sqlite3_result_blob(db, val.begin(), int(val.size()), SQLITE_STATIC);
|
||||
}
|
||||
|
||||
inline void store_result_in_db(sqlite3_context* db, uint256&& val) {
|
||||
sqlite3_result_blob(db, val.begin(), int(val.size()), SQLITE_TRANSIENT);
|
||||
}
|
||||
}
|
||||
@@ -104,22 +88,6 @@ namespace sqlite
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
inline int sync(database& db, std::size_t attempts = 20)
|
||||
{
|
||||
int code = SQLITE_OK;
|
||||
for (auto i = 0u; i < attempts; ++i) {
|
||||
code = sqlite3_wal_checkpoint_v2(db.connection().get(), nullptr, SQLITE_CHECKPOINT_FULL, nullptr, nullptr);
|
||||
if (code != SQLITE_OK) {
|
||||
sqlite3_wal_checkpoint_v2(db.connection().get(), nullptr, SQLITE_CHECKPOINT_PASSIVE, nullptr, nullptr);
|
||||
using namespace std::chrono_literals;
|
||||
std::this_thread::sleep_for(200ms);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SQLITE_H
|
||||
@@ -32,18 +32,14 @@
|
||||
#include <string_view>
|
||||
namespace sqlite
|
||||
{
|
||||
typedef const std::string_view& str_ref;
|
||||
typedef std::string_view&& str_uni_ref;
|
||||
typedef const std::u16string_view& u16str_ref;
|
||||
typedef std::u16string_view&& u16str_uni_ref;
|
||||
typedef const std::string_view str_ref;
|
||||
typedef const std::u16string_view u16str_ref;
|
||||
}
|
||||
#else
|
||||
namespace sqlite
|
||||
{
|
||||
typedef const std::string& str_ref;
|
||||
typedef std::string&& str_uni_ref;
|
||||
typedef const std::u16string& u16str_ref;
|
||||
typedef std::u16string&& u16str_uni_ref;
|
||||
}
|
||||
#endif
|
||||
#include "../../sqlite3.h"
|
||||
@@ -186,17 +182,12 @@ namespace sqlite {
|
||||
template<>
|
||||
struct has_sqlite_type<std::string, SQLITE_BLOB, void> : std::true_type {}; //
|
||||
inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, str_ref val) {
|
||||
return sqlite3_bind_blob(stmt, inx, val.data(), val.length(), SQLITE_STATIC);
|
||||
}
|
||||
|
||||
// str_uni_ref
|
||||
inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, str_uni_ref val) {
|
||||
return sqlite3_bind_blob(stmt, inx, val.data(), val.length(), SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
// Convert char* to string_view to trigger op<<(..., const str_ref )
|
||||
template<std::size_t N> inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, const char(&STR)[N]) {
|
||||
return sqlite3_bind_blob(stmt, inx, &STR[0], N-1, SQLITE_STATIC);
|
||||
return sqlite3_bind_blob(stmt, inx, &STR[0], N-1, SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
inline std::string get_col_from_db(sqlite3_stmt* stmt, int inx, result_type<std::string>) {
|
||||
@@ -229,26 +220,18 @@ namespace sqlite {
|
||||
}
|
||||
|
||||
inline void store_result_in_db(sqlite3_context* db, str_ref val) {
|
||||
sqlite3_result_blob(db, val.data(), val.length(), SQLITE_STATIC);
|
||||
}
|
||||
|
||||
inline void store_result_in_db(sqlite3_context* db, str_uni_ref val) {
|
||||
sqlite3_result_blob(db, val.data(), val.length(), SQLITE_TRANSIENT);
|
||||
}
|
||||
// u16str_ref
|
||||
template<>
|
||||
struct has_sqlite_type<std::u16string, SQLITE3_TEXT, void> : std::true_type {};
|
||||
inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, u16str_ref val) {
|
||||
return sqlite3_bind_text16(stmt, inx, val.data(), sizeof(char16_t) * val.length(), SQLITE_STATIC);
|
||||
}
|
||||
|
||||
inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, u16str_uni_ref val) {
|
||||
return sqlite3_bind_text16(stmt, inx, val.data(), sizeof(char16_t) * val.length(), SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
// Convert char* to string_view to trigger op<<(..., const str_ref )
|
||||
template<std::size_t N> inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, const char16_t(&STR)[N]) {
|
||||
return sqlite3_bind_text16(stmt, inx, &STR[0], sizeof(char16_t) * (N-1), SQLITE_STATIC);
|
||||
return sqlite3_bind_text16(stmt, inx, &STR[0], sizeof(char16_t) * (N-1), SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
inline std::u16string get_col_from_db(sqlite3_stmt* stmt, int inx, result_type<std::u16string>) {
|
||||
@@ -261,10 +244,6 @@ namespace sqlite {
|
||||
}
|
||||
|
||||
inline void store_result_in_db(sqlite3_context* db, u16str_ref val) {
|
||||
sqlite3_result_text16(db, val.data(), sizeof(char16_t) * val.length(), SQLITE_STATIC);
|
||||
}
|
||||
|
||||
inline void store_result_in_db(sqlite3_context* db, u16str_uni_ref val) {
|
||||
sqlite3_result_text16(db, val.data(), sizeof(char16_t) * val.length(), SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
@@ -294,21 +273,11 @@ namespace sqlite {
|
||||
struct has_sqlite_type<std::vector<T, A>, SQLITE_BLOB, void> : std::true_type {};
|
||||
|
||||
template<typename T, typename A> inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, const std::vector<T, A>& vec) {
|
||||
void const* buf = reinterpret_cast<void const *>(vec.data());
|
||||
int bytes = vec.size() * sizeof(T);
|
||||
return sqlite3_bind_blob(stmt, inx, buf, bytes, SQLITE_STATIC);
|
||||
}
|
||||
template<typename T, typename A> inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, std::vector<T, A>&& vec) {
|
||||
void const* buf = reinterpret_cast<void const *>(vec.data());
|
||||
int bytes = vec.size() * sizeof(T);
|
||||
return sqlite3_bind_blob(stmt, inx, buf, bytes, SQLITE_TRANSIENT);
|
||||
}
|
||||
template<typename T, typename A> inline void store_result_in_db(sqlite3_context* db, const std::vector<T, A>& vec) {
|
||||
void const* buf = reinterpret_cast<void const *>(vec.data());
|
||||
int bytes = vec.size() * sizeof(T);
|
||||
sqlite3_result_blob(db, buf, bytes, SQLITE_STATIC);
|
||||
}
|
||||
template<typename T, typename A> inline void store_result_in_db(sqlite3_context* db, std::vector<T, A>&& vec) {
|
||||
void const* buf = reinterpret_cast<void const *>(vec.data());
|
||||
int bytes = vec.size() * sizeof(T);
|
||||
sqlite3_result_blob(db, buf, bytes, SQLITE_TRANSIENT);
|
||||
|
||||
+120
-185
@@ -40,11 +40,10 @@ static const sqlite::sqlite_config sharedConfig {
|
||||
void applyPragmas(sqlite::database& db, std::size_t cache)
|
||||
{
|
||||
db << "PRAGMA cache_size=-" + std::to_string(cache); // in -KB
|
||||
db << "PRAGMA synchronous=OFF"; // don't disk sync after transaction commit
|
||||
db << "PRAGMA journal_mode=WAL";
|
||||
db << "PRAGMA temp_store=MEMORY";
|
||||
db << "PRAGMA case_sensitive_like=true";
|
||||
db << "PRAGMA journal_mode=WAL";
|
||||
db << "PRAGMA synchronous=OFF"; // don't disk sync after transaction commit; we handle that elsewhere
|
||||
db << "PRAGMA wal_autocheckpoint=4000"; // 4k page size * 4000 = 16MB
|
||||
|
||||
db.define("POPS", [](std::string s) -> std::string { if (!s.empty()) s.pop_back(); return s; });
|
||||
db.define("REVERSE", [](std::vector<uint8_t> s) -> std::vector<uint8_t> { std::reverse(s.begin(), s.end()); return s; });
|
||||
@@ -72,11 +71,11 @@ CClaimTrie::CClaimTrie(std::size_t cacheBytes, bool fWipe, int height,
|
||||
nExtendedClaimExpirationForkHeight(nExtendedClaimExpirationForkHeight),
|
||||
nAllClaimsInMerkleForkHeight(nAllClaimsInMerkleForkHeight)
|
||||
{
|
||||
applyPragmas(db, cacheBytes >> 10U); // in KB
|
||||
applyPragmas(db, 5U * 1024U); // in KB
|
||||
|
||||
db << "CREATE TABLE IF NOT EXISTS node (name BLOB NOT NULL PRIMARY KEY, "
|
||||
"parent BLOB REFERENCES node(name) DEFERRABLE INITIALLY DEFERRED, "
|
||||
"hash BLOB, claimsHash BLOB)";
|
||||
"hash BLOB)";
|
||||
|
||||
db << "CREATE TABLE IF NOT EXISTS claim (claimID BLOB NOT NULL PRIMARY KEY, name BLOB NOT NULL, "
|
||||
"nodeName BLOB NOT NULL REFERENCES node(name) DEFERRABLE INITIALLY DEFERRED, "
|
||||
@@ -99,8 +98,6 @@ CClaimTrie::CClaimTrie(std::size_t cacheBytes, bool fWipe, int height,
|
||||
db << "DELETE FROM takeover";
|
||||
}
|
||||
|
||||
doNodeTableMigration();
|
||||
|
||||
db << "CREATE INDEX IF NOT EXISTS node_hash_len_name ON node (hash, LENGTH(name) DESC)";
|
||||
// db << "CREATE UNIQUE INDEX IF NOT EXISTS node_parent_name ON node (parent, name)"; // no apparent gain
|
||||
db << "CREATE INDEX IF NOT EXISTS node_parent ON node (parent)";
|
||||
@@ -119,29 +116,6 @@ CClaimTrie::CClaimTrie(std::size_t cacheBytes, bool fWipe, int height,
|
||||
db << "INSERT OR IGNORE INTO node(name, hash) VALUES(x'', ?)" << one; // ensure that we always have our root node
|
||||
}
|
||||
|
||||
void CClaimTrie::doNodeTableMigration()
|
||||
{
|
||||
try {
|
||||
isNodeMigrationStart = false;
|
||||
for (auto&& row : db << "SELECT claimsHash FROM node WHERE name = x''")
|
||||
break;
|
||||
} catch (const sqlite::sqlite_exception&) {
|
||||
logPrint << "Running one-time upgrade of node table to cache the hash of claims..." << Clog::endl;
|
||||
isNodeMigrationStart = true;
|
||||
|
||||
// new node schema
|
||||
db << "CREATE TABLE node_new (name BLOB NOT NULL PRIMARY KEY, "
|
||||
"parent BLOB REFERENCES node(name) DEFERRABLE INITIALLY DEFERRED, "
|
||||
"hash BLOB, claimsHash BLOB)";
|
||||
|
||||
db << "INSERT OR REPLACE INTO node_new(name, parent, hash) "
|
||||
"SELECT name, parent, hash FROM node";
|
||||
|
||||
db << "DROP TABLE node";
|
||||
db << "ALTER TABLE node_new RENAME TO node";
|
||||
}
|
||||
}
|
||||
|
||||
CClaimTrieCacheBase::~CClaimTrieCacheBase()
|
||||
{
|
||||
if (transacting) {
|
||||
@@ -155,17 +129,15 @@ CClaimTrieCacheBase::~CClaimTrieCacheBase()
|
||||
|
||||
bool CClaimTrie::SyncToDisk()
|
||||
{
|
||||
db << "PRAGMA optimize";
|
||||
// alternatively, switch to full sync after we are caught up on the chain
|
||||
return sqlite::sync(db) == SQLITE_OK;
|
||||
auto rc = sqlite3_wal_checkpoint_v2(db.connection().get(), nullptr, SQLITE_CHECKPOINT_FULL, nullptr, nullptr);
|
||||
return rc == SQLITE_OK;
|
||||
}
|
||||
|
||||
bool CClaimTrie::empty() // only used for testing
|
||||
bool CClaimTrie::empty()
|
||||
{
|
||||
sqlite::database local(dbFile, sharedConfig);
|
||||
applyPragmas(local, 100);
|
||||
int64_t count;
|
||||
local << "SELECT COUNT(*) FROM (SELECT 1 FROM claim WHERE activationHeight < ?1 AND expirationHeight >= ?1 LIMIT 1)" << nNextHeight >> count;
|
||||
db << "SELECT COUNT(*) FROM (SELECT 1 FROM claim WHERE activationHeight < ?1 AND expirationHeight >= ?1 LIMIT 1)" << nNextHeight >> count;
|
||||
return count == 0;
|
||||
}
|
||||
|
||||
@@ -224,27 +196,6 @@ bool CClaimTrieCacheBase::haveSupportInQueue(const std::string& name, const COut
|
||||
return false;
|
||||
}
|
||||
|
||||
bool emptyNodeShouldExistAt(sqlite::database& db, const std::string& name, int nNextHeight, int requiredChildren) {
|
||||
auto end = name + std::string(256, std::numeric_limits<char>::max()); // 256 == MAX_CLAIM_NAME_SIZE + 1
|
||||
auto query = db << "SELECT DISTINCT nodeName FROM claim "
|
||||
"WHERE nodeName BETWEEN ?1 AND ?2 "
|
||||
"AND activationHeight < ?3 AND expirationHeight >= ?3 "
|
||||
"ORDER BY nodeName"
|
||||
<< name << end << nNextHeight;
|
||||
std::unordered_set<char> ss;
|
||||
for (auto&& row: query) {
|
||||
std::string nn;
|
||||
row >> nn;
|
||||
if (nn == name)
|
||||
return false;
|
||||
assert(nn.size() > name.size());
|
||||
ss.insert(nn[name.size()]);
|
||||
if (ss.size() >= requiredChildren)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CClaimTrieCacheBase::deleteNodeIfPossible(const std::string& name, std::string& parent, int64_t& claims)
|
||||
{
|
||||
if (name.empty()) return false;
|
||||
@@ -303,7 +254,7 @@ void CClaimTrieCacheBase::ensureTreeStructureIsUpToDate()
|
||||
"name IN (WITH RECURSIVE prefix(p) AS (VALUES(?) UNION ALL "
|
||||
"SELECT POPS(p) FROM prefix WHERE p != x'') SELECT p FROM prefix)";
|
||||
|
||||
auto insertQuery = db << "INSERT INTO node(name, parent, hash, claimsHash) VALUES(?, ?, NULL, NULL) "
|
||||
auto insertQuery = db << "INSERT INTO node(name, parent, hash) VALUES(?, ?, NULL) "
|
||||
"ON CONFLICT(name) DO UPDATE SET parent = excluded.parent, hash = NULL";
|
||||
|
||||
auto nodeQuery = db << "SELECT name FROM node WHERE parent = ?";
|
||||
@@ -391,7 +342,7 @@ int64_t CClaimTrieCacheBase::getTotalValueOfClaimsInTrie(bool fControllingOnly)
|
||||
int64_t ret = 0;
|
||||
const std::string query = fControllingOnly ?
|
||||
"SELECT SUM(amount) FROM (SELECT c.amount as amount, "
|
||||
"(SELECT(SELECT IFNULL(SUM(s.amount),0)+c.amount FROM support s INDEXED BY support_supportedClaimID "
|
||||
"(SELECT(SELECT IFNULL(SUM(s.amount),0)+c.amount FROM support s "
|
||||
"WHERE s.supportedClaimID = c.claimID AND c.nodeName = s.nodeName "
|
||||
"AND s.activationHeight < ?1 AND s.expirationHeight >= ?1) as effective "
|
||||
"ORDER BY effective DESC LIMIT 1) as winner FROM claim c "
|
||||
@@ -462,7 +413,7 @@ void completeHash(uint256& partialHash, const std::string& key, int to)
|
||||
partialHash = Hash(it, it + 1, partialHash.begin(), partialHash.end());
|
||||
}
|
||||
|
||||
uint256 CClaimTrieCacheBase::computeNodeHash(const std::string& name, uint256& claimsHash, int takeoverHeight)
|
||||
uint256 CClaimTrieCacheBase::computeNodeHash(const std::string& name, int takeoverHeight)
|
||||
{
|
||||
const auto pos = name.size();
|
||||
std::vector<uint8_t> vchToHash;
|
||||
@@ -474,14 +425,10 @@ uint256 CClaimTrieCacheBase::computeNodeHash(const std::string& name, uint256& c
|
||||
};
|
||||
childHashQuery++;
|
||||
|
||||
if (takeoverHeight > 0) {
|
||||
if (claimsHash.IsNull()) {
|
||||
CClaimValue claim;
|
||||
if (getInfoForName(name, claim))
|
||||
claimsHash = getValueHash(claim.outPoint, takeoverHeight);
|
||||
}
|
||||
if (!claimsHash.IsNull())
|
||||
vchToHash.insert(vchToHash.end(), claimsHash.begin(), claimsHash.end());
|
||||
CClaimValue claim;
|
||||
if (getInfoForName(name, claim)) {
|
||||
auto valueHash = getValueHash(claim.outPoint, takeoverHeight);
|
||||
vchToHash.insert(vchToHash.end(), valueHash.begin(), valueHash.end());
|
||||
}
|
||||
|
||||
return vchToHash.empty() ? one : Hash(vchToHash.begin(), vchToHash.end());
|
||||
@@ -489,57 +436,23 @@ uint256 CClaimTrieCacheBase::computeNodeHash(const std::string& name, uint256& c
|
||||
|
||||
bool CClaimTrieCacheBase::checkConsistency()
|
||||
{
|
||||
auto checkQuery = db << "PRAGMA quick_check";
|
||||
for (auto&& row: checkQuery) {
|
||||
std::string message;
|
||||
row >> message;
|
||||
if (message != "ok") {
|
||||
logPrint << message << Clog::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// verify that all claims hash to the values on the nodes
|
||||
|
||||
if (base->isNodeMigrationStart)
|
||||
ensureTransacting();
|
||||
|
||||
auto updateQuery = db << "UPDATE node SET claimsHash = ? WHERE name = ?";
|
||||
// not checking everything as it takes too long
|
||||
auto query = db << (base->isNodeMigrationStart ?
|
||||
"SELECT n.name, n.hash, n.claimsHash, "
|
||||
"IFNULL((SELECT CASE WHEN t.claimID IS NULL THEN 0 ELSE t.height END "
|
||||
"FROM takeover t WHERE t.name = n.name ORDER BY t.height DESC LIMIT 1), 0) "
|
||||
"FROM node n ORDER BY LENGTH(n.name) DESC"
|
||||
:
|
||||
"SELECT n.name, n.hash, n.claimsHash, "
|
||||
"IFNULL((SELECT CASE WHEN t.claimID IS NULL THEN 0 ELSE t.height END "
|
||||
"FROM takeover t WHERE t.name = n.name ORDER BY t.height DESC LIMIT 1), 0) "
|
||||
"FROM node n WHERE n.name IN "
|
||||
"(SELECT r.name FROM node r ORDER BY RANDOM() LIMIT 100000) OR n.parent = x''");
|
||||
auto query = db << "SELECT n.name, n.hash, "
|
||||
"COALESCE((SELECT CASE WHEN t.claimID IS NULL THEN 0 ELSE t.height END "
|
||||
"FROM takeover t WHERE t.name = n.name ORDER BY t.height DESC LIMIT 1), "
|
||||
"(SELECT ONE(c.activationHeight) FROM claim c WHERE c.nodeName = n.name "
|
||||
"AND c.activationHeight < ?1 AND c.expirationHeight >= ?1), "
|
||||
"0) FROM node n" << nNextHeight;
|
||||
for (auto&& row: query) {
|
||||
std::string name;
|
||||
uint256 hash;
|
||||
int takeoverHeight;
|
||||
uint256 hash, claimsHash, computedClaimsHash;
|
||||
row >> name >> hash >> claimsHash >> takeoverHeight;
|
||||
auto computedHash = computeNodeHash(name, computedClaimsHash, takeoverHeight);
|
||||
if (computedHash != hash) {
|
||||
logPrint << "Invalid hash at " << name << Clog::endl;
|
||||
row >> name >> hash >> takeoverHeight;
|
||||
auto computedHash = computeNodeHash(name, takeoverHeight);
|
||||
if (computedHash != hash)
|
||||
return false;
|
||||
}
|
||||
if (base->isNodeMigrationStart) {
|
||||
assert(!computedClaimsHash.IsNull());
|
||||
updateQuery << computedClaimsHash << name;
|
||||
updateQuery++;
|
||||
} else if (computedClaimsHash != claimsHash) {
|
||||
logPrint << "Invalid claimsHash at " << name << Clog::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
updateQuery.used(true);
|
||||
|
||||
if (base->isNodeMigrationStart)
|
||||
return flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -581,7 +494,7 @@ const std::string childHashQuery_s = "SELECT name, hash FROM node WHERE parent =
|
||||
|
||||
const std::string claimHashQuery_s =
|
||||
"SELECT c.txID, c.txN, c.claimID, c.updateHeight, c.activationHeight, c.amount, "
|
||||
"(SELECT IFNULL(SUM(s.amount),0)+c.amount FROM support s INDEXED BY support_supportedClaimID "
|
||||
"(SELECT IFNULL(SUM(s.amount),0)+c.amount FROM support s "
|
||||
"WHERE s.supportedClaimID = c.claimID AND s.nodeName = c.nodeName "
|
||||
"AND s.activationHeight < ?1 AND s.expirationHeight >= ?1) as effectiveAmount "
|
||||
"FROM claim c WHERE c.nodeName = ?2 AND c.activationHeight < ?1 AND c.expirationHeight >= ?1 "
|
||||
@@ -590,28 +503,42 @@ const std::string claimHashQuery_s =
|
||||
const std::string claimHashQueryLimit_s = claimHashQuery_s + " LIMIT 1";
|
||||
|
||||
extern const std::string proofClaimQuery_s =
|
||||
"SELECT n.name, IFNULL((SELECT CASE WHEN t.claimID IS NULL THEN 0 ELSE t.height END "
|
||||
"FROM takeover t WHERE t.name = n.name ORDER BY t.height DESC LIMIT 1), 0) FROM node n "
|
||||
"WHERE n.name IN (WITH RECURSIVE prefix(p) AS (VALUES(?) UNION ALL "
|
||||
"SELECT n.name, COALESCE((SELECT CASE WHEN t.claimID IS NULL THEN 0 ELSE t.height END "
|
||||
"FROM takeover t WHERE t.name = n.name ORDER BY t.height DESC LIMIT 1), "
|
||||
"(SELECT ONE(c.activationHeight) FROM claim c WHERE c.nodeName = n.name "
|
||||
"AND c.activationHeight < ?2 AND c.expirationHeight >= ?2), "
|
||||
"0) FROM node n "
|
||||
"WHERE n.name IN (WITH RECURSIVE prefix(p) AS (VALUES(?1) UNION ALL "
|
||||
"SELECT POPS(p) FROM prefix WHERE p != x'') SELECT p FROM prefix) "
|
||||
"ORDER BY n.name";
|
||||
|
||||
CClaimTrieCacheBase::CClaimTrieCacheBase(CClaimTrie* base)
|
||||
: base(base), db(base->db.connection()), transacting(false),
|
||||
: base(base), db(base->dbFile, sharedConfig), transacting(false),
|
||||
childHashQuery(db << childHashQuery_s),
|
||||
claimHashQuery(db << claimHashQuery_s),
|
||||
claimHashQueryLimit(db << claimHashQueryLimit_s)
|
||||
{
|
||||
assert(base);
|
||||
nNextHeight = base->nNextHeight;
|
||||
|
||||
applyPragmas(db, base->dbCacheBytes >> 10U); // in KB
|
||||
db.define("POPS", [](std::string s) -> std::string { if (!s.empty()) s.pop_back(); return s; });
|
||||
|
||||
// db.define("MERKLE_ROOT", [](std::vector<uint256>& hashes, const std::vector<unsigned char>& blob) { hashes.emplace_back(uint256(blob)); },
|
||||
// [](const std::vector<uint256>& hashes) { return ComputeMerkleRoot(hashes); });
|
||||
|
||||
db.define("ONE",
|
||||
[](std::vector<sqlite_int64>& accumulator, const sqlite_int64& value) { accumulator.push_back(value); },
|
||||
[](const std::vector<sqlite_int64>& accumulator) -> sqlite_int64 {
|
||||
if (accumulator.size() != 1) return 0;
|
||||
return accumulator[0];
|
||||
});
|
||||
}
|
||||
|
||||
void CClaimTrieCacheBase::ensureTransacting()
|
||||
{
|
||||
if (!transacting) {
|
||||
transacting = true;
|
||||
int isNotInTransaction = sqlite3_get_autocommit(db.connection().get());
|
||||
assert(isNotInTransaction);
|
||||
db << "BEGIN";
|
||||
}
|
||||
}
|
||||
@@ -625,20 +552,23 @@ uint256 CClaimTrieCacheBase::getMerkleHash()
|
||||
{
|
||||
ensureTreeStructureIsUpToDate();
|
||||
uint256 hash;
|
||||
for (auto&& row : db << "SELECT hash FROM node WHERE name = x''") {
|
||||
row >> hash;
|
||||
if (!hash.IsNull())
|
||||
return hash;
|
||||
}
|
||||
db << "SELECT hash FROM node WHERE name = x''"
|
||||
>> [&hash](std::unique_ptr<uint256> rootHash) {
|
||||
if (rootHash)
|
||||
hash = std::move(*rootHash);
|
||||
};
|
||||
if (!hash.IsNull())
|
||||
return hash;
|
||||
assert(transacting); // no data changed but we didn't have the root hash there already?
|
||||
auto updateQuery = db << "UPDATE node SET hash = ?, claimsHash = ? WHERE name = ?";
|
||||
db << "SELECT n.name, n.claimsHash, "
|
||||
"IFNULL((SELECT CASE WHEN t.claimID IS NULL THEN 0 ELSE t.height END "
|
||||
"FROM takeover t WHERE t.name = n.name ORDER BY t.height DESC LIMIT 1), 0) "
|
||||
"FROM node n WHERE n.hash IS NULL ORDER BY LENGTH(n.name) DESC" // assumes n.name is blob
|
||||
>> [&](const std::string& name, uint256 claimsHash, int takeoverHeight) {
|
||||
hash = computeNodeHash(name, claimsHash, takeoverHeight);
|
||||
updateQuery << hash << claimsHash << name;
|
||||
auto updateQuery = db << "UPDATE node SET hash = ? WHERE name = ?";
|
||||
db << "SELECT n.name, COALESCE((SELECT CASE WHEN t.claimID IS NULL THEN 0 ELSE t.height END "
|
||||
"FROM takeover t WHERE t.name = n.name ORDER BY t.height DESC LIMIT 1), "
|
||||
"(SELECT ONE(c.activationHeight) FROM claim c WHERE c.nodeName = n.name "
|
||||
"AND c.activationHeight < ?1 AND c.expirationHeight >= ?1), "
|
||||
"0) FROM node n WHERE n.hash IS NULL ORDER BY LENGTH(n.name) DESC" << nNextHeight
|
||||
>> [this, &hash, &updateQuery](const std::string& name, int takeoverHeight) {
|
||||
hash = computeNodeHash(name, takeoverHeight);
|
||||
updateQuery << hash << name;
|
||||
updateQuery++;
|
||||
};
|
||||
updateQuery.used(true);
|
||||
@@ -658,6 +588,16 @@ bool CClaimTrieCacheBase::getLastTakeoverForName(const std::string& name, uint16
|
||||
return true;
|
||||
}
|
||||
}
|
||||
auto query2 = db << "SELECT ONE(c.activationHeight), c.claimID FROM claim c WHERE c.nodeName = ?1 "
|
||||
"AND c.activationHeight < ?2 AND c.expirationHeight >= ?2" << name << nNextHeight;
|
||||
it = query2.begin();
|
||||
if (it != query2.end()) {
|
||||
*it >> takeoverHeight >> claimId;
|
||||
if (takeoverHeight > 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
takeoverHeight = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -692,7 +632,7 @@ bool CClaimTrieCacheBase::addClaim(const std::string& name, const COutPoint& out
|
||||
<< originalHeight << nHeight << nValidHeight << nValidHeight << expires;
|
||||
|
||||
if (nValidHeight < nNextHeight)
|
||||
db << "INSERT INTO node(name) VALUES(?) ON CONFLICT(name) DO UPDATE SET hash = NULL, claimsHash = NULL" << nodeName;
|
||||
db << "INSERT INTO node(name) VALUES(?) ON CONFLICT(name) DO UPDATE SET hash = NULL" << nodeName;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -713,7 +653,7 @@ bool CClaimTrieCacheBase::addSupport(const std::string& name, const COutPoint& o
|
||||
<< supportedClaimId << name << nodeName << outPoint.hash << outPoint.n << nAmount << nHeight << nValidHeight << nValidHeight << expires;
|
||||
|
||||
if (nValidHeight < nNextHeight)
|
||||
db << "UPDATE node SET hash = NULL, claimsHash = NULL WHERE name = ?" << nodeName;
|
||||
db << "UPDATE node SET hash = NULL WHERE name = ?" << nodeName;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -744,16 +684,25 @@ bool CClaimTrieCacheBase::removeClaim(const uint160& claimId, const COutPoint& o
|
||||
if (!db.rows_modified())
|
||||
return false;
|
||||
|
||||
db << "UPDATE node SET hash = NULL, claimsHash = NULL WHERE name = ?" << nodeName;
|
||||
db << "UPDATE node SET hash = NULL WHERE name = ?" << nodeName;
|
||||
|
||||
// when node should be deleted from cache but instead it's kept
|
||||
// because it's a parent one and should not be effectively erased
|
||||
// we had a bug in the old code where that situation would force a zero delay on re-add
|
||||
if (nNextHeight >= base->nMinRemovalWorkaroundHeight
|
||||
&& nNextHeight < base->nMaxRemovalWorkaroundHeight
|
||||
) {
|
||||
if (emptyNodeShouldExistAt(db, nodeName, nNextHeight, 1))
|
||||
removalWorkaround.insert(nodeName);
|
||||
&& nNextHeight < base->nMaxRemovalWorkaroundHeight) { // TODO: hard fork this out (which we already tried once but failed)
|
||||
// neither LIKE nor SUBSTR will use an index on a blob, but BETWEEN is a good, fast alternative
|
||||
auto end = nodeName + std::string( 256, std::numeric_limits<char>::max()); // 256 == MAX_CLAIM_NAME_SIZE + 1
|
||||
auto innerQuery = db << "SELECT nodeName FROM claim WHERE nodeName BETWEEN ?1 AND ?2 "
|
||||
"AND activationHeight < ?3 AND expirationHeight >= ?3 ORDER BY nodeName LIMIT 1"
|
||||
<< nodeName << end << nNextHeight;
|
||||
for (auto&& row: innerQuery) {
|
||||
std::string shortestMatch;
|
||||
row >> shortestMatch;
|
||||
if (shortestMatch != nodeName)
|
||||
// set this when there are no more claims on that name and that node still has children
|
||||
removalWorkaround.insert(nodeName);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -775,8 +724,7 @@ bool CClaimTrieCacheBase::removeSupport(const COutPoint& outPoint, std::string&
|
||||
db << "DELETE FROM support WHERE txID = ? AND txN = ?" << outPoint.hash << outPoint.n;
|
||||
if (!db.rows_modified())
|
||||
return false;
|
||||
|
||||
db << "UPDATE node SET hash = NULL, claimsHash = NULL WHERE name = ?" << nodeName;
|
||||
db << "UPDATE node SET hash = NULL WHERE name = ?" << nodeName;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -793,29 +741,23 @@ bool CClaimTrieCacheBase::incrementBlock()
|
||||
|
||||
db << "INSERT INTO node(name) SELECT nodeName FROM claim INDEXED BY claim_activationHeight "
|
||||
"WHERE activationHeight = ?1 AND expirationHeight > ?1 "
|
||||
"ON CONFLICT(name) DO UPDATE SET hash = NULL, claimsHash = NULL"
|
||||
"ON CONFLICT(name) DO UPDATE SET hash = NULL"
|
||||
<< nNextHeight;
|
||||
|
||||
// don't make new nodes for items in supports or items that expire this block that don't exist in claims
|
||||
db << "UPDATE node SET hash = NULL, claimsHash = NULL WHERE name IN "
|
||||
db << "UPDATE node SET hash = NULL WHERE name IN "
|
||||
"(SELECT nodeName FROM claim WHERE expirationHeight = ?1 "
|
||||
"UNION SELECT nodeName FROM support WHERE expirationHeight = ?1 OR activationHeight = ?1)"
|
||||
<< nNextHeight;
|
||||
|
||||
insertTakeovers();
|
||||
|
||||
nNextHeight++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CClaimTrieCacheBase::insertTakeovers(bool allowReplace) {
|
||||
auto insertTakeoverQuery = allowReplace ?
|
||||
db << "INSERT OR REPLACE INTO takeover(name, height, claimID) VALUES(?, ?, ?)" :
|
||||
db << "INSERT INTO takeover(name, height, claimID) VALUES(?, ?, ?)";
|
||||
auto insertTakeoverQuery = db << "INSERT INTO takeover(name, height, claimID) VALUES(?, ?, ?)";
|
||||
auto checkExistingCountQuery = db << "SELECT COUNT(*) FROM (SELECT nodeName FROM claim WHERE nodeName = ?1 "
|
||||
"AND activationHeight <= ?2 AND expirationHeight > ?2 UNION ALL "
|
||||
"SELECT name FROM takeover WHERE name = ?1 LIMIT 2)";
|
||||
|
||||
// takeover handling:
|
||||
db << "SELECT name FROM node WHERE hash IS NULL"
|
||||
>> [this, &insertTakeoverQuery](const std::string& nameWithTakeover) {
|
||||
db << "SELECT name FROM node WHERE hash IS NULL"
|
||||
>> [this, &insertTakeoverQuery, &checkExistingCountQuery](const std::string& nameWithTakeover) {
|
||||
// if somebody activates on this block and they are the new best, then everybody activates on this block
|
||||
CClaimValue candidateValue;
|
||||
auto hasCandidate = getInfoForName(nameWithTakeover, candidateValue, 1);
|
||||
@@ -840,8 +782,13 @@ void CClaimTrieCacheBase::insertTakeovers(bool allowReplace) {
|
||||
logPrint << "Takeover on " << nameWithTakeover << " at " << nNextHeight << ", happening: " << takeoverHappening << ", set before: " << hasCurrentWinner << Clog::endl;
|
||||
|
||||
if (takeoverHappening) {
|
||||
if (hasCandidate)
|
||||
insertTakeoverQuery << nameWithTakeover << nNextHeight << candidateValue.claimId;
|
||||
if (hasCandidate) {
|
||||
int64_t existing = 0;
|
||||
checkExistingCountQuery << nameWithTakeover << nNextHeight >> existing;
|
||||
checkExistingCountQuery++;
|
||||
if (existing != 1)
|
||||
insertTakeoverQuery << nameWithTakeover << nNextHeight << candidateValue.claimId;
|
||||
}
|
||||
else
|
||||
insertTakeoverQuery << nameWithTakeover << nNextHeight << nullptr;
|
||||
insertTakeoverQuery++;
|
||||
@@ -849,6 +796,10 @@ void CClaimTrieCacheBase::insertTakeovers(bool allowReplace) {
|
||||
};
|
||||
|
||||
insertTakeoverQuery.used(true);
|
||||
checkExistingCountQuery.used(true);
|
||||
|
||||
nNextHeight++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CClaimTrieCacheBase::activateAllFor(const std::string& name)
|
||||
@@ -872,10 +823,10 @@ bool CClaimTrieCacheBase::decrementBlock()
|
||||
nNextHeight--;
|
||||
|
||||
db << "INSERT INTO node(name) SELECT nodeName FROM claim "
|
||||
"WHERE expirationHeight = ? ON CONFLICT(name) DO UPDATE SET hash = NULL, claimsHash = NULL"
|
||||
"WHERE expirationHeight = ? ON CONFLICT(name) DO UPDATE SET hash = NULL"
|
||||
<< nNextHeight;
|
||||
|
||||
db << "UPDATE node SET hash = NULL, claimsHash = NULL WHERE name IN("
|
||||
db << "UPDATE node SET hash = NULL WHERE name IN("
|
||||
"SELECT nodeName FROM support WHERE expirationHeight = ?1 OR activationHeight = ?1 "
|
||||
"UNION SELECT nodeName FROM claim WHERE activationHeight = ?1)"
|
||||
<< nNextHeight;
|
||||
@@ -891,7 +842,7 @@ bool CClaimTrieCacheBase::decrementBlock()
|
||||
|
||||
bool CClaimTrieCacheBase::finalizeDecrement()
|
||||
{
|
||||
db << "UPDATE node SET hash = NULL, claimsHash = NULL WHERE name IN "
|
||||
db << "UPDATE node SET hash = NULL WHERE name IN "
|
||||
"(SELECT nodeName FROM claim WHERE activationHeight = ?1 AND expirationHeight > ?1 "
|
||||
"UNION SELECT nodeName FROM support WHERE activationHeight = ?1 AND expirationHeight > ?1 "
|
||||
"UNION SELECT name FROM takeover WHERE height = ?1)" << nNextHeight;
|
||||
@@ -911,30 +862,14 @@ int CClaimTrieCacheBase::getDelayForName(const std::string& name, const uint160&
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (nNextHeight > base->nMaxRemovalWorkaroundHeight) {
|
||||
if (!hasCurrentWinner)
|
||||
return 0;
|
||||
|
||||
// TODO: hard fork this out! It's wrong but kept for backwards compatibility
|
||||
// Plan: if we have no claims for this node but we do have multiple children
|
||||
// such that we have an implicit node here then return a 0
|
||||
if (emptyNodeShouldExistAt(db, name, nNextHeight, 2))
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
// NOTE: old code had a bug in it where nodes with no claims but with children would get left in the cache after removal.
|
||||
// This would cause the getNumBlocksOfContinuousOwnership to return zero (causing incorrect takeover height calc).
|
||||
auto hit = removalWorkaround.find(name);
|
||||
if (hit != removalWorkaround.end()) {
|
||||
removalWorkaround.erase(hit);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasCurrentWinner)
|
||||
// NOTE: old code had a bug in it where nodes with no claims but with children would get left in the cache after removal.
|
||||
// This would cause the getNumBlocksOfContinuousOwnership to return zero (causing incorrect takeover height calc).
|
||||
auto hit = removalWorkaround.find(name);
|
||||
if (hit != removalWorkaround.end()) {
|
||||
removalWorkaround.erase(hit);
|
||||
return 0;
|
||||
|
||||
return std::min((nNextHeight - winningTakeoverHeight) / base->nProportionalDelayFactor, 4032);
|
||||
}
|
||||
return hasCurrentWinner ? std::min((nNextHeight - winningTakeoverHeight) / base->nProportionalDelayFactor, 4032) : 0;
|
||||
}
|
||||
|
||||
std::string CClaimTrieCacheBase::adjustNameForValidHeight(const std::string& name, int validHeight) const
|
||||
@@ -947,7 +882,7 @@ bool CClaimTrieCacheBase::getProofForName(const std::string& name, const uint160
|
||||
// cache the parent nodes
|
||||
getMerkleHash();
|
||||
proof = CClaimTrieProof();
|
||||
for (auto&& row: db << proofClaimQuery_s << name) {
|
||||
for (auto&& row: db << proofClaimQuery_s << name << nNextHeight) {
|
||||
CClaimValue claim;
|
||||
std::string key;
|
||||
int takeoverHeight;
|
||||
|
||||
@@ -49,7 +49,6 @@ protected:
|
||||
std::size_t dbCacheBytes;
|
||||
const std::string dbFile;
|
||||
sqlite::database db;
|
||||
bool isNodeMigrationStart;
|
||||
const int nProportionalDelayFactor;
|
||||
|
||||
const int nNormalizedNameForkHeight;
|
||||
@@ -58,9 +57,6 @@ protected:
|
||||
const int64_t nExtendedClaimExpirationTime;
|
||||
const int64_t nExtendedClaimExpirationForkHeight;
|
||||
const int64_t nAllClaimsInMerkleForkHeight;
|
||||
|
||||
private:
|
||||
void doNodeTableMigration();
|
||||
};
|
||||
|
||||
class CClaimTrieCacheBase
|
||||
@@ -123,7 +119,7 @@ protected:
|
||||
|
||||
mutable sqlite::database_binder claimHashQuery, childHashQuery, claimHashQueryLimit;
|
||||
|
||||
virtual uint256 computeNodeHash(const std::string& name, uint256& claimsHash, int takeoverHeight);
|
||||
virtual uint256 computeNodeHash(const std::string& name, int takeoverHeight);
|
||||
supportEntryType getSupportsForName(const std::string& name) const;
|
||||
|
||||
virtual int getDelayForName(const std::string& name, const uint160& claimId) const;
|
||||
@@ -131,7 +127,6 @@ protected:
|
||||
bool deleteNodeIfPossible(const std::string& name, std::string& parent, int64_t& claims);
|
||||
void ensureTreeStructureIsUpToDate();
|
||||
void ensureTransacting();
|
||||
void insertTakeovers(bool allowReplace=false);
|
||||
|
||||
private:
|
||||
bool transacting;
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
#include <blob.h>
|
||||
#include <string>
|
||||
|
||||
#include <primitives/robin_hood.h>
|
||||
|
||||
class uint160 : public CBaseBlob<160>
|
||||
{
|
||||
public:
|
||||
@@ -42,26 +40,4 @@ uint160 uint160S(const std::string& s);
|
||||
uint256 uint256S(const char* str);
|
||||
uint256 uint256S(const std::string& s);
|
||||
|
||||
namespace std {
|
||||
|
||||
template <>
|
||||
struct hash<uint160>
|
||||
{
|
||||
size_t operator()(const uint160& k) const
|
||||
{
|
||||
return robin_hood::hash_bytes(k.begin(), k.size());
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<uint256>
|
||||
{
|
||||
size_t operator()(const uint256& k) const
|
||||
{
|
||||
return robin_hood::hash_bytes(k.begin(), k.size());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // CLAIMTRIE_UINTS_H
|
||||
+15
-5
@@ -10,9 +10,14 @@
|
||||
bool CCoinsView::GetCoin(const COutPoint &outpoint, Coin &coin) const { return false; }
|
||||
uint256 CCoinsView::GetBestBlock() const { return uint256(); }
|
||||
std::vector<uint256> CCoinsView::GetHeadBlocks() const { return std::vector<uint256>(); }
|
||||
bool CCoinsView::BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlock, bool sync) { return false; }
|
||||
bool CCoinsView::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, bool sync) { return false; }
|
||||
CCoinsViewCursor *CCoinsView::Cursor() const { return nullptr; }
|
||||
bool CCoinsView::HaveCoin(const COutPoint &outpoint) const { return false; }
|
||||
|
||||
bool CCoinsView::HaveCoin(const COutPoint &outpoint) const
|
||||
{
|
||||
Coin coin;
|
||||
return GetCoin(outpoint, coin);
|
||||
}
|
||||
|
||||
CCoinsViewBacked::CCoinsViewBacked(CCoinsView *viewIn) : base(viewIn) { }
|
||||
bool CCoinsViewBacked::GetCoin(const COutPoint &outpoint, Coin &coin) const { return base->GetCoin(outpoint, coin); }
|
||||
@@ -20,7 +25,7 @@ bool CCoinsViewBacked::HaveCoin(const COutPoint &outpoint) const { return base->
|
||||
uint256 CCoinsViewBacked::GetBestBlock() const { return base->GetBestBlock(); }
|
||||
std::vector<uint256> CCoinsViewBacked::GetHeadBlocks() const { return base->GetHeadBlocks(); }
|
||||
void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { base = &viewIn; }
|
||||
bool CCoinsViewBacked::BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlock, bool sync) { return base->BatchWrite(mapCoins, hashBlock, sync); }
|
||||
bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, bool sync) { return base->BatchWrite(mapCoins, hashBlock, sync); }
|
||||
CCoinsViewCursor *CCoinsViewBacked::Cursor() const { return base->Cursor(); }
|
||||
size_t CCoinsViewBacked::EstimateSize() const { return base->EstimateSize(); }
|
||||
|
||||
@@ -122,6 +127,11 @@ bool CCoinsViewCache::HaveCoin(const COutPoint &outpoint) const {
|
||||
return (it != cacheCoins.end() && !it->second.coin.IsSpent());
|
||||
}
|
||||
|
||||
bool CCoinsViewCache::HaveCoinInCache(const COutPoint &outpoint) const {
|
||||
CCoinsMap::const_iterator it = cacheCoins.find(outpoint);
|
||||
return (it != cacheCoins.end() && !it->second.coin.IsSpent());
|
||||
}
|
||||
|
||||
uint256 CCoinsViewCache::GetBestBlock() const {
|
||||
if (hashBlock.IsNull())
|
||||
hashBlock = base->GetBestBlock();
|
||||
@@ -132,8 +142,8 @@ void CCoinsViewCache::SetBestBlock(const uint256 &hashBlockIn) {
|
||||
hashBlock = hashBlockIn;
|
||||
}
|
||||
|
||||
bool CCoinsViewCache::BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlockIn, bool sync) {
|
||||
for (auto it = mapCoins.begin(); it != mapCoins.end(); ++it) {
|
||||
bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlockIn, bool sync) {
|
||||
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end(); it = mapCoins.erase(it)) {
|
||||
// Ignore non-dirty entries (optimization).
|
||||
if (!(it->second.flags & CCoinsCacheEntry::DIRTY)) {
|
||||
continue;
|
||||
|
||||
+10
-3
@@ -163,7 +163,7 @@ public:
|
||||
|
||||
//! Do a bulk modification (multiple Coin changes + BestBlock change).
|
||||
//! The passed mapCoins can be modified.
|
||||
virtual bool BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlock, bool sync);
|
||||
virtual bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, bool sync);
|
||||
|
||||
//! Get a cursor to iterate over the whole state
|
||||
virtual CCoinsViewCursor *Cursor() const;
|
||||
@@ -189,7 +189,7 @@ public:
|
||||
uint256 GetBestBlock() const override;
|
||||
std::vector<uint256> GetHeadBlocks() const override;
|
||||
void SetBackend(CCoinsView &viewIn);
|
||||
bool BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlock, bool sync) override;
|
||||
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, bool sync) override;
|
||||
CCoinsViewCursor *Cursor() const override;
|
||||
size_t EstimateSize() const override;
|
||||
};
|
||||
@@ -222,11 +222,18 @@ public:
|
||||
bool HaveCoin(const COutPoint &outpoint) const override;
|
||||
uint256 GetBestBlock() const override;
|
||||
void SetBestBlock(const uint256 &hashBlock);
|
||||
bool BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlock, bool sync) override;
|
||||
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, bool sync) override;
|
||||
CCoinsViewCursor* Cursor() const override {
|
||||
throw std::logic_error("CCoinsViewCache cursor iteration not supported.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we have the given utxo already loaded in this cache.
|
||||
* The semantics are the same as HaveCoin(), but no calls to
|
||||
* the backing CCoinsView are made.
|
||||
*/
|
||||
bool HaveCoinInCache(const COutPoint &outpoint) const;
|
||||
|
||||
/**
|
||||
* Return a reference to Coin in the cache, or a pruned one if not found. This is
|
||||
* more efficient than GetCoin.
|
||||
|
||||
+1
-8
@@ -102,15 +102,8 @@ typedef void* sockopt_arg_type;
|
||||
typedef char* sockopt_arg_type;
|
||||
#endif
|
||||
|
||||
// Note these both should work with the current usage of poll, but best to be safe
|
||||
// WIN32 poll is broken https://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken/
|
||||
// __APPLE__ poll is broke https://github.com/bitcoin/bitcoin/pull/14336#issuecomment-437384408
|
||||
#if defined(__linux__)
|
||||
#define USE_POLL
|
||||
#endif
|
||||
|
||||
bool static inline IsSelectableSocket(const SOCKET& s) {
|
||||
#if defined(USE_POLL) || defined(WIN32)
|
||||
#ifdef WIN32
|
||||
return true;
|
||||
#else
|
||||
return (s < FD_SETSIZE);
|
||||
|
||||
@@ -30,40 +30,26 @@
|
||||
#endif // !defined(bswap_16)
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/endian/detail/intrinsic.hpp>
|
||||
|
||||
// Non-Mac OS X / non-Darwin
|
||||
|
||||
#if HAVE_DECL_BSWAP_16 == 0
|
||||
inline uint16_t bswap_16(uint16_t x)
|
||||
{
|
||||
#ifdef BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2
|
||||
return BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2(x);
|
||||
#else
|
||||
return (x >> 8) | (x << 8);
|
||||
#endif
|
||||
}
|
||||
#endif // HAVE_DECL_BSWAP16 == 0
|
||||
|
||||
#if HAVE_DECL_BSWAP_32 == 0
|
||||
inline uint32_t bswap_32(uint32_t x)
|
||||
{
|
||||
#ifdef BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4
|
||||
return BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4(x);
|
||||
#else
|
||||
return (((x & 0xff000000U) >> 24) | ((x & 0x00ff0000U) >> 8) |
|
||||
((x & 0x0000ff00U) << 8) | ((x & 0x000000ffU) << 24));
|
||||
#endif
|
||||
}
|
||||
#endif // HAVE_DECL_BSWAP32 == 0
|
||||
|
||||
#if HAVE_DECL_BSWAP_64 == 0
|
||||
inline uint64_t bswap_64(uint64_t x)
|
||||
{
|
||||
#ifdef BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8
|
||||
return BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8(x);
|
||||
#else
|
||||
return (((x & 0xff00000000000000ull) >> 56)
|
||||
| ((x & 0x00ff000000000000ull) >> 40)
|
||||
| ((x & 0x0000ff0000000000ull) >> 24)
|
||||
@@ -72,7 +58,6 @@ inline uint64_t bswap_64(uint64_t x)
|
||||
| ((x & 0x0000000000ff0000ull) << 24)
|
||||
| ((x & 0x000000000000ff00ull) << 40)
|
||||
| ((x & 0x00000000000000ffull) << 56));
|
||||
#endif
|
||||
}
|
||||
#endif // HAVE_DECL_BSWAP64 == 0
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <sync.h>
|
||||
#include <ui_interface.h>
|
||||
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
+14
-22
@@ -241,7 +241,7 @@ void Shutdown()
|
||||
|
||||
// FlushStateToDisk generates a ChainStateFlushed callback, which we should avoid missing
|
||||
if (pcoinsTip != nullptr) {
|
||||
FlushStateToDisk(true);
|
||||
FlushStateToDisk();
|
||||
}
|
||||
|
||||
// After there are no more peers/RPC left to give us new data which may generate
|
||||
@@ -257,7 +257,7 @@ void Shutdown()
|
||||
{
|
||||
LOCK(cs_main);
|
||||
if (pcoinsTip != nullptr) {
|
||||
FlushStateToDisk(true);
|
||||
FlushStateToDisk();
|
||||
}
|
||||
pcoinsTip.reset();
|
||||
pcoinscatcher.reset();
|
||||
@@ -370,7 +370,6 @@ void SetupServerArgs()
|
||||
gArgs.AddArg("-feefilter", strprintf("Tell other nodes to filter invs to us by our mempool min fee (default: %u)", DEFAULT_FEEFILTER), true, OptionsCategory::OPTIONS);
|
||||
gArgs.AddArg("-includeconf=<file>", "Specify additional configuration file, relative to the -datadir path (only useable from configuration file, not command line)", false, OptionsCategory::OPTIONS);
|
||||
gArgs.AddArg("-loadblock=<file>", "Imports blocks from external blk000??.dat file on startup", false, OptionsCategory::OPTIONS);
|
||||
gArgs.AddArg("-maxblockfilesize=<n>", strprintf("Keep the block files below n megabytes each. (default: %d, minimum: 8)", DEFAULT_MAX_BLOCKFILE_SIZE >> 20U), false, OptionsCategory::OPTIONS);
|
||||
gArgs.AddArg("-maxmempool=<n>", strprintf("Keep the transaction memory pool below <n> megabytes (default: %u)", DEFAULT_MAX_MEMPOOL_SIZE), false, OptionsCategory::OPTIONS);
|
||||
gArgs.AddArg("-maxorphantx=<n>", strprintf("Keep at most <n> unconnectable transactions in memory (default: %u)", DEFAULT_MAX_ORPHAN_TRANSACTIONS), false, OptionsCategory::OPTIONS);
|
||||
gArgs.AddArg("-mempoolexpiry=<n>", strprintf("Do not keep transactions in the mempool longer than <n> hours (default: %u)", DEFAULT_MEMPOOL_EXPIRY), false, OptionsCategory::OPTIONS);
|
||||
@@ -942,13 +941,8 @@ bool AppInitParameterInteraction()
|
||||
|
||||
// Trim requested connection counts, to fit into system limitations
|
||||
// <int> in std::min<int>(...) to work around FreeBSD compilation issue described in #2695
|
||||
nMaxConnections = std::max(std::min<int>(nMaxConnections, FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS), 0);
|
||||
nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS + MAX_ADDNODE_CONNECTIONS);
|
||||
#ifdef USE_POLL
|
||||
int fd_max = nFD;
|
||||
#else
|
||||
int fd_max = FD_SETSIZE;
|
||||
#endif
|
||||
nMaxConnections = std::max(std::min<int>(nMaxConnections, fd_max - nBind - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS), 0);
|
||||
if (nFD < MIN_CORE_FILEDESCRIPTORS)
|
||||
return InitError(_("Not enough file descriptors available."));
|
||||
nMaxConnections = std::min(nFD - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS, nMaxConnections);
|
||||
@@ -1219,8 +1213,6 @@ bool AppInitLockDataDirectory()
|
||||
return true;
|
||||
}
|
||||
|
||||
extern CChainState g_chainstate;
|
||||
|
||||
bool AppInitMain()
|
||||
{
|
||||
const CChainParams& chainparams = Params();
|
||||
@@ -1428,7 +1420,7 @@ bool AppInitMain()
|
||||
// however, we want the claimtrie cache to be larger than the others
|
||||
|
||||
int64_t nBlockTreeDBCache = std::min(nTotalCache / 4, nMaxBlockDBCache << 20);
|
||||
int64_t nCoinDBCache = std::min(nTotalCache / 4, nMaxCoinsDBCache << 20);
|
||||
int64_t nCoinDBCache = std::min(nTotalCache / 8, nMaxCoinsDBCache << 20);
|
||||
int64_t nClaimtrieCache = nTotalCache / 4;
|
||||
nTotalCache -= nBlockTreeDBCache;
|
||||
nTotalCache -= nCoinDBCache;
|
||||
@@ -1444,7 +1436,6 @@ bool AppInitMain()
|
||||
|
||||
bool fLoaded = false;
|
||||
while (!fLoaded && !ShutdownRequested()) {
|
||||
bool fReset = fReindex; // reindex flag gets changed out from underneath us
|
||||
std::string strLoadError;
|
||||
|
||||
uiInterface.InitMessage(_("Loading block index..."));
|
||||
@@ -1461,7 +1452,7 @@ bool AppInitMain()
|
||||
// new CBlockTreeDB tries to delete the existing file, which
|
||||
// fails if it's still open from the previous loop. Close it first:
|
||||
pblocktree.reset();
|
||||
pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, false, fReset));
|
||||
pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, false, fReindex));
|
||||
|
||||
// use faster N way hash function
|
||||
// NOTE: it assumes memory is continuous
|
||||
@@ -1470,7 +1461,7 @@ bool AppInitMain()
|
||||
SHA256D64(hashes[0].begin(), hashes[0].begin(), hashes.size() / 2);
|
||||
};
|
||||
|
||||
if (fReset) {
|
||||
if (fReindex) {
|
||||
pblocktree->WriteReindexing(true);
|
||||
//If we're reindexing in prune mode, wipe away unusable block files and all undo data files
|
||||
if (fPruneMode)
|
||||
@@ -1490,7 +1481,7 @@ bool AppInitMain()
|
||||
|
||||
// If the loaded chain has a wrong genesis, bail out immediately
|
||||
// (we're likely using a testnet datadir, or the other way around).
|
||||
if (!g_chainstate.mapBlockIndex.empty() && !LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) {
|
||||
if (!mapBlockIndex.empty() && !LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) {
|
||||
return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?"));
|
||||
}
|
||||
|
||||
@@ -1513,7 +1504,7 @@ bool AppInitMain()
|
||||
// At this point we're either in reindex or we've loaded a useful
|
||||
// block tree into mapBlockIndex!
|
||||
|
||||
pcoinsdbview.reset(new CCoinsViewDB(nCoinDBCache, false, fReset || fReindexChainState));
|
||||
pcoinsdbview.reset(new CCoinsViewDB(nCoinDBCache, false, fReindex || fReindexChainState));
|
||||
pcoinscatcher.reset(new CCoinsViewErrorCatcher(pcoinsdbview.get()));
|
||||
|
||||
if (g_logger->Enabled() && LogAcceptCategory(BCLog::CLAIMS))
|
||||
@@ -1521,7 +1512,7 @@ bool AppInitMain()
|
||||
|
||||
delete pclaimTrie;
|
||||
auto& consensus = chainparams.GetConsensus();
|
||||
pclaimTrie = new CClaimTrie(nClaimtrieCache, fReset || fReindexChainState, 0,
|
||||
pclaimTrie = new CClaimTrie(nClaimtrieCache, fReindex || fReindexChainState, 0,
|
||||
GetDataDir().string(),
|
||||
consensus.nNormalizedNameForkHeight,
|
||||
consensus.nMinRemovalWorkaroundHeight,
|
||||
@@ -1541,7 +1532,7 @@ bool AppInitMain()
|
||||
// The on-disk coinsdb is now in a good state, create the cache
|
||||
pcoinsTip.reset(new CCoinsViewCache(pcoinscatcher.get()));
|
||||
|
||||
bool is_coinsview_empty = fReset || fReindexChainState || pcoinsTip->GetBestBlock().IsNull();
|
||||
bool is_coinsview_empty = fReindex || fReindexChainState || pcoinsTip->GetBestBlock().IsNull();
|
||||
if (!is_coinsview_empty) {
|
||||
// LoadChainTip sets chainActive based on pcoinsTip's best block
|
||||
if (!LoadChainTip(chainparams)) {
|
||||
@@ -1558,7 +1549,7 @@ bool AppInitMain()
|
||||
break;
|
||||
}
|
||||
|
||||
if (!fReset) {
|
||||
if (!fReindex) {
|
||||
// Note that RewindBlockIndex MUST run even if we're about to -reindex-chainstate.
|
||||
// It both disconnects blocks based on chainActive, and drops block data in
|
||||
// mapBlockIndex based on lack of available witness data.
|
||||
@@ -1603,7 +1594,7 @@ bool AppInitMain()
|
||||
|
||||
if (!fLoaded && !ShutdownRequested()) {
|
||||
// first suggest a reindex
|
||||
if (!fReset) {
|
||||
if (!fReindex) {
|
||||
bool fRet = uiInterface.ThreadSafeQuestion(
|
||||
strLoadError + ".\n\n" + _("Do you want to rebuild the block database now?"),
|
||||
strLoadError + ".\nPlease restart with -reindex to recover.",
|
||||
@@ -1623,7 +1614,7 @@ bool AppInitMain()
|
||||
if (fReindex) {
|
||||
// remove old LevelDB indexes
|
||||
boost::system::error_code ec;
|
||||
fs::remove_all(GetBlocksDir() / "index", ec);
|
||||
fs::remove_all(GetDataDir() / "blocks" / "index", ec);
|
||||
fs::remove_all(GetDataDir() / "chainstate", ec);
|
||||
fs::remove_all(GetDataDir() / "claimtrie", ec);
|
||||
}
|
||||
@@ -1720,6 +1711,7 @@ bool AppInitMain()
|
||||
//// debug print
|
||||
{
|
||||
LOCK(cs_main);
|
||||
LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size());
|
||||
chain_active_height = chainActive.Height();
|
||||
}
|
||||
LogPrintf("nBestHeight = %d\n", chain_active_height);
|
||||
|
||||
@@ -88,7 +88,8 @@ WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
|
||||
WalletTxStatus MakeWalletTxStatus(const CWalletTx& wtx)
|
||||
{
|
||||
WalletTxStatus result;
|
||||
CBlockIndex* block = LookupBlockIndex(wtx.hashBlock);
|
||||
auto mi = ::mapBlockIndex.find(wtx.hashBlock);
|
||||
CBlockIndex* block = mi != ::mapBlockIndex.end() ? mi->second : nullptr;
|
||||
result.block_height = (block ? block->nHeight : std::numeric_limits<int>::max());
|
||||
result.blocks_to_maturity = wtx.GetBlocksToMaturity();
|
||||
result.depth_in_main_chain = wtx.GetDepthInMainChain();
|
||||
|
||||
+3
-6
@@ -15,9 +15,6 @@
|
||||
|
||||
#include <boost/signals2/signal.hpp>
|
||||
|
||||
#include <primitives/robin_hood.h>
|
||||
#include <set>
|
||||
|
||||
/** A virtual base class for key stores */
|
||||
class CKeyStore : public SigningProvider
|
||||
{
|
||||
@@ -47,9 +44,9 @@ class CBasicKeyStore : public CKeyStore
|
||||
protected:
|
||||
mutable CCriticalSection cs_KeyStore;
|
||||
|
||||
using KeyMap = robin_hood::unordered_map<CKeyID, CKey>;
|
||||
using WatchKeyMap = robin_hood::unordered_map<CKeyID, CPubKey>;
|
||||
using ScriptMap = robin_hood::unordered_map<CScriptID, CScript>;
|
||||
using KeyMap = std::map<CKeyID, CKey>;
|
||||
using WatchKeyMap = std::map<CKeyID, CPubKey>;
|
||||
using ScriptMap = std::map<CScriptID, CScript>;
|
||||
using WatchOnlySet = std::set<CScript>;
|
||||
|
||||
KeyMap mapKeys GUARDED_BY(cs_KeyStore);
|
||||
|
||||
+3
-50
@@ -119,57 +119,10 @@ bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector
|
||||
vvchParams.push_back(std::move(vchParam2));
|
||||
if (last_drop == OP_2DROP)
|
||||
vvchParams.push_back(std::move(vchParam3));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// this overload exists because optimizer wouldn't inline GetScriptOp:
|
||||
bool DecodeClaimScript(const CScript& scriptIn, int& op, CScript::const_iterator& pc, bool allowSupportMetadata)
|
||||
{
|
||||
op = -1;
|
||||
opcodetype opcode;
|
||||
if (!scriptIn.GetOp(pc, opcode))
|
||||
return false;
|
||||
|
||||
if (opcode != OP_CLAIM_NAME && opcode != OP_SUPPORT_CLAIM && opcode != OP_UPDATE_CLAIM)
|
||||
return false;
|
||||
|
||||
op = opcode;
|
||||
|
||||
// Valid formats:
|
||||
// OP_CLAIM_NAME vchName vchValue OP_2DROP OP_DROP pubkeyscript
|
||||
// OP_UPDATE_CLAIM vchName vchClaimId vchValue OP_2DROP OP_2DROP pubkeyscript
|
||||
// OP_SUPPORT_CLAIM vchName vchClaimId OP_2DROP OP_DROP pubkeyscript
|
||||
// OP_SUPPORT_CLAIM vchName vchClaimId vchValue OP_2DROP OP_2DROP pubkeyscript
|
||||
// All others are invalid.
|
||||
|
||||
if (!scriptIn.GetOp(pc, opcode) || opcode < 0 || opcode > OP_PUSHDATA4)
|
||||
return false;
|
||||
|
||||
if (!scriptIn.GetOp(pc, opcode) || opcode < 0 || opcode > OP_PUSHDATA4)
|
||||
return false;
|
||||
|
||||
if (!scriptIn.GetOp(pc, opcode))
|
||||
return false;
|
||||
|
||||
auto last_drop = OP_DROP;
|
||||
if (opcode >= 0 && opcode <= OP_PUSHDATA4 && op != OP_CLAIM_NAME) {
|
||||
if (!scriptIn.GetOp(pc, opcode))
|
||||
return false;
|
||||
last_drop = OP_2DROP;
|
||||
} else if (op == OP_UPDATE_CLAIM)
|
||||
return false;
|
||||
|
||||
if (opcode != OP_2DROP)
|
||||
return false;
|
||||
|
||||
if (!scriptIn.GetOp(pc, opcode) || opcode != last_drop)
|
||||
return false;
|
||||
|
||||
return !(op == OP_SUPPORT_CLAIM && last_drop == OP_2DROP && !allowSupportMetadata);
|
||||
|
||||
}
|
||||
|
||||
|
||||
uint160 ClaimIdHash(const uint256& txhash, uint32_t nOut)
|
||||
{
|
||||
std::vector<unsigned char> claimToHash(txhash.begin(), txhash.end());
|
||||
@@ -186,10 +139,10 @@ CScript StripClaimScriptPrefix(const CScript& scriptIn)
|
||||
|
||||
CScript StripClaimScriptPrefix(const CScript& scriptIn, int& op)
|
||||
{
|
||||
std::vector<std::vector<unsigned char> > vvchParams;
|
||||
CScript::const_iterator pc = scriptIn.begin();
|
||||
|
||||
auto isClaim = DecodeClaimScript(scriptIn, op, pc);
|
||||
if (!isClaim)
|
||||
if (!DecodeClaimScript(scriptIn, op, vvchParams, pc))
|
||||
return scriptIn;
|
||||
|
||||
return CScript(pc, scriptIn.end());
|
||||
|
||||
@@ -30,7 +30,6 @@ CScript SupportClaimScript(std::string name, uint160 claimId, std::string value=
|
||||
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 allowSupportMetadata=true);
|
||||
bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector<std::vector<unsigned char> >& vvchParams, CScript::const_iterator& pc, bool allowSupportMetadata=true);
|
||||
bool DecodeClaimScript(const CScript& scriptIn, int& op, CScript::const_iterator& pc, bool allowSupportMetadata=true);
|
||||
CScript StripClaimScriptPrefix(const CScript& scriptIn);
|
||||
CScript StripClaimScriptPrefix(const CScript& scriptIn, int& op);
|
||||
uint160 ClaimIdHash(const uint256& txhash, uint32_t nOut);
|
||||
|
||||
+10
-63
@@ -26,10 +26,6 @@
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#ifdef USE_POLL
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
#ifdef USE_UPNP
|
||||
#include <miniupnpc/miniupnpc.h>
|
||||
#include <miniupnpc/miniwget.h>
|
||||
@@ -39,7 +35,6 @@
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <unordered_map>
|
||||
|
||||
// Dump addresses to peers.dat and banlist.dat every 15 minutes (900s)
|
||||
#define DUMP_ADDRESSES_INTERVAL 900
|
||||
@@ -76,10 +71,6 @@ enum BindFlags {
|
||||
BF_WHITELIST = (1U << 2),
|
||||
};
|
||||
|
||||
// The set of sockets cannot be modified while waiting
|
||||
// The sleep time needs to be small to avoid new sockets stalling
|
||||
static const uint64_t SELECT_TIMEOUT_MILLISECONDS = 50;
|
||||
|
||||
const static std::string NET_MESSAGE_COMMAND_OTHER = "*other*";
|
||||
|
||||
static const uint64_t RANDOMIZER_ID_NETGROUP = 0x6c0edd8036ef4036ULL; // SHA256("netgroup")[0:8]
|
||||
@@ -172,7 +163,7 @@ CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
|
||||
static int GetnScore(const CService& addr)
|
||||
{
|
||||
LOCK(cs_mapLocalHost);
|
||||
if (mapLocalHost.count(addr) == 0)
|
||||
if (mapLocalHost.count(addr) == LOCAL_NONE)
|
||||
return 0;
|
||||
return mapLocalHost[addr].nScore;
|
||||
}
|
||||
@@ -926,8 +917,7 @@ size_t CConnman::SocketSendData(CNode *pnode) const
|
||||
int nErr = WSAGetLastError();
|
||||
if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS)
|
||||
{
|
||||
LogPrintf("socket send error: %s%s\n", NetworkErrorString(nErr),
|
||||
fLogIPs ? (", peeraddr=" + pnode->addrName) : std::string());
|
||||
LogPrintf("socket send error %s\n", NetworkErrorString(nErr));
|
||||
pnode->CloseSocketDisconnect();
|
||||
}
|
||||
}
|
||||
@@ -1242,34 +1232,23 @@ void CConnman::ThreadSocketHandler()
|
||||
//
|
||||
// Find which sockets have data to receive
|
||||
//
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 50000; // frequency to poll pnode->vSend
|
||||
|
||||
fd_set fdsetRecv;
|
||||
fd_set fdsetSend;
|
||||
fd_set fdsetError;
|
||||
FD_ZERO(&fdsetRecv);
|
||||
FD_ZERO(&fdsetSend);
|
||||
FD_ZERO(&fdsetError);
|
||||
|
||||
#ifdef USE_POLL
|
||||
std::unordered_map<SOCKET, struct pollfd> pollfds;
|
||||
#else
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = SELECT_TIMEOUT_MILLISECONDS * 1000; // frequency to poll pnode->vSend
|
||||
|
||||
SOCKET hSocketMax = 0;
|
||||
bool have_fds = false;
|
||||
#endif
|
||||
|
||||
for (const ListenSocket& hListenSocket : vhListenSocket) {
|
||||
#ifdef USE_POLL
|
||||
pollfds[hListenSocket.socket].fd = hListenSocket.socket;
|
||||
pollfds[hListenSocket.socket].events = POLLIN;
|
||||
pollfds[hListenSocket.socket].revents = 0;
|
||||
#else
|
||||
FD_SET(hListenSocket.socket, &fdsetRecv);
|
||||
hSocketMax = std::max(hSocketMax, hListenSocket.socket);
|
||||
have_fds = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1298,54 +1277,24 @@ void CConnman::ThreadSocketHandler()
|
||||
if (pnode->hSocket == INVALID_SOCKET)
|
||||
continue;
|
||||
|
||||
#ifdef USE_POLL
|
||||
pollfds[pnode->hSocket].fd = pnode->hSocket;
|
||||
pollfds[pnode->hSocket].events = POLLERR|POLLHUP;
|
||||
pollfds[pnode->hSocket].revents = 0;
|
||||
#else
|
||||
FD_SET(pnode->hSocket, &fdsetError);
|
||||
hSocketMax = std::max(hSocketMax, pnode->hSocket);
|
||||
have_fds = true;
|
||||
#endif
|
||||
|
||||
if (select_send) {
|
||||
#ifdef USE_POLL
|
||||
pollfds[pnode->hSocket].events |= POLLOUT;
|
||||
#else
|
||||
FD_SET(pnode->hSocket, &fdsetSend);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
if (select_recv) {
|
||||
#ifdef USE_POLL
|
||||
pollfds[pnode->hSocket].events |= POLLIN;
|
||||
#else
|
||||
FD_SET(pnode->hSocket, &fdsetRecv);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (interruptNet)
|
||||
return;
|
||||
|
||||
#ifdef USE_POLL
|
||||
std::vector<struct pollfd> vpollfds;
|
||||
vpollfds.reserve(pollfds.size());
|
||||
for (auto it : pollfds)
|
||||
vpollfds.push_back(std::move(it.second));
|
||||
|
||||
if (poll(vpollfds.data(), vpollfds.size(), SELECT_TIMEOUT_MILLISECONDS) < 0)
|
||||
return;
|
||||
|
||||
for (struct pollfd pollfd_entry : vpollfds) {
|
||||
if (pollfd_entry.revents & POLLIN) FD_SET(pollfd_entry.fd, &fdsetRecv);
|
||||
if (pollfd_entry.revents & POLLOUT) FD_SET(pollfd_entry.fd, &fdsetSend);
|
||||
if (pollfd_entry.revents & (POLLERR|POLLHUP)) FD_SET(pollfd_entry.fd, &fdsetError);
|
||||
}
|
||||
#else
|
||||
int nSelect = select(have_fds ? hSocketMax + 1 : 0,
|
||||
&fdsetRecv, &fdsetSend, &fdsetError, &timeout);
|
||||
if (interruptNet)
|
||||
return;
|
||||
|
||||
if (nSelect == SOCKET_ERROR)
|
||||
{
|
||||
@@ -1361,7 +1310,6 @@ void CConnman::ThreadSocketHandler()
|
||||
if (!interruptNet.sleep_for(std::chrono::milliseconds(timeout.tv_usec/1000)))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
// Accept new connections
|
||||
@@ -1387,7 +1335,7 @@ void CConnman::ThreadSocketHandler()
|
||||
for (CNode* pnode : vNodesCopy)
|
||||
{
|
||||
if (interruptNet)
|
||||
break;
|
||||
return;
|
||||
|
||||
//
|
||||
// Receive
|
||||
@@ -1452,8 +1400,7 @@ void CConnman::ThreadSocketHandler()
|
||||
if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS)
|
||||
{
|
||||
if (!pnode->fDisconnect)
|
||||
LogPrintf("socket recv error: %s%s\n", NetworkErrorString(nErr),
|
||||
fLogIPs ? (", peeraddr=" + pnode->addrName) : std::string());
|
||||
LogPrintf("socket recv error %s\n", NetworkErrorString(nErr));
|
||||
pnode->CloseSocketDisconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1049,8 +1049,8 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||
|
||||
return recentRejects->contains(inv.hash) ||
|
||||
mempool.exists(inv.hash) ||
|
||||
pcoinsTip->HaveCoin(COutPoint(inv.hash, 0)) || // Best effort: only try output 0 and 1
|
||||
pcoinsTip->HaveCoin(COutPoint(inv.hash, 1));
|
||||
pcoinsTip->HaveCoinInCache(COutPoint(inv.hash, 0)) || // Best effort: only try output 0 and 1
|
||||
pcoinsTip->HaveCoinInCache(COutPoint(inv.hash, 1));
|
||||
}
|
||||
case MSG_BLOCK:
|
||||
case MSG_WITNESS_BLOCK:
|
||||
@@ -1981,9 +1981,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||
{
|
||||
pfrom->AddInventoryKnown(inv);
|
||||
if (fBlocksOnly) {
|
||||
LogPrint(BCLog::NET, "transaction (%s) inv sent in violation of protocol, disconnecting peer=%d\n", inv.hash.ToString(), pfrom->GetId());
|
||||
pfrom->fDisconnect = true;
|
||||
return true;
|
||||
LogPrint(BCLog::NET, "transaction (%s) inv sent in violation of protocol peer=%d\n", inv.hash.ToString(), pfrom->GetId());
|
||||
} else if (!fAlreadyHave && !fImporting && !fReindex && !IsInitialBlockDownload()) {
|
||||
pfrom->AskFor(inv);
|
||||
}
|
||||
@@ -2208,7 +2206,6 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||
if (!fRelayTxes && (!pfrom->fWhitelisted || !gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)))
|
||||
{
|
||||
LogPrint(BCLog::NET, "transaction sent in violation of protocol peer=%d\n", pfrom->GetId());
|
||||
pfrom->fDisconnect = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+1
-24
@@ -19,10 +19,6 @@
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#ifdef USE_POLL
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
|
||||
|
||||
#if !defined(MSG_NOSIGNAL)
|
||||
@@ -268,22 +264,11 @@ static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, int timeout, c
|
||||
if (!IsSelectableSocket(hSocket)) {
|
||||
return IntrRecvError::NetworkError;
|
||||
}
|
||||
// Only wait at most maxWait milliseconds at a time, unless
|
||||
// we're approaching the end of the specified total timeout
|
||||
int timeout_ms = std::min(endTime - curTime, maxWait);
|
||||
#ifdef USE_POLL
|
||||
struct pollfd pollfd;
|
||||
pollfd.fd = hSocket;
|
||||
pollfd.events = POLLIN;
|
||||
pollfd.revents = 0;
|
||||
int nRet = poll(&pollfd, 1, timeout_ms);
|
||||
#else
|
||||
struct timeval tval = MillisToTimeval(timeout_ms);
|
||||
struct timeval tval = MillisToTimeval(std::min(endTime - curTime, maxWait));
|
||||
fd_set fdset;
|
||||
FD_ZERO(&fdset);
|
||||
FD_SET(hSocket, &fdset);
|
||||
int nRet = select(hSocket + 1, &fdset, nullptr, nullptr, &tval);
|
||||
#endif
|
||||
if (nRet == SOCKET_ERROR) {
|
||||
return IntrRecvError::NetworkError;
|
||||
}
|
||||
@@ -514,19 +499,11 @@ bool ConnectSocketDirectly(const CService &addrConnect, const SOCKET& hSocket, i
|
||||
// WSAEINVAL is here because some legacy version of winsock uses it
|
||||
if (nErr == WSAEINPROGRESS || nErr == WSAEWOULDBLOCK || nErr == WSAEINVAL)
|
||||
{
|
||||
#ifdef USE_POLL
|
||||
struct pollfd pollfd;
|
||||
pollfd.fd = hSocket;
|
||||
pollfd.events = POLLIN | POLLOUT;
|
||||
pollfd.revents = 0;
|
||||
int nRet = poll(&pollfd, 1, nTimeout);
|
||||
#else
|
||||
struct timeval timeout = MillisToTimeval(nTimeout);
|
||||
fd_set fdset;
|
||||
FD_ZERO(&fdset);
|
||||
FD_SET(hSocket, &fdset);
|
||||
int nRet = select(hSocket + 1, nullptr, &fdset, nullptr, &timeout);
|
||||
#endif
|
||||
if (nRet == 0)
|
||||
{
|
||||
LogPrint(BCLog::NET, "connection to %s timeout\n", addrConnect.ToString());
|
||||
|
||||
+1
-2
@@ -288,8 +288,7 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
|
||||
nConf += confAvg[periodTarget - 1][bucket];
|
||||
totalNum += txCtAvg[bucket];
|
||||
failNum += failAvg[periodTarget - 1][bucket];
|
||||
const auto maxConfirms = GetMaxConfirms();
|
||||
for (unsigned int confct = confTarget; confct < maxConfirms; ++confct)
|
||||
for (unsigned int confct = confTarget; confct < GetMaxConfirms(); confct++)
|
||||
extraNum += unconfTxs[(nBlockHeight - confct)%bins][bucket];
|
||||
extraNum += oldUnconfTxs[bucket];
|
||||
// If we have enough transaction data points in this range of buckets,
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -36,17 +36,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
namespace std {
|
||||
template <>
|
||||
struct hash<CKeyID>
|
||||
{
|
||||
size_t operator()(const CKeyID& k) const
|
||||
{
|
||||
return robin_hood::hash_bytes(k.begin(), k.size());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
typedef uint256 ChainCode;
|
||||
|
||||
/** An encapsulated public key. */
|
||||
|
||||
@@ -1299,8 +1299,6 @@ struct CompareBlocksByHeight
|
||||
}
|
||||
};
|
||||
|
||||
extern CChainState g_chainstate;
|
||||
|
||||
static UniValue getchaintips(const JSONRPCRequest& request)
|
||||
{
|
||||
if (request.fHelp || request.params.size() != 0)
|
||||
@@ -1349,11 +1347,11 @@ static UniValue getchaintips(const JSONRPCRequest& request)
|
||||
std::set<const CBlockIndex*> setOrphans;
|
||||
std::set<const CBlockIndex*> setPrevs;
|
||||
|
||||
for (const auto& item : g_chainstate.mapBlockIndex)
|
||||
for (const std::pair<const uint256, CBlockIndex*>& item : mapBlockIndex)
|
||||
{
|
||||
if (!chainActive.Contains(item)) {
|
||||
setOrphans.insert(item);
|
||||
setPrevs.insert(item->pprev);
|
||||
if (!chainActive.Contains(item.second)) {
|
||||
setOrphans.insert(item.second);
|
||||
setPrevs.insert(item.second->pprev);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1373,7 +1371,7 @@ static UniValue getchaintips(const JSONRPCRequest& request)
|
||||
{
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.pushKV("height", block->nHeight);
|
||||
obj.pushKV("hash", block->hash.GetHex());
|
||||
obj.pushKV("hash", block->phashBlock->GetHex());
|
||||
|
||||
// not use ForkAt method because we need the previous one as well
|
||||
const CBlockIndex *forkAt = block, *forkPrev = block;
|
||||
@@ -1385,8 +1383,8 @@ static UniValue getchaintips(const JSONRPCRequest& request)
|
||||
const int branchLen = block->nHeight - forkAt->nHeight;
|
||||
obj.pushKV("branchlen", branchLen);
|
||||
if (forkAt != forkPrev) {
|
||||
obj.pushKV("branchhash", forkAt->hash.GetHex());
|
||||
obj.pushKV("branchhashNext", forkPrev->hash.GetHex());
|
||||
obj.pushKV("branchhash", forkAt->phashBlock->GetHex());
|
||||
obj.pushKV("branchhashNext", forkPrev->phashBlock->GetHex());
|
||||
}
|
||||
|
||||
std::string status;
|
||||
|
||||
@@ -288,7 +288,7 @@ CLAIM_OUTPUT
|
||||
"]",
|
||||
|
||||
// GETCLAIMPROOFBYBID
|
||||
S1("getclaimproofbybid \"" T_NAME "\" ( " T_BID " \"" T_BLOCKHASH R"(" )
|
||||
S1("getclaimproofbyid \"" T_NAME "\" ( " T_BID " \"" T_BLOCKHASH R"(" )
|
||||
Return the cryptographic proof that a name maps to a value or doesn't by a bid.
|
||||
Arguments:)")
|
||||
S3("1. ", T_NAME, NAME_TEXT)
|
||||
|
||||
@@ -33,15 +33,16 @@ void ParseClaimtrieId(const UniValue& v, std::string& claimId, const std::string
|
||||
|
||||
static CBlockIndex* BlockHashIndex(const uint256& blockHash)
|
||||
{
|
||||
auto index = LookupBlockIndex(blockHash);
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
if (index == nullptr)
|
||||
if (mapBlockIndex.count(blockHash) == 0)
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
||||
|
||||
if (!chainActive.Contains(index))
|
||||
CBlockIndex* pblockIndex = mapBlockIndex[blockHash];
|
||||
if (!chainActive.Contains(pblockIndex))
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not in main chain");
|
||||
|
||||
return index;
|
||||
return pblockIndex;
|
||||
}
|
||||
|
||||
#define MAX_RPC_BLOCK_DECREMENTS 500
|
||||
|
||||
+2
-7
@@ -142,10 +142,9 @@ UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGen
|
||||
continue;
|
||||
}
|
||||
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);
|
||||
auto lastInBatch = ++nHeight >= nHeightEnd;
|
||||
if (!ProcessNewBlock(Params(), shared_pblock, true, nullptr, lastInBatch))
|
||||
if (!ProcessNewBlock(Params(), shared_pblock, true, nullptr))
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted");
|
||||
|
||||
++nHeight;
|
||||
blockHashes.push_back(pblock->GetHash().GetHex());
|
||||
|
||||
//mark script as important because it was used at least for one coinbase output if the script came from the wallet
|
||||
@@ -174,10 +173,6 @@ static UniValue generatetoaddress(const JSONRPCRequest& request)
|
||||
+ HelpExampleCli("generatetoaddress", "11 \"myaddress\"")
|
||||
);
|
||||
|
||||
if (IsInitialBlockDownload()) {
|
||||
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "generatetoaddress is not available during the initial block download");
|
||||
}
|
||||
|
||||
int nGenerate = request.params[0].get_int();
|
||||
uint64_t nMaxTries = 1000000;
|
||||
if (!request.params[2].isNull()) {
|
||||
|
||||
@@ -27,17 +27,6 @@ public:
|
||||
CScriptID(const uint160& in) : uint160(in) {}
|
||||
};
|
||||
|
||||
namespace std {
|
||||
template <>
|
||||
struct hash<CScriptID>
|
||||
{
|
||||
size_t operator()(const CScriptID& k) const
|
||||
{
|
||||
return robin_hood::hash_bytes(k.begin(), k.size());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Default setting for nMaxDatacarrierBytes. 80 bytes of data, +1 for OP_RETURN,
|
||||
* +2 for the pushdata opcodes.
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <rpc/blockchain.h>
|
||||
#include <test/test_bitcoin.h>
|
||||
#include <txdb.h>
|
||||
@@ -14,7 +16,7 @@ static bool DoubleEquals(double a, double b, double epsilon)
|
||||
|
||||
static CBlockIndex* CreateBlockIndexWithNbits(uint32_t nbits)
|
||||
{
|
||||
CBlockIndex* block_index = new CBlockIndex((uint256()));
|
||||
CBlockIndex* block_index = new CBlockIndex();
|
||||
block_index->nHeight = 46367;
|
||||
block_index->nTime = 1269211443;
|
||||
block_index->nBits = nbits;
|
||||
|
||||
@@ -24,32 +24,6 @@ BOOST_AUTO_TEST_CASE(claim_replace_test) {
|
||||
BOOST_CHECK(fixture.is_best_claim("bassfisher", tx2));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(triple_update_test)
|
||||
{
|
||||
ClaimTrieChainFixture fixture;
|
||||
CMutableTransaction tx1 = fixture.MakeClaim(fixture.GetCoinbase(), "test", "one", 10);
|
||||
fixture.IncrementBlocks(1);
|
||||
CMutableTransaction tx1a = fixture.MakeClaim(fixture.GetCoinbase(), "tester", "one", 3);
|
||||
CMutableTransaction tx2 = fixture.MakeClaim(fixture.GetCoinbase(), "test", "one", 5);
|
||||
auto height = chainActive.Tip()->nHeight;
|
||||
fixture.IncrementBlocks(9);
|
||||
|
||||
CMutableTransaction tx3 = fixture.MakeUpdate(tx1, "test", "two", ClaimIdHash(tx1.GetHash(), 0), 10);
|
||||
CMutableTransaction tx4 = fixture.MakeUpdate(tx2, "test", "two", ClaimIdHash(tx2.GetHash(), 0), 15);
|
||||
CMutableTransaction tx5 = fixture.MakeUpdate(tx4, "test", "two", ClaimIdHash(tx2.GetHash(), 0), 5);
|
||||
|
||||
fixture.IncrementBlocks(1);
|
||||
BOOST_CHECK(fixture.is_best_claim("test", tx3));
|
||||
uint160 id; int takeover;
|
||||
BOOST_REQUIRE(fixture.getLastTakeoverForName("test", id, takeover));
|
||||
BOOST_CHECK_EQUAL(takeover, height);
|
||||
id = ClaimIdHash(tx2.GetHash(), 0);
|
||||
std::string name;
|
||||
CClaimValue value;
|
||||
BOOST_REQUIRE(fixture.getClaimById(id, name, value));
|
||||
BOOST_CHECK_EQUAL(value.nValidAtHeight, height+20);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(takeover_stability_test) {
|
||||
// no competing bids
|
||||
ClaimTrieChainFixture fixture;
|
||||
|
||||
@@ -15,7 +15,7 @@ class CClaimTrieCacheTest : public CClaimTrieCacheBase
|
||||
public:
|
||||
explicit CClaimTrieCacheTest(CClaimTrie* base): CClaimTrieCacheBase(base)
|
||||
{
|
||||
nNextHeight = std::max(2, nNextHeight);
|
||||
nNextHeight = 2;
|
||||
}
|
||||
|
||||
bool insertClaimIntoTrie(const std::string& key, const CClaimValue& value)
|
||||
@@ -63,10 +63,6 @@ public:
|
||||
assert(!ret || nodeName == key);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void processTakeovers() {
|
||||
insertTakeovers(true);
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(claimtriecache_tests, RegTestingSetup)
|
||||
@@ -101,122 +97,110 @@ BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
|
||||
COutPoint tx6OutPoint(tx6.GetHash(), 0);
|
||||
|
||||
uint256 hash1;
|
||||
hash1.SetHex("917106c2e4a5d454c6463e366ec2c70fde57a3deacb36f566fc0c8568e4523d5");
|
||||
hash1.SetHex("71c7b8d35b9a3d7ad9a1272b68972979bbd18589f1efe6f27b0bf260a6ba78fa");
|
||||
|
||||
uint256 hash2;
|
||||
hash2.SetHex("79d0482510cb3da12b31096d459f8221cd094d268c03d96d897c932716e130e5");
|
||||
hash2.SetHex("c4fc0e2ad56562a636a0a237a96a5f250ef53495c2cb5edd531f087a8de83722");
|
||||
|
||||
uint256 hash3;
|
||||
hash3.SetHex("14ba954095acc42e8a5c1c3c1ca1203a1f1fb44d66b4141272cbb5a16837e3e6");
|
||||
hash3.SetHex("baf52472bd7da19fe1e35116cfb3bd180d8770ffbe3ae9243df1fb58a14b0975");
|
||||
|
||||
uint256 hash4;
|
||||
hash4.SetHex("446b9dd04a1ff062c984cbbf0d5ab5aaea4ee3db1a9b65c5d06be0cb2090dbcf");
|
||||
hash4.SetHex("c73232a755bf015f22eaa611b283ff38100f2a23fb6222e86eca363452ba0c51");
|
||||
|
||||
auto dataDir = GetDataDir() / "merkle_test";
|
||||
fs::create_directories(dataDir);
|
||||
CClaimTrie trie(10*1024*1024, true, 3, dataDir.string(), 1000, 1000, -1, 1000, 1000, 1000, 1000, 1);
|
||||
{
|
||||
CClaimTrieCacheTest ntState(&trie);
|
||||
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, {}, 50, 2, 2));
|
||||
ntState.insertClaimIntoTrie(std::string("test2"), CClaimValue(tx2OutPoint, {}, 50, 2, 2));
|
||||
CClaimTrieCacheTest ntState(pclaimTrie);
|
||||
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, {}, 50, 0, 0));
|
||||
ntState.insertClaimIntoTrie(std::string("test2"), CClaimValue(tx2OutPoint, {}, 50, 0, 0));
|
||||
|
||||
BOOST_CHECK(trie.empty());
|
||||
BOOST_CHECK(pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState.getTotalClaimsInTrie(), 2U);
|
||||
ntState.processTakeovers();
|
||||
BOOST_CHECK_EQUAL(ntState.getMerkleHash(), hash1);
|
||||
|
||||
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3OutPoint, {}, 50, 3, 3));
|
||||
ntState.processTakeovers();
|
||||
ntState.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3OutPoint, {}, 50, 1, 1));
|
||||
BOOST_CHECK_EQUAL(ntState.getMerkleHash(), hash1);
|
||||
ntState.insertClaimIntoTrie(std::string("tes"), CClaimValue(tx4OutPoint, {}, 50, 2, 2));
|
||||
ntState.processTakeovers();
|
||||
ntState.insertClaimIntoTrie(std::string("tes"), CClaimValue(tx4OutPoint, {}, 50, 0, 0));
|
||||
BOOST_CHECK_EQUAL(ntState.getMerkleHash(), hash2);
|
||||
ntState.insertClaimIntoTrie(std::string("testtesttesttest"),
|
||||
CClaimValue(tx5OutPoint, {}, 50, 2, 2));
|
||||
CClaimValue(tx5OutPoint, {}, 50, 0, 0));
|
||||
ntState.removeClaimFromTrie(std::string("testtesttesttest"), tx5OutPoint);
|
||||
ntState.processTakeovers();
|
||||
BOOST_CHECK_EQUAL(ntState.getMerkleHash(), hash2);
|
||||
ntState.flush();
|
||||
|
||||
BOOST_CHECK(!trie.empty());
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState.getMerkleHash(), hash2);
|
||||
BOOST_CHECK(ntState.checkConsistency());
|
||||
}
|
||||
{
|
||||
CClaimTrieCacheTest ntState1(&trie);
|
||||
CClaimTrieCacheTest ntState1(pclaimTrie);
|
||||
ntState1.removeClaimFromTrie(std::string("test"), tx1OutPoint);
|
||||
ntState1.removeClaimFromTrie(std::string("test2"), tx2OutPoint);
|
||||
ntState1.removeClaimFromTrie(std::string("test"), tx3OutPoint);
|
||||
ntState1.removeClaimFromTrie(std::string("tes"), tx4OutPoint);
|
||||
|
||||
ntState1.processTakeovers();
|
||||
BOOST_CHECK_EQUAL(ntState1.getMerkleHash(), hash0);
|
||||
}
|
||||
{
|
||||
CClaimTrieCacheTest ntState2(&trie);
|
||||
ntState2.insertClaimIntoTrie(std::string("abab"), CClaimValue(tx6OutPoint, {}, 50, 2, 200));
|
||||
CClaimTrieCacheTest ntState2(pclaimTrie);
|
||||
ntState2.insertClaimIntoTrie(std::string("abab"), CClaimValue(tx6OutPoint, {}, 50, 0, 200));
|
||||
ntState2.removeClaimFromTrie(std::string("test"), tx1OutPoint);
|
||||
|
||||
ntState2.processTakeovers();
|
||||
BOOST_CHECK_EQUAL(ntState2.getMerkleHash(), hash3);
|
||||
|
||||
ntState2.flush();
|
||||
|
||||
BOOST_CHECK(!trie.empty());
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState2.getMerkleHash(), hash3);
|
||||
BOOST_CHECK(ntState2.checkConsistency());
|
||||
}
|
||||
{
|
||||
CClaimTrieCacheTest ntState3(&trie);
|
||||
ntState3.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, {}, 50, 2, 2));
|
||||
ntState3.processTakeovers();
|
||||
CClaimTrieCacheTest ntState3(pclaimTrie);
|
||||
ntState3.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, {}, 50, 0, 0));
|
||||
BOOST_CHECK_EQUAL(ntState3.getMerkleHash(), hash4);
|
||||
ntState3.flush();
|
||||
BOOST_CHECK(!trie.empty());
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState3.getMerkleHash(), hash4);
|
||||
BOOST_CHECK(ntState3.checkConsistency());
|
||||
}
|
||||
{
|
||||
CClaimTrieCacheTest ntState4(&trie);
|
||||
CClaimTrieCacheTest ntState4(pclaimTrie);
|
||||
ntState4.removeClaimFromTrie(std::string("abab"), tx6OutPoint);
|
||||
ntState4.processTakeovers();
|
||||
BOOST_CHECK_EQUAL(ntState4.getMerkleHash(), hash2);
|
||||
ntState4.flush();
|
||||
BOOST_CHECK(!trie.empty());
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState4.getMerkleHash(), hash2);
|
||||
BOOST_CHECK(ntState4.checkConsistency());
|
||||
}
|
||||
{
|
||||
CClaimTrieCacheTest ntState5(&trie);
|
||||
CClaimTrieCacheTest ntState5(pclaimTrie);
|
||||
ntState5.removeClaimFromTrie(std::string("test"), tx3OutPoint);
|
||||
ntState5.processTakeovers();
|
||||
|
||||
BOOST_CHECK_EQUAL(ntState5.getMerkleHash(), hash2);
|
||||
ntState5.flush();
|
||||
BOOST_CHECK(!trie.empty());
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState5.getMerkleHash(), hash2);
|
||||
BOOST_CHECK(ntState5.checkConsistency());
|
||||
}
|
||||
{
|
||||
CClaimTrieCacheTest ntState6(&trie);
|
||||
ntState6.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3OutPoint, {}, 50, 3, 3));
|
||||
ntState6.processTakeovers();
|
||||
CClaimTrieCacheTest ntState6(pclaimTrie);
|
||||
ntState6.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3OutPoint, {}, 50, 1, 1));
|
||||
|
||||
BOOST_CHECK_EQUAL(ntState6.getMerkleHash(), hash2);
|
||||
ntState6.flush();
|
||||
BOOST_CHECK(!trie.empty());
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState6.getMerkleHash(), hash2);
|
||||
BOOST_CHECK(ntState6.checkConsistency());
|
||||
}
|
||||
{
|
||||
CClaimTrieCacheTest ntState7(&trie);
|
||||
CClaimTrieCacheTest ntState7(pclaimTrie);
|
||||
ntState7.removeClaimFromTrie(std::string("test"), tx3OutPoint);
|
||||
ntState7.removeClaimFromTrie(std::string("test"), tx1OutPoint);
|
||||
ntState7.removeClaimFromTrie(std::string("tes"), tx4OutPoint);
|
||||
ntState7.removeClaimFromTrie(std::string("test2"), tx2OutPoint);
|
||||
|
||||
ntState7.processTakeovers();
|
||||
BOOST_CHECK_EQUAL(ntState7.getMerkleHash(), hash0);
|
||||
ntState7.flush();
|
||||
BOOST_CHECK(trie.empty());
|
||||
BOOST_CHECK(pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState7.getMerkleHash(), hash0);
|
||||
BOOST_CHECK(ntState7.checkConsistency());
|
||||
}
|
||||
|
||||
@@ -823,12 +823,11 @@ BOOST_AUTO_TEST_CASE(removal_workaround_functions)
|
||||
fixture.IncrementBlocks(1);
|
||||
BOOST_CHECK(fixture.is_best_claim("a", tx3a));
|
||||
|
||||
// TODO: bring this back after we hard fork out the removal workaround part 2!
|
||||
// fixture.IncrementBlocks(7);
|
||||
// CMutableTransaction tx4a = fixture.MakeUpdate(tx2a, "b", "b", ClaimIdHash(tx2a.GetHash(), 0), 4);
|
||||
// CMutableTransaction tx4b = fixture.MakeUpdate(tx2b, "b", "b", ClaimIdHash(tx2b.GetHash(), 0), 5); // trigger a takeover
|
||||
// fixture.IncrementBlocks(1);
|
||||
// BOOST_CHECK(fixture.is_best_claim("b", tx4b));
|
||||
fixture.IncrementBlocks(7);
|
||||
CMutableTransaction tx4a = fixture.MakeUpdate(tx2a, "b", "b", ClaimIdHash(tx2a.GetHash(), 0), 4);
|
||||
CMutableTransaction tx4b = fixture.MakeUpdate(tx2b, "b", "b", ClaimIdHash(tx2b.GetHash(), 0), 5); // trigger a takeover
|
||||
fixture.IncrementBlocks(1);
|
||||
BOOST_CHECK(fixture.is_best_claim("b", tx4b));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -192,7 +192,7 @@ bool ClaimTrieChainFixture::CreateBlock(const std::unique_ptr<CBlockTemplate>& p
|
||||
break;
|
||||
}
|
||||
}
|
||||
auto success = ProcessNewBlock(Params(), std::make_shared<const CBlock>(*pblock), true, nullptr, false);
|
||||
auto success = ProcessNewBlock(Params(), std::make_shared<const CBlock>(*pblock), true, nullptr);
|
||||
return success && pblock->GetHash() == chainActive.Tip()->GetBlockHash();
|
||||
}
|
||||
|
||||
|
||||
@@ -395,7 +395,7 @@ BOOST_AUTO_TEST_CASE(bogus_claimtrie_hash_test)
|
||||
break;
|
||||
}
|
||||
}
|
||||
bool success = ProcessNewBlock(Params(), std::make_shared<const CBlock>(pblockTemp->block), true, nullptr, false);
|
||||
bool success = ProcessNewBlock(Params(), std::make_shared<const CBlock>(pblockTemp->block), true, nullptr);
|
||||
// will process , but will not be connected
|
||||
BOOST_CHECK(success);
|
||||
BOOST_CHECK(pblockTemp->block.GetHash() != chainActive.Tip()->GetBlockHash());
|
||||
|
||||
@@ -54,9 +54,9 @@ public:
|
||||
|
||||
uint256 GetBestBlock() const override { return hashBestBlock_; }
|
||||
|
||||
bool BatchWrite(const CCoinsMap& mapCoins, const uint256& hashBlock, bool sync) override
|
||||
bool BatchWrite(CCoinsMap& mapCoins, const uint256& hashBlock, bool sync) override
|
||||
{
|
||||
for (auto it = mapCoins.begin(); it != mapCoins.end(); ++it) {
|
||||
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end(); ) {
|
||||
if (it->second.flags & CCoinsCacheEntry::DIRTY) {
|
||||
// Same optimization used in CCoinsViewDB is to only write dirty entries.
|
||||
map_[it->first] = it->second.coin;
|
||||
@@ -65,6 +65,7 @@ public:
|
||||
map_.erase(it->first);
|
||||
}
|
||||
}
|
||||
mapCoins.erase(it++);
|
||||
}
|
||||
if (!hashBlock.IsNull())
|
||||
hashBestBlock_ = hashBlock;
|
||||
@@ -185,7 +186,7 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
|
||||
COutPoint out(txids[InsecureRand32() % txids.size()], 0);
|
||||
int cacheid = InsecureRand32() % stack.size();
|
||||
stack[cacheid]->Uncache(out);
|
||||
uncached_an_entry |= !stack[cacheid]->HaveCoin(out);
|
||||
uncached_an_entry |= !stack[cacheid]->HaveCoinInCache(out);
|
||||
}
|
||||
|
||||
// Once every 1000 iterations and at the end, verify the full cache.
|
||||
@@ -198,7 +199,7 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
|
||||
if (coin.IsSpent()) {
|
||||
missed_an_entry = true;
|
||||
} else {
|
||||
BOOST_CHECK(stack.back()->HaveCoin(entry.first));
|
||||
BOOST_CHECK(stack.back()->HaveCoinInCache(entry.first));
|
||||
found_an_entry = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ const unsigned int nonces[] = {
|
||||
|
||||
static CBlockIndex CreateBlockIndex(int nHeight)
|
||||
{
|
||||
CBlockIndex index((uint256()));
|
||||
CBlockIndex index;
|
||||
index.nHeight = nHeight;
|
||||
index.pprev = chainActive.Tip();
|
||||
return index;
|
||||
@@ -254,7 +254,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
#endif
|
||||
}
|
||||
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);
|
||||
BOOST_CHECK(ProcessNewBlock(chainparams, shared_pblock, true, nullptr, false));
|
||||
BOOST_CHECK(ProcessNewBlock(chainparams, shared_pblock, true, nullptr));
|
||||
}
|
||||
|
||||
LOCK(cs_main);
|
||||
@@ -376,7 +376,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
// Create an actual 209999-long block chain (without valid blocks).
|
||||
while (chainActive.Tip()->nHeight < 209999) {
|
||||
CBlockIndex* prev = chainActive.Tip();
|
||||
CBlockIndex* next = new CBlockIndex(InsecureRand256());
|
||||
CBlockIndex* next = new CBlockIndex();
|
||||
next->phashBlock = new uint256(InsecureRand256());
|
||||
next->hashClaimTrie = pblocktemplate->block.hashClaimTrie;
|
||||
pcoinsTip->SetBestBlock(next->GetBlockHash());
|
||||
next->pprev = prev;
|
||||
@@ -388,7 +389,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
// Extend to a 210000-long block chain.
|
||||
while (chainActive.Tip()->nHeight < 210000) {
|
||||
CBlockIndex* prev = chainActive.Tip();
|
||||
CBlockIndex* next = new CBlockIndex(InsecureRand256());
|
||||
CBlockIndex* next = new CBlockIndex();
|
||||
next->phashBlock = new uint256(InsecureRand256());
|
||||
next->hashClaimTrie = pblocktemplate->block.hashClaimTrie;
|
||||
pcoinsTip->SetBestBlock(next->GetBlockHash());
|
||||
next->pprev = prev;
|
||||
@@ -421,6 +423,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
CBlockIndex* del = chainActive.Tip();
|
||||
chainActive.SetTip(del->pprev);
|
||||
pcoinsTip->SetBestBlock(del->pprev->GetBlockHash());
|
||||
delete del->phashBlock;
|
||||
delete del;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ BOOST_AUTO_TEST_CASE(get_next_work)
|
||||
{
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
int64_t nLastRetargetTime = 1261130161; // Block #30240
|
||||
CBlockIndex pindexLast((uint256()));
|
||||
CBlockIndex pindexLast;
|
||||
pindexLast.nHeight = 32255;
|
||||
pindexLast.nTime = 1262152739; // Block #32255
|
||||
pindexLast.nBits = 0x1d00ffff;
|
||||
@@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_pow_limit)
|
||||
{
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
int64_t nLastRetargetTime = 1231006505; // Block #0
|
||||
CBlockIndex pindexLast((uint256()));
|
||||
CBlockIndex pindexLast;
|
||||
pindexLast.nHeight = 2015;
|
||||
pindexLast.nTime = 1233061996; // Block #2015
|
||||
pindexLast.nBits = 0x1d00ffff;
|
||||
@@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual)
|
||||
{
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
int64_t nLastRetargetTime = 1279008237; // Block #66528
|
||||
CBlockIndex pindexLast((uint256()));
|
||||
CBlockIndex pindexLast;
|
||||
pindexLast.nHeight = 68543;
|
||||
pindexLast.nTime = 1279297671; // Block #68543
|
||||
pindexLast.nBits = 0x1c05a3f4;
|
||||
@@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual)
|
||||
{
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
int64_t nLastRetargetTime = 1263163443; // NOTE: Not an actual block time
|
||||
CBlockIndex pindexLast((uint256()));
|
||||
CBlockIndex pindexLast;
|
||||
pindexLast.nHeight = 46367;
|
||||
pindexLast.nTime = 1269211443; // Block #46367
|
||||
pindexLast.nBits = 0x1c387f6f;
|
||||
@@ -64,10 +64,8 @@ BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual)
|
||||
BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
|
||||
{
|
||||
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
||||
std::vector<CBlockIndex> blocks;
|
||||
blocks.reserve(10000);
|
||||
std::vector<CBlockIndex> blocks(10000);
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
blocks.emplace_back(uint256());
|
||||
blocks[i].pprev = i ? &blocks[i - 1] : nullptr;
|
||||
blocks[i].nHeight = i;
|
||||
blocks[i].nTime = 1269211443 + i * chainParams->GetConsensus().nPowTargetSpacing;
|
||||
|
||||
+11
-16
@@ -16,11 +16,9 @@ BOOST_FIXTURE_TEST_SUITE(skiplist_tests, BasicTestingSetup)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(skiplist_test)
|
||||
{
|
||||
std::vector<CBlockIndex> vIndex;
|
||||
vIndex.reserve(SKIPLIST_LENGTH);
|
||||
std::vector<CBlockIndex> vIndex(SKIPLIST_LENGTH);
|
||||
|
||||
for (int i=0; i<SKIPLIST_LENGTH; i++) {
|
||||
vIndex.emplace_back(uint256());
|
||||
vIndex[i].nHeight = i;
|
||||
vIndex[i].pprev = (i == 0) ? nullptr : &vIndex[i - 1];
|
||||
vIndex[i].BuildSkip();
|
||||
@@ -49,13 +47,12 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
|
||||
{
|
||||
// Build a main chain 100000 blocks long.
|
||||
std::vector<uint256> vHashMain(100000);
|
||||
std::vector<CBlockIndex> vBlocksMain;
|
||||
vBlocksMain.reserve(100000);
|
||||
for (unsigned int i=0; i<vHashMain.size(); i++) {
|
||||
std::vector<CBlockIndex> vBlocksMain(100000);
|
||||
for (unsigned int i=0; i<vBlocksMain.size(); i++) {
|
||||
vHashMain[i] = ArithToUint256(i); // Set the hash equal to the height, so we can quickly check the distances.
|
||||
vBlocksMain.emplace_back(vHashMain[i]);
|
||||
vBlocksMain[i].nHeight = i;
|
||||
vBlocksMain[i].pprev = i ? &vBlocksMain[i - 1] : nullptr;
|
||||
vBlocksMain[i].phashBlock = &vHashMain[i];
|
||||
vBlocksMain[i].BuildSkip();
|
||||
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksMain[i].GetBlockHash()).GetLow64(), vBlocksMain[i].nHeight);
|
||||
BOOST_CHECK(vBlocksMain[i].pprev == nullptr || vBlocksMain[i].nHeight == vBlocksMain[i].pprev->nHeight + 1);
|
||||
@@ -63,13 +60,12 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
|
||||
|
||||
// Build a branch that splits off at block 49999, 50000 blocks long.
|
||||
std::vector<uint256> vHashSide(50000);
|
||||
std::vector<CBlockIndex> vBlocksSide;
|
||||
vBlocksSide.reserve(50000);
|
||||
for (unsigned int i=0; i<vHashSide.size(); i++) {
|
||||
std::vector<CBlockIndex> vBlocksSide(50000);
|
||||
for (unsigned int i=0; i<vBlocksSide.size(); i++) {
|
||||
vHashSide[i] = ArithToUint256(i + 50000 + (arith_uint256(1) << 128)); // Add 1<<128 to the hashes, so GetLow64() still returns the height.
|
||||
vBlocksSide.emplace_back(vHashSide[i]);
|
||||
vBlocksSide[i].nHeight = i + 50000;
|
||||
vBlocksSide[i].pprev = i ? &vBlocksSide[i - 1] : (vBlocksMain.data()+49999);
|
||||
vBlocksSide[i].phashBlock = &vHashSide[i];
|
||||
vBlocksSide[i].BuildSkip();
|
||||
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksSide[i].GetBlockHash()).GetLow64(), vBlocksSide[i].nHeight);
|
||||
BOOST_CHECK(vBlocksSide[i].pprev == nullptr || vBlocksSide[i].nHeight == vBlocksSide[i].pprev->nHeight + 1);
|
||||
@@ -106,13 +102,12 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
|
||||
BOOST_AUTO_TEST_CASE(findearliestatleast_test)
|
||||
{
|
||||
std::vector<uint256> vHashMain(100000);
|
||||
std::vector<CBlockIndex> vBlocksMain;
|
||||
vBlocksMain.reserve(100000);
|
||||
for (unsigned int i=0; i<vHashMain.size(); i++) {
|
||||
std::vector<CBlockIndex> vBlocksMain(100000);
|
||||
for (unsigned int i=0; i<vBlocksMain.size(); i++) {
|
||||
vHashMain[i] = ArithToUint256(i); // Set the hash equal to the height
|
||||
vBlocksMain.emplace_back(vHashMain[i]);
|
||||
vBlocksMain[i].nHeight = i;
|
||||
vBlocksMain[i].pprev = i ? &vBlocksMain[i - 1] : nullptr;
|
||||
vBlocksMain[i].phashBlock = &vHashMain[i];
|
||||
vBlocksMain[i].BuildSkip();
|
||||
if (i < 10) {
|
||||
vBlocksMain[i].nTime = i;
|
||||
@@ -153,7 +148,7 @@ BOOST_AUTO_TEST_CASE(findearliestatleast_edge_test)
|
||||
std::list<CBlockIndex> blocks;
|
||||
for (unsigned int timeMax : {100, 100, 100, 200, 200, 200, 300, 300, 300}) {
|
||||
CBlockIndex* prev = blocks.empty() ? nullptr : &blocks.back();
|
||||
blocks.emplace_back(uint256());
|
||||
blocks.emplace_back();
|
||||
blocks.back().nHeight = prev ? prev->nHeight + 1 : 0;
|
||||
blocks.back().pprev = prev;
|
||||
blocks.back().BuildSkip();
|
||||
|
||||
@@ -230,7 +230,7 @@ TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransaction>&
|
||||
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, false);
|
||||
ProcessNewBlock(chainparams, shared_pblock, true, nullptr);
|
||||
|
||||
CBlock result = block;
|
||||
return result;
|
||||
|
||||
@@ -138,7 +138,7 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
|
||||
BOOST_CHECK(ProcessNewBlockHeaders(headers, state, Params()));
|
||||
|
||||
// Connect the genesis block and drain any outstanding events
|
||||
ProcessNewBlock(Params(), std::make_shared<CBlock>(Params().GenesisBlock()), true, &ignored, false);
|
||||
ProcessNewBlock(Params(), std::make_shared<CBlock>(Params().GenesisBlock()), true, &ignored);
|
||||
SyncWithValidationInterfaceQueue();
|
||||
|
||||
// subscribe to events (this subscriber will validate event ordering)
|
||||
@@ -159,13 +159,13 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
|
||||
bool ignored;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
auto block = blocks[GetRand(blocks.size() - 1)];
|
||||
ProcessNewBlock(Params(), block, true, &ignored, false);
|
||||
ProcessNewBlock(Params(), block, true, &ignored);
|
||||
}
|
||||
|
||||
// to make sure that eventually we process the full chain - do it here
|
||||
for (auto block : blocks) {
|
||||
if (block->vtx.size() == 1) {
|
||||
bool processed = ProcessNewBlock(Params(), block, true, &ignored, false);
|
||||
bool processed = ProcessNewBlock(Params(), block, true, &ignored);
|
||||
assert(processed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
|
||||
VersionBitsTester& Mine(unsigned int height, int32_t nTime, int32_t nVersion) {
|
||||
while (vpblock.size() < height) {
|
||||
CBlockIndex* pindex = new CBlockIndex((uint256()));
|
||||
CBlockIndex* pindex = new CBlockIndex();
|
||||
pindex->nHeight = vpblock.size();
|
||||
pindex->pprev = vpblock.size() > 0 ? vpblock.back() : nullptr;
|
||||
pindex->nTime = nTime;
|
||||
|
||||
+91
-98
@@ -30,11 +30,10 @@ CCoinsViewDB::CCoinsViewDB(size_t nCacheSize, bool fMemory, bool fWipe)
|
||||
: db(fMemory ? ":memory:" : (GetDataDir() / "coins.sqlite").string(), sharedConfig)
|
||||
{
|
||||
db << "PRAGMA cache_size=-" + std::to_string(nCacheSize >> 10); // in -KB
|
||||
db << "PRAGMA synchronous=OFF"; // don't disk sync after transaction commit
|
||||
db << "PRAGMA journal_mode=WAL";
|
||||
db << "PRAGMA temp_store=MEMORY";
|
||||
db << "PRAGMA case_sensitive_like=true";
|
||||
db << "PRAGMA journal_mode=WAL";
|
||||
db << "PRAGMA synchronous=OFF"; // don't disk sync after transaction commit; we handle that elsewhere
|
||||
db << "PRAGMA wal_autocheckpoint=4000"; // 4k page size * 4000 = 16MB
|
||||
|
||||
db << "CREATE TABLE IF NOT EXISTS unspent (txID BLOB NOT NULL COLLATE BINARY, txN INTEGER NOT NULL, "
|
||||
"isCoinbase INTEGER NOT NULL, blockHeight INTEGER NOT NULL, amount INTEGER NOT NULL, "
|
||||
@@ -93,63 +92,73 @@ std::vector<uint256> CCoinsViewDB::GetHeadBlocks() const {
|
||||
return vhashHeadBlocks;
|
||||
}
|
||||
|
||||
bool CCoinsViewDB::BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlock, bool sync) {
|
||||
bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, bool sync) {
|
||||
|
||||
size_t count = 0;
|
||||
size_t changed = 0;
|
||||
int crash_simulate = gArgs.GetArg("-dbcrashratio", 0);
|
||||
assert(!hashBlock.IsNull());
|
||||
|
||||
uint256 old_tip = GetBestBlock();
|
||||
if (old_tip.IsNull()) {
|
||||
// We may be in the middle of replaying.
|
||||
std::vector<uint256> old_heads = GetHeadBlocks();
|
||||
if (old_heads.size() == 2) {
|
||||
assert(old_heads[0] == hashBlock);
|
||||
old_tip = old_heads[1];
|
||||
}
|
||||
}
|
||||
|
||||
db << "BEGIN";
|
||||
if (!mapCoins.empty()) {
|
||||
db << "INSERT OR REPLACE INTO marker VALUES('head_block', ?)" << hashBlock;
|
||||
auto dbd = db << "DELETE FROM unspent WHERE txID = ? AND txN = ?";
|
||||
auto dbi = db << "INSERT OR REPLACE INTO unspent VALUES(?,?,?,?,?,?,?)";
|
||||
for (auto it = mapCoins.begin(); it != mapCoins.end(); ++it) {
|
||||
if (it->second.flags & CCoinsCacheEntry::DIRTY) {
|
||||
if (it->second.coin.IsSpent()) {
|
||||
// at present the "IsSpent" flag is used for both "spent" and "block going backwards"
|
||||
dbd << it->first.hash << it->first.n;
|
||||
dbd++;
|
||||
} else {
|
||||
CTxDestination address;
|
||||
std::string destination;
|
||||
if (ExtractDestination(it->second.coin.out.scriptPubKey, address))
|
||||
destination = EncodeDestination(address);
|
||||
uint32_t isCoinBase = it->second.coin.fCoinBase; // bit-field
|
||||
uint32_t coinHeight = it->second.coin.nHeight; // bit-field
|
||||
dbi << it->first.hash << it->first.n << isCoinBase << coinHeight
|
||||
<< it->second.coin.out.nValue << it->second.coin.out.scriptPubKey << destination;
|
||||
dbi++;
|
||||
}
|
||||
changed++;
|
||||
db << "INSERT OR REPLACE INTO marker VALUES('head_block', ?)" << hashBlock;
|
||||
|
||||
auto dbd = db << "DELETE FROM unspent WHERE txID = ? AND txN = ?";
|
||||
auto dbi = db << "INSERT OR REPLACE INTO unspent VALUES(?,?,?,?,?,?,?)";
|
||||
for (auto it = mapCoins.begin(); it != mapCoins.end();) {
|
||||
if (it->second.flags & CCoinsCacheEntry::DIRTY) {
|
||||
if (it->second.coin.IsSpent()) {
|
||||
// at present the "IsSpent" flag is used for both "spent" and "block going backwards"
|
||||
dbd << it->first.hash << it->first.n;
|
||||
dbd++;
|
||||
}
|
||||
if (crash_simulate && ++count % 200000 == 0) {
|
||||
static FastRandomContext rng;
|
||||
if (rng.randrange(crash_simulate) == 0) {
|
||||
LogPrintf("Simulating a crash. Goodbye.\n");
|
||||
_Exit(0);
|
||||
}
|
||||
else {
|
||||
CTxDestination address;
|
||||
std::string destination;
|
||||
if (ExtractDestination(it->second.coin.out.scriptPubKey, address))
|
||||
destination = EncodeDestination(address);
|
||||
uint32_t isCoinBase = it->second.coin.fCoinBase; // bit-field
|
||||
uint32_t coinHeight = it->second.coin.nHeight; // bit-field
|
||||
dbi << it->first.hash << it->first.n << isCoinBase << coinHeight
|
||||
<< it->second.coin.out.nValue << it->second.coin.out.scriptPubKey << destination;
|
||||
dbi++;
|
||||
}
|
||||
changed++;
|
||||
}
|
||||
count++;
|
||||
auto itOld = it++;
|
||||
mapCoins.erase(itOld);
|
||||
if (crash_simulate && count % 200000 == 0) {
|
||||
static FastRandomContext rng;
|
||||
if (rng.randrange(crash_simulate) == 0) {
|
||||
LogPrintf("Simulating a crash. Goodbye.\n");
|
||||
_Exit(0);
|
||||
}
|
||||
}
|
||||
dbd.used(true);
|
||||
dbi.used(true);
|
||||
db << "DELETE FROM marker WHERE name = 'head_block'";
|
||||
}
|
||||
dbd.used(true);
|
||||
dbi.used(true);
|
||||
db << "INSERT OR REPLACE INTO marker VALUES('best_block', ?)" << hashBlock;
|
||||
db << "DELETE FROM marker WHERE name = 'head_block'";
|
||||
|
||||
auto code = sqlite::commit(db);
|
||||
if (code != SQLITE_OK) {
|
||||
LogPrintf("%s: Error committing coins info to database. SQLite error: %d\n", __func__, code);
|
||||
LogPrint(BCLog::COINDB, "Error committing transaction outputs changes to coin database. SQLite error: %d\n", code);
|
||||
return false;
|
||||
}
|
||||
LogPrint(BCLog::COINDB, "Committed %zu changed transaction outputs (out of %zu) to coin database...\n", changed, count);
|
||||
LogPrint(BCLog::COINDB, "Committed %u changed transaction outputs (out of %u) to coin database...\n", (unsigned int)changed, (unsigned int)count);
|
||||
if (sync) {
|
||||
code = sqlite::sync(db);
|
||||
if (code != SQLITE_OK) {
|
||||
LogPrintf("%s: Error syncing coin database. SQLite error: %d\n", __func__, code);
|
||||
// don't return false as it may happen if someone else is reading our DB
|
||||
}
|
||||
auto rc = sqlite3_wal_checkpoint_v2(db.connection().get(), nullptr, SQLITE_CHECKPOINT_FULL, nullptr, nullptr);
|
||||
return rc == SQLITE_OK;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -157,19 +166,18 @@ bool CCoinsViewDB::BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBloc
|
||||
size_t CCoinsViewDB::EstimateSize() const
|
||||
{
|
||||
size_t ret = 0;
|
||||
db << "SELECT COUNT(*) FROM unspent ORDER BY txID, txN" >> ret; // force index use via order by
|
||||
return ret * 770; // number chosen empirically
|
||||
db << "SELECT COUNT(*) FROM unspent" >> ret;
|
||||
return ret * 100;
|
||||
}
|
||||
|
||||
CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe)
|
||||
: db(fMemory ? ":memory:" : (GetDataDir() / "block_index.sqlite").string(), sharedConfig)
|
||||
{
|
||||
db << "PRAGMA cache_size=-" + std::to_string(nCacheSize >> 10); // in -KB
|
||||
db << "PRAGMA synchronous=OFF"; // don't disk sync after transaction commit
|
||||
db << "PRAGMA journal_mode=WAL";
|
||||
db << "PRAGMA temp_store=MEMORY";
|
||||
db << "PRAGMA case_sensitive_like=true";
|
||||
db << "PRAGMA journal_mode=WAL";
|
||||
db << "PRAGMA synchronous=OFF"; // don't disk sync after transaction commit; we handle that elsewhere
|
||||
db << "PRAGMA wal_autocheckpoint=4000"; // 4k page size * 4000 = 16MB
|
||||
|
||||
db << "CREATE TABLE IF NOT EXISTS block_file ("
|
||||
"file INTEGER NOT NULL PRIMARY KEY, "
|
||||
@@ -256,8 +264,7 @@ CCoinsViewCursor *CCoinsViewDB::Cursor() const
|
||||
|
||||
CCoinsViewDBCursor::CCoinsViewDBCursor(const uint256 &hashBlockIn, const CCoinsViewDB* view)
|
||||
: CCoinsViewCursor(hashBlockIn), owner(view),
|
||||
query(owner->db << "SELECT txID, txN, isCoinbase, blockHeight, amount, script "
|
||||
"FROM unspent ORDER BY txID ASC, txN ASC")
|
||||
query(owner->db << "SELECT txID, txN, isCoinbase, blockHeight, amount, script FROM unspent")
|
||||
{
|
||||
iter = query.begin();
|
||||
}
|
||||
@@ -300,34 +307,27 @@ void CCoinsViewDBCursor::Next()
|
||||
bool CBlockTreeDB::BatchWrite(const std::vector<std::pair<int, const CBlockFileInfo*> >& fileInfo,
|
||||
int nLastFile, const std::vector<const CBlockIndex*>& blockInfo, bool sync) {
|
||||
db << "BEGIN";
|
||||
if (!fileInfo.empty()) {
|
||||
auto ibf = db << "INSERT OR REPLACE INTO block_file(file, blocks, size, undoSize, heightFirst, "
|
||||
"heightLast, timeFirst, timeLast) VALUES(?,?,?,?,?,?,?,?)";
|
||||
for (auto &kvp: fileInfo) {
|
||||
ibf << kvp.first << kvp.second->nBlocks << kvp.second->nSize << kvp.second->nUndoSize
|
||||
<< kvp.second->nHeightFirst << kvp.second->nHeightLast << kvp.second->nTimeFirst
|
||||
<< kvp.second->nTimeLast;
|
||||
ibf++;
|
||||
}
|
||||
ibf.used(true);
|
||||
auto ibf = db << "INSERT OR REPLACE INTO block_file(file, blocks, size, undoSize, heightFirst, heightLast, timeFirst, timeLast) "
|
||||
"VALUES(?,?,?,?,?,?,?,?)";
|
||||
for (auto& kvp: fileInfo) {
|
||||
ibf << kvp.first << kvp.second->nBlocks << kvp.second->nSize << kvp.second->nUndoSize
|
||||
<< kvp.second->nHeightFirst << kvp.second->nHeightLast << kvp.second->nTimeFirst << kvp.second->nTimeLast;
|
||||
ibf++;
|
||||
}
|
||||
|
||||
ibf.used(true);
|
||||
db << "INSERT OR REPLACE INTO flag VALUES('last_block', ?)" << nLastFile; // TODO: is this always max(file column)?
|
||||
|
||||
if(!blockInfo.empty()) {
|
||||
const static uint256 empty;
|
||||
auto ibi = db << "INSERT OR REPLACE INTO block_info(hash, prevHash, height, file, dataPos, undoPos, "
|
||||
"txCount, status, version, rootTxHash, rootTrieHash, time, bits, nonce) "
|
||||
"VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
for (auto &bi: blockInfo) {
|
||||
ibi << bi->hash << (bi->pprev ? bi->pprev->hash : empty)
|
||||
<< bi->nHeight << bi->nFile << bi->nDataPos << bi->nUndoPos << bi->nTx
|
||||
<< bi->nStatus << bi->nVersion << bi->hashMerkleRoot << bi->hashClaimTrie
|
||||
<< bi->nTime << bi->nBits << bi->nNonce;
|
||||
ibi++;
|
||||
}
|
||||
ibi.used(true);
|
||||
auto ibi = db << "INSERT OR REPLACE INTO block_info(hash, prevHash, height, file, dataPos, undoPos, "
|
||||
"txCount, status, version, rootTxHash, rootTrieHash, time, bits, nonce) "
|
||||
"VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
for (auto& bi: blockInfo) {
|
||||
ibi << bi->GetBlockHash() << (bi->pprev ? bi->pprev->GetBlockHash() : uint256())
|
||||
<< bi->nHeight << bi->nFile << bi->nDataPos << bi->nUndoPos << bi->nTx
|
||||
<< bi->nStatus << bi->nVersion << bi->hashMerkleRoot << bi->hashClaimTrie
|
||||
<< bi->nTime << bi->nBits << bi->nNonce;
|
||||
ibi++;
|
||||
}
|
||||
ibi.used(true);
|
||||
auto code = sqlite::commit(db);
|
||||
if (code != SQLITE_OK) {
|
||||
LogPrintf("%s: Error committing block info to database. SQLite error: %d\n", __func__, code);
|
||||
@@ -335,11 +335,8 @@ bool CBlockTreeDB::BatchWrite(const std::vector<std::pair<int, const CBlockFileI
|
||||
}
|
||||
// by Sync they mean disk sync:
|
||||
if (sync) {
|
||||
code = sqlite::sync(db);
|
||||
if (code != SQLITE_OK) {
|
||||
LogPrintf("%s: Error syncing block database. SQLite error: %d\n", __func__, code);
|
||||
// don't return false here as this may happen if someone else is reading our DB
|
||||
}
|
||||
auto rc = sqlite3_wal_checkpoint_v2(db.connection().get(), nullptr, SQLITE_CHECKPOINT_FULL, nullptr, nullptr);
|
||||
return rc == SQLITE_OK;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -364,29 +361,31 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
|
||||
{
|
||||
auto query = db << "SELECT hash, prevHash, height, file, dataPos, undoPos, txCount, "
|
||||
"version, rootTxHash, rootTrieHash, time, bits, nonce, status "
|
||||
"FROM block_info ORDER BY height";
|
||||
"FROM block_info"; // insertBlockIndex puts them in order
|
||||
|
||||
// Load mapBlockIndex
|
||||
for (auto&& row: query) {
|
||||
boost::this_thread::interruption_point();
|
||||
// Construct block index object
|
||||
uint256 hash, prevHash;
|
||||
row >> hash >> prevHash;
|
||||
CBlockIndex* pindexNew = insertBlockIndex(hash);
|
||||
pindexNew->pprev = insertBlockIndex(prevHash);
|
||||
|
||||
row >> pindexNew->nHeight
|
||||
>> pindexNew->nFile
|
||||
>> pindexNew->nDataPos
|
||||
>> pindexNew->nUndoPos
|
||||
>> pindexNew->nTx
|
||||
>> pindexNew->nVersion
|
||||
>> pindexNew->hashMerkleRoot
|
||||
>> pindexNew->hashClaimTrie
|
||||
>> pindexNew->nTime
|
||||
>> pindexNew->nBits
|
||||
>> pindexNew->nNonce
|
||||
>> pindexNew->nStatus;
|
||||
row >> pindexNew->nHeight;
|
||||
row >> pindexNew->nFile;
|
||||
row >> pindexNew->nDataPos;
|
||||
row >> pindexNew->nUndoPos;
|
||||
row >> pindexNew->nTx;
|
||||
row >> pindexNew->nVersion;
|
||||
row >> pindexNew->hashMerkleRoot;
|
||||
row >> pindexNew->hashClaimTrie;
|
||||
row >> pindexNew->nTime;
|
||||
row >> pindexNew->nBits;
|
||||
row >> pindexNew->nNonce;
|
||||
row >> pindexNew->nStatus;
|
||||
|
||||
// nChainTx gets set later; don't set it here or you'll mess up the Unlinked list
|
||||
pindexNew->nChainTx = pindexNew->pprev ? pindexNew->pprev->nChainTx + pindexNew->nTx : pindexNew->nTx;
|
||||
|
||||
if (!CheckProofOfWork(pindexNew->GetBlockPoWHash(), pindexNew->nBits, consensusParams))
|
||||
{
|
||||
@@ -394,12 +393,6 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
|
||||
LogPrintf("%s: CheckProofOfWorkFailed: %s (hash %s, nBits=%x, nTime=%d)\n", __func__, pindexNew->GetBlockPoWHash().GetHex(), pindexNew->GetBlockHash().GetHex(), pindexNew->nBits, pindexNew->nTime);
|
||||
return error("%s: CheckProofOfWork failed: %s", __func__, pindexNew->ToString());
|
||||
}
|
||||
|
||||
if ((pindexNew->nHeight & 0x3ff) == 0x3ff) { // don't check for shutdown on every single block
|
||||
boost::this_thread::interruption_point();
|
||||
if (ShutdownRequested())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
+3
-11
@@ -23,15 +23,7 @@ namespace sqlite {
|
||||
return sqlite3_bind_blob(stmt, inx, val.data(), int(val.size()), SQLITE_STATIC);
|
||||
}
|
||||
|
||||
inline int bind_col_in_db(sqlite3_stmt* stmt, int inx, CScript&& val) {
|
||||
return sqlite3_bind_blob(stmt, inx, val.data(), int(val.size()), SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
inline void store_result_in_db(sqlite3_context* db, const CScript& val) {
|
||||
sqlite3_result_blob(db, val.data(), int(val.size()), SQLITE_STATIC);
|
||||
}
|
||||
|
||||
inline void store_result_in_db(sqlite3_context* db, CScript&& val) {
|
||||
sqlite3_result_blob(db, val.data(), int(val.size()), SQLITE_TRANSIENT);
|
||||
}
|
||||
}
|
||||
@@ -58,7 +50,7 @@ class uint256;
|
||||
//! 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 = 800;
|
||||
static const int64_t nDefaultDbCache = 480;
|
||||
//! -dbbatchsize default (bytes)
|
||||
static const int64_t nDefaultDbBatchSize = 16 << 20;
|
||||
//! max. -dbcache (MiB)
|
||||
@@ -68,7 +60,7 @@ static const int64_t nMinDbCache = 4;
|
||||
//! Max memory allocated to block tree DB specific cache
|
||||
static const int64_t nMaxBlockDBCache = 260;
|
||||
//! Max memory allocated to coin DB specific cache (MiB)
|
||||
static const int64_t nMaxCoinsDBCache = 200;
|
||||
static const int64_t nMaxCoinsDBCache = 40;
|
||||
|
||||
|
||||
struct CDiskTxPos : public CDiskBlockPos
|
||||
@@ -109,7 +101,7 @@ public:
|
||||
bool HaveCoin(const COutPoint &outpoint) const override;
|
||||
uint256 GetBestBlock() const override;
|
||||
std::vector<uint256> GetHeadBlocks() const override;
|
||||
bool BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlock, bool sync) override;
|
||||
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, bool sync) override;
|
||||
CCoinsViewCursor *Cursor() const override;
|
||||
size_t EstimateSize() const override;
|
||||
};
|
||||
|
||||
+11
-18
@@ -703,22 +703,17 @@ const fs::path &GetBlocksDir(bool fNetSpecific)
|
||||
|
||||
if (gArgs.IsArgSet("-blocksdir")) {
|
||||
path = fs::system_complete(gArgs.GetArg("-blocksdir", ""));
|
||||
if (fs::exists(path) && !fs::is_directory(path)) {
|
||||
LogPrintf("%s: %s is not a directory, falling back to GetDataDir\n", __func__, path);
|
||||
path.clear();
|
||||
if (!fs::is_directory(path)) {
|
||||
path = "";
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
bool usingDataDir = path.empty();
|
||||
if (usingDataDir)
|
||||
} else {
|
||||
path = GetDataDir(false);
|
||||
|
||||
}
|
||||
if (fNetSpecific)
|
||||
path /= BaseParams().DataDir();
|
||||
|
||||
if (usingDataDir)
|
||||
path /= "blocks";
|
||||
|
||||
path /= "blocks";
|
||||
fs::create_directories(path);
|
||||
return path;
|
||||
}
|
||||
@@ -737,15 +732,13 @@ const fs::path &GetDataDir(bool fNetSpecific)
|
||||
|
||||
if (gArgs.IsArgSet("-datadir")) {
|
||||
path = fs::system_complete(gArgs.GetArg("-datadir", ""));
|
||||
if (fs::exists(path) && !fs::is_directory(path)) {
|
||||
LogPrintf("%s: %s is not a directory, falling back to GetDefaultDataDir\n", __func__, path);
|
||||
path.clear();
|
||||
if (!fs::is_directory(path)) {
|
||||
path = "";
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
if (path.empty())
|
||||
} else {
|
||||
path = GetDefaultDataDir();
|
||||
|
||||
}
|
||||
if (fNetSpecific)
|
||||
path /= BaseParams().DataDir();
|
||||
|
||||
|
||||
+106
-111
@@ -62,6 +62,7 @@
|
||||
CChainState g_chainstate;
|
||||
CCriticalSection cs_main;
|
||||
|
||||
BlockMap& mapBlockIndex = g_chainstate.mapBlockIndex;
|
||||
CChain& chainActive = g_chainstate.chainActive;
|
||||
CBlockIndex *pindexBestHeader = nullptr;
|
||||
CWaitableCriticalSection g_best_block_mutex;
|
||||
@@ -156,7 +157,7 @@ enum class FlushStateMode {
|
||||
};
|
||||
|
||||
// See definition for documentation
|
||||
static bool FlushStateToDisk(const CChainParams& chainParams, CValidationState &state, FlushStateMode mode, int nManualPruneHeight=0, bool syncToDisk=false);
|
||||
static bool FlushStateToDisk(const CChainParams& chainParams, CValidationState &state, FlushStateMode mode, int nManualPruneHeight=0);
|
||||
static void FindFilesToPruneManual(std::set<int>& setFilesToPrune, int nManualPruneHeight);
|
||||
static void FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight);
|
||||
bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks = nullptr);
|
||||
@@ -220,7 +221,7 @@ bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp, bool
|
||||
CBlockIndex* tip = chainActive.Tip();
|
||||
assert(tip != nullptr);
|
||||
|
||||
CBlockIndex index((uint256()));
|
||||
CBlockIndex index;
|
||||
index.pprev = tip;
|
||||
// CheckSequenceLocks() uses chainActive.Height()+1 to evaluate
|
||||
// height based locks because when SequenceLocks() is called within
|
||||
@@ -505,14 +506,14 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
|
||||
|
||||
// do all inputs exist?
|
||||
for (const CTxIn& txin : tx.vin) {
|
||||
if (!pcoinsTip->HaveCoin(txin.prevout)) {
|
||||
if (!pcoinsTip->HaveCoinInCache(txin.prevout)) {
|
||||
coins_to_uncache.push_back(txin.prevout);
|
||||
}
|
||||
if (!view.HaveCoin(txin.prevout)) {
|
||||
// Are inputs missing because we already have the tx?
|
||||
for (size_t out = 0; out < tx.vout.size(); out++) {
|
||||
// Optimistically just do efficient check of cache for outputs
|
||||
if (pcoinsTip->HaveCoin(COutPoint(hash, out))) {
|
||||
if (pcoinsTip->HaveCoinInCache(COutPoint(hash, out))) {
|
||||
return state.Invalid(false, REJECT_DUPLICATE, "txn-already-known");
|
||||
}
|
||||
}
|
||||
@@ -1106,7 +1107,7 @@ bool IsInitialBlockDownload()
|
||||
return true;
|
||||
if (chainActive.Tip()->nChainWork < nMinimumChainWork)
|
||||
return true;
|
||||
if (Params().NetworkIDString() == CBaseChainParams::MAIN && chainActive.Tip()->GetBlockTime() < (GetTime() - nMaxTipAge))
|
||||
if (chainActive.Tip()->GetBlockTime() < (GetTime() - nMaxTipAge))
|
||||
return true;
|
||||
LogPrintf("Leaving InitialBlockDownload (latching to false)\n");
|
||||
latchToFalse.store(true, std::memory_order_relaxed);
|
||||
@@ -1151,14 +1152,14 @@ static void CheckForkWarningConditions()
|
||||
if (!GetfLargeWorkForkFound() && pindexBestForkBase)
|
||||
{
|
||||
std::string warning = std::string("'Warning: Large-work fork detected, forking after block ") +
|
||||
pindexBestForkBase->hash.ToString() + std::string("'");
|
||||
pindexBestForkBase->phashBlock->ToString() + std::string("'");
|
||||
AlertNotify(warning);
|
||||
}
|
||||
if (pindexBestForkTip && pindexBestForkBase)
|
||||
{
|
||||
LogPrintf("%s: Warning: Large valid fork found\n forking the chain at height %d (%s)\n lasting to height %d (%s).\nChain state database corruption likely.\n", __func__,
|
||||
pindexBestForkBase->nHeight, pindexBestForkBase->hash.ToString(),
|
||||
pindexBestForkTip->nHeight, pindexBestForkTip->hash.ToString());
|
||||
pindexBestForkBase->nHeight, pindexBestForkBase->phashBlock->ToString(),
|
||||
pindexBestForkTip->nHeight, pindexBestForkTip->phashBlock->ToString());
|
||||
SetfLargeWorkForkFound(true);
|
||||
}
|
||||
else
|
||||
@@ -1713,8 +1714,8 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens
|
||||
// mainnet and testnet), so for simplicity, always leave P2SH
|
||||
// on except for the one violating block.
|
||||
if (consensusparams.BIP16Exception.IsNull() || // no bip16 exception on this chain
|
||||
pindex->hash.IsNull() || // this is a new candidate block, eg from TestBlockValidity()
|
||||
pindex->hash != consensusparams.BIP16Exception) // this block isn't the historical exception
|
||||
pindex->phashBlock == nullptr || // this is a new candidate block, eg from TestBlockValidity()
|
||||
*pindex->phashBlock != consensusparams.BIP16Exception) // this block isn't the historical exception
|
||||
{
|
||||
flags |= SCRIPT_VERIFY_P2SH;
|
||||
}
|
||||
@@ -1766,7 +1767,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
assert(pindex);
|
||||
assert(pindex->hash == block.GetHash());
|
||||
assert(*pindex->phashBlock == block.GetHash());
|
||||
int64_t nTimeStart = GetTimeMicros();
|
||||
|
||||
// Check it again in case a previous version let a bad block in
|
||||
@@ -1822,9 +1823,9 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||
// relative to a piece of software is an objective fact these defaults can be easily reviewed.
|
||||
// This setting doesn't force the selection of any particular chain but makes validating some faster by
|
||||
// effectively caching the result of part of the verification.
|
||||
auto it = mapBlockIndex.find(hashAssumeValid);
|
||||
BlockMap::const_iterator it = mapBlockIndex.find(hashAssumeValid);
|
||||
if (it != mapBlockIndex.end()) {
|
||||
if ((*it)->GetAncestor(pindex->nHeight) == pindex &&
|
||||
if (it->second->GetAncestor(pindex->nHeight) == pindex &&
|
||||
pindexBestHeader->GetAncestor(pindex->nHeight) == pindex &&
|
||||
pindexBestHeader->nChainWork >= nMinimumChainWork) {
|
||||
// This block is a member of the assumed verified chain and an ancestor of the best header.
|
||||
@@ -2059,15 +2060,15 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||
// TODO: if the "just check" flag is set, we should reduce the work done here. Incrementing blocks twice per mine is not efficient.
|
||||
assert(trieCache.incrementBlock());
|
||||
|
||||
int64_t nTime3 = GetTimeMicros(); nTimeConnect += nTime3 - nTime2;
|
||||
LogPrint(BCLog::BENCH, " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs (%.2fms/blk)]\n", (unsigned)block.vtx.size(), MILLI * (nTime3 - nTime2), MILLI * (nTime3 - nTime2) / block.vtx.size(), nInputs <= 1 ? 0 : MILLI * (nTime3 - nTime2) / (nInputs-1), nTimeConnect * MICRO, nTimeConnect * MILLI / nBlocksTotal);
|
||||
|
||||
if (trieCache.getMerkleHash() != block.hashClaimTrie) {
|
||||
return state.DoS(100, error("ConnectBlock() : the merkle root of the claim trie does not match "
|
||||
"(actual=%s vs block=%s on height=%d)", trieCache.getMerkleHash().GetHex(),
|
||||
block.hashClaimTrie.GetHex(), pindex->nHeight), REJECT_INVALID, "bad-claim-merkle-hash");
|
||||
}
|
||||
|
||||
int64_t nTime3 = GetTimeMicros(); nTimeConnect += nTime3 - nTime2;
|
||||
LogPrint(BCLog::BENCH, " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs (%.2fms/blk)]\n", (unsigned)block.vtx.size(), MILLI * (nTime3 - nTime2), MILLI * (nTime3 - nTime2) / block.vtx.size(), nInputs <= 1 ? 0 : MILLI * (nTime3 - nTime2) / (nInputs-1), nTimeConnect * MICRO, nTimeConnect * MILLI / nBlocksTotal);
|
||||
|
||||
CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus());
|
||||
if (block.vtx[0]->GetValueOut() > blockReward)
|
||||
return state.DoS(100,
|
||||
@@ -2077,8 +2078,8 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||
|
||||
if (!control.Wait())
|
||||
return state.DoS(100, error("%s: CheckQueue failed", __func__), REJECT_INVALID, "block-validation-failed");
|
||||
int64_t nTime4 = GetTimeMicros(); nTimeVerify += nTime4 - nTime3;
|
||||
LogPrint(BCLog::BENCH, " - Verify %u txins: %.2fms (%.3fms/txin) [%.2fs (%.2fms/blk)]\n", nInputs - 1, MILLI * (nTime4 - nTime3), nInputs <= 1 ? 0 : MILLI * (nTime4 - nTime3) / (nInputs-1), nTimeVerify * MICRO, nTimeVerify * MILLI / nBlocksTotal);
|
||||
int64_t nTime4 = GetTimeMicros(); nTimeVerify += nTime4 - nTime2;
|
||||
LogPrint(BCLog::BENCH, " - Verify %u txins: %.2fms (%.3fms/txin) [%.2fs (%.2fms/blk)]\n", nInputs - 1, MILLI * (nTime4 - nTime2), nInputs <= 1 ? 0 : MILLI * (nTime4 - nTime2) / (nInputs-1), nTimeVerify * MICRO, nTimeVerify * MILLI / nBlocksTotal);
|
||||
|
||||
if (fJustCheck)
|
||||
return true;
|
||||
@@ -2095,7 +2096,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||
setDirtyBlockIndex.insert(pindex);
|
||||
}
|
||||
|
||||
assert(!pindex->hash.IsNull());
|
||||
assert(pindex->phashBlock);
|
||||
// add this block to the view's block chain
|
||||
view.SetBestBlock(pindex->GetBlockHash());
|
||||
|
||||
@@ -2117,8 +2118,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||
* If FlushStateMode::NONE is used, then FlushStateToDisk(...) won't do anything
|
||||
* besides checking if we need to prune.
|
||||
*/
|
||||
bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &state,
|
||||
FlushStateMode mode, int nManualPruneHeight, bool syncToDisk) {
|
||||
bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &state, FlushStateMode mode, int nManualPruneHeight) {
|
||||
int64_t nMempoolUsage = mempool.DynamicMemoryUsage();
|
||||
LOCK(cs_main);
|
||||
static int64_t nLastWrite = 0;
|
||||
@@ -2187,7 +2187,7 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
|
||||
vBlocks.push_back(*it);
|
||||
setDirtyBlockIndex.erase(it++);
|
||||
}
|
||||
if (!pblocktree->BatchWrite(vFiles, nLastBlockFile, vBlocks, syncToDisk)) {
|
||||
if (!pblocktree->BatchWrite(vFiles, nLastBlockFile, vBlocks, mode == FlushStateMode::ALWAYS)) {
|
||||
return AbortNode(state, "Failed to write to block index database");
|
||||
}
|
||||
}
|
||||
@@ -2205,10 +2205,10 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
|
||||
// overwrite one. Still, use a conservative safety factor of 2.
|
||||
if (!CheckDiskSpace(48 * 2 * 2 * pcoinsTip->GetCacheSize()))
|
||||
return state.Error("out of disk space");
|
||||
if (syncToDisk && !pclaimTrie->SyncToDisk())
|
||||
LogPrintf("Failed to sync claim trie database to disk");
|
||||
if (mode == FlushStateMode::ALWAYS && !pclaimTrie->SyncToDisk())
|
||||
return state.Error("Failed to write to claim trie database");
|
||||
// Flush the chainstate (which may refer to block index entries).
|
||||
if (!pcoinsTip->Flush(syncToDisk))
|
||||
if (!pcoinsTip->Flush(mode == FlushStateMode::ALWAYS))
|
||||
return AbortNode(state, "Failed to write to coin database");
|
||||
nLastFlush = nNow;
|
||||
full_flush_completed = true;
|
||||
@@ -2225,10 +2225,10 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
|
||||
return true;
|
||||
}
|
||||
|
||||
void FlushStateToDisk(bool diskSync) {
|
||||
void FlushStateToDisk() {
|
||||
CValidationState state;
|
||||
const CChainParams& chainparams = Params();
|
||||
if (!FlushStateToDisk(chainparams, state, FlushStateMode::ALWAYS, 0, diskSync)) {
|
||||
if (!FlushStateToDisk(chainparams, state, FlushStateMode::ALWAYS)) {
|
||||
LogPrintf("%s: failed to flush state (%s)\n", __func__, FormatStateMessage(state));
|
||||
}
|
||||
}
|
||||
@@ -2355,7 +2355,7 @@ bool CChainState::DisconnectTip(CValidationState& state, const CChainParams& cha
|
||||
assert(pindexDelete->pprev->hashClaimTrie == trieCache.getMerkleHash());
|
||||
}
|
||||
LogPrint(BCLog::BENCH, "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * MILLI);
|
||||
// Write the chain state to disk, if necessary, to keep RAM usage down
|
||||
// Write the chain state to disk, if necessary.
|
||||
if (!FlushStateToDisk(chainparams, state, FlushStateMode::IF_NEEDED))
|
||||
return false;
|
||||
|
||||
@@ -2502,7 +2502,7 @@ bool CChainState::ConnectTip(CValidationState& state, const CChainParams& chainp
|
||||
}
|
||||
int64_t nTime4 = GetTimeMicros(); nTimeFlush += nTime4 - nTime3;
|
||||
LogPrint(BCLog::BENCH, " - Flush: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime4 - nTime3) * MILLI, nTimeFlush * MICRO, nTimeFlush * MILLI / nBlocksTotal);
|
||||
// Write the chain state to disk, if necessary, to keep memory usage down
|
||||
// Write the chain state to disk, if necessary.
|
||||
if (!FlushStateToDisk(chainparams, state, FlushStateMode::IF_NEEDED))
|
||||
return false;
|
||||
int64_t nTime5 = GetTimeMicros(); nTimeChainState += nTime5 - nTime4;
|
||||
@@ -2532,7 +2532,7 @@ CBlockIndex* CChainState::FindMostWorkChain() {
|
||||
|
||||
// Find the best candidate header.
|
||||
{
|
||||
auto it = setBlockIndexCandidates.rbegin();
|
||||
std::set<CBlockIndex*, CBlockIndexWorkComparator>::reverse_iterator it = setBlockIndexCandidates.rbegin();
|
||||
if (it == setBlockIndexCandidates.rend())
|
||||
return nullptr;
|
||||
pindexNew = *it;
|
||||
@@ -2709,7 +2709,7 @@ static void NotifyHeaderTip() LOCKS_EXCLUDED(cs_main) {
|
||||
* we avoid holding cs_main for an extended period of time; the length of this
|
||||
* call may be quite long during reindexing or a substantial reorg.
|
||||
*/
|
||||
bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock, bool lastInBatch) {
|
||||
bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock) {
|
||||
// Note that while we're often called here from ProcessNewBlock, this is
|
||||
// far from a guarantee. Things in the P2P/RPC will often end up calling
|
||||
// us in the middle of ProcessNewBlock - do not assume pblock is set
|
||||
@@ -2767,31 +2767,20 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
|
||||
pindexMostWork = nullptr;
|
||||
}
|
||||
pindexNewTip = chainActive.Tip();
|
||||
auto wantsAnotherRound = !pindexNewTip || (starting_tip && CBlockIndexWorkComparator()(pindexNewTip, starting_tip));
|
||||
|
||||
// flush before we send any signals:
|
||||
auto flushMode = !lastInBatch || !blocks_connected || IsInitialBlockDownload() ? FlushStateMode::IF_NEEDED : FlushStateMode::ALWAYS;
|
||||
auto diskSync = chainparams.NetworkIDString() != CBaseChainParams::REGTEST
|
||||
&& flushMode == FlushStateMode::ALWAYS && !wantsAnotherRound && pindexNewTip == pindexMostWork;
|
||||
if (!FlushStateToDisk(chainparams, state, flushMode, 0, diskSync))
|
||||
return error("Unable to flush after ActivateBestChainStep");
|
||||
|
||||
for (const PerBlockConnectTrace& trace : connectTrace.GetBlocksConnected()) {
|
||||
assert(trace.pblock && trace.pindex);
|
||||
GetMainSignals().BlockConnected(trace.pblock, trace.pindex, trace.conflictedTxs);
|
||||
}
|
||||
|
||||
if (!wantsAnotherRound)
|
||||
break;
|
||||
} while (true);
|
||||
} while (!chainActive.Tip() || (starting_tip && CBlockIndexWorkComparator()(chainActive.Tip(), starting_tip)));
|
||||
if (!blocks_connected) return true;
|
||||
|
||||
const CBlockIndex* pindexFork = chainActive.FindFork(starting_tip);
|
||||
bool fInitialDownload = IsInitialBlockDownload();
|
||||
|
||||
// Notify external listeners about the new tip.
|
||||
// Enqueue while holding cs_main to ensure that UpdatedBlockTip is called in the order in which blocks are connected
|
||||
if (pindexFork != pindexNewTip) {
|
||||
bool fInitialDownload = IsInitialBlockDownload();
|
||||
// Notify ValidationInterface subscribers
|
||||
GetMainSignals().UpdatedBlockTip(pindexNewTip, pindexFork, fInitialDownload);
|
||||
|
||||
@@ -2813,7 +2802,15 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
|
||||
|
||||
auto& consensus = chainparams.GetConsensus();
|
||||
CheckBlockIndex(consensus);
|
||||
return true;
|
||||
|
||||
auto flushMode = FlushStateMode::PERIODIC;
|
||||
if (pindexNewTip && chainparams.NetworkIDString() != CBaseChainParams::REGTEST
|
||||
&& pindexNewTip->nTime + consensus.nPowTargetSpacing > GetAdjustedTime()) {
|
||||
// trying to ensure that we flush to disk after new blocks when we're caught up to the chain
|
||||
// they're technically allowed to be two hours late, but experience says one minute is more likely
|
||||
flushMode = FlushStateMode::ALWAYS;
|
||||
}
|
||||
return FlushStateToDisk(chainparams, state, flushMode);
|
||||
}
|
||||
|
||||
bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock) {
|
||||
@@ -2899,12 +2896,12 @@ bool CChainState::InvalidateBlock(CValidationState& state, const CChainParams& c
|
||||
|
||||
// The resulting new best tip may not be in setBlockIndexCandidates anymore, so
|
||||
// add it again.
|
||||
auto it = mapBlockIndex.begin();
|
||||
BlockMap::iterator it = mapBlockIndex.begin();
|
||||
while (it != mapBlockIndex.end()) {
|
||||
if ((*it)->IsValid(BLOCK_VALID_TRANSACTIONS) && (*it)->nChainTx && !setBlockIndexCandidates.value_comp()(*it, chainActive.Tip())) {
|
||||
setBlockIndexCandidates.insert(*it);
|
||||
if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->nChainTx && !setBlockIndexCandidates.value_comp()(it->second, chainActive.Tip())) {
|
||||
setBlockIndexCandidates.insert(it->second);
|
||||
}
|
||||
++it;
|
||||
it++;
|
||||
}
|
||||
|
||||
InvalidChainFound(pindex);
|
||||
@@ -2925,21 +2922,21 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
|
||||
int nHeight = pindex->nHeight;
|
||||
|
||||
// Remove the invalidity flag from this block and all its descendants.
|
||||
auto it = mapBlockIndex.begin();
|
||||
BlockMap::iterator it = mapBlockIndex.begin();
|
||||
while (it != mapBlockIndex.end()) {
|
||||
if (!(*it)->IsValid() && (*it)->GetAncestor(nHeight) == pindex) {
|
||||
(*it)->nStatus &= ~BLOCK_FAILED_MASK;
|
||||
setDirtyBlockIndex.insert(*it);
|
||||
if ((*it)->IsValid(BLOCK_VALID_TRANSACTIONS) && (*it)->nChainTx && setBlockIndexCandidates.value_comp()(chainActive.Tip(), *it)) {
|
||||
setBlockIndexCandidates.insert(*it);
|
||||
if (!it->second->IsValid() && it->second->GetAncestor(nHeight) == pindex) {
|
||||
it->second->nStatus &= ~BLOCK_FAILED_MASK;
|
||||
setDirtyBlockIndex.insert(it->second);
|
||||
if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->nChainTx && setBlockIndexCandidates.value_comp()(chainActive.Tip(), it->second)) {
|
||||
setBlockIndexCandidates.insert(it->second);
|
||||
}
|
||||
if (*it == pindexBestInvalid) {
|
||||
if (it->second == pindexBestInvalid) {
|
||||
// Reset invalid block marker if it was pointing to one of those.
|
||||
pindexBestInvalid = nullptr;
|
||||
}
|
||||
m_failed_blocks.erase(*it);
|
||||
m_failed_blocks.erase(it->second);
|
||||
}
|
||||
++it;
|
||||
it++;
|
||||
}
|
||||
|
||||
// Remove the invalidity flag from all ancestors too.
|
||||
@@ -2963,9 +2960,9 @@ CBlockIndex* CChainState::AddToBlockIndex(const CBlockHeader& block)
|
||||
|
||||
// Check for duplicate
|
||||
uint256 hash = block.GetHash();
|
||||
auto it = mapBlockIndex.find(hash);
|
||||
BlockMap::iterator it = mapBlockIndex.find(hash);
|
||||
if (it != mapBlockIndex.end())
|
||||
return *it;
|
||||
return it->second;
|
||||
|
||||
// Construct new block index object
|
||||
CBlockIndex* pindexNew = new CBlockIndex(block);
|
||||
@@ -2973,11 +2970,12 @@ CBlockIndex* CChainState::AddToBlockIndex(const CBlockHeader& block)
|
||||
// to avoid miners withholding blocks but broadcasting headers, to get a
|
||||
// competitive advantage.
|
||||
pindexNew->nSequenceId = 0;
|
||||
mapBlockIndex.insert(pindexNew);
|
||||
BlockMap::iterator mi = mapBlockIndex.insert(std::make_pair(hash, pindexNew)).first;
|
||||
pindexNew->phashBlock = &((*mi).first);
|
||||
BlockMap::iterator miPrev = mapBlockIndex.find(block.hashPrevBlock);
|
||||
if (miPrev != mapBlockIndex.end())
|
||||
{
|
||||
pindexNew->pprev = *miPrev;
|
||||
pindexNew->pprev = (*miPrev).second;
|
||||
pindexNew->nHeight = pindexNew->pprev->nHeight + 1;
|
||||
pindexNew->BuildSkip();
|
||||
}
|
||||
@@ -3049,8 +3047,7 @@ static bool FindBlockPos(CDiskBlockPos &pos, unsigned int nAddSize, unsigned int
|
||||
}
|
||||
|
||||
if (!fKnown) {
|
||||
const static int64_t maxBlockfileSize = std::max<int64_t>(BLOCKFILE_CHUNK_SIZE, gArgs.GetArg("-maxblockfilesize", DEFAULT_MAX_BLOCKFILE_SIZE >> 20U) << 20U);
|
||||
while (vinfoBlockFile[nFile].nSize + nAddSize >= maxBlockfileSize) {
|
||||
while (vinfoBlockFile[nFile].nSize + nAddSize >= MAX_BLOCKFILE_SIZE) {
|
||||
nFile++;
|
||||
if (vinfoBlockFile.size() <= nFile) {
|
||||
vinfoBlockFile.resize(nFile + 1);
|
||||
@@ -3408,12 +3405,12 @@ bool CChainState::AcceptBlockHeader(const CBlockHeader& block, CValidationState&
|
||||
AssertLockHeld(cs_main);
|
||||
// Check for duplicate
|
||||
uint256 hash = block.GetHash();
|
||||
auto miSelf = mapBlockIndex.find(hash);
|
||||
BlockMap::iterator miSelf = mapBlockIndex.find(hash);
|
||||
CBlockIndex *pindex = nullptr;
|
||||
if (hash != chainparams.GetConsensus().hashGenesisBlock) {
|
||||
if (miSelf != mapBlockIndex.end()) {
|
||||
// Block header is already known.
|
||||
pindex = *miSelf;
|
||||
pindex = miSelf->second;
|
||||
if (ppindex)
|
||||
*ppindex = pindex;
|
||||
if (pindex->nStatus & BLOCK_FAILED_MASK)
|
||||
@@ -3426,10 +3423,10 @@ bool CChainState::AcceptBlockHeader(const CBlockHeader& block, CValidationState&
|
||||
|
||||
// Get prev block index
|
||||
CBlockIndex* pindexPrev = nullptr;
|
||||
auto mi = mapBlockIndex.find(block.hashPrevBlock);
|
||||
BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock);
|
||||
if (mi == mapBlockIndex.end())
|
||||
return state.DoS(10, error("%s: prev block not found", __func__), 0, "prev-blk-not-found");
|
||||
pindexPrev = *mi;
|
||||
pindexPrev = (*mi).second;
|
||||
if (pindexPrev->nStatus & BLOCK_FAILED_MASK)
|
||||
return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk");
|
||||
if (!ContextualCheckBlockHeader(block, state, chainparams, pindexPrev, GetAdjustedTime()))
|
||||
@@ -3584,7 +3581,7 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CVali
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool *fNewBlock, bool lastInBatch)
|
||||
bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool *fNewBlock)
|
||||
{
|
||||
AssertLockNotHeld(cs_main);
|
||||
|
||||
@@ -3611,7 +3608,7 @@ bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<cons
|
||||
NotifyHeaderTip();
|
||||
|
||||
CValidationState state; // Only used to report errors, not invalidity - ignore it
|
||||
if (!g_chainstate.ActivateBestChain(state, chainparams, pblock, lastInBatch)) {
|
||||
if (!g_chainstate.ActivateBestChain(state, chainparams, pblock)) {
|
||||
return error("%s: ActivateBestChain failed (%s)", __func__, FormatStateMessage(state));
|
||||
}
|
||||
|
||||
@@ -3624,9 +3621,11 @@ bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams,
|
||||
assert(pindexPrev && pindexPrev == chainActive.Tip());
|
||||
CCoinsViewCache viewNew(pcoinsTip.get());
|
||||
CClaimTrieCache trieCache(pclaimTrie);
|
||||
uint256 block_hash(block.GetHash());
|
||||
CBlockIndex indexDummy(block);
|
||||
indexDummy.pprev = pindexPrev;
|
||||
indexDummy.nHeight = pindexPrev->nHeight + 1;
|
||||
indexDummy.phashBlock = &block_hash;
|
||||
|
||||
// NOTE: CheckBlockHeader is called by CheckBlock
|
||||
if (!ContextualCheckBlockHeader(block, state, chainparams, pindexPrev, GetAdjustedTime()))
|
||||
@@ -3663,8 +3662,8 @@ void PruneOneBlockFile(const int fileNumber)
|
||||
{
|
||||
LOCK(cs_LastBlockFile);
|
||||
|
||||
for (const auto& entry : g_chainstate.mapBlockIndex) {
|
||||
CBlockIndex* pindex = entry;
|
||||
for (const auto& entry : mapBlockIndex) {
|
||||
CBlockIndex* pindex = entry.second;
|
||||
if (pindex->nFile == fileNumber) {
|
||||
pindex->nStatus &= ~BLOCK_HAVE_DATA;
|
||||
pindex->nStatus &= ~BLOCK_HAVE_UNDO;
|
||||
@@ -3858,17 +3857,18 @@ CBlockIndex * CChainState::InsertBlockIndex(const uint256& hash)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
// Return existing
|
||||
auto mi = mapBlockIndex.find(hash);
|
||||
if (mi != mapBlockIndex.end())
|
||||
return *mi;
|
||||
|
||||
if (hash.IsNull())
|
||||
return nullptr;
|
||||
|
||||
// Return existing
|
||||
BlockMap::iterator mi = mapBlockIndex.find(hash);
|
||||
if (mi != mapBlockIndex.end())
|
||||
return (*mi).second;
|
||||
|
||||
// Create new
|
||||
CBlockIndex* pindexNew = new CBlockIndex(hash);
|
||||
mapBlockIndex.insert(pindexNew);
|
||||
CBlockIndex* pindexNew = new CBlockIndex();
|
||||
mi = mapBlockIndex.insert(std::make_pair(hash, pindexNew)).first;
|
||||
pindexNew->phashBlock = &((*mi).first);
|
||||
|
||||
return pindexNew;
|
||||
}
|
||||
@@ -3883,8 +3883,9 @@ bool CChainState::LoadBlockIndex(const Consensus::Params& consensus_params, CBlo
|
||||
// Calculate nChainWork
|
||||
std::vector<std::pair<int, CBlockIndex*> > vSortedByHeight;
|
||||
vSortedByHeight.reserve(mapBlockIndex.size());
|
||||
for (const auto& pindex : mapBlockIndex)
|
||||
for (const std::pair<const uint256, CBlockIndex*>& item : mapBlockIndex)
|
||||
{
|
||||
CBlockIndex* pindex = item.second;
|
||||
vSortedByHeight.push_back(std::make_pair(pindex->nHeight, pindex));
|
||||
}
|
||||
sort(vSortedByHeight.begin(), vSortedByHeight.end());
|
||||
@@ -3949,13 +3950,14 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams) EXCLUSIVE_LOCKS_RE
|
||||
// Check presence of blk files
|
||||
LogPrintf("Checking all blk files are present...\n");
|
||||
std::set<int> setBlkDataFiles;
|
||||
for (const auto& pindex : g_chainstate.mapBlockIndex)
|
||||
for (const std::pair<const uint256, CBlockIndex*>& item : mapBlockIndex)
|
||||
{
|
||||
CBlockIndex* pindex = item.second;
|
||||
if (pindex->nStatus & BLOCK_HAVE_DATA) {
|
||||
setBlkDataFiles.insert(pindex->nFile);
|
||||
}
|
||||
}
|
||||
for (auto it = setBlkDataFiles.begin(); it != setBlkDataFiles.end(); ++it)
|
||||
for (std::set<int>::iterator it = setBlkDataFiles.begin(); it != setBlkDataFiles.end(); it++)
|
||||
{
|
||||
CDiskBlockPos pos(*it, 0);
|
||||
if (CAutoFile(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION).IsNull()) {
|
||||
@@ -3982,7 +3984,7 @@ bool LoadChainTip(const CChainParams& chainparams)
|
||||
|
||||
if (chainActive.Tip() && chainActive.Tip()->GetBlockHash() == pcoinsTip->GetBestBlock()) return true;
|
||||
|
||||
if (pcoinsTip->GetBestBlock().IsNull() && g_chainstate.mapBlockIndex.size() == 1) {
|
||||
if (pcoinsTip->GetBestBlock().IsNull() && mapBlockIndex.size() == 1) {
|
||||
// In case we just added the genesis block, connect it now, so
|
||||
// that we always have a chainActive.Tip() when we return.
|
||||
LogPrintf("%s: Connecting genesis block...\n", __func__);
|
||||
@@ -4137,7 +4139,10 @@ bool CChainState::RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& i
|
||||
|
||||
bool CChainState::ReplayBlocks(const CChainParams& params, CCoinsView* view)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
LOCK(cs_main);
|
||||
|
||||
CCoinsViewCache cache(view);
|
||||
CClaimTrieCache trieCache(pclaimTrie);
|
||||
|
||||
std::vector<uint256> hashHeads = view->GetHeadBlocks();
|
||||
if (hashHeads.empty()) return true; // We're already in a consistent state.
|
||||
@@ -4150,25 +4155,20 @@ bool CChainState::ReplayBlocks(const CChainParams& params, CCoinsView* view)
|
||||
const CBlockIndex* pindexNew; // New tip during the interrupted flush.
|
||||
const CBlockIndex* pindexFork = nullptr; // Latest block common to both the old and the new tip.
|
||||
|
||||
auto it = mapBlockIndex.find(hashHeads[0]);
|
||||
if (it == mapBlockIndex.end()) {
|
||||
if (mapBlockIndex.count(hashHeads[0]) == 0) {
|
||||
return error("ReplayBlocks(): reorganization to unknown block requested");
|
||||
}
|
||||
pindexNew = *it;
|
||||
pindexNew = mapBlockIndex[hashHeads[0]];
|
||||
|
||||
if (!hashHeads[1].IsNull()) { // The old tip is allowed to be 0, indicating it's the first flush.
|
||||
it = mapBlockIndex.find(hashHeads[1]);
|
||||
if (it == mapBlockIndex.end()) {
|
||||
if (mapBlockIndex.count(hashHeads[1]) == 0) {
|
||||
return error("ReplayBlocks(): reorganization from unknown block requested");
|
||||
}
|
||||
pindexOld = *it;
|
||||
pindexOld = mapBlockIndex[hashHeads[1]];
|
||||
pindexFork = LastCommonAncestor(pindexOld, pindexNew);
|
||||
assert(pindexFork != nullptr);
|
||||
}
|
||||
|
||||
CCoinsViewCache cache(view);
|
||||
CClaimTrieCache trieCache(pclaimTrie);
|
||||
|
||||
// Rollback along the old branch.
|
||||
while (pindexOld != pindexFork) {
|
||||
if (pindexOld->nHeight > 0) { // Never disconnect the genesis block.
|
||||
@@ -4250,7 +4250,8 @@ bool CChainState::RewindBlockIndex(const CChainParams& params)
|
||||
// Reduce validity flag and have-data flags.
|
||||
// We do this after actual disconnecting, otherwise we'll end up writing the lack of data
|
||||
// to disk before writing the chainstate, resulting in a failure to continue if interrupted.
|
||||
for (const auto& pindexIter : mapBlockIndex) {
|
||||
for (const auto& entry : mapBlockIndex) {
|
||||
CBlockIndex* pindexIter = entry.second;
|
||||
|
||||
// Note: If we encounter an insufficiently validated block that
|
||||
// is on chainActive, it must be because we are a pruning node, and
|
||||
@@ -4343,10 +4344,10 @@ void UnloadBlockIndex()
|
||||
warningcache[b].clear();
|
||||
}
|
||||
|
||||
for (auto& entry : g_chainstate.mapBlockIndex) {
|
||||
delete entry;
|
||||
for (BlockMap::value_type& entry : mapBlockIndex) {
|
||||
delete entry.second;
|
||||
}
|
||||
g_chainstate.mapBlockIndex.clear();
|
||||
mapBlockIndex.clear();
|
||||
fHavePruned = false;
|
||||
|
||||
g_chainstate.UnloadBlockIndex();
|
||||
@@ -4359,10 +4360,10 @@ bool LoadBlockIndex(const CChainParams& chainparams)
|
||||
if (!fReindex) {
|
||||
bool ret = LoadBlockIndexDB(chainparams);
|
||||
if (!ret) return false;
|
||||
needs_init = g_chainstate.mapBlockIndex.empty();
|
||||
needs_init = mapBlockIndex.empty();
|
||||
|
||||
if (needs_init) {
|
||||
auto& blockDir = GetBlocksDir();
|
||||
auto blockDir = GetDataDir() / "blocks";
|
||||
for (auto it: fs::directory_iterator(blockDir)) {
|
||||
boost::system::error_code ec;
|
||||
if (fs::file_size(it, ec) > 100000000) {
|
||||
@@ -4392,7 +4393,7 @@ bool CChainState::LoadGenesisBlock(const CChainParams& chainparams)
|
||||
// mapBlockIndex. Note that we can't use chainActive here, since it is
|
||||
// set based on the coins db, not the block index db, which is the only
|
||||
// thing loaded at this point.
|
||||
if (mapBlockIndex.find(chainparams.GenesisBlock().GetHash()) != mapBlockIndex.end())
|
||||
if (mapBlockIndex.count(chainparams.GenesisBlock().GetHash()))
|
||||
return true;
|
||||
|
||||
try {
|
||||
@@ -4555,7 +4556,7 @@ void CChainState::CheckBlockIndex(const Consensus::Params& consensusParams)
|
||||
// Build forward-pointing map of the entire block tree.
|
||||
std::multimap<CBlockIndex*,CBlockIndex*> forward;
|
||||
for (auto& entry : mapBlockIndex) {
|
||||
forward.insert(std::make_pair(entry->pprev, entry));
|
||||
forward.insert(std::make_pair(entry.second->pprev, entry.second));
|
||||
}
|
||||
|
||||
assert(forward.size() == mapBlockIndex.size());
|
||||
@@ -4898,21 +4899,15 @@ double GuessVerificationProgress(const ChainTxData& data, const CBlockIndex *pin
|
||||
return pindex->nChainTx / fTxTotal;
|
||||
}
|
||||
|
||||
CBlockIndex *LookupBlockIndex(const uint256 &hash) {
|
||||
AssertLockHeld(cs_main);
|
||||
auto it = g_chainstate.mapBlockIndex.find(hash);
|
||||
return it == g_chainstate.mapBlockIndex.end() ? nullptr : *it;
|
||||
}
|
||||
|
||||
class CMainCleanup
|
||||
{
|
||||
public:
|
||||
CMainCleanup() {}
|
||||
~CMainCleanup() {
|
||||
// block headers
|
||||
auto it1 = g_chainstate.mapBlockIndex.begin();
|
||||
for (; it1 != g_chainstate.mapBlockIndex.end(); ++it1)
|
||||
delete *it1;
|
||||
g_chainstate.mapBlockIndex.clear();
|
||||
BlockMap::iterator it1 = mapBlockIndex.begin();
|
||||
for (; it1 != mapBlockIndex.end(); it1++)
|
||||
delete (*it1).second;
|
||||
mapBlockIndex.clear();
|
||||
}
|
||||
} instance_of_cmaincleanup;
|
||||
+19
-33
@@ -17,7 +17,6 @@
|
||||
#include <nameclaim.h>
|
||||
#include <protocol.h> // For CMessageHeader::MessageStartChars
|
||||
#include <policy/feerate.h>
|
||||
#include <primitives/robin_hood.h>
|
||||
#include <script/script_error.h>
|
||||
#include <sync.h>
|
||||
#include <txmempool.h>
|
||||
@@ -75,9 +74,9 @@ static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 336;
|
||||
/** Maximum kilobytes for transactions to store for processing during reorg */
|
||||
static const unsigned int MAX_DISCONNECTED_TX_POOL_SIZE = 20000;
|
||||
/** The maximum size of a blk?????.dat file (since 0.8) */
|
||||
static const unsigned int DEFAULT_MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
|
||||
static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
|
||||
/** The pre-allocation chunk size for blk?????.dat files (since 0.8) */
|
||||
static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x800000; // 8 MiB
|
||||
static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
|
||||
/** The pre-allocation chunk size for rev?????.dat files (since 0.8) */
|
||||
static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
|
||||
|
||||
@@ -140,36 +139,18 @@ static const bool DEFAULT_PEERBLOOMFILTERS = true;
|
||||
/** Default for -stopatheight */
|
||||
static const int DEFAULT_STOPATHEIGHT = 0;
|
||||
|
||||
struct BlockHasher
|
||||
{
|
||||
size_t operator()(const uint256& hash) const { return GetCheapHash(hash); }
|
||||
};
|
||||
|
||||
extern CScript COINBASE_FLAGS;
|
||||
extern CCriticalSection cs_main;
|
||||
extern CBlockPolicyEstimator feeEstimator;
|
||||
extern CTxMemPool mempool;
|
||||
extern std::atomic_bool g_is_mempool_loaded;
|
||||
|
||||
struct BlockMapHasher {
|
||||
std::size_t operator()(const CBlockIndex* block) const {
|
||||
return robin_hood::hash_bytes(block->hash.begin(), block->hash.size());
|
||||
}
|
||||
};
|
||||
|
||||
struct BlockMapComparer {
|
||||
bool operator()(const CBlockIndex* a, const CBlockIndex* b) const {
|
||||
return a == b || a->hash == b->hash;
|
||||
}
|
||||
};
|
||||
|
||||
struct BlockMap : public robin_hood::unordered_set<CBlockIndex*, BlockMapHasher, BlockMapComparer> {
|
||||
inline iterator find(const uint256& blockHash) {
|
||||
CBlockIndex temp(blockHash);
|
||||
return robin_hood::unordered_set<CBlockIndex*, BlockMapHasher, BlockMapComparer>::find(&temp);
|
||||
}
|
||||
|
||||
inline const_iterator find(const uint256& blockHash) const {
|
||||
CBlockIndex temp(blockHash);
|
||||
return robin_hood::unordered_set<CBlockIndex*, BlockMapHasher, BlockMapComparer>::find(&temp);
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
|
||||
extern BlockMap& mapBlockIndex;
|
||||
extern uint64_t nLastBlockTx;
|
||||
extern uint64_t nLastBlockWeight;
|
||||
extern const std::string strMessageMagic;
|
||||
@@ -251,7 +232,7 @@ static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
|
||||
* @param[out] fNewBlock A boolean which is set to indicate if the block was first received via this call
|
||||
* @return True if state.IsValid()
|
||||
*/
|
||||
bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool* fNewBlock, bool lastInBatch=true) LOCKS_EXCLUDED(cs_main);
|
||||
bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool* fNewBlock) LOCKS_EXCLUDED(cs_main);
|
||||
|
||||
/**
|
||||
* Process incoming block headers.
|
||||
@@ -316,7 +297,7 @@ void PruneOneBlockFile(const int fileNumber);
|
||||
void UnlinkPrunedFiles(const std::set<int>& setFilesToPrune);
|
||||
|
||||
/** Flush all state, indexes and buffers to disk. */
|
||||
void FlushStateToDisk(bool diskSync = false);
|
||||
void FlushStateToDisk();
|
||||
/** Prune block files and flush state to disk. */
|
||||
void PruneAndFlush();
|
||||
/** Prune block files up to a given height */
|
||||
@@ -480,11 +461,11 @@ public:
|
||||
|
||||
bool LoadBlockIndex(const Consensus::Params& consensus_params, CBlockTreeDB& blocktree) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
|
||||
bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock, bool lastInBatch=true);
|
||||
bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock);
|
||||
|
||||
/**
|
||||
* If a block header hasn't already been seen, call CheckBlockHeader on it, ensure
|
||||
* that it doesn't descend from an invalid block, and then add it to mapBlockIndex.
|
||||
* that it doesn't descend from an invalid block, and then add it to mapBlockIndex.
|
||||
*/
|
||||
bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested, const CDiskBlockPos* dbp, bool* fNewBlock) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
@@ -616,7 +597,12 @@ public:
|
||||
/** Replay blocks that aren't fully applied to the database. */
|
||||
bool ReplayBlocks(const CChainParams& params, CCoinsView* view);
|
||||
|
||||
CBlockIndex* LookupBlockIndex(const uint256& hash);
|
||||
inline CBlockIndex* LookupBlockIndex(const uint256& hash)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
BlockMap::const_iterator it = mapBlockIndex.find(hash);
|
||||
return it == mapBlockIndex.end() ? nullptr : it->second;
|
||||
}
|
||||
|
||||
/** Find the last common block between the parameter chain and a locator. */
|
||||
CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator);
|
||||
|
||||
@@ -126,7 +126,7 @@ private:
|
||||
bool fDecryptionThoroughlyChecked;
|
||||
|
||||
protected:
|
||||
using CryptedKeyMap = std::unordered_map<CKeyID, std::pair<CPubKey, std::vector<unsigned char>>>;
|
||||
using CryptedKeyMap = std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char>>>;
|
||||
|
||||
bool SetCrypted();
|
||||
|
||||
|
||||
+4
-5
@@ -469,10 +469,10 @@ bool BerkeleyEnvironment::Salvage(const std::string& strFile, bool fAggressive,
|
||||
}
|
||||
|
||||
|
||||
void BerkeleyEnvironment::CheckpointLSN(const std::string& strFile, bool lsnReset)
|
||||
void BerkeleyEnvironment::CheckpointLSN(const std::string& strFile)
|
||||
{
|
||||
dbenv->txn_checkpoint(0, 0, 0);
|
||||
if (fMockDb || !lsnReset)
|
||||
if (fMockDb)
|
||||
return;
|
||||
dbenv->lsn_reset(strFile.c_str(), 0);
|
||||
}
|
||||
@@ -799,10 +799,9 @@ bool BerkeleyBatch::PeriodicFlush(BerkeleyDatabase& database)
|
||||
|
||||
// Flush wallet file so it's self contained
|
||||
env->CloseDb(strFile);
|
||||
// don't call lsn_reset at periodic time
|
||||
// it causes performace issues on big wallets
|
||||
env->CheckpointLSN(strFile, /* lsnReset */ false);
|
||||
env->CheckpointLSN(strFile);
|
||||
|
||||
env->mapFileUseCount.erase(mi++);
|
||||
LogPrint(BCLog::DB, "Flushed %s %dms\n", strFile, GetTimeMillis() - nStart);
|
||||
ret = true;
|
||||
}
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ public:
|
||||
bool Open(bool retry);
|
||||
void Close();
|
||||
void Flush(bool fShutdown);
|
||||
void CheckpointLSN(const std::string& strFile, bool lsnReset = true);
|
||||
void CheckpointLSN(const std::string& strFile);
|
||||
|
||||
void CloseDb(const std::string& strFile);
|
||||
void ReloadDbEnv();
|
||||
|
||||
+1
-1
@@ -245,7 +245,7 @@ void WalletInit::Start(CScheduler& scheduler) const
|
||||
}
|
||||
|
||||
// Run a thread to flush wallet periodically
|
||||
scheduler.scheduleEvery(MaybeCompactWalletDB, 1000);
|
||||
scheduler.scheduleEvery(MaybeCompactWalletDB, 500);
|
||||
}
|
||||
|
||||
void WalletInit::Flush() const
|
||||
|
||||
+26
-25
@@ -467,11 +467,15 @@ static UniValue getaddressesbyaccount(const JSONRPCRequest& request)
|
||||
static CTransactionRef SendMoney(CWallet * const pwallet, const CTxDestination &address, CAmount nValue,
|
||||
bool fSubtractFeeFromAmount, const CCoinControl& coin_control, mapValue_t mapValue, std::string fromAccount,
|
||||
const CScript& prefix = CScript()){
|
||||
CAmount curBalance = pwallet->GetBalance();
|
||||
|
||||
// Check amount
|
||||
if (nValue <= 0)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount");
|
||||
|
||||
if (nValue > curBalance)
|
||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
|
||||
|
||||
if (pwallet->GetBroadcastTransactions() && !g_connman) {
|
||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||
}
|
||||
@@ -489,7 +493,6 @@ static CTransactionRef SendMoney(CWallet * const pwallet, const CTxDestination &
|
||||
vecSend.push_back(recipient);
|
||||
CTransactionRef tx;
|
||||
if (!pwallet->CreateTransaction(vecSend, tx, reservekey, nFeeRequired, nChangePosRet, strError, coin_control)) {
|
||||
CAmount curBalance = pwallet->GetBalance();
|
||||
if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance)
|
||||
strError = strprintf("Error: This transaction requires a transaction fee of at least %s", FormatMoney(nFeeRequired));
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, strError);
|
||||
@@ -762,19 +765,23 @@ void ListNameClaims(const CWalletTx& wtx, CWallet* const pwallet, const std::str
|
||||
|
||||
CClaimTrieCache trieCache(pclaimTrie);
|
||||
|
||||
auto pindex = LookupBlockIndex(wtx.hashBlock);
|
||||
if (pindex)
|
||||
auto it = mapBlockIndex.find(wtx.hashBlock);
|
||||
if (it != mapBlockIndex.end())
|
||||
{
|
||||
entry.pushKV("height", pindex->nHeight);
|
||||
entry.pushKV("expiration height", pindex->nHeight + trieCache.expirationTime());
|
||||
if (pindex->nHeight + trieCache.expirationTime() > chainActive.Height())
|
||||
CBlockIndex* pindex = it->second;
|
||||
if (pindex)
|
||||
{
|
||||
entry.pushKV("expired", false);
|
||||
entry.pushKV("blocks to expiration", pindex->nHeight + trieCache.expirationTime() - chainActive.Height());
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.pushKV("expired", true);
|
||||
entry.pushKV("height", pindex->nHeight);
|
||||
entry.pushKV("expiration height", pindex->nHeight + trieCache.expirationTime());
|
||||
if (pindex->nHeight + trieCache.expirationTime() > chainActive.Height())
|
||||
{
|
||||
entry.pushKV("expired", false);
|
||||
entry.pushKV("blocks to expiration", pindex->nHeight + trieCache.expirationTime() - chainActive.Height());
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.pushKV("expired", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
entry.pushKV("confirmations", wtx.GetDepthInMainChain());
|
||||
@@ -1286,7 +1293,7 @@ static UniValue getreceivedbyaddress(const JSONRPCRequest& request)
|
||||
|
||||
// Tally
|
||||
CAmount nAmount = 0;
|
||||
for (const auto& pairWtx : pwallet->mapWallet) {
|
||||
for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
|
||||
const CWalletTx& wtx = pairWtx.second;
|
||||
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
|
||||
continue;
|
||||
@@ -1354,7 +1361,7 @@ static UniValue getreceivedbylabel(const JSONRPCRequest& request)
|
||||
|
||||
// Tally
|
||||
CAmount nAmount = 0;
|
||||
for (const auto& pairWtx : pwallet->mapWallet) {
|
||||
for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
|
||||
const CWalletTx& wtx = pairWtx.second;
|
||||
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
|
||||
continue;
|
||||
@@ -2138,7 +2145,7 @@ static UniValue ListReceived(CWallet * const pwallet, const UniValue& params, bo
|
||||
|
||||
// Tally
|
||||
std::map<CTxDestination, tallyitem> mapTally;
|
||||
for (const auto& pairWtx : pwallet->mapWallet) {
|
||||
for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
|
||||
const CWalletTx& wtx = pairWtx.second;
|
||||
|
||||
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
|
||||
@@ -2190,6 +2197,7 @@ static UniValue ListReceived(CWallet * const pwallet, const UniValue& params, bo
|
||||
for (auto item_it = start; item_it != end; ++item_it)
|
||||
{
|
||||
const CTxDestination& address = item_it->first;
|
||||
const std::string& label = item_it->second.name;
|
||||
auto it = mapTally.find(address);
|
||||
if (it == mapTally.end() && !fIncludeEmpty)
|
||||
continue;
|
||||
@@ -2204,7 +2212,6 @@ static UniValue ListReceived(CWallet * const pwallet, const UniValue& params, bo
|
||||
fIsWatchonly = (*it).second.fIsWatchonly;
|
||||
}
|
||||
|
||||
const std::string& label = item_it->second.name;
|
||||
if (by_label)
|
||||
{
|
||||
tallyitem& _item = label_tally[label];
|
||||
@@ -2222,7 +2229,6 @@ static UniValue ListReceived(CWallet * const pwallet, const UniValue& params, bo
|
||||
obj.pushKV("amount", ValueFromAmount(nAmount));
|
||||
obj.pushKV("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf));
|
||||
obj.pushKV("label", label);
|
||||
obj.pushKV("purpose", item_it->second.purpose);
|
||||
UniValue transactions(UniValue::VARR);
|
||||
if (it != mapTally.end())
|
||||
{
|
||||
@@ -2731,7 +2737,7 @@ static UniValue listaccounts(const JSONRPCRequest& request)
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& pairWtx : pwallet->mapWallet) {
|
||||
for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
|
||||
const CWalletTx& wtx = pairWtx.second;
|
||||
CAmount nFee;
|
||||
std::string strSentAccount;
|
||||
@@ -2869,7 +2875,7 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
|
||||
|
||||
UniValue transactions(UniValue::VARR);
|
||||
|
||||
for (const auto& pairWtx : pwallet->mapWallet) {
|
||||
for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
|
||||
CWalletTx tx = pairWtx.second;
|
||||
|
||||
if (depth == -1 || tx.GetDepthInMainChain() < depth) {
|
||||
@@ -3993,8 +3999,7 @@ static UniValue listunspent(const JSONRPCRequest& request)
|
||||
std::vector<COutput> vecOutputs;
|
||||
{
|
||||
LOCK2(cs_main, pwallet->cs_wallet);
|
||||
pwallet->AvailableCoins(vecOutputs, !include_unsafe, nullptr,
|
||||
nMinimumAmount, nMaximumAmount, nMinimumSumAmount, nMaximumCount, nMinDepth, nMaxDepth, true);
|
||||
pwallet->AvailableCoins(vecOutputs, !include_unsafe, nullptr, nMinimumAmount, nMaximumAmount, nMinimumSumAmount, nMaximumCount, nMinDepth, nMaxDepth);
|
||||
}
|
||||
|
||||
LOCK(pwallet->cs_wallet);
|
||||
@@ -4497,10 +4502,6 @@ UniValue generate(const JSONRPCRequest& request)
|
||||
);
|
||||
}
|
||||
|
||||
if (IsInitialBlockDownload()) {
|
||||
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "generate is not available during the initial block download");
|
||||
}
|
||||
|
||||
int num_generate = request.params[0].get_int();
|
||||
uint64_t max_tries = 1000000;
|
||||
if (!request.params[1].isNull()) {
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#ifndef BITCOIN_WALLET_RPCWALLET_H
|
||||
#define BITCOIN_WALLET_RPCWALLET_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class CRPCTable;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
@@ -11,6 +13,7 @@
|
||||
#include <test/test_bitcoin.h>
|
||||
#include <validation.h>
|
||||
#include <wallet/coincontrol.h>
|
||||
#include <wallet/test/wallet_test_fixture.h>
|
||||
#include <policy/policy.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
@@ -93,15 +96,6 @@ UniValue LookupAllNames() {
|
||||
return rpc_method(req);
|
||||
}
|
||||
|
||||
UniValue PruneAbandonFunds(const uint256& txid) {
|
||||
rpcfn_type rpc_method = tableRPC["removeprunedfunds"]->actor;
|
||||
JSONRPCRequest req;
|
||||
req.URI = "/wallet/tester_wallet";
|
||||
req.params = UniValue(UniValue::VARR);
|
||||
req.params.push_back(txid.GetHex());
|
||||
return rpc_method(req);
|
||||
}
|
||||
|
||||
std::vector<uint256> generateBlock(int blocks = 1) {
|
||||
rpcfn_type rpc_method = tableRPC["generate"]->actor;
|
||||
JSONRPCRequest req;
|
||||
@@ -131,7 +125,7 @@ void rollbackBlock(const std::vector<uint256>& ids) {
|
||||
}
|
||||
// totally weird that invalidateblock is async
|
||||
while (GetMainSignals().CallbacksPending())
|
||||
MilliSleep(5);
|
||||
usleep(5000);
|
||||
}
|
||||
|
||||
uint256 AbandonAClaim(const uint256& txid, bool isSupport = false) {
|
||||
@@ -497,17 +491,5 @@ BOOST_AUTO_TEST_CASE(can_claim_after_each_fork)
|
||||
BOOST_CHECK_EQUAL(looked.size(), 4U);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(remove_pruned_funds)
|
||||
{
|
||||
generateBlock(140);
|
||||
// claim a name
|
||||
auto txid = ClaimAName("tester", "deadbeef", "1.0");
|
||||
generateBlock();
|
||||
// abandon claim
|
||||
AbandonAClaim(txid);
|
||||
generateBlock();
|
||||
PruneAbandonFunds(txid);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
extern UniValue importmulti(const JSONRPCRequest& request);
|
||||
extern UniValue dumpwallet(const JSONRPCRequest& request);
|
||||
extern UniValue importwallet(const JSONRPCRequest& request);
|
||||
extern CChainState g_chainstate;
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup)
|
||||
|
||||
@@ -39,7 +38,7 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup)
|
||||
// Cap last block file size, and mine new block in a new block file.
|
||||
CBlockIndex* const nullBlock = nullptr;
|
||||
CBlockIndex* oldTip = chainActive.Tip();
|
||||
GetBlockFileInfo(oldTip->GetBlockPos().nFile)->nSize = DEFAULT_MAX_BLOCKFILE_SIZE;
|
||||
GetBlockFileInfo(oldTip->GetBlockPos().nFile)->nSize = MAX_BLOCKFILE_SIZE;
|
||||
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
|
||||
CBlockIndex* newTip = chainActive.Tip();
|
||||
|
||||
@@ -207,9 +206,12 @@ static int64_t AddTx(CWallet& wallet, uint32_t lockTime, int64_t mockTime, int64
|
||||
CBlockIndex* block = nullptr;
|
||||
if (blockTime > 0) {
|
||||
LOCK(cs_main);
|
||||
auto inserted = g_chainstate.mapBlockIndex.insert(new CBlockIndex(GetRandHash()));
|
||||
block = *inserted.first;
|
||||
auto inserted = mapBlockIndex.emplace(GetRandHash(), new CBlockIndex);
|
||||
assert(inserted.second);
|
||||
const uint256& hash = inserted.first->first;
|
||||
block = inserted.first->second;
|
||||
block->nTime = blockTime;
|
||||
block->phashBlock = &hash;
|
||||
}
|
||||
|
||||
CWalletTx wtx(&wallet, MakeTransactionRef(tx));
|
||||
|
||||
+132
-170
@@ -30,7 +30,7 @@
|
||||
#include <wallet/fees.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <assert.h>
|
||||
#include <future>
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
@@ -44,7 +44,7 @@ bool AddWallet(const std::shared_ptr<CWallet>& wallet)
|
||||
{
|
||||
LOCK(cs_wallets);
|
||||
assert(wallet);
|
||||
auto i = std::find(vpwallets.begin(), vpwallets.end(), wallet);
|
||||
std::vector<std::shared_ptr<CWallet>>::const_iterator i = std::find(vpwallets.begin(), vpwallets.end(), wallet);
|
||||
if (i != vpwallets.end()) return false;
|
||||
vpwallets.push_back(wallet);
|
||||
return true;
|
||||
@@ -54,7 +54,7 @@ bool RemoveWallet(const std::shared_ptr<CWallet>& wallet)
|
||||
{
|
||||
LOCK(cs_wallets);
|
||||
assert(wallet);
|
||||
auto i = std::find(vpwallets.begin(), vpwallets.end(), wallet);
|
||||
std::vector<std::shared_ptr<CWallet>>::iterator i = std::find(vpwallets.begin(), vpwallets.end(), wallet);
|
||||
if (i == vpwallets.end()) return false;
|
||||
vpwallets.erase(i);
|
||||
return true;
|
||||
@@ -92,8 +92,8 @@ static void ReleaseWallet(CWallet* wallet)
|
||||
// so that it's in sync with the current chainstate.
|
||||
wallet->WalletLogPrintf("Releasing wallet\n");
|
||||
wallet->BlockUntilSyncedToCurrentChain();
|
||||
UnregisterValidationInterface(wallet);
|
||||
wallet->Flush();
|
||||
UnregisterValidationInterface(wallet);
|
||||
delete wallet;
|
||||
// Wallet is now released, notify UnloadWallet, if any.
|
||||
{
|
||||
@@ -208,7 +208,7 @@ public:
|
||||
const CWalletTx* CWallet::GetWalletTx(const uint256& hash) const
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
auto it = mapWallet.find(hash);
|
||||
std::map<uint256, CWalletTx>::const_iterator it = mapWallet.find(hash);
|
||||
if (it == mapWallet.end())
|
||||
return nullptr;
|
||||
return &(it->second);
|
||||
@@ -560,23 +560,20 @@ std::set<uint256> CWallet::GetConflicts(const uint256& txid) const
|
||||
std::set<uint256> result;
|
||||
AssertLockHeld(cs_wallet);
|
||||
|
||||
auto it = mapWallet.find(txid);
|
||||
std::map<uint256, CWalletTx>::const_iterator it = mapWallet.find(txid);
|
||||
if (it == mapWallet.end())
|
||||
return result;
|
||||
const CWalletTx& wtx = it->second;
|
||||
|
||||
std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range;
|
||||
|
||||
for (const CTxIn& txin : wtx.tx->vin)
|
||||
{
|
||||
auto hitTx = mapTxSpends.find(txin.prevout.hash);
|
||||
if (hitTx == mapTxSpends.end())
|
||||
continue;
|
||||
auto hitN = hitTx->second.find(txin.prevout.n);
|
||||
if (hitN == hitTx->second.end())
|
||||
continue;
|
||||
if (hitN->second.size() <= 1U)
|
||||
if (mapTxSpends.count(txin.prevout) <= 1)
|
||||
continue; // No conflict if zero or one spends
|
||||
for (auto& spend: hitN->second)
|
||||
result.insert(spend);
|
||||
range = mapTxSpends.equal_range(txin.prevout);
|
||||
for (TxSpends::const_iterator _it = range.first; _it != range.second; ++_it)
|
||||
result.insert(_it->second);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -584,14 +581,8 @@ std::set<uint256> CWallet::GetConflicts(const uint256& txid) const
|
||||
bool CWallet::HasWalletSpend(const uint256& txid) const
|
||||
{
|
||||
AssertLockHeld(cs_wallet);
|
||||
auto hitTx = mapTxSpends.find(txid);
|
||||
if (hitTx == mapTxSpends.end())
|
||||
return false;
|
||||
for (auto& kvp: hitTx->second) {
|
||||
if (!kvp.second.empty())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
auto iter = mapTxSpends.lower_bound(COutPoint(txid, 0));
|
||||
return (iter != mapTxSpends.end() && iter->first.hash == txid);
|
||||
}
|
||||
|
||||
void CWallet::Flush(bool shutdown)
|
||||
@@ -599,7 +590,7 @@ void CWallet::Flush(bool shutdown)
|
||||
database->Flush(shutdown);
|
||||
}
|
||||
|
||||
void CWallet::SyncMetaData(const COutPoint& outPoint)
|
||||
void CWallet::SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator> range)
|
||||
{
|
||||
// We want all the wallet transactions in range to have the same metadata as
|
||||
// the oldest (smallest nOrderPos).
|
||||
@@ -607,43 +598,36 @@ void CWallet::SyncMetaData(const COutPoint& outPoint)
|
||||
|
||||
int nMinOrderPos = std::numeric_limits<int>::max();
|
||||
const CWalletTx* copyFrom = nullptr;
|
||||
|
||||
auto hitTx = mapTxSpends.find(outPoint.hash);
|
||||
if (hitTx != mapTxSpends.end()) {
|
||||
auto hitN = hitTx->second.find(outPoint.n);
|
||||
if (hitN != hitTx->second.end()) {
|
||||
for (auto &spend: hitN->second) {
|
||||
if (auto wtx = GetWalletTx(spend)) {
|
||||
if (wtx->nOrderPos < nMinOrderPos) {
|
||||
nMinOrderPos = wtx->nOrderPos;
|
||||
copyFrom = wtx;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!copyFrom) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Now copy data from copyFrom to rest:
|
||||
for (auto &hash: hitN->second) {
|
||||
auto it = mapWallet.find(hash);
|
||||
if (it != mapWallet.end()) continue;
|
||||
CWalletTx* copyTo = &it->second;
|
||||
if (copyFrom == copyTo) continue;
|
||||
assert(copyFrom && "Oldest wallet transaction in range assumed to have been found.");
|
||||
if (!copyFrom->IsEquivalentTo(*copyTo)) continue;
|
||||
copyTo->mapValue = copyFrom->mapValue;
|
||||
copyTo->vOrderForm = copyFrom->vOrderForm;
|
||||
// fTimeReceivedIsTxTime not copied on purpose
|
||||
// nTimeReceived not copied on purpose
|
||||
copyTo->nTimeSmart = copyFrom->nTimeSmart;
|
||||
copyTo->fFromMe = copyFrom->fFromMe;
|
||||
copyTo->strFromAccount = copyFrom->strFromAccount;
|
||||
// nOrderPos not copied on purpose
|
||||
// cached members not copied on purpose
|
||||
}
|
||||
for (TxSpends::iterator it = range.first; it != range.second; ++it) {
|
||||
const CWalletTx* wtx = &mapWallet.at(it->second);
|
||||
if (wtx->nOrderPos < nMinOrderPos) {
|
||||
nMinOrderPos = wtx->nOrderPos;
|
||||
copyFrom = wtx;
|
||||
}
|
||||
}
|
||||
|
||||
if (!copyFrom) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Now copy data from copyFrom to rest:
|
||||
for (TxSpends::iterator it = range.first; it != range.second; ++it)
|
||||
{
|
||||
const uint256& hash = it->second;
|
||||
CWalletTx* copyTo = &mapWallet.at(hash);
|
||||
if (copyFrom == copyTo) continue;
|
||||
assert(copyFrom && "Oldest wallet transaction in range assumed to have been found.");
|
||||
if (!copyFrom->IsEquivalentTo(*copyTo)) continue;
|
||||
copyTo->mapValue = copyFrom->mapValue;
|
||||
copyTo->vOrderForm = copyFrom->vOrderForm;
|
||||
// fTimeReceivedIsTxTime not copied on purpose
|
||||
// nTimeReceived not copied on purpose
|
||||
copyTo->nTimeSmart = copyFrom->nTimeSmart;
|
||||
copyTo->fFromMe = copyFrom->fFromMe;
|
||||
copyTo->strFromAccount = copyFrom->strFromAccount;
|
||||
// nOrderPos not copied on purpose
|
||||
// cached members not copied on purpose
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -652,15 +636,14 @@ void CWallet::SyncMetaData(const COutPoint& outPoint)
|
||||
*/
|
||||
bool CWallet::IsSpent(const uint256& hash, unsigned int n) const
|
||||
{
|
||||
auto hitTx = mapTxSpends.find(hash);
|
||||
if (hitTx == mapTxSpends.end())
|
||||
return false;
|
||||
auto hitN = hitTx->second.find(n);
|
||||
if (hitN == hitTx->second.end())
|
||||
return false;
|
||||
const COutPoint outpoint(hash, n);
|
||||
std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range;
|
||||
range = mapTxSpends.equal_range(outpoint);
|
||||
|
||||
for (auto& wtxid: hitN->second) {
|
||||
auto mit = mapWallet.find(wtxid);
|
||||
for (TxSpends::const_iterator it = range.first; it != range.second; ++it)
|
||||
{
|
||||
const uint256& wtxid = it->second;
|
||||
std::map<uint256, CWalletTx>::const_iterator mit = mapWallet.find(wtxid);
|
||||
if (mit != mapWallet.end()) {
|
||||
int depth = mit->second.GetDepthInMainChain();
|
||||
if (depth > 0 || (depth == 0 && !mit->second.isAbandoned()))
|
||||
@@ -672,19 +655,26 @@ bool CWallet::IsSpent(const uint256& hash, unsigned int n) const
|
||||
|
||||
void CWallet::AddToSpends(const COutPoint& outpoint, const uint256& wtxid)
|
||||
{
|
||||
mapTxSpends[outpoint.hash][outpoint.n].push_back(wtxid);
|
||||
mapTxSpends.insert(std::make_pair(outpoint, wtxid));
|
||||
|
||||
setLockedCoins.erase(outpoint);
|
||||
SyncMetaData(outpoint);
|
||||
|
||||
std::pair<TxSpends::iterator, TxSpends::iterator> range;
|
||||
range = mapTxSpends.equal_range(outpoint);
|
||||
SyncMetaData(range);
|
||||
}
|
||||
|
||||
|
||||
void CWallet::AddToSpends(const CWalletTx& wtx)
|
||||
void CWallet::AddToSpends(const uint256& wtxid)
|
||||
{
|
||||
if (wtx.IsCoinBase()) // Coinbases don't spend anything!
|
||||
auto it = mapWallet.find(wtxid);
|
||||
assert(it != mapWallet.end());
|
||||
CWalletTx& thisTx = it->second;
|
||||
if (thisTx.IsCoinBase()) // Coinbases don't spend anything!
|
||||
return;
|
||||
|
||||
for (const CTxIn& txin : wtx.tx->vin)
|
||||
AddToSpends(txin.prevout, wtx.GetHash());
|
||||
for (const CTxIn& txin : thisTx.tx->vin)
|
||||
AddToSpends(txin.prevout, wtxid);
|
||||
}
|
||||
|
||||
bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
||||
@@ -917,7 +907,9 @@ bool CWallet::GetLabelDestination(CTxDestination &dest, const std::string& label
|
||||
else {
|
||||
// Check if the current key has been used (TODO: check other addresses with the same key)
|
||||
CScript scriptPubKey = GetScriptForDestination(GetDestinationForKey(account.vchPubKey, m_default_address_type));
|
||||
for (auto it = mapWallet.begin(); it != mapWallet.end() && account.vchPubKey.IsValid(); ++it)
|
||||
for (std::map<uint256, CWalletTx>::iterator it = mapWallet.begin();
|
||||
it != mapWallet.end() && account.vchPubKey.IsValid();
|
||||
++it)
|
||||
for (const CTxOut& txout : (*it).second.tx->vout)
|
||||
if (txout.scriptPubKey == scriptPubKey) {
|
||||
bForceNew = true;
|
||||
@@ -946,7 +938,7 @@ void CWallet::MarkDirty()
|
||||
{
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
for (auto& item : mapWallet)
|
||||
for (std::pair<const uint256, CWalletTx>& item : mapWallet)
|
||||
item.second.MarkDirty();
|
||||
}
|
||||
}
|
||||
@@ -986,10 +978,10 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
|
||||
|
||||
WalletBatch batch(*database, "r+", fFlushOnClose);
|
||||
|
||||
const uint256& hash = wtxIn.GetHash();
|
||||
uint256 hash = wtxIn.GetHash();
|
||||
|
||||
// Inserts only if not already there, returns tx inserted or tx found
|
||||
auto ret = mapWallet.emplace(hash, wtxIn);
|
||||
std::pair<std::map<uint256, CWalletTx>::iterator, bool> ret = mapWallet.insert(std::make_pair(hash, wtxIn));
|
||||
CWalletTx& wtx = (*ret.first).second;
|
||||
wtx.BindWallet(this);
|
||||
bool fInsertedNew = ret.second;
|
||||
@@ -998,7 +990,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
|
||||
wtx.nOrderPos = IncOrderPosNext(&batch);
|
||||
wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr)));
|
||||
wtx.nTimeSmart = ComputeTimeSmart(wtx);
|
||||
AddToSpends(wtx);
|
||||
AddToSpends(hash);
|
||||
}
|
||||
|
||||
bool fUpdated = false;
|
||||
@@ -1038,8 +1030,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
|
||||
}
|
||||
|
||||
//// debug print
|
||||
if (LogAcceptCategory(BCLog::DB))
|
||||
WalletLogPrintf("AddToWallet %s%s%s\n", wtxIn.GetHash().ToString(), (fInsertedNew ? " new" : ""), (fUpdated ? " update" : ""));
|
||||
WalletLogPrintf("AddToWallet %s %s%s\n", wtxIn.GetHash().ToString(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : ""));
|
||||
|
||||
// Write to disk
|
||||
if (fInsertedNew || fUpdated)
|
||||
@@ -1067,14 +1058,14 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
|
||||
|
||||
void CWallet::LoadToWallet(const CWalletTx& wtxIn)
|
||||
{
|
||||
const uint256& hash = wtxIn.GetHash();
|
||||
uint256 hash = wtxIn.GetHash();
|
||||
const auto& ins = mapWallet.emplace(hash, wtxIn);
|
||||
CWalletTx& wtx = ins.first->second;
|
||||
wtx.BindWallet(this);
|
||||
if (/* insertion took place */ ins.second) {
|
||||
wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr)));
|
||||
}
|
||||
AddToSpends(wtx);
|
||||
AddToSpends(hash);
|
||||
for (const CTxIn& txin : wtx.tx->vin) {
|
||||
auto it = mapWallet.find(txin.prevout.hash);
|
||||
if (it != mapWallet.end()) {
|
||||
@@ -1094,19 +1085,13 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const CBlockI
|
||||
|
||||
if (pIndex != nullptr) {
|
||||
for (const CTxIn& txin : tx.vin) {
|
||||
auto hitTx = mapTxSpends.find(txin.prevout.hash);
|
||||
if (hitTx == mapTxSpends.end())
|
||||
continue;
|
||||
auto hitN = hitTx->second.find(txin.prevout.n);
|
||||
if (hitN == hitTx->second.end())
|
||||
continue;
|
||||
|
||||
for (auto& spend: hitN->second) {
|
||||
if (spend != tx.GetHash()) {
|
||||
WalletLogPrintf("Transaction %s (in block %s) conflicts with wallet transaction %s (both spend %s:%i)\n",
|
||||
tx.GetHash().ToString(), pIndex->GetBlockHash().ToString(), spend.ToString(), hitTx->first.ToString(), hitN->first);
|
||||
MarkConflicted(pIndex->GetBlockHash(), spend);
|
||||
std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range(txin.prevout);
|
||||
while (range.first != range.second) {
|
||||
if (range.first->second != tx.GetHash()) {
|
||||
WalletLogPrintf("Transaction %s (in block %s) conflicts with wallet transaction %s (both spend %s:%i)\n", tx.GetHash().ToString(), pIndex->GetBlockHash().ToString(), range.first->second.ToString(), range.first->first.hash.ToString(), range.first->first.n);
|
||||
MarkConflicted(pIndex->GetBlockHash(), range.first->second);
|
||||
}
|
||||
range.first++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1127,7 +1112,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const CBlockI
|
||||
std::vector<CKeyID> vAffected;
|
||||
CAffectedKeysVisitor(*this, vAffected).Process(txout.scriptPubKey);
|
||||
for (const CKeyID &keyid : vAffected) {
|
||||
auto mi = m_pool_key_to_index.find(keyid);
|
||||
std::map<CKeyID, int64_t>::const_iterator mi = m_pool_key_to_index.find(keyid);
|
||||
if (mi != m_pool_key_to_index.end()) {
|
||||
WalletLogPrintf("%s: Detected a used keypool key, mark all keypool key up to this key as used\n", __func__);
|
||||
MarkReserveKeysAsUsed(mi->second);
|
||||
@@ -1191,7 +1176,7 @@ bool CWallet::AbandonTransaction(const uint256& hashTx)
|
||||
uint256 now = *todo.begin();
|
||||
todo.erase(now);
|
||||
done.insert(now);
|
||||
it = mapWallet.find(now);
|
||||
auto it = mapWallet.find(now);
|
||||
assert(it != mapWallet.end());
|
||||
CWalletTx& wtx = it->second;
|
||||
int currentconfirm = wtx.GetDepthInMainChain();
|
||||
@@ -1207,14 +1192,12 @@ bool CWallet::AbandonTransaction(const uint256& hashTx)
|
||||
batch.WriteTx(wtx);
|
||||
NotifyTransactionChanged(this, wtx.GetHash(), CT_UPDATED);
|
||||
// Iterate over all its outputs, and mark transactions in the wallet that spend them abandoned too
|
||||
auto hitTx = mapTxSpends.find(now);
|
||||
if (hitTx != mapTxSpends.end()) {
|
||||
for (auto &kvp: hitTx->second) {
|
||||
for (auto &spent: kvp.second) {
|
||||
if (!done.count(spent))
|
||||
todo.insert(spent);
|
||||
}
|
||||
TxSpends::const_iterator iter = mapTxSpends.lower_bound(COutPoint(now, 0));
|
||||
while (iter != mapTxSpends.end() && iter->first.hash == now) {
|
||||
if (!done.count(iter->second)) {
|
||||
todo.insert(iter->second);
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
// If a transaction changes 'conflicted' state, that changes the balance
|
||||
// available of the outputs it spends. So force those to be recomputed
|
||||
@@ -1265,14 +1248,12 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
|
||||
wtx.MarkDirty();
|
||||
batch.WriteTx(wtx);
|
||||
// Iterate over all its outputs, and mark transactions in the wallet that spend them conflicted too
|
||||
auto hitTx = mapTxSpends.find(now);
|
||||
if (hitTx != mapTxSpends.end()) {
|
||||
for (auto &kvp: hitTx->second) {
|
||||
for (auto &spent: kvp.second) {
|
||||
if (!done.count(spent))
|
||||
todo.insert(spent);
|
||||
}
|
||||
}
|
||||
TxSpends::const_iterator iter = mapTxSpends.lower_bound(COutPoint(now, 0));
|
||||
while (iter != mapTxSpends.end() && iter->first.hash == now) {
|
||||
if (!done.count(iter->second)) {
|
||||
todo.insert(iter->second);
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
// If a transaction changes 'conflicted' state, that changes the balance
|
||||
// available of the outputs it spends. So force those to be recomputed
|
||||
@@ -1345,23 +1326,24 @@ void CWallet::BlockUntilSyncedToCurrentChain() {
|
||||
AssertLockNotHeld(cs_main);
|
||||
AssertLockNotHeld(cs_wallet);
|
||||
|
||||
// we want to ensure that head block is processed
|
||||
// otherwise it can lead to race condition or data misplace
|
||||
while(true) {
|
||||
{
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
const CBlockIndex* initialChainTip = chainActive.Tip();
|
||||
{
|
||||
// Skip the queue-draining stuff if we know we're caught up with
|
||||
// chainActive.Tip()...
|
||||
// We could also take cs_wallet here, and call m_last_block_processed
|
||||
// protected by cs_wallet instead of cs_main, but as long as we need
|
||||
// cs_main here anyway, it's easier to just call it cs_main-protected.
|
||||
LOCK(cs_main);
|
||||
const CBlockIndex* initialChainTip = chainActive.Tip();
|
||||
|
||||
if (m_last_block_processed && m_last_block_processed->GetAncestor(initialChainTip->nHeight) == initialChainTip) {
|
||||
return;
|
||||
}
|
||||
if (m_last_block_processed && m_last_block_processed->GetAncestor(initialChainTip->nHeight) == initialChainTip) {
|
||||
return;
|
||||
}
|
||||
|
||||
// ...otherwise put a callback in the validation interface queue and wait
|
||||
// for the queue to drain enough to execute it (indicating we are caught up
|
||||
// at least with the time we entered this function).
|
||||
SyncWithValidationInterfaceQueue();
|
||||
}
|
||||
|
||||
// ...otherwise put a callback in the validation interface queue and wait
|
||||
// for the queue to drain enough to execute it (indicating we are caught up
|
||||
// at least with the time we entered this function).
|
||||
SyncWithValidationInterfaceQueue();
|
||||
}
|
||||
|
||||
|
||||
@@ -1369,7 +1351,7 @@ isminetype CWallet::IsMine(const CTxIn &txin) const
|
||||
{
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
auto mi = mapWallet.find(txin.prevout.hash);
|
||||
std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(txin.prevout.hash);
|
||||
if (mi != mapWallet.end())
|
||||
{
|
||||
const CWalletTx& prev = (*mi).second;
|
||||
@@ -1386,7 +1368,7 @@ CAmount CWallet::GetDebit(const CTxIn &txin, const isminefilter& filter) const
|
||||
{
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
auto mi = mapWallet.find(txin.prevout.hash);
|
||||
std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(txin.prevout.hash);
|
||||
if (mi != mapWallet.end())
|
||||
{
|
||||
const CWalletTx& prev = (*mi).second;
|
||||
@@ -1865,7 +1847,7 @@ void CWallet::ReacceptWalletTransactions()
|
||||
std::map<int64_t, CWalletTx*> mapSorted;
|
||||
|
||||
// Sort pending wallet transactions based on their initial wallet insertion order
|
||||
for (auto& item : mapWallet)
|
||||
for (std::pair<const uint256, CWalletTx>& item : mapWallet)
|
||||
{
|
||||
const uint256& wtxid = item.first;
|
||||
CWalletTx& wtx = item.second;
|
||||
@@ -1894,8 +1876,7 @@ bool CWalletTx::RelayWalletTransaction(CConnman* connman)
|
||||
CValidationState state;
|
||||
/* GetDepthInMainChain already catches known conflicts. */
|
||||
if (InMempool() || AcceptToMemoryPool(maxTxFee, state)) {
|
||||
if (LogAcceptCategory(BCLog::DB))
|
||||
pwallet->WalletLogPrintf("Relaying wtx %s\n", GetHash().ToString());
|
||||
pwallet->WalletLogPrintf("Relaying wtx %s\n", GetHash().ToString());
|
||||
if (connman) {
|
||||
CInv inv(MSG_TX, GetHash());
|
||||
connman->ForEachNode([&inv](CNode* pnode)
|
||||
@@ -1914,7 +1895,7 @@ std::set<uint256> CWalletTx::GetConflicts() const
|
||||
std::set<uint256> result;
|
||||
if (pwallet != nullptr)
|
||||
{
|
||||
const uint256& myHash = GetHash();
|
||||
uint256 myHash = GetHash();
|
||||
result = pwallet->GetConflicts(myHash);
|
||||
result.erase(myHash);
|
||||
}
|
||||
@@ -2024,7 +2005,7 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache, const isminefilter& filter
|
||||
}
|
||||
|
||||
CAmount nCredit = 0;
|
||||
const uint256& hashTx = GetHash();
|
||||
uint256 hashTx = GetHash();
|
||||
for (unsigned int i = 0; i < tx->vout.size(); i++)
|
||||
{
|
||||
if (!pwallet->IsSpent(hashTx, i))
|
||||
@@ -2120,7 +2101,7 @@ std::vector<uint256> CWallet::ResendWalletTransactionsBefore(int64_t nTime, CCon
|
||||
|
||||
// Sort them in chronological order
|
||||
std::multimap<unsigned int, CWalletTx*> mapSorted;
|
||||
for (auto& item : mapWallet)
|
||||
for (std::pair<const uint256, CWalletTx>& item : mapWallet)
|
||||
{
|
||||
CWalletTx& wtx = item.second;
|
||||
// Don't rebroadcast if newer than nTime:
|
||||
@@ -2304,9 +2285,7 @@ CAmount CWallet::GetAvailableBalance(const CCoinControl* coinControl) const
|
||||
return balance;
|
||||
}
|
||||
|
||||
void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlySafe, const CCoinControl *coinControl,
|
||||
const CAmount &nMinimumAmount, const CAmount &nMaximumAmount, const CAmount &nMinimumSumAmount,
|
||||
const uint64_t nMaximumCount, const int nMinDepth, const int nMaxDepth, bool computeSolvable) const
|
||||
void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlySafe, const CCoinControl *coinControl, const CAmount &nMinimumAmount, const CAmount &nMaximumAmount, const CAmount &nMinimumSumAmount, const uint64_t nMaximumCount, const int nMinDepth, const int nMaxDepth) const
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
AssertLockHeld(cs_wallet);
|
||||
@@ -2393,23 +2372,17 @@ void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlySafe, const
|
||||
continue;
|
||||
}
|
||||
|
||||
bool solvable = IsSolvable(*this, pcoin->tx->vout[i].scriptPubKey);
|
||||
bool spendable = (mine & ISMINE_SPENDABLE) || (((mine & ISMINE_WATCH_ONLY) != ISMINE_NO) && (coinControl && coinControl->fAllowWatchOnly && solvable));
|
||||
|
||||
// spending claims or supports requires specific selection:
|
||||
auto isClaimCoin = bool(mine & ISMINE_STAKE);
|
||||
auto isClaimCoin = (mine & ISMINE_CLAIM) || (mine & ISMINE_SUPPORT);
|
||||
auto claimSpendRequested = isClaimCoin && coinControl && coinControl->IsSelected(COutPoint(entry.first, i));
|
||||
if (isClaimCoin && !claimSpendRequested)
|
||||
|
||||
if (spendable && isClaimCoin && !claimSpendRequested)
|
||||
continue;
|
||||
|
||||
bool solvable = false, computedSolvable = false;
|
||||
bool spendable = bool(mine & ISMINE_SPENDABLE);
|
||||
if (!spendable && bool(mine & ISMINE_WATCH_ONLY) && coinControl && coinControl->fAllowWatchOnly) {
|
||||
solvable = IsSolvable(*this, pcoin->tx->vout[i].scriptPubKey); // this is a slow call
|
||||
spendable = solvable;
|
||||
computedSolvable = true;
|
||||
}
|
||||
if (computeSolvable && !computedSolvable)
|
||||
solvable = IsSolvable(*this, pcoin->tx->vout[i].scriptPubKey);
|
||||
|
||||
vCoins.emplace_back(pcoin, i, nDepth, spendable, solvable, safeTx, (coinControl && coinControl->fAllowWatchOnly));
|
||||
vCoins.push_back(COutput(pcoin, i, nDepth, spendable, solvable, safeTx, (coinControl && coinControl->fAllowWatchOnly)));
|
||||
|
||||
// Checks the sum amount of all UTXO's.
|
||||
if (nMinimumSumAmount != MAX_MONEY) {
|
||||
@@ -2577,7 +2550,7 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
|
||||
bnb_used = false;
|
||||
coin_selection_params.use_bnb = false;
|
||||
|
||||
auto it = mapWallet.find(outpoint.hash);
|
||||
std::map<uint256, CWalletTx>::const_iterator it = mapWallet.find(outpoint.hash);
|
||||
if (it != mapWallet.end())
|
||||
{
|
||||
const CWalletTx* pcoin = &it->second;
|
||||
@@ -2639,7 +2612,7 @@ bool CWallet::SignTransaction(CMutableTransaction &tx)
|
||||
// sign the new tx
|
||||
int nIn = 0;
|
||||
for (auto& input : tx.vin) {
|
||||
auto mi = mapWallet.find(input.prevout.hash);
|
||||
std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(input.prevout.hash);
|
||||
if(mi == mapWallet.end() || input.prevout.n >= mi->second.tx->vout.size()) {
|
||||
return false;
|
||||
}
|
||||
@@ -3254,18 +3227,9 @@ DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // mapWallet
|
||||
DBErrors nZapSelectTxRet = WalletBatch(*database,"cr+").ZapSelectTx(vHashIn, vHashOut);
|
||||
for (const uint256& hash : vHashOut) {
|
||||
auto it = mapWallet.find(hash);
|
||||
if (it == mapWallet.end())
|
||||
continue;
|
||||
for (uint256 hash : vHashOut) {
|
||||
const auto& it = mapWallet.find(hash);
|
||||
wtxOrdered.erase(it->second.m_it_wtxOrdered);
|
||||
for (auto& txin : it->second.tx->vin) {
|
||||
auto mit = mapTxSpends.find(txin.prevout.hash);
|
||||
if (mit != mapTxSpends.end()) {
|
||||
if (mit->second.erase(txin.prevout.n) && mit->second.empty())
|
||||
mapTxSpends.erase(mit);
|
||||
}
|
||||
}
|
||||
mapWallet.erase(it);
|
||||
}
|
||||
|
||||
@@ -3530,8 +3494,7 @@ bool CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool, bool fRe
|
||||
}
|
||||
|
||||
m_pool_key_to_index.erase(keypool.vchPubKey.GetID());
|
||||
if (LogAcceptCategory(BCLog::DB))
|
||||
WalletLogPrintf("keypool reserve %d\n", nIndex);
|
||||
WalletLogPrintf("keypool reserve %d\n", nIndex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -3541,8 +3504,7 @@ void CWallet::KeepKey(int64_t nIndex)
|
||||
// Remove from key pool
|
||||
WalletBatch batch(*database);
|
||||
batch.ErasePool(nIndex);
|
||||
if (LogAcceptCategory(BCLog::DB))
|
||||
WalletLogPrintf("keypool keep %d\n", nIndex);
|
||||
WalletLogPrintf("keypool keep %d\n", nIndex);
|
||||
}
|
||||
|
||||
void CWallet::ReturnKey(int64_t nIndex, bool fInternal, const CPubKey& pubkey)
|
||||
@@ -3855,7 +3817,7 @@ void CWallet::UnlockAllCoins()
|
||||
setLockedCoins.clear();
|
||||
}
|
||||
|
||||
bool CWallet::IsLockedCoin(const uint256& hash, unsigned int n) const
|
||||
bool CWallet::IsLockedCoin(uint256 hash, unsigned int n) const
|
||||
{
|
||||
AssertLockHeld(cs_wallet); // setLockedCoins
|
||||
COutPoint outpt(hash, n);
|
||||
@@ -3912,7 +3874,7 @@ void CWallet::GetKeyBirthTimes(std::map<CTxDestination, int64_t> &mapKeyBirth) c
|
||||
CAffectedKeysVisitor(*this, vAffected).Process(txout.scriptPubKey);
|
||||
for (const CKeyID &keyid : vAffected) {
|
||||
// ... and all their affected keys
|
||||
auto rit = mapKeyFirstBlock.find(keyid);
|
||||
std::map<CKeyID, CBlockIndex*>::iterator rit = mapKeyFirstBlock.find(keyid);
|
||||
if (rit != mapKeyFirstBlock.end() && nHeight < rit->second->nHeight)
|
||||
rit->second = pindex;
|
||||
}
|
||||
@@ -4406,8 +4368,8 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(const WalletLocation& loc
|
||||
|
||||
for (const CWalletTx& wtxOld : vWtx)
|
||||
{
|
||||
const uint256& hash = wtxOld.GetHash();
|
||||
auto mi = walletInstance->mapWallet.find(hash);
|
||||
uint256 hash = wtxOld.GetHash();
|
||||
std::map<uint256, CWalletTx>::iterator mi = walletInstance->mapWallet.find(hash);
|
||||
if (mi != walletInstance->mapWallet.end())
|
||||
{
|
||||
const CWalletTx* copyFrom = &wtxOld;
|
||||
|
||||
+21
-24
@@ -9,7 +9,6 @@
|
||||
#include <amount.h>
|
||||
#include <outputtype.h>
|
||||
#include <policy/feerate.h>
|
||||
#include <primitives/robin_hood.h>
|
||||
#include <streams.h>
|
||||
#include <tinyformat.h>
|
||||
#include <ui_interface.h>
|
||||
@@ -29,6 +28,7 @@
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <stdexcept>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -508,8 +508,8 @@ public:
|
||||
int i;
|
||||
int nDepth;
|
||||
|
||||
/** estimated size of this output as a fully-signed input in a transaction. Can be -1 */
|
||||
mutable int nInputBytes;
|
||||
/** Pre-computed estimated size of this output as a fully-signed input in a transaction. Can be -1 if it could not be calculated */
|
||||
int nInputBytes;
|
||||
|
||||
/** Whether we have the private keys to spend this output */
|
||||
bool fSpendable;
|
||||
@@ -527,22 +527,20 @@ public:
|
||||
*/
|
||||
bool fSafe;
|
||||
|
||||
COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn,
|
||||
bool fSolvableIn, bool fSafeIn, bool use_max_sig_in = false)
|
||||
: tx(txIn), i(iIn), nDepth(nDepthIn), fSpendable(fSpendableIn), fSolvable(fSolvableIn),
|
||||
fSafe(fSafeIn), nInputBytes(-1), use_max_sig(use_max_sig_in)
|
||||
COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn, bool fSolvableIn, bool fSafeIn, bool use_max_sig_in = false)
|
||||
{
|
||||
tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn; fSolvable = fSolvableIn; fSafe = fSafeIn; nInputBytes = -1; use_max_sig = use_max_sig_in;
|
||||
// If known and signable by the given wallet, compute nInputBytes
|
||||
// Failure will keep this value -1
|
||||
if (fSpendable && tx) {
|
||||
nInputBytes = tx->GetSpendSize(i, use_max_sig);
|
||||
}
|
||||
}
|
||||
|
||||
std::string ToString() const;
|
||||
|
||||
inline CInputCoin GetInputCoin() const
|
||||
{
|
||||
// If known and signable by the given wallet, compute nInputBytes
|
||||
// Failure will keep this value -1
|
||||
if (nInputBytes < 0 && fSpendable && tx) {
|
||||
nInputBytes = tx->GetSpendSize(i, use_max_sig);
|
||||
}
|
||||
return CInputCoin(tx->tx, i, nInputBytes);
|
||||
}
|
||||
};
|
||||
@@ -699,10 +697,10 @@ private:
|
||||
* detect and report conflicts (double-spends or
|
||||
* mutated transactions where the mutant gets mined).
|
||||
*/
|
||||
typedef robin_hood::unordered_map<uint256, robin_hood::unordered_map<uint32_t, std::vector<uint256>>> TxSpends;
|
||||
typedef std::multimap<COutPoint, uint256> TxSpends;
|
||||
TxSpends mapTxSpends;
|
||||
void AddToSpends(const COutPoint& outpoint, const uint256& wtxid);
|
||||
void AddToSpends(const CWalletTx& wtx);
|
||||
void AddToSpends(const uint256& wtxid);
|
||||
|
||||
/**
|
||||
* Add a transaction to the wallet, or update it. pIndex and posInBlock should
|
||||
@@ -725,7 +723,7 @@ private:
|
||||
/* Mark a transaction's inputs dirty, thus forcing the outputs to be recomputed */
|
||||
void MarkInputsDirty(const CTransactionRef& tx);
|
||||
|
||||
void SyncMetaData(const COutPoint& outpoint);
|
||||
void SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator>);
|
||||
|
||||
/* Used by TransactionAddedToMemorypool/BlockConnected/Disconnected/ScanForWalletTransactions.
|
||||
* Should be called with pindexBlock and posInBlock if this is for a transaction that is included in a block. */
|
||||
@@ -808,18 +806,17 @@ public:
|
||||
void MarkPreSplitKeys();
|
||||
|
||||
// Map from Key ID to key metadata.
|
||||
robin_hood::unordered_map<CKeyID, CKeyMetadata> mapKeyMetadata;
|
||||
std::map<CKeyID, CKeyMetadata> mapKeyMetadata;
|
||||
|
||||
// Map from Script ID to key metadata (for watch-only keys).
|
||||
robin_hood::unordered_map<CScriptID, CKeyMetadata> m_script_metadata;
|
||||
std::map<CScriptID, CKeyMetadata> m_script_metadata;
|
||||
|
||||
typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
|
||||
MasterKeyMap mapMasterKeys;
|
||||
unsigned int nMasterKeyMaxID = 0;
|
||||
|
||||
/** Construct wallet with specified name and database implementation. */
|
||||
CWallet(const WalletLocation& location, std::unique_ptr<WalletDatabase> database)
|
||||
: m_location(location), database(std::move(database))
|
||||
CWallet(const WalletLocation& location, std::unique_ptr<WalletDatabase> database) : m_location(location), database(std::move(database))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -831,7 +828,7 @@ public:
|
||||
encrypted_batch = nullptr;
|
||||
}
|
||||
|
||||
robin_hood::unordered_node_map<uint256, CWalletTx> mapWallet;
|
||||
std::map<uint256, CWalletTx> mapWallet;
|
||||
std::list<CAccountingEntry> laccentries;
|
||||
|
||||
typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair;
|
||||
@@ -853,7 +850,7 @@ public:
|
||||
/**
|
||||
* populate vCoins with vector of available COutputs.
|
||||
*/
|
||||
void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlySafe=true, const CCoinControl *coinControl = nullptr, const CAmount& nMinimumAmount = 1, const CAmount& nMaximumAmount = MAX_MONEY, const CAmount& nMinimumSumAmount = MAX_MONEY, const uint64_t nMaximumCount = 0, const int nMinDepth = 0, const int nMaxDepth = 9999999, bool computeSolvable=false) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlySafe=true, const CCoinControl *coinControl = nullptr, const CAmount& nMinimumAmount = 1, const CAmount& nMaximumAmount = MAX_MONEY, const CAmount& nMinimumSumAmount = MAX_MONEY, const uint64_t nMaximumCount = 0, const int nMinDepth = 0, const int nMaxDepth = 9999999) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
|
||||
/**
|
||||
* Return list of available coins and locked coins grouped by non-change output address.
|
||||
@@ -877,7 +874,7 @@ public:
|
||||
bool IsSpent(const uint256& hash, unsigned int n) const;
|
||||
std::vector<OutputGroup> GroupOutputs(const std::vector<COutput>& outputs, bool single_coin) const;
|
||||
|
||||
bool IsLockedCoin(const uint256& hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
bool IsLockedCoin(uint256 hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
void LockCoin(const COutPoint& output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
void UnlockCoin(const COutPoint& output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
void UnlockAllCoins() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
@@ -1214,8 +1211,8 @@ public:
|
||||
|
||||
/** Returns a bracketed wallet name for displaying in logs, will return [default wallet] if the wallet has no name */
|
||||
const std::string GetDisplayName() const {
|
||||
const std::string wallet_name = GetName();
|
||||
return strprintf("[%s]", wallet_name.empty() ? "default wallet" : wallet_name);
|
||||
std::string wallet_name = GetName().length() == 0 ? "default wallet" : GetName();
|
||||
return strprintf("[%s]", wallet_name);
|
||||
};
|
||||
|
||||
/** Prepends the wallet name in logging output to ease debugging in multi-wallet use cases */
|
||||
|
||||
@@ -51,7 +51,7 @@ bool WalletBatch::WriteTx(const CWalletTx& wtx)
|
||||
return WriteIC(std::make_pair(std::string("tx"), wtx.GetHash()), wtx);
|
||||
}
|
||||
|
||||
bool WalletBatch::EraseTx(const uint256& hash)
|
||||
bool WalletBatch::EraseTx(uint256 hash)
|
||||
{
|
||||
return EraseIC(std::make_pair(std::string("tx"), hash));
|
||||
}
|
||||
@@ -639,7 +639,7 @@ DBErrors WalletBatch::FindWalletTx(std::vector<uint256>& vTxHash, std::vector<CW
|
||||
|
||||
try {
|
||||
int nMinVersion = 0;
|
||||
if (m_batch.Read(std::string("minversion"), nMinVersion))
|
||||
if (m_batch.Read((std::string)"minversion", nMinVersion))
|
||||
{
|
||||
if (nMinVersion > FEATURE_LATEST)
|
||||
return DBErrors::TOO_NEW;
|
||||
@@ -707,10 +707,10 @@ DBErrors WalletBatch::ZapSelectTx(std::vector<uint256>& vTxHashIn, std::vector<u
|
||||
|
||||
// erase each matching wallet TX
|
||||
bool delerror = false;
|
||||
auto it = vTxHashIn.begin();
|
||||
for (const uint256& hash : vTxHash) {
|
||||
while (it != vTxHashIn.end() && (*it) < hash) {
|
||||
++it;
|
||||
std::vector<uint256>::iterator it = vTxHashIn.begin();
|
||||
for (uint256 hash : vTxHash) {
|
||||
while (it < vTxHashIn.end() && (*it) < hash) {
|
||||
it++;
|
||||
}
|
||||
if (it == vTxHashIn.end()) {
|
||||
break;
|
||||
@@ -739,7 +739,7 @@ DBErrors WalletBatch::ZapWalletTx(std::vector<CWalletTx>& vWtx)
|
||||
return err;
|
||||
|
||||
// erase each wallet TX
|
||||
for (const uint256& hash : vTxHash) {
|
||||
for (uint256& hash : vTxHash) {
|
||||
if (!EraseTx(hash))
|
||||
return DBErrors::CORRUPT;
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ public:
|
||||
bool ErasePurpose(const std::string& strAddress);
|
||||
|
||||
bool WriteTx(const CWalletTx& wtx);
|
||||
bool EraseTx(const uint256& hash);
|
||||
bool EraseTx(uint256 hash);
|
||||
|
||||
bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta);
|
||||
bool WriteCryptedKey(const CPubKey& vchPubKey, const std::vector<unsigned char>& vchCryptedSecret, const CKeyMetadata &keyMeta);
|
||||
|
||||
@@ -70,7 +70,6 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
|
||||
))['hex']
|
||||
txid_in_block = node.sendrawtransaction(hexstring=raw_tx_in_block, allowhighfees=True)
|
||||
node.generate(1)
|
||||
self.mempool_size = 0
|
||||
self.check_mempool_result(
|
||||
result_expected=[{'txid': txid_in_block, 'allowed': False, 'reject-reason': '18: txn-already-known'}],
|
||||
rawtxs=[raw_tx_in_block],
|
||||
|
||||
Reference in new issue
Block a user