diff options
83 files changed, 1018 insertions, 368 deletions
diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md index 55d5d24cca..f0d25fd7a2 100644 --- a/contrib/devtools/README.md +++ b/contrib/devtools/README.md @@ -36,3 +36,14 @@ Configuring the github-merge tool for the bitcoin repository is done in the foll git config githubmerge.testcmd "make -j4 check" (adapt to whatever you want to use for testing) git config --global user.signingkey mykeyid (if you want to GPG sign) +## fix-copyright-headers.py + +Every year newly updated files need to have its copyright headers updated to reflect the current year. +If you run this script from src/ it will automatically update the year on the copyright header for all +.cpp and .h files if these have a git commit from the current year. + +For example a file changed in 2014 (with 2014 being the current year): +```// Copyright (c) 2009-2013 The Bitcoin developers``` + +would be changed to: +```// Copyright (c) 2009-2014 The Bitcoin developers```
\ No newline at end of file diff --git a/contrib/devtools/fix-copyright-headers.py b/contrib/devtools/fix-copyright-headers.py new file mode 100755 index 0000000000..52fdc99144 --- /dev/null +++ b/contrib/devtools/fix-copyright-headers.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +''' +Run this script inside of src/ and it will look for all the files +that were changed this year that still have the last year in the +copyright headers, and it will fix the headers on that file using +a perl regex one liner. + +For example: if it finds something like this and we're in 2014 + +// Copyright (c) 2009-2013 The Bitcoin developers + +it will change it to + +// Copyright (c) 2009-2014 The Bitcoin developers + +It will do this for all the files in the folder and its children. + +Author: @gubatron +''' +import os +import time + +year = time.gmtime()[0] +last_year = year - 1 +command = "perl -pi -e 's/%s The Bitcoin/%s The Bitcoin/' %s" +listFilesCommand = "find . | grep %s" + +extensions = [".cpp",".h"] + +def getLastGitModifiedDate(filePath): + gitGetLastCommitDateCommand = "git log " + filePath +" | grep Date | head -n 1" + p = os.popen(gitGetLastCommitDateCommand) + result = "" + for l in p: + result = l + break + result = result.replace("\n","") + return result + +n=1 +for extension in extensions: + foundFiles = os.popen(listFilesCommand % extension) + for filePath in foundFiles: + filePath = filePath[1:-1] + if filePath.endswith(extension): + filePath = os.getcwd() + filePath + modifiedTime = getLastGitModifiedDate(filePath) + if len(modifiedTime) > 0 and str(year) in modifiedTime: + print n,"Last Git Modified: ", modifiedTime, " - ", filePath + os.popen(command % (last_year,year,filePath)) + n = n + 1 + + diff --git a/contrib/gitian-descriptors/boost-linux.yml b/contrib/gitian-descriptors/boost-linux.yml index 48b27aa26d..a538ff30a8 100644 --- a/contrib/gitian-descriptors/boost-linux.yml +++ b/contrib/gitian-descriptors/boost-linux.yml @@ -19,12 +19,16 @@ files: - "boost_1_55_0.tar.bz2" script: | STAGING="$HOME/install" + TEMPDIR="$HOME/tmp" export LIBRARY_PATH="$STAGING/lib" + export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1 + export FAKETIME=$REFERENCE_DATETIME + export TZ=UTC # Input Integrity Check echo "fff00023dd79486d444c8e29922f4072e1d451fc5a4d2b6075852ead7f2b7b52 boost_1_55_0.tar.bz2" | shasum -c mkdir -p "$STAGING" - tar xjf boost_1_55_0.tar.bz2 + tar --warning=no-timestamp -xjf boost_1_55_0.tar.bz2 cd boost_1_55_0 GCCVERSION=$(g++ -E -dM $(mktemp --suffix=.h) | grep __VERSION__ | cut -d ' ' -f 3 | cut -d '"' -f 2) # note: bjam with -d+2 reveals that -O3 is implied by default, no need to provide it in cxxflags @@ -35,9 +39,16 @@ script: | ./bootstrap.sh --without-icu - ./bjam toolset=gcc threadapi=pthread threading=multi variant=release link=static runtime-link=shared --user-config=user-config.jam --without-mpi --without-python -sNO_BZIP2=1 --layout=tagged --build-type=complete --prefix="$STAGING" $MAKEOPTS install + ./bjam toolset=gcc threadapi=pthread threading=multi variant=release link=static runtime-link=shared --user-config=user-config.jam --without-mpi --without-python -sNO_BZIP2=1 --layout=tagged --build-type=complete --prefix="$STAGING" $MAKEOPTS -d+2 install + # post-process all generated libraries to be deterministic + # extract them to a temporary directory then re-build them deterministically + for LIB in $(find $STAGING -name \*.a); do + rm -rf $TEMPDIR && mkdir $TEMPDIR && cd $TEMPDIR + ar xv $LIB | cut -b5- > /tmp/list.txt + rm $LIB + ar crsD $LIB $(cat /tmp/list.txt) + done + # cd "$STAGING" - export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1 - export FAKETIME=$REFERENCE_DATETIME - zip -r $OUTDIR/boost-linux${GBUILD_BITS}-1.55.0-gitian-r1.zip * + find | sort | zip -X@ $OUTDIR/boost-linux${GBUILD_BITS}-1.55.0-gitian-r1.zip diff --git a/contrib/gitian-descriptors/boost-win.yml b/contrib/gitian-descriptors/boost-win.yml index 15aeccf543..db5d6bab1d 100644 --- a/contrib/gitian-descriptors/boost-win.yml +++ b/contrib/gitian-descriptors/boost-win.yml @@ -16,8 +16,11 @@ files: - "boost-mingw-gas-cross-compile-2013-03-03.patch" script: | # Defines + export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1 + export FAKETIME=$REFERENCE_DATETIME export TZ=UTC INDIR=$HOME/build + TEMPDIR=$HOME/tmp # Input Integrity Check echo "fff00023dd79486d444c8e29922f4072e1d451fc5a4d2b6075852ead7f2b7b52 boost_1_55_0.tar.bz2" | shasum -c echo "d2b7f6a1d7051faef3c9cf41a92fa3671d905ef1e1da920d07651a43299f6268 boost-mingw-gas-cross-compile-2013-03-03.patch" | shasum -c @@ -35,7 +38,7 @@ script: | mkdir -p $INSTALLPREFIX $BUILDDIR cd $BUILDDIR # - tar xjf $INDIR/boost_1_55_0.tar.bz2 + tar --warning=no-timestamp -xjf $INDIR/boost_1_55_0.tar.bz2 cd boost_1_55_0 GCCVERSION=$($HOST-g++ -E -dM $(mktemp --suffix=.h) | grep __VERSION__ | cut -d ' ' -f 3 | cut -d '"' -f 2) echo "using gcc : $GCCVERSION : $HOST-g++ @@ -68,12 +71,16 @@ script: | # http://statmt.org/~s0565741/software/boost_1_52_0/libs/context/doc/html/context/requirements.html # "For cross-compiling the lib you must specify certain additional properties at bjam command line: target-os, abi, binary-format, architecture and address-model." ./bjam toolset=gcc binary-format=pe target-os=windows threadapi=win32 address-model=$BITS threading=multi variant=release link=static runtime-link=static --user-config=user-config.jam --without-mpi --without-python -sNO_BZIP2=1 -sNO_ZLIB=1 --layout=tagged --build-type=complete --prefix="$INSTALLPREFIX" $MAKEOPTS install + # post-process all generated libraries to be deterministic + # extract them to a temporary directory then re-build them deterministically + for LIB in $(find $INSTALLPREFIX -name \*.a); do + rm -rf $TEMPDIR && mkdir $TEMPDIR && cd $TEMPDIR + $HOST-ar xv $LIB | cut -b5- > /tmp/list.txt + rm $LIB + $HOST-ar crsD $LIB $(cat /tmp/list.txt) + done # cd "$INSTALLPREFIX" - export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1 - export FAKETIME=$REFERENCE_DATETIME - zip -r $OUTDIR/boost-win$BITS-1.55.0-gitian-r6.zip * - unset LD_PRELOAD - unset FAKETIME + find | sort | zip -X@ $OUTDIR/boost-win$BITS-1.55.0-gitian-r6.zip done # for BITS in diff --git a/contrib/gitian-descriptors/deps-linux.yml b/contrib/gitian-descriptors/deps-linux.yml index 12c3179ea1..908f9321a4 100644 --- a/contrib/gitian-descriptors/deps-linux.yml +++ b/contrib/gitian-descriptors/deps-linux.yml @@ -23,7 +23,11 @@ files: - "db-4.8.30.NC.tar.gz" script: | STAGING="$HOME/install" + TEMPDIR="$HOME/tmp" OPTFLAGS='-O2' + export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1 + export FAKETIME=$REFERENCE_DATETIME + export TZ=UTC export LIBRARY_PATH="$STAGING/lib" # Integrity Check echo "f74f15e8c8ff11aa3d5bb5f276d202ec18d7246e95f961db76054199c69c1ae3 openssl-1.0.1e.tar.gz" | sha256sum -c @@ -37,6 +41,7 @@ script: | cd openssl-1.0.1e # need -fPIC to avoid relocation error in 64 bit builds ./config no-shared no-zlib no-dso no-krb5 --openssldir=$STAGING -fPIC + # need to build OpenSSL with faketime because a timestamp is embedded into cversion.o make make install_sw cd .. @@ -48,18 +53,26 @@ script: | rm -f $STAGING/lib/libminiupnpc.so* # no way to skip shared lib build cd .. # - tar xjfm qrencode-3.4.3.tar.bz2 + tar xjf qrencode-3.4.3.tar.bz2 cd qrencode-3.4.3 + unset FAKETIME # unset fake time during configure, as it does some clock sanity tests # need --with-pic to avoid relocation error in 64 bit builds - ./configure --prefix=$STAGING --enable-static --disable-shared --with-pic --without-tools --disable-maintainer-mode --disable-dependency-tracking + ./configure --prefix=$STAGING --enable-static --disable-shared --with-pic --without-tools --disable-dependency-tracking + # Workaround to prevent re-configuring by make; make all files have a date in the past + find . -print0 | xargs -r0 touch -t 200001010000 + export FAKETIME=$REFERENCE_DATETIME make $MAKEOPTS install cd .. # - tar xjfm protobuf-2.5.0.tar.bz2 + tar xjf protobuf-2.5.0.tar.bz2 cd protobuf-2.5.0 mkdir -p $STAGING/host/bin + unset FAKETIME # unset fake time during configure, as it does some clock sanity tests # need --with-pic to avoid relocation error in 64 bit builds - ./configure --prefix=$STAGING --bindir=$STAGING/host/bin --enable-static --disable-shared --with-pic + ./configure --prefix=$STAGING --bindir=$STAGING/host/bin --enable-static --disable-shared --with-pic --without-zlib + # Workaround to prevent re-configuring by make; make all files have a date in the past + find . -print0 | xargs -r0 touch -t 200001010000 + export FAKETIME=$REFERENCE_DATETIME make $MAKEOPTS install cd .. # @@ -67,9 +80,19 @@ script: | cd db-4.8.30.NC/build_unix # need --with-pic to avoid relocation error in 64 bit builds ../dist/configure --prefix=$STAGING --enable-cxx --disable-shared --with-pic + # Workaround to prevent re-configuring by make; make all files have a date in the past + find . -print0 | xargs -r0 touch -t 200001010000 make $MAKEOPTS library_build make install_lib install_include cd ../.. + # post-process all generated libraries to be deterministic + # extract them to a temporary directory then re-build them deterministically + for LIB in $(find $STAGING -name \*.a); do + rm -rf $TEMPDIR && mkdir $TEMPDIR && cd $TEMPDIR + ar xv $LIB | cut -b5- > /tmp/list.txt + rm $LIB + ar crsD $LIB $(cat /tmp/list.txt) + done # cd $STAGING - zip -r $OUTDIR/bitcoin-deps-linux${GBUILD_BITS}-gitian-r2.zip include lib bin host + find include lib bin host | sort | zip -X@ $OUTDIR/bitcoin-deps-linux${GBUILD_BITS}-gitian-r3.zip diff --git a/contrib/gitian-descriptors/deps-win.yml b/contrib/gitian-descriptors/deps-win.yml index 13d3a86fd9..87ebf3e87b 100644 --- a/contrib/gitian-descriptors/deps-win.yml +++ b/contrib/gitian-descriptors/deps-win.yml @@ -26,6 +26,7 @@ script: | export FAKETIME=$REFERENCE_DATETIME export TZ=UTC INDIR=$HOME/build + TEMPDIR=$HOME/tmp # Input Integrity Check echo "f74f15e8c8ff11aa3d5bb5f276d202ec18d7246e95f961db76054199c69c1ae3 openssl-1.0.1e.tar.gz" | sha256sum -c echo "12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef db-4.8.30.NC.tar.gz" | sha256sum -c @@ -107,11 +108,21 @@ script: | # tar xjf $INDIR/qrencode-3.4.3.tar.bz2 cd qrencode-3.4.3 - png_CFLAGS="-I$INSTALLPREFIX/include" png_LIBS="-L$INSTALLPREFIX/lib -lpng" ./configure --prefix=$INSTALLPREFIX --host=$HOST --enable-static --disable-shared --without-tools --disable-maintainer-mode --disable-dependency-tracking + png_CFLAGS="-I$INSTALLPREFIX/include" png_LIBS="-L$INSTALLPREFIX/lib -lpng" ./configure --prefix=$INSTALLPREFIX --host=$HOST --enable-static --disable-shared --without-tools --disable-dependency-tracking + # Workaround to prevent re-configuring by make (resulting in missing m4 error); make all files have a date in the past + find . -print0 | xargs -r0 touch -t 200001010000 make make install cd .. + # post-process all generated libraries to be deterministic + # extract them to a temporary directory then re-build them deterministically + for LIB in $(find $INSTALLPREFIX -name \*.a); do + rm -rf $TEMPDIR && mkdir $TEMPDIR && cd $TEMPDIR + $HOST-ar xv $LIB | cut -b5- > /tmp/list.txt + rm $LIB + $HOST-ar crsD $LIB $(cat /tmp/list.txt) + done # cd $INSTALLPREFIX - zip -r $OUTDIR/bitcoin-deps-win$BITS-gitian-r10.zip include lib + find include lib | sort | zip -X@ $OUTDIR/bitcoin-deps-win$BITS-gitian-r10.zip done # for BITS in diff --git a/contrib/gitian-descriptors/gitian-linux.yml b/contrib/gitian-descriptors/gitian-linux.yml index 329f4c6b49..bf355fd828 100644 --- a/contrib/gitian-descriptors/gitian-linux.yml +++ b/contrib/gitian-descriptors/gitian-linux.yml @@ -21,33 +21,40 @@ remotes: - "url": "https://github.com/bitcoin/bitcoin.git" "dir": "bitcoin" files: -- "bitcoin-deps-linux32-gitian-r2.zip" -- "bitcoin-deps-linux64-gitian-r2.zip" +- "bitcoin-deps-linux32-gitian-r3.zip" +- "bitcoin-deps-linux64-gitian-r3.zip" - "boost-linux32-1.55.0-gitian-r1.zip" - "boost-linux64-1.55.0-gitian-r1.zip" script: | STAGING="$HOME/install" OPTFLAGS='-O2' BINDIR="${OUTDIR}/bin/${GBUILD_BITS}" # 32/64 bit build specific output directory + TEMPDIR="$HOME/tempdir" + export TZ=UTC export LIBRARY_PATH="$STAGING/lib" mkdir -p ${BINDIR} # mkdir -p $STAGING cd $STAGING - unzip ../build/bitcoin-deps-linux${GBUILD_BITS}-gitian-r2.zip + unzip ../build/bitcoin-deps-linux${GBUILD_BITS}-gitian-r3.zip unzip ../build/boost-linux${GBUILD_BITS}-1.55.0-gitian-r1.zip cd ../build # cd bitcoin - export TAR_OPTIONS=--mtime=`echo $REFERENCE_DATETIME | awk '{ print $1 }'` ./autogen.sh ./configure --prefix=$STAGING --bindir=$BINDIR --with-protoc-bindir=$STAGING/host/bin --with-boost=$STAGING --disable-maintainer-mode --disable-dependency-tracking PKG_CONFIG_PATH="$STAGING/lib/pkgconfig" CPPFLAGS="-I$STAGING/include ${OPTFLAGS}" LDFLAGS="-L$STAGING/lib ${OPTFLAGS}" CXXFLAGS="-frandom-seed=bitcoin ${OPTFLAGS}" BOOST_CHRONO_EXTRALIBS="-lrt" make dist + DISTNAME=`echo bitcoin-*.tar.gz` mkdir -p distsrc cd distsrc - tar --strip-components=1 -xf ../bitcoin-*.tar.* + tar --strip-components=1 -xf ../$DISTNAME ./configure --prefix=$STAGING --bindir=$BINDIR --with-protoc-bindir=$STAGING/host/bin --with-boost=$STAGING --disable-maintainer-mode --disable-dependency-tracking PKG_CONFIG_PATH="$STAGING/lib/pkgconfig" CPPFLAGS="-I$STAGING/include ${OPTFLAGS}" LDFLAGS="-L$STAGING/lib ${OPTFLAGS}" CXXFLAGS="-frandom-seed=bitcoin ${OPTFLAGS}" BOOST_CHRONO_EXTRALIBS="-lrt" make $MAKEOPTS make $MAKEOPTS install-strip + + # sort distribution tar file and normalize user/group/mtime information for deterministic output mkdir -p $OUTDIR/src - cp ../bitcoin-*.tar.* $OUTDIR/src + rm -rf $TEMPDIR + mkdir -p $TEMPDIR + cd $TEMPDIR + tar -xvf $HOME/build/bitcoin/$DISTNAME | sort | tar --no-recursion -cT /dev/stdin --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 --mtime="$REFERENCE_DATETIME" | gzip -n > $OUTDIR/src/$DISTNAME diff --git a/contrib/gitian-descriptors/gitian-win.yml b/contrib/gitian-descriptors/gitian-win.yml index db0966c201..6e43c21823 100644 --- a/contrib/gitian-descriptors/gitian-win.yml +++ b/contrib/gitian-descriptors/gitian-win.yml @@ -35,6 +35,7 @@ script: | export TZ=UTC INDIR=$HOME/build OPTFLAGS='-O2' + TEMPDIR="$HOME/tempdir" NEEDDIST=1 # Qt: workaround for determinism in resource ordering # Qt5's rcc uses a QHash to store the files for the resource. @@ -54,6 +55,7 @@ script: | else HOST=x86_64-w64-mingw32 fi + export PATH=$STAGING/host/bin:$PATH mkdir -p $STAGING $BUILDDIR $BINDIR # cd $STAGING @@ -63,22 +65,18 @@ script: | unzip $INDIR/protobuf-win${BITS}-2.5.0-gitian-r4.zip if [ "$NEEDDIST" == "1" ]; then # Make source code archive which is architecture independent so it only needs to be done once - cd $HOME/build/ - cd bitcoin - export PATH=$STAGING/host/bin:$PATH - export TAR_OPTIONS=--mtime=`echo $REFERENCE_DATETIME | awk '{ print $1 }'` + cd $HOME/build/bitcoin ./autogen.sh ./configure --bindir=$OUTDIR --prefix=$STAGING --host=$HOST --with-qt-plugindir=$STAGING/plugins --with-qt-incdir=$STAGING/include --with-qt-bindir=$STAGING/host/bin --with-boost=$STAGING --disable-maintainer-mode --with-protoc-bindir=$STAGING/host/bin --disable-dependency-tracking CPPFLAGS="-I$STAGING/include ${OPTFLAGS}" LDFLAGS="-L$STAGING/lib ${OPTFLAGS}" CXXFLAGS="-frandom-seed=bitcoin ${OPTFLAGS}" make dist - mkdir -p $OUTDIR/src - cp -f bitcoin-*.tar.* $OUTDIR/src + DISTNAME=`echo bitcoin-*.tar.gz` NEEDDIST=0 fi # Build platform-dependent executables from source archive cd $BUILDDIR mkdir -p distsrc cd distsrc - tar --strip-components=1 -xf $HOME/build/bitcoin/bitcoin-*.tar.* + tar --strip-components=1 -xf $HOME/build/bitcoin/$DISTNAME ./configure --bindir=$BINDIR --prefix=$STAGING --host=$HOST --with-qt-plugindir=$STAGING/plugins --with-qt-incdir=$STAGING/include --with-qt-bindir=$STAGING/host/bin --with-boost=$STAGING --disable-maintainer-mode --with-protoc-bindir=$STAGING/host/bin --disable-dependency-tracking CPPFLAGS="-I$STAGING/include ${OPTFLAGS}" LDFLAGS="-L$STAGING/lib ${OPTFLAGS}" CXXFLAGS="-frandom-seed=bitcoin ${OPTFLAGS}" export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1 export FAKETIME=$REFERENCE_DATETIME @@ -90,3 +88,10 @@ script: | unset FAKETIME done # for BITS in + # sort distribution tar file and normalize user/group/mtime information for deterministic output + mkdir -p $OUTDIR/src + rm -rf $TEMPDIR + mkdir -p $TEMPDIR + cd $TEMPDIR + tar -xvf $HOME/build/bitcoin/$DISTNAME | sort | tar --no-recursion -cT /dev/stdin --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 --mtime="$REFERENCE_DATETIME" | gzip -n > $OUTDIR/src/$DISTNAME + diff --git a/contrib/gitian-descriptors/protobuf-win.yml b/contrib/gitian-descriptors/protobuf-win.yml index 7fcac72fea..543f20b394 100644 --- a/contrib/gitian-descriptors/protobuf-win.yml +++ b/contrib/gitian-descriptors/protobuf-win.yml @@ -17,6 +17,7 @@ script: | # export TZ=UTC INDIR=$HOME/build + TEMPDIR=$HOME/tmp OPTFLAGS="-O2" # Integrity Check echo "13bfc5ae543cf3aa180ac2485c0bc89495e3ae711fc6fab4f8ffe90dfb4bb677 protobuf-2.5.0.tar.bz2" | sha256sum -c @@ -44,13 +45,21 @@ script: | # Now recompile with the mingw cross-compiler: make distclean ./configure --prefix=$INSTALLPREFIX --enable-shared=no --disable-dependency-tracking --with-protoc=$INSTALLPREFIX/host/bin/protoc --host=$HOST CXXFLAGS="-frandom-seed=11 ${OPTFLAGS}" + export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1 + export FAKETIME=$REFERENCE_DATETIME make make install + # post-process all generated libraries to be deterministic + # extract them to a temporary directory then re-build them deterministically + for LIB in $(find $INSTALLPREFIX -name \*.a); do + rm -rf $TEMPDIR && mkdir $TEMPDIR && cd $TEMPDIR + $HOST-ar xv $LIB | cut -b5- > /tmp/list.txt + rm $LIB + $HOST-ar crsD $LIB $(cat /tmp/list.txt) + done # cd $INSTALLPREFIX - export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1 - export FAKETIME=$REFERENCE_DATETIME - zip -r $OUTDIR/protobuf-win$BITS-2.5.0-gitian-r4.zip include lib host + find include lib host | sort | zip -X@ $OUTDIR/protobuf-win$BITS-2.5.0-gitian-r4.zip unset LD_PRELOAD unset FAKETIME done # for BITS in diff --git a/contrib/gitian-descriptors/qt-win.yml b/contrib/gitian-descriptors/qt-win.yml index fed39cbc7c..e3de2c02ef 100644 --- a/contrib/gitian-descriptors/qt-win.yml +++ b/contrib/gitian-descriptors/qt-win.yml @@ -21,6 +21,7 @@ script: | # Defines export TZ=UTC INDIR=$HOME/build + TEMPDIR=$HOME/tmp # Qt: workaround for determinism in resource ordering # Qt5's rcc uses a QHash to store the files for the resource. # A security fix in QHash makes the ordering of keys to be different on every run @@ -55,31 +56,37 @@ script: | cd qt-everywhere-opensource-src-5.2.0 SPECNAME="win32-g++" SPECFILE="qtbase/mkspecs/${SPECNAME}/qmake.conf" - sed 's/$TODAY/2011-01-30/' -i configure + sed 's/qt_instdate=`date +%Y-%m-%d`/qt_instdate=2011-01-30/' -i qtbase/configure sed --posix "s|QMAKE_CFLAGS = -pipe -fno-keep-inline-dllexport|QMAKE_CFLAGS\t\t= -pipe -fno-keep-inline-dllexport -isystem /usr/$HOST/include/ -frandom-seed=qtbuild -I$DEPSDIR/include|" -i ${SPECFILE} sed --posix "s|QMAKE_LFLAGS =|QMAKE_LFLAGS\t\t= -L$DEPSDIR/lib|" -i ${SPECFILE} - # ar adds timestamps to every object file included in the static library - # providing -D as ar argument is supposed to solve it, but doesn't work as qmake strips off the arguments and adds -M to pass a script... - # which somehow cannot be combined with other flags. - # use faketime only for ar, as it confuses make/qmake into hanging sometimes - sed --posix "s|QMAKE_LIB = \\\$\\\${CROSS_COMPILE}ar -ru|QMAKE_LIB\t\t= $HOME/ar -Dr|" -i ${SPECFILE} - echo '#!/bin/bash' > $HOME/ar - echo 'export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1' >> $HOME/ar - echo "$HOST-ar \"\$@\"" >> $HOME/ar - chmod +x $HOME/ar + # Before we tried to pass arguments to ar (static linking) in using QMAKE_LIB, however + # qt removes the arguments for ar and provides a script which makes it impossible to pass the determinism flag - + # so rather than try to replace ar, post-process all libraries and plugins at the end. + # # Don't load faketime while compiling Qt, qmake will get stuck in nearly infinite loops #export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1 - export FAKETIME=$REFERENCE_DATETIME + #export FAKETIME=$REFERENCE_DATETIME # # Compile static libraries, and use statically linked openssl (-openssl-linked): OPENSSL_LIBS="-L$DEPSDIR/lib -lssl -lcrypto -lgdi32" ./configure -prefix $INSTALLPREFIX -bindir $INSTALLPREFIX/host/bin -confirm-license -release -opensource -static -xplatform $SPECNAME -device-option CROSS_COMPILE="$HOST-" -no-audio-backend -no-javascript-jit -no-sql-sqlite -no-sql-odbc -no-nis -no-cups -no-iconv -no-dbus -no-gif -no-opengl -no-compile-examples -no-feature-style-windowsce -no-feature-style-windowsmobile -no-qml-debug -openssl-linked -skip qtsvg -skip qtwebkit -skip qtwebkit-examples -skip qtserialport -skip qtdeclarative -skip qtmultimedia -skip qtimageformats -skip qtlocation -skip qtsensors -skip qtquick1 -skip qtquickcontrols -skip qtactiveqt -skip qtconnectivity -skip qtwinextras -skip qtxmlpatterns -skip qtscript -skip qtdoc -system-libpng -system-zlib make $MAKEOPTS install + # post-process all generated libraries and plugins to be deterministic + # extract them to a temporary directory then re-build them deterministically + for LIB in $(find $INSTALLPREFIX -name *.a); do + rm -rf $TEMPDIR && mkdir $TEMPDIR && cd $TEMPDIR + $HOST-ar xv $LIB | cut -b5- > /tmp/list.txt + rm $LIB + $HOST-ar crsD $LIB $(cat /tmp/list.txt) + done # cd $INSTALLPREFIX - + # Remove unused non-deterministic stuff + rm host/bin/qtpaths.exe lib/libQt5Bootstrap.a lib/libQt5Bootstrap.la # as zip stores file timestamps, use faketime to intercept stat calls to set dates for all files to reference date export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1 - zip -r $OUTDIR/qt-win${BITS}-5.2.0-gitian-r2.zip * + export FAKETIME=$REFERENCE_DATETIME + find -print0 | xargs -r0 touch # fix up timestamps before packaging + find | sort | zip -X@ $OUTDIR/qt-win${BITS}-5.2.0-gitian-r2.zip unset LD_PRELOAD unset FAKETIME done # for BITS in diff --git a/contrib/linearize/example-linearize.cfg b/contrib/linearize/example-linearize.cfg index 65bba712a5..f5cdab5325 100644 --- a/contrib/linearize/example-linearize.cfg +++ b/contrib/linearize/example-linearize.cfg @@ -1,7 +1,7 @@ # bitcoind RPC settings rpcuser=someuser -rpcpass=somepassword +rpcpassword=somepassword host=127.0.0.1 port=8332 diff --git a/contrib/linearize/linearize.py b/contrib/linearize/linearize.py index ea3814ab72..650f7d3684 100644 --- a/contrib/linearize/linearize.py +++ b/contrib/linearize/linearize.py @@ -71,7 +71,7 @@ def getblock(rpc, settings, n): def get_blocks(settings): rpc = BitcoinRPC(settings['host'], settings['port'], - settings['rpcuser'], settings['rpcpass']) + settings['rpcuser'], settings['rpcpassword']) outf = open(settings['output'], 'ab') @@ -118,7 +118,7 @@ if __name__ == '__main__': settings['min_height'] = 0 if 'max_height' not in settings: settings['max_height'] = 279000 - if 'rpcuser' not in settings or 'rpcpass' not in settings: + if 'rpcuser' not in settings or 'rpcpassword' not in settings: print "Missing username and/or password in cfg file" sys.exit(1) diff --git a/doc/release-notes.md b/doc/release-notes.md index 5c7b8bce03..40bb26e28e 100644 --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -2,8 +2,8 @@ Bitcoin Core version 0.9.0rc1 is now available from: http://sourceforge.net/projects/bitcoin/files/Bitcoin/bitcoin-0.9.0rc1/ -This is a release candidate for a new major version. A major version brings both -new features and bug fixes. +This is a release candidate for a new major version. A major version brings +both new features and bug fixes. Please report bugs using the issue tracker at github: @@ -12,33 +12,31 @@ Please report bugs using the issue tracker at github: How to Upgrade -------------- -If you are running an older version, shut it down. Wait -until it has completely shut down (which might take a few minutes for older -versions), uninstall all earlier versions of Bitcoin, -then run the installer (on Windows) or just copy over -/Applications/Bitcoin-Qt (on Mac) or bitcoind/bitcoin-qt (on Linux). +If you are running an older version, shut it down. Wait until it has completely +shut down (which might take a few minutes for older versions), uninstall all +earlier versions of Bitcoin, then run the installer (on Windows) or just copy +over /Applications/Bitcoin-Qt (on Mac) or bitcoind/bitcoin-qt (on Linux). -If you are upgrading from version 0.7.2 or earlier, the first time you -run 0.9.0 your blockchain files will be re-indexed, which will take -anywhere from 30 minutes to several hours, depending on the speed of -your machine. +If you are upgrading from version 0.7.2 or earlier, the first time you run +0.9.0 your blockchain files will be re-indexed, which will take anywhere from +30 minutes to several hours, depending on the speed of your machine. -On Windows, do not forget to uninstall all earlier versions of the Bitcoin +On Windows, do not forget to uninstall all earlier versions of the Bitcoin client first, especially if you are switching to the 64-bit version. Windows 64-bit installer ------------------------- -New in 0.9.0 is the Windows 64-bit version of the client. -There have been frequent reports of users running out of virtual memory on 32-bit systems -during the initial sync. Because of this it is recommended to install the 64-bit version if -your system supports it. +New in 0.9.0 is the Windows 64-bit version of the client. There have been +frequent reports of users running out of virtual memory on 32-bit systems +during the initial sync. Because of this it is recommended to install the +64-bit version if your system supports it. Rebranding to Bitcoin Core --------------------------- -To reduce confusion between Bitcoin-the-network and Bitcoin-the-software we have -renamed the reference client to Bitcoin Core. +To reduce confusion between Bitcoin-the-network and Bitcoin-the-software we +have renamed the reference client to Bitcoin Core. Autotools build system ----------------------- @@ -55,12 +53,11 @@ Be sure to check doc/build-*.md for your platform before building from source. Bitcoin-cli ------------- -Another change in the 0.9 release is moving away from the -bitcoind executable functioning both as a server and as a RPC client. The RPC -client functionality (“tell the running bitcoin daemon to do THIS”) was split -into a separate executable, 'bitcoin-cli'. The RPC client code will -eventually be removed from bitcoind, but will be kept for backwards -compatibility for a release or two. +Another change in the 0.9 release is moving away from the bitcoind executable +functioning both as a server and as a RPC client. The RPC client functionality +(“tell the running bitcoin daemon to do THIS”) was split into a separate +executable, 'bitcoin-cli'. The RPC client code will eventually be removed from +bitcoind, but will be kept for backwards compatibility for a release or two. 0.9.0rc1 Release notes ======================= @@ -69,12 +66,14 @@ RPC: - 'listreceivedbyaddress' now provides tx ids - Updated help and tests for 'getreceivedby(account|address)' -- In 'getblock', accept 2nd 'verbose' parameter, similar to getrawtransaction, but defaulting to 1 for backward compatibility +- In 'getblock', accept 2nd 'verbose' parameter, similar to getrawtransaction, + but defaulting to 1 for backward compatibility - Add 'verifychain', to verify chain database at runtime - Add 'dumpwallet' and 'importwallet' RPCs - 'keypoolrefill' gains optional size parameter - Add 'getbestblockhash', to return tip of best chain -- Add 'chainwork' (the total work done by all blocks since the genesis block) to 'getblock' output +- Add 'chainwork' (the total work done by all blocks since the genesis block) + to 'getblock' output - Make RPC password resistant to timing attacks - Clarify help messages and add examples - Add 'getrawchangeaddress' call for raw transaction change destinations @@ -82,7 +81,8 @@ RPC: - Add RPC call 'decodescript' to decode a hex-encoded transaction script - Make 'validateaddress' provide redeemScript - Add 'getnetworkhashps' to get the calculated network hashrate -- New RPC 'ping' command to request ping, new 'pingtime' and 'pingwait' fields in 'getpeerinfo' output +- New RPC 'ping' command to request ping, new 'pingtime' and 'pingwait' fields + in 'getpeerinfo' output - Adding new 'addrlocal' field to 'getpeerinfo' output - Add verbose boolean to 'getrawmempool' - Add rpc command 'getunconfirmedbalance' to obtain total unconfirmed balance @@ -103,10 +103,12 @@ Command-line options: Block-chain handling and storage: - Update leveldb to 1.15 -- Check for correct genesis (prevent cases where accidentally a datadir from the wrong network is loaded) +- Check for correct genesis (prevent cases where a datadir from the wrong + network is accidentally loaded) - Allow txindex to be removed and add a reindex dialog - Log aborted block database rebuilds - Store orphan blocks in serialized form, to save memory +- Limit the number of orphan blocks in memory to 750 - Fix non-standard disconnected transactions causing mempool orphans - Add a new checkpoint at block 279,000 @@ -120,6 +122,7 @@ Wallet: - Don't count txins for priority to encourage sweeping - Don't create empty transactions when reading a corrupted wallet - Fix rescan to start from beginning after importprivkey +- Only create signatures with low S values. Mining: @@ -129,7 +132,7 @@ Mining: Protocol and network: - Send tx relay flag with version -- New 'reject' P2P message (BIP 0061) +- New 'reject' P2P message (BIP 0061, see https://gist.github.com/gavinandresen/7079034 for draft) - Dump addresses every 15 minutes instead of 10 seconds - Relay OP_RETURN data TxOut as standard transaction type - Remove CENT-output free transaction rule when relaying @@ -146,24 +149,21 @@ Protocol and network: Validation: - Log reason for non-standard transaction rejection -- Prune provably-unspendable outputs -- Detect any sufficiently long fork and add a warning. -- Call the -alertnotify script when we see a long or invalid fork. +- Prune provably-unspendable outputs, and adapt consistency check for it. +- Detect any sufficiently long fork and add a warning +- Call the -alertnotify script when we see a long or invalid fork - Fix multi-block reorg transaction resurrection - Reject non-canonically-encoded serialization sizes -- Only create signatures with even S, and verification mode to check. - Reject dust amounts during validation -- Use 'low S' as malleability breaker rather than 'even S' -- Skip unspendable outputs in consistency check -- Generalize the remove-outputs check for fully-prunable transactions -- Accept nLockTime transactions that finalize in the next block" +- Accept nLockTime transactions that finalize in the next block Build system: - Switch to autotools-based build system -- Build without wallet by passing `--disable-wallet` to configure, this - removes the BerkeleyDB dependency -- Upgrade gitian dependencies (libpng, libz, libupnpc, boost, openssl) to more recent versions +- Build without wallet by passing `--disable-wallet` to configure, this removes + the BerkeleyDB dependency +- Upgrade gitian dependencies (libpng, libz, libupnpc, boost, openssl) to more + recent versions - Windows 64-bit build support - Solaris compatibility fixes - Check integrity of gitian input source tarballs @@ -183,22 +183,24 @@ GUI: - Add network traffic graph in debug window - Add open URI dialog - Add Coin Control Features -- Improve receive coins workflow: make the 'Receive' tab into a form to - request payments, and move historical address list functionality to File menu. +- Improve receive coins workflow: make the 'Receive' tab into a form to request + payments, and move historical address list functionality to File menu. - Rebrand to `Bitcoin Core` -- Move initialization/shutdown to a thread. This prevents "Not responding" messages during start. - Also show a window during shutdown. +- Move initialization/shutdown to a thread. This prevents “Not responding” + messages during startup. Also show a window during shutdown. - Don't regenerate autostart link on every client startup - Show and store message of normal bitcoin:URI - Fix richtext detection hang issue on very old Qt versions -- osx: make use of the 10.8+ user notification center to display growl like notifications -- osx: Added NSHighResolutionCapable flag to Info.plist for better font rendering on Retina displays. -- osx: fix bitcoin-qt startup crash when clicking dock icon +- osx: Make use of the 10.8+ user notification center to display growl like + notifications +- osx: Added NSHighResolutionCapable flag to Info.plist for better font + rendering on Retina displays. +- osx: Fix bitcoin-qt startup crash when clicking dock icon - linux: Fix Gnome bitcoin: URI handler Miscellaneous: -- Add Linux script (contrib/qos/tc.sh) to limit outgoing bandwidth used by Bitcoin +- Add Linux script (contrib/qos/tc.sh) to limit outgoing bandwidth - Add '-regtest' mode, similar to testnet but private with instant block generation with 'setgenerate' RPC. - Add 'linearize.py' script to contrib, for creating bootstrap.dat diff --git a/qa/rpc-tests/send.sh b/qa/rpc-tests/send.sh index fdfb1867bc..2c0d5375c0 100755 --- a/qa/rpc-tests/send.sh +++ b/qa/rpc-tests/send.sh @@ -1,14 +1,28 @@ #!/bin/bash TIMEOUT=10 SIGNAL=HUP +PIDFILE=.send.pid if [ $# -eq 0 ]; then echo -e "Usage:\t$0 <cmd>" echo -e "\tRuns <cmd> and wait ${TIMEOUT} seconds or until SIG${SIGNAL} is received." echo -e "\tReturns: 0 if SIG${SIGNAL} is received, 1 otherwise." + echo -e "Or:\t$0 -STOP" + echo -e "\tsends SIG${SIGNAL} to running send.sh" exit 0 fi + +if [ $1 == "-STOP" ]; then + if [ -s ${PIDFILE} ]; then + kill -s ${SIGNAL} $(<${PIDFILE}) + fi + exit 0 +fi + trap '[[ ${PID} ]] && kill ${PID}' ${SIGNAL} +trap 'rm -f ${PIDFILE}' EXIT +echo $$ > ${PIDFILE} "$@" sleep ${TIMEOUT} & PID=$! wait ${PID} && exit 1 + exit 0 diff --git a/qa/rpc-tests/txnmall.sh b/qa/rpc-tests/txnmall.sh new file mode 100755 index 0000000000..6bf92fce40 --- /dev/null +++ b/qa/rpc-tests/txnmall.sh @@ -0,0 +1,148 @@ +#!/usr/bin/env bash + +# Test block generation and basic wallet sending + +if [ $# -lt 1 ]; then + echo "Usage: $0 path_to_binaries" + echo "e.g. $0 ../../src" + exit 1 +fi + +BITCOIND=${1}/bitcoind +CLI=${1}/bitcoin-cli + +DIR="${BASH_SOURCE%/*}" +SENDANDWAIT="${DIR}/send.sh" +if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi +. "$DIR/util.sh" + +D=$(mktemp -d test.XXXXX) + +# Two nodes; one will play the part of merchant, the +# other an evil transaction-mutating miner. + +D1=${D}/node1 +CreateDataDir $D1 port=11000 rpcport=11001 +B1ARGS="-datadir=$D1 -debug" +$BITCOIND $B1ARGS & +B1PID=$! + +D2=${D}/node2 +CreateDataDir $D2 port=11010 rpcport=11011 +B2ARGS="-datadir=$D2 -debug" +$BITCOIND $B2ARGS & +B2PID=$! + +trap "kill -9 $B1PID $B2PID; rm -rf $D" EXIT + +# Wait until all four nodes are at the same block number +function WaitBlocks { + while : + do + sleep 1 + BLOCKS1=$( GetBlocks $B1ARGS ) + BLOCKS2=$( GetBlocks $B2ARGS ) + if (( $BLOCKS1 == $BLOCKS2 )) + then + break + fi + done +} + +# Wait until node has $N peers +function WaitPeers { + while : + do + PEERS=$( $CLI $1 getconnectioncount ) + if (( "$PEERS" == $2 )) + then + break + fi + sleep 1 + done +} + +# Start with B2 connected to B1: +$CLI $B2ARGS addnode 127.0.0.1:11000 onetry +WaitPeers "$B1ARGS" 1 + +# 1 block, 50 XBT each == 50 XBT +$CLI $B1ARGS setgenerate true 1 + +WaitBlocks +# 100 blocks, 0 mature == 0 XBT +$CLI $B2ARGS setgenerate true 100 +WaitBlocks + +CheckBalance $B1ARGS 50 +CheckBalance $B2ARGS 0 + +# restart B2 with no connection +$CLI $B2ARGS stop > /dev/null 2>&1 +wait $B2PID +$BITCOIND $B2ARGS & +B2PID=$! + +B2ADDRESS=$( $CLI $B2ARGS getnewaddress ) + +# Have B1 create two transactions; second will +# spend change from first, since B1 starts with only a single +# 50 bitcoin output: +$CLI $B1ARGS move "" "foo" 10.0 +$CLI $B1ARGS move "" "bar" 10.0 +TXID1=$( $CLI $B1ARGS sendfrom foo $B2ADDRESS 1.0 0) +TXID2=$( $CLI $B1ARGS sendfrom bar $B2ADDRESS 2.0 0) + +# Mutate TXID1 and add it to B2's memory pool: +RAWTX1=$( $CLI $B1ARGS getrawtransaction $TXID1 ) +RAWTX2=$( $CLI $B1ARGS getrawtransaction $TXID2 ) +# ... mutate RAWTX1: +# RAWTX1 is hex-encoded, serialized transaction. So each +# byte is two characters; we'll prepend the first +# "push" in the scriptsig with OP_PUSHDATA1 (0x4c), +# and add one to the length of the signature. +# Fields are fixed; from the beginning: +# 4-byte version +# 1-byte varint number-of inputs (one in this case) +# 32-byte previous txid +# 4-byte previous output +# 1-byte varint length-of-scriptsig +# 1-byte PUSH this many bytes onto stack +# ... etc +# So: to mutate, we want to get byte 41 (hex characters 82-83), +# increment it, and insert 0x4c after it. +L=${RAWTX1:82:2} +NEWLEN=$( printf "%x" $(( 16#$L + 1 )) ) +MUTATEDTX1=${RAWTX1:0:82}${NEWLEN}4c${RAWTX1:84} +# ... give mutated tx1 to B2: +MUTATEDTXID=$( $CLI $B2ARGS sendrawtransaction $MUTATEDTX1 ) + +echo "TXID1: " $TXID1 +echo "Mutated: " $MUTATEDTXID + +# Re-connect nodes, and have B2 mine a block +$CLI $B2ARGS addnode 127.0.0.1:11000 onetry +WaitPeers "$B1ARGS" 1 + +$CLI $B2ARGS setgenerate true 3 +WaitBlocks +$CLI $B1ARGS setgenerate true 3 +WaitBlocks + +$CLI $B2ARGS stop > /dev/null 2>&1 +wait $B2PID +$CLI $B1ARGS stop > /dev/null 2>&1 +wait $B1PID + +trap "" EXIT + +echo "Done, bitcoind's shut down. To rerun/poke around:" +echo "${1}/bitcoind -datadir=$D1 -daemon" +echo "${1}/bitcoind -datadir=$D2 -daemon -connect=127.0.0.1:11000" +echo "To cleanup:" +echo "killall bitcoind; rm -rf test.*" +exit 0 + +echo "Tests successful, cleaning up" +rm -rf $D +exit 0 diff --git a/qa/rpc-tests/util.sh b/qa/rpc-tests/util.sh index fed7d32561..d1e4c941cc 100644 --- a/qa/rpc-tests/util.sh +++ b/qa/rpc-tests/util.sh @@ -23,7 +23,7 @@ function CreateDataDir { echo "rpcuser=rt" >> $CONF echo "rpcpassword=rt" >> $CONF echo "rpcwait=1" >> $CONF - echo "walletnotify=killall -HUP `basename ${SENDANDWAIT}`" >> $CONF + echo "walletnotify=${SENDANDWAIT} -STOP" >> $CONF shift while (( "$#" )); do echo $1 >> $CONF diff --git a/src/alert.cpp b/src/alert.cpp index f9cd58d38b..4dd3716e80 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 31aa0dc9e9..5e6566a7ac 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/core.cpp b/src/core.cpp index 57e72489a1..f5c460761e 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/db.cpp b/src/db.cpp index 51c28cda69..592512c947 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/init.cpp b/src/init.cpp index 114a73d0f1..9ba77105b4 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -270,10 +270,12 @@ std::string HelpMessage(HelpMessageMode hmm) strUsage += " -disablewallet " + _("Do not load the wallet and disable wallet RPC calls") + "\n"; strUsage += " -paytxfee=<amt> " + _("Fee per kB to add to transactions you send") + "\n"; strUsage += " -rescan " + _("Rescan the block chain for missing wallet transactions") + "\n"; + strUsage += " -zapwallettxes " + _("Clear list of wallet transactions (diagnostic tool; implies -rescan)") + "\n"; strUsage += " -salvagewallet " + _("Attempt to recover private keys from a corrupt wallet.dat") + "\n"; strUsage += " -upgradewallet " + _("Upgrade wallet to latest format") + "\n"; strUsage += " -wallet=<file> " + _("Specify wallet file (within data directory)") + "\n"; strUsage += " -walletnotify=<cmd> " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n"; + strUsage += " -spendzeroconfchange " + _("Spend unconfirmed change when sending transactions (default: 1)") + "\n"; #endif strUsage += "\n" + _("Block creation options:") + "\n"; strUsage += " -blockminsize=<n> " + _("Set minimum block size in bytes (default: 0)") + "\n"; @@ -457,6 +459,12 @@ bool AppInit2(boost::thread_group& threadGroup) LogPrintf("AppInit2 : parameter interaction: -salvagewallet=1 -> setting -rescan=1\n"); } + // -zapwallettx implies a rescan + if (GetBoolArg("-zapwallettxes", false)) { + if (SoftSetBoolArg("-rescan", true)) + LogPrintf("AppInit2 : parameter interaction: -zapwallettxes=1 -> setting -rescan=1\n"); + } + // Make sure enough file descriptors are available int nBind = std::max((int)mapArgs.count("-bind"), 1); nMaxConnections = GetArg("-maxconnections", 125); @@ -543,6 +551,7 @@ bool AppInit2(boost::thread_group& threadGroup) if (nTransactionFee > 0.25 * COIN) InitWarning(_("Warning: -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction.")); } + bSpendZeroConfChange = GetArg("-spendzeroconfchange", true); strWalletFile = GetArg("-wallet", "wallet.dat"); #endif @@ -901,6 +910,20 @@ bool AppInit2(boost::thread_group& threadGroup) pwalletMain = NULL; LogPrintf("Wallet disabled!\n"); } else { + if (GetBoolArg("-zapwallettxes", false)) { + uiInterface.InitMessage(_("Zapping all transactions from wallet...")); + + pwalletMain = new CWallet(strWalletFile); + DBErrors nZapWalletRet = pwalletMain->ZapWalletTx(); + if (nZapWalletRet != DB_LOAD_OK) { + uiInterface.InitMessage(_("Error loading wallet.dat: Wallet corrupted")); + return false; + } + + delete pwalletMain; + pwalletMain = NULL; + } + uiInterface.InitMessage(_("Loading wallet...")); nStart = GetTimeMillis(); diff --git a/src/leveldbwrapper.cpp b/src/leveldbwrapper.cpp index c2935ed017..43c737a599 100644 --- a/src/leveldbwrapper.cpp +++ b/src/leveldbwrapper.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2012-2013 The Bitcoin developers +// Copyright (c) 2012-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/main.cpp b/src/main.cpp index 4532b776c6..f61b282865 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -442,6 +442,10 @@ bool IsStandardTx(const CTransaction& tx, string& reason) reason = "scriptsig-not-pushonly"; return false; } + if (!txin.scriptSig.HasCanonicalPushes()) { + reason = "non-canonical-push"; + return false; + } } unsigned int nDataOut = 0; @@ -868,7 +872,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } -int CMerkleTx::GetDepthInMainChain(CBlockIndex* &pindexRet) const +int CMerkleTx::GetDepthInMainChainINTERNAL(CBlockIndex* &pindexRet) const { if (hashBlock == 0 || nIndex == -1) return 0; @@ -893,6 +897,14 @@ int CMerkleTx::GetDepthInMainChain(CBlockIndex* &pindexRet) const return chainActive.Height() - pindex->nHeight + 1; } +int CMerkleTx::GetDepthInMainChain(CBlockIndex* &pindexRet) const +{ + int nResult = GetDepthInMainChainINTERNAL(pindexRet); + if (nResult == 0 && !mempool.exists(GetHash())) + return -1; // Not in chain, not in mempool + + return nResult; +} int CMerkleTx::GetBlocksToMaturity() const { @@ -1054,6 +1066,31 @@ uint256 static GetOrphanRoot(const uint256& hash) } while(true); } +// Remove a random orphan block (which does not have any dependent orphans). +void static PruneOrphanBlocks() +{ + if (mapOrphanBlocksByPrev.size() <= MAX_ORPHAN_BLOCKS) + return; + + // Pick a random orphan block. + int pos = insecure_rand() % mapOrphanBlocksByPrev.size(); + std::multimap<uint256, COrphanBlock*>::iterator it = mapOrphanBlocksByPrev.begin(); + while (pos--) it++; + + // As long as this block has other orphans depending on it, move to one of those successors. + do { + std::multimap<uint256, COrphanBlock*>::iterator it2 = mapOrphanBlocksByPrev.find(it->second->hashBlock); + if (it2 == mapOrphanBlocksByPrev.end()) + break; + it = it2; + } while(1); + + uint256 hash = it->second->hashBlock; + delete it->second; + mapOrphanBlocksByPrev.erase(it); + mapOrphanBlocks.erase(hash); +} + int64_t GetBlockValue(int nHeight, int64_t nFees) { int64_t nSubsidy = 50 * COIN; @@ -2373,10 +2410,11 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl // If we don't already have its previous block, shunt it off to holding area until we get it if (pblock->hashPrevBlock != 0 && !mapBlockIndex.count(pblock->hashPrevBlock)) { - LogPrintf("ProcessBlock: ORPHAN BLOCK, prev=%s\n", pblock->hashPrevBlock.ToString()); + LogPrintf("ProcessBlock: ORPHAN BLOCK %lu, prev=%s\n", (unsigned long)mapOrphanBlocks.size(), pblock->hashPrevBlock.ToString()); // Accept orphans as long as there is a node to request its parents from if (pfrom) { + PruneOrphanBlocks(); COrphanBlock* pblock2 = new COrphanBlock(); { CDataStream ss(SER_DISK, CLIENT_VERSION); diff --git a/src/main.h b/src/main.h index bbf6fce48b..781562854f 100644 --- a/src/main.h +++ b/src/main.h @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -45,6 +45,8 @@ static const unsigned int MAX_STANDARD_TX_SIZE = 100000; static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50; /** The maximum number of orphan transactions kept in memory */ static const unsigned int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100; +/** The maximum number of orphan blocks kept in memory */ +static const unsigned int MAX_ORPHAN_BLOCKS = 750; /** The maximum size of a blk?????.dat file (since 0.8) */ static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB /** The pre-allocation chunk size for blk?????.dat files (since 0.8) */ @@ -75,12 +77,6 @@ static const unsigned char REJECT_CHECKPOINT = 0x43; extern CScript COINBASE_FLAGS; - - - - - - extern CCriticalSection cs_main; extern CTxMemPool mempool; extern std::map<uint256, CBlockIndex*> mapBlockIndex; @@ -94,7 +90,6 @@ extern bool fBenchmark; extern int nScriptCheckThreads; extern bool fTxIndex; extern unsigned int nCoinCacheSize; -extern bool fHaveGUI; // Minimum disk space required - used in CheckDiskSpace() static const uint64_t nMinDiskSpace = 52428800; @@ -421,6 +416,8 @@ public: /** A transaction with a merkle branch linking it to the block chain. */ class CMerkleTx : public CTransaction { +private: + int GetDepthInMainChainINTERNAL(CBlockIndex* &pindexRet) const; public: uint256 hashBlock; std::vector<uint256> vMerkleBranch; @@ -459,9 +456,14 @@ public: int SetMerkleBranch(const CBlock* pblock=NULL); + + // Return depth of transaction in blockchain: + // -1 : not in blockchain, and not in memory pool (conflicted transaction) + // 0 : in memory pool, waiting to be included in a block + // >=1 : this many blocks deep in the main chain int GetDepthInMainChain(CBlockIndex* &pindexRet) const; int GetDepthInMainChain() const { CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet); } - bool IsInMainChain() const { return GetDepthInMainChain() > 0; } + bool IsInMainChain() const { CBlockIndex *pindexRet; return GetDepthInMainChainINTERNAL(pindexRet) > 0; } int GetBlocksToMaturity() const; bool AcceptToMemoryPool(bool fLimitFree=true); }; diff --git a/src/miner.cpp b/src/miner.cpp index f9dab4bd67..73dd0a749d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/net.cpp b/src/net.cpp index 3d967004c5..359e629295 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/netbase.cpp b/src/netbase.cpp index 5ec760be38..d5b75d6afd 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/noui.cpp b/src/noui.cpp index f176e0eb59..32c861b0d9 100644 --- a/src/noui.cpp +++ b/src/noui.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/protocol.cpp b/src/protocol.cpp index cc98e7e40c..c77a92f020 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/qt/Makefile.am b/src/qt/Makefile.am index 7de47291cc..030804db6e 100644 --- a/src/qt/Makefile.am +++ b/src/qt/Makefile.am @@ -243,6 +243,7 @@ RES_ICONS = \ res/icons/toolbar_testnet.png \ res/icons/transaction0.png \ res/icons/transaction2.png \ + res/icons/transaction_conflicted.png \ res/icons/tx_inout.png \ res/icons/tx_input.png \ res/icons/tx_output.png \ diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index e274b7626a..162009f5de 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -376,9 +376,6 @@ void BitcoinApplication::initializeResult(int retval) returnValue = retval ? 0 : 1; if(retval) { - // Miscellaneous initialization after core is initialized - optionsModel->Upgrade(); // Must be done after AppInit2 - #ifdef ENABLE_WALLET PaymentServer::LoadRootCAs(); paymentServer->setOptionsModel(optionsModel); diff --git a/src/qt/bitcoin.qrc b/src/qt/bitcoin.qrc index 746b5a4092..7c3a7756b7 100644 --- a/src/qt/bitcoin.qrc +++ b/src/qt/bitcoin.qrc @@ -12,6 +12,7 @@ <file alias="connect_4">res/icons/connect4_16.png</file> <file alias="transaction_0">res/icons/transaction0.png</file> <file alias="transaction_confirmed">res/icons/transaction2.png</file> + <file alias="transaction_conflicted">res/icons/transaction_conflicted.png</file> <file alias="transaction_1">res/icons/clock1.png</file> <file alias="transaction_2">res/icons/clock2.png</file> <file alias="transaction_3">res/icons/clock3.png</file> diff --git a/src/qt/bitcoinamountfield.cpp b/src/qt/bitcoinamountfield.cpp index c1f2f18d45..923b17e66d 100644 --- a/src/qt/bitcoinamountfield.cpp +++ b/src/qt/bitcoinamountfield.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index f548c65161..f66fab496c 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 4dce4431ba..0cc1ebc502 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/qt/forms/optionsdialog.ui b/src/qt/forms/optionsdialog.ui index e0d99aac39..b4a9f1f580 100644 --- a/src/qt/forms/optionsdialog.ui +++ b/src/qt/forms/optionsdialog.ui @@ -28,52 +28,6 @@ </attribute> <layout class="QVBoxLayout" name="verticalLayout_Main"> <item> - <widget class="QLabel" name="transactionFeeInfoLabel"> - <property name="text"> - <string>Optional transaction fee per kB that helps make sure your transactions are processed quickly. Most transactions are 1 kB.</string> - </property> - <property name="textFormat"> - <enum>Qt::PlainText</enum> - </property> - <property name="wordWrap"> - <bool>true</bool> - </property> - </widget> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_1_Main"> - <item> - <widget class="QLabel" name="transactionFeeLabel"> - <property name="text"> - <string>Pay transaction &fee</string> - </property> - <property name="textFormat"> - <enum>Qt::PlainText</enum> - </property> - <property name="buddy"> - <cstring>transactionFee</cstring> - </property> - </widget> - </item> - <item> - <widget class="BitcoinAmountField" name="transactionFee"/> - </item> - <item> - <spacer name="horizontalSpacer_1_Main"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item> <widget class="QCheckBox" name="bitcoinAtStartup"> <property name="toolTip"> <string>Automatically start Bitcoin after logging in to the system.</string> @@ -194,6 +148,89 @@ </item> </layout> </widget> + <widget class="QWidget" name="tabWallet"> + <attribute name="title"> + <string>W&allet</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_Network"> + <item> + <widget class="QLabel" name="transactionFeeInfoLabel"> + <property name="text"> + <string>Optional transaction fee per kB that helps make sure your transactions are processed quickly. Most transactions are 1 kB.</string> + </property> + <property name="textFormat"> + <enum>Qt::PlainText</enum> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_1_Main"> + <item> + <widget class="QLabel" name="transactionFeeLabel"> + <property name="text"> + <string>Pay transaction &fee</string> + </property> + <property name="textFormat"> + <enum>Qt::PlainText</enum> + </property> + <property name="buddy"> + <cstring>transactionFee</cstring> + </property> + </widget> + </item> + <item> + <widget class="BitcoinAmountField" name="transactionFee"/> + </item> + <item> + <spacer name="horizontalSpacer_1_Main"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>If you disable the spending of unconfirmed change, the change from a transaction cannot be used until that transaction has at least one confirmation. This also affects how your balance is computed.</string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="spendZeroConfChange"> + <property name="text"> + <string>Spend unconfirmed change (experts only)</string> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> <widget class="QWidget" name="tabNetwork"> <attribute name="title"> <string>&Network</string> diff --git a/src/qt/guiconstants.h b/src/qt/guiconstants.h index d1a601706b..9f6588bc9e 100644 --- a/src/qt/guiconstants.h +++ b/src/qt/guiconstants.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp index 453bbdf374..fc1258827e 100644 --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index f61bb3ed2c..317e1db7d3 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -148,11 +148,14 @@ void OptionsDialog::setModel(OptionsModel *model) void OptionsDialog::setMapper() { /* Main */ - mapper->addMapping(ui->transactionFee, OptionsModel::Fee); mapper->addMapping(ui->bitcoinAtStartup, OptionsModel::StartAtStartup); mapper->addMapping(ui->threadsScriptVerif, OptionsModel::ThreadsScriptVerif); mapper->addMapping(ui->databaseCache, OptionsModel::DatabaseCache); + /* Wallet */ + mapper->addMapping(ui->transactionFee, OptionsModel::Fee); + mapper->addMapping(ui->spendZeroConfChange, OptionsModel::SpendZeroConfChange); + /* Network */ mapper->addMapping(ui->mapPortUpnp, OptionsModel::MapPortUPnP); diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index c1dbd916b3..eff73b7702 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -76,6 +76,11 @@ void OptionsModel::Init() nTransactionFee = settings.value("nTransactionFee").toLongLong(); // if -paytxfee is set, this will be overridden later in init.cpp if (mapArgs.count("-paytxfee")) strOverriddenByCommandLine += "-paytxfee "; + + if (!settings.contains("bSpendZeroConfChange")) + settings.setValue("bSpendZeroConfChange", true); + if (!SoftSetBoolArg("-spendzeroconfchange", settings.value("bSpendZeroConfChange").toBool())) + strOverriddenByCommandLine += "-spendzeroconfchange "; #endif if (!settings.contains("nDatabaseCache")) @@ -130,69 +135,6 @@ void OptionsModel::Reset() // default setting for OptionsModel::StartAtStartup - disabled if (GUIUtil::GetStartOnSystemStartup()) GUIUtil::SetStartOnSystemStartup(false); - - // Ensure Upgrade() is not running again by setting the bImportFinished flag - settings.setValue("bImportFinished", true); -} - -void OptionsModel::Upgrade() -{ - QSettings settings; - - // Already upgraded - if (settings.contains("bImportFinished")) - return; - - settings.setValue("bImportFinished", true); - -#ifdef ENABLE_WALLET - // Move settings from old wallet.dat (if any): - CWalletDB walletdb(strWalletFile); - - QList<QString> intOptions; - intOptions << "nDisplayUnit" << "nTransactionFee"; - foreach(QString key, intOptions) - { - int value = 0; - if (walletdb.ReadSetting(key.toStdString(), value)) - { - settings.setValue(key, value); - walletdb.EraseSetting(key.toStdString()); - } - } - QList<QString> boolOptions; - boolOptions << "bDisplayAddresses" << "fMinimizeToTray" << "fMinimizeOnClose" << "fUseProxy" << "fUseUPnP"; - foreach(QString key, boolOptions) - { - bool value = false; - if (walletdb.ReadSetting(key.toStdString(), value)) - { - settings.setValue(key, value); - walletdb.EraseSetting(key.toStdString()); - } - } - try - { - CAddress addrProxyAddress; - if (walletdb.ReadSetting("addrProxy", addrProxyAddress)) - { - settings.setValue("addrProxy", addrProxyAddress.ToStringIPPort().c_str()); - walletdb.EraseSetting("addrProxy"); - } - } - catch (std::ios_base::failure &e) - { - // 0.6.0rc1 saved this as a CService, which causes failure when parsing as a CAddress - CService addrProxy; - if (walletdb.ReadSetting("addrProxy", addrProxy)) - { - settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str()); - walletdb.EraseSetting("addrProxy"); - } - } -#endif - - Init(); } int OptionsModel::rowCount(const QModelIndex & parent) const @@ -247,6 +189,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const // Todo: Consider to revert back to use just nTransactionFee here, if we don't want // -paytxfee to update our QSettings! return settings.value("nTransactionFee"); + case SpendZeroConfChange: + return settings.value("bSpendZeroConfChange"); #endif case DisplayUnit: return nDisplayUnit; @@ -337,6 +281,12 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in settings.setValue("nTransactionFee", (qint64)nTransactionFee); emit transactionFeeChanged(nTransactionFee); break; + case SpendZeroConfChange: + if (settings.value("bSpendZeroConfChange") != value) { + settings.setValue("bSpendZeroConfChange", value); + setRestartRequired(true); + } + break; #endif case DisplayUnit: nDisplayUnit = value.toInt(); diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 7a71b772b2..a3487ddd2e 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -40,15 +40,13 @@ public: CoinControlFeatures, // bool ThreadsScriptVerif, // int DatabaseCache, // int + SpendZeroConfChange, // bool OptionIDRowCount, }; void Init(); void Reset(); - /* Migrate settings from wallet.dat after app initialization */ - void Upgrade(); - int rowCount(const QModelIndex & parent = QModelIndex()) const; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole); diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 016097c5a0..1a9d1de571 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -175,6 +175,7 @@ void OverviewPage::setWalletModel(WalletModel *model) filter->setLimit(NUM_ITEMS); filter->setDynamicSortFilter(true); filter->setSortRole(Qt::EditRole); + filter->setShowInactive(false); filter->sort(TransactionTableModel::Status, Qt::DescendingOrder); ui->listTransactions->setModel(filter); diff --git a/src/qt/paymentserver.h b/src/qt/paymentserver.h index af19661bdd..d84d09c57d 100644 --- a/src/qt/paymentserver.h +++ b/src/qt/paymentserver.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/qt/receivecoinsdialog.cpp b/src/qt/receivecoinsdialog.cpp index 8ef80d32ea..7539645b47 100644 --- a/src/qt/receivecoinsdialog.cpp +++ b/src/qt/receivecoinsdialog.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/qt/receivecoinsdialog.h b/src/qt/receivecoinsdialog.h index 2c6de0cbca..12d2235782 100644 --- a/src/qt/receivecoinsdialog.h +++ b/src/qt/receivecoinsdialog.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/qt/recentrequeststablemodel.cpp b/src/qt/recentrequeststablemodel.cpp index 64f140bc86..844d62518c 100644 --- a/src/qt/recentrequeststablemodel.cpp +++ b/src/qt/recentrequeststablemodel.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/qt/recentrequeststablemodel.h b/src/qt/recentrequeststablemodel.h index 6fed208345..d4cc5078aa 100644 --- a/src/qt/recentrequeststablemodel.h +++ b/src/qt/recentrequeststablemodel.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/qt/res/icons/transaction_conflicted.png b/src/qt/res/icons/transaction_conflicted.png Binary files differnew file mode 100644 index 0000000000..51fff649ab --- /dev/null +++ b/src/qt/res/icons/transaction_conflicted.png diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index b1671b8a0e..bd29efee86 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 0cfd1c80d1..e5da01546a 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index c3a4e4a0db..33621e54b0 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp index c21679ea8a..cacf5dc49b 100644 --- a/src/qt/splashscreen.cpp +++ b/src/qt/splashscreen.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/qt/splashscreen.h b/src/qt/splashscreen.h index 6bc10e60ab..d79038d81d 100644 --- a/src/qt/splashscreen.h +++ b/src/qt/splashscreen.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index c76b29861d..4aebaa1e7f 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -30,7 +30,9 @@ QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx) else { int nDepth = wtx.GetDepthInMainChain(); - if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0) + if (nDepth < 0) + return tr("conflicted"); + else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0) return tr("%1/offline").arg(nDepth); else if (nDepth < 6) return tr("%1/unconfirmed").arg(nDepth); diff --git a/src/qt/transactionfilterproxy.cpp b/src/qt/transactionfilterproxy.cpp index a14e74a469..f9546fddb5 100644 --- a/src/qt/transactionfilterproxy.cpp +++ b/src/qt/transactionfilterproxy.cpp @@ -5,6 +5,7 @@ #include "transactionfilterproxy.h" #include "transactiontablemodel.h" +#include "transactionrecord.h" #include <cstdlib> @@ -22,7 +23,8 @@ TransactionFilterProxy::TransactionFilterProxy(QObject *parent) : addrPrefix(), typeFilter(ALL_TYPES), minAmount(0), - limitRows(-1) + limitRows(-1), + showInactive(true) { } @@ -35,7 +37,10 @@ bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex & QString address = index.data(TransactionTableModel::AddressRole).toString(); QString label = index.data(TransactionTableModel::LabelRole).toString(); qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong()); + int status = index.data(TransactionTableModel::StatusRole).toInt(); + if(!showInactive && status == TransactionStatus::Conflicted) + return false; if(!(TYPE(type) & typeFilter)) return false; if(datetime < dateFrom || datetime > dateTo) @@ -78,6 +83,12 @@ void TransactionFilterProxy::setLimit(int limit) this->limitRows = limit; } +void TransactionFilterProxy::setShowInactive(bool showInactive) +{ + this->showInactive = showInactive; + invalidateFilter(); +} + int TransactionFilterProxy::rowCount(const QModelIndex &parent) const { if(limitRows != -1) diff --git a/src/qt/transactionfilterproxy.h b/src/qt/transactionfilterproxy.h index 6d1644d48d..9919bc3fd6 100644 --- a/src/qt/transactionfilterproxy.h +++ b/src/qt/transactionfilterproxy.h @@ -36,6 +36,9 @@ public: /** Set maximum number of rows returned, -1 if unlimited. */ void setLimit(int limit); + /** Set whether to show conflicted transactions. */ + void setShowInactive(bool showInactive); + int rowCount(const QModelIndex &parent = QModelIndex()) const; protected: @@ -48,6 +51,7 @@ private: quint32 typeFilter; qint64 minAmount; int limitRows; + bool showInactive; }; #endif // TRANSACTIONFILTERPROXY_H diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 257151b926..8cfaed27c7 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -164,7 +164,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx) (wtx.IsCoinBase() ? 1 : 0), wtx.nTimeReceived, idx); - status.confirmed = wtx.IsConfirmed(); + status.confirmed = wtx.IsTrusted(); status.depth = wtx.GetDepthInMainChain(); status.cur_num_blocks = chainActive.Height(); @@ -183,7 +183,11 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx) } else { - if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0) + if (status.depth < 0) + { + status.status = TransactionStatus::Conflicted; + } + else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0) { status.status = TransactionStatus::Offline; } diff --git a/src/qt/transactionrecord.h b/src/qt/transactionrecord.h index 8a7c9044e3..d7be0bc438 100644 --- a/src/qt/transactionrecord.h +++ b/src/qt/transactionrecord.h @@ -36,7 +36,8 @@ public: OpenUntilBlock, Offline, Unconfirmed, - HaveConfirmations + HaveConfirmations, + Conflicted }; bool confirmed; diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index b29be7e0cb..7d76204ba4 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -312,7 +312,7 @@ QString TransactionTableModel::formatTxStatus(const TransactionRecord *wtx) cons status = tr("Open until %1").arg(GUIUtil::dateTimeStr(wtx->status.open_for)); break; case TransactionStatus::Offline: - status = tr("Offline (%1 confirmations)").arg(wtx->status.depth); + status = tr("Offline"); break; case TransactionStatus::Unconfirmed: status = tr("Unconfirmed (%1 of %2 confirmations)").arg(wtx->status.depth).arg(TransactionRecord::NumConfirmations); @@ -320,6 +320,9 @@ QString TransactionTableModel::formatTxStatus(const TransactionRecord *wtx) cons case TransactionStatus::HaveConfirmations: status = tr("Confirmed (%1 confirmations)").arg(wtx->status.depth); break; + case TransactionStatus::Conflicted: + status = tr("Conflicted"); + break; } } @@ -471,7 +474,6 @@ QVariant TransactionTableModel::txStatusDecoration(const TransactionRecord *wtx) case TransactionStatus::OpenUntilBlock: case TransactionStatus::OpenUntilDate: return QColor(64,64,255); - break; case TransactionStatus::Offline: return QColor(192,192,192); case TransactionStatus::Unconfirmed: @@ -486,6 +488,8 @@ QVariant TransactionTableModel::txStatusDecoration(const TransactionRecord *wtx) }; case TransactionStatus::HaveConfirmations: return QIcon(":/icons/transaction_confirmed"); + case TransactionStatus::Conflicted: + return QIcon(":/icons/transaction_conflicted"); } } return QColor(0,0,0); @@ -587,6 +591,8 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const rec->status.maturity != TransactionStatus::Mature); case FormattedAmountRole: return formatTxAmount(rec, false); + case StatusRole: + return rec->status.status; } return QVariant(); } diff --git a/src/qt/transactiontablemodel.h b/src/qt/transactiontablemodel.h index c23c606c31..7b9cf09cbe 100644 --- a/src/qt/transactiontablemodel.h +++ b/src/qt/transactiontablemodel.h @@ -53,7 +53,9 @@ public: /** Is transaction confirmed? */ ConfirmedRole, /** Formatted amount, without brackets when unconfirmed */ - FormattedAmountRole + FormattedAmountRole, + /** Transaction status (TransactionRecord::Status) */ + StatusRole }; int rowCount(const QModelIndex &parent) const; diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index ddc8c6ea79..3549cd49f0 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -494,7 +494,9 @@ void WalletModel::getOutputs(const std::vector<COutPoint>& vOutpoints, std::vect BOOST_FOREACH(const COutPoint& outpoint, vOutpoints) { if (!wallet->mapWallet.count(outpoint.hash)) continue; - COutput out(&wallet->mapWallet[outpoint.hash], outpoint.n, wallet->mapWallet[outpoint.hash].GetDepthInMainChain()); + int nDepth = wallet->mapWallet[outpoint.hash].GetDepthInMainChain(); + if (nDepth < 0) continue; + COutput out(&wallet->mapWallet[outpoint.hash], outpoint.n, nDepth); vOutputs.push_back(out); } } @@ -513,7 +515,9 @@ void WalletModel::listCoins(std::map<QString, std::vector<COutput> >& mapCoins) BOOST_FOREACH(const COutPoint& outpoint, vLockedCoins) { if (!wallet->mapWallet.count(outpoint.hash)) continue; - COutput out(&wallet->mapWallet[outpoint.hash], outpoint.n, wallet->mapWallet[outpoint.hash].GetDepthInMainChain()); + int nDepth = wallet->mapWallet[outpoint.hash].GetDepthInMainChain(); + if (nDepth < 0) continue; + COutput out(&wallet->mapWallet[outpoint.hash], outpoint.n, nDepth); vCoins.push_back(out); } diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 6d9d866b25..91a6fba222 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2013 The Bitcoin developers +// Copyright (c) 2011-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 661deffb19..78a92ce1e9 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -410,8 +410,8 @@ Value verifychain(const Array& params, bool fHelp) "verifychain ( checklevel numblocks )\n" "\nVerifies blockchain database.\n" "\nArguments:\n" - "1. checklevel (numeric, optional, default=3) The level\n" - "2. numblocks (numeric, optional, 288) The number of blocks\n" + "1. checklevel (numeric, optional, 0-4, default=3) How thorough the block verification is.\n" + "2. numblocks (numeric, optional, default=288, 0=all) The number of blocks to check.\n" "\nResult:\n" "true|false (boolean) Verified or not\n" "\nExamples:\n" diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp index f66dbc0eb0..a912ea7670 100644 --- a/src/rpcdump.cpp +++ b/src/rpcdump.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 1d3237dfc1..353fb77b88 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index a3b37aa9e5..b764349338 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -47,7 +47,7 @@ Value ping(const Array& params, bool fHelp) "ping\n" "\nRequests that a ping be sent to all other nodes, to measure ping time.\n" "Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.\n" - "Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping." + "Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping.\n" "\nExamples:\n" + HelpExampleCli("ping", "") + HelpExampleRpc("ping", "") diff --git a/src/rpcprotocol.cpp b/src/rpcprotocol.cpp index 0632bdae6f..4ea84e99be 100644 --- a/src/rpcprotocol.cpp +++ b/src/rpcprotocol.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/rpcprotocol.h b/src/rpcprotocol.h index d3ed48525f..80cdb34f15 100644 --- a/src/rpcprotocol.h +++ b/src/rpcprotocol.h @@ -1,5 +1,5 @@ // Copyright (c) 2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index ff652ca34d..e2bdc80aef 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index ef43ecdeb1..4d110124b2 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/rpcserver.h b/src/rpcserver.h index 9008c32810..0dd583c8eb 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -1,5 +1,5 @@ // Copyright (c) 2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 8311b39c4e..c9152d7759 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -45,13 +45,18 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry) entry.push_back(Pair("confirmations", confirms)); if (wtx.IsCoinBase()) entry.push_back(Pair("generated", true)); - if (confirms) + if (confirms > 0) { entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex())); entry.push_back(Pair("blockindex", wtx.nIndex)); entry.push_back(Pair("blocktime", (boost::int64_t)(mapBlockIndex[wtx.hashBlock]->nTime))); } - entry.push_back(Pair("txid", wtx.GetHash().GetHex())); + uint256 hash = wtx.GetHash(); + entry.push_back(Pair("txid", hash.GetHex())); + Array conflicts; + BOOST_FOREACH(const uint256& conflict, wtx.GetConflicts()) + conflicts.push_back(conflict.GetHex()); + entry.push_back(Pair("walletconflicts", conflicts)); entry.push_back(Pair("time", (boost::int64_t)wtx.GetTxTime())); entry.push_back(Pair("timereceived", (boost::int64_t)wtx.nTimeReceived)); BOOST_FOREACH(const PAIRTYPE(string,string)& item, wtx.mapValue) @@ -621,7 +626,7 @@ Value getbalance(const Array& params, bool fHelp) for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx& wtx = (*it).second; - if (!wtx.IsConfirmed()) + if (!wtx.IsTrusted() || wtx.GetBlocksToMaturity() > 0) continue; int64_t allFee; @@ -1109,7 +1114,10 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe Object entry; entry.push_back(Pair("account", strSentAccount)); MaybePushAddress(entry, s.first); - entry.push_back(Pair("category", "send")); + if (wtx.GetDepthInMainChain() < 0) + entry.push_back(Pair("category", "conflicted")); + else + entry.push_back(Pair("category", "send")); entry.push_back(Pair("amount", ValueFromAmount(-s.second))); entry.push_back(Pair("fee", ValueFromAmount(-nFee))); if (fLong) @@ -1141,7 +1149,12 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe entry.push_back(Pair("category", "generate")); } else - entry.push_back(Pair("category", "receive")); + { + if (wtx.GetDepthInMainChain() < 0) + entry.push_back(Pair("category", "conflicted")); + else + entry.push_back(Pair("category", "receive")); + } entry.push_back(Pair("amount", ValueFromAmount(r.second))); if (fLong) WalletTxToJSON(wtx, entry); @@ -1317,6 +1330,8 @@ Value listaccounts(const Array& params, bool fHelp) string strSentAccount; list<pair<CTxDestination, int64_t> > listReceived; list<pair<CTxDestination, int64_t> > listSent; + if (wtx.GetBlocksToMaturity() > 0) + continue; wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount); mapAccountBalances[strSentAccount] -= nFee; BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64_t)& s, listSent) @@ -1448,7 +1463,8 @@ Value gettransaction(const Array& params, bool fHelp) " \"amount\" : x.xxx (numeric) The amount in btc\n" " }\n" " ,...\n" - " ]\n" + " ],\n" + " \"hex\" : \"data\" (string) Raw data for transaction\n" "}\n" "\nbExamples\n" @@ -1479,6 +1495,11 @@ Value gettransaction(const Array& params, bool fHelp) ListTransactions(wtx, "*", 0, false, details); entry.push_back(Pair("details", details)); + CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); + ssTx << wtx; + string strHex = HexStr(ssTx.begin(), ssTx.end()); + entry.push_back(Pair("hex", strHex)); + return entry; } @@ -1850,9 +1871,9 @@ Value settxfee(const Array& params, bool fHelp) if (fHelp || params.size() < 1 || params.size() > 1) throw runtime_error( "settxfee amount\n" - "\nSet the transaction fee per KB.\n" + "\nSet the transaction fee per kB.\n" "\nArguments:\n" - "1. amount (numeric, required) The transaction fee in BTC/KB rounded to the nearest 0.00000001\n" + "1. amount (numeric, required) The transaction fee in BTC/kB rounded to the nearest 0.00000001\n" "\nResult\n" "true|false (boolean) Returns true if successful\n" "\nExamples:\n" diff --git a/src/script.cpp b/src/script.cpp index 2b66bc73d6..83fc91956c 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -1863,6 +1863,51 @@ bool CScript::IsPayToScriptHash() const this->at(22) == OP_EQUAL); } +bool CScript::IsPushOnly() const +{ + const_iterator pc = begin(); + while (pc < end()) + { + opcodetype opcode; + if (!GetOp(pc, opcode)) + return false; + // Note that IsPushOnly() *does* consider OP_RESERVED to be a + // push-type opcode, however execution of OP_RESERVED fails, so + // it's not relevant to P2SH as the scriptSig would fail prior to + // the P2SH special validation code being executed. + if (opcode > OP_16) + return false; + } + return true; +} + +bool CScript::HasCanonicalPushes() const +{ + const_iterator pc = begin(); + while (pc < end()) + { + opcodetype opcode; + std::vector<unsigned char> data; + if (!GetOp(pc, opcode, data)) + return false; + if (opcode > OP_16) + continue; + if (opcode < OP_PUSHDATA1 && opcode > OP_0 && (data.size() == 1 && data[0] <= 16)) + // Could have used an OP_n code, rather than a 1-byte push. + return false; + if (opcode == OP_PUSHDATA1 && data.size() < OP_PUSHDATA1) + // Could have used a normal n-byte push, rather than OP_PUSHDATA1. + return false; + if (opcode == OP_PUSHDATA2 && data.size() <= 0xFF) + // Could have used an OP_PUSHDATA1. + return false; + if (opcode == OP_PUSHDATA4 && data.size() <= 0xFFFF) + // Could have used an OP_PUSHDATA2. + return false; + } + return true; +} + class CScriptVisitor : public boost::static_visitor<bool> { private: diff --git a/src/script.h b/src/script.h index bd120cc07d..335ddfb1b2 100644 --- a/src/script.h +++ b/src/script.h @@ -541,24 +541,11 @@ public: bool IsPayToScriptHash() const; - // Called by IsStandardTx - bool IsPushOnly() const - { - const_iterator pc = begin(); - while (pc < end()) - { - opcodetype opcode; - if (!GetOp(pc, opcode)) - return false; - // Note that IsPushOnly() *does* consider OP_RESERVED to be a - // push-type opcode, however execution of OP_RESERVED fails, so - // it's not relevant to P2SH as the scriptSig would fail prior to - // the P2SH special validation code being executed. - if (opcode > OP_16) - return false; - } - return true; - } + // Called by IsStandardTx and P2SH VerifyScript (which makes it consensus-critical). + bool IsPushOnly() const; + + // Called by IsStandardTx. + bool HasCanonicalPushes() const; // Returns whether the script is guaranteed to fail at execution, // regardless of the initial stack. This allows outputs to be pruned diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index dee0f110ad..dd1b613047 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -438,4 +438,22 @@ BOOST_AUTO_TEST_CASE(script_combineSigs) BOOST_CHECK(combined == partial3c); } +BOOST_AUTO_TEST_CASE(script_standard_push) +{ + for (int i=0; i<1000; i++) { + CScript script; + script << i; + BOOST_CHECK_MESSAGE(script.IsPushOnly(), "Number " << i << " is not pure push."); + BOOST_CHECK_MESSAGE(script.HasCanonicalPushes(), "Number " << i << " push is not canonical."); + } + + for (int i=0; i<1000; i++) { + std::vector<unsigned char> data(i, '\111'); + CScript script; + script << data; + BOOST_CHECK_MESSAGE(script.IsPushOnly(), "Length " << i << " is not pure push."); + BOOST_CHECK_MESSAGE(script.HasCanonicalPushes(), "Length " << i << " push is not canonical."); + } +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/src/txdb.cpp b/src/txdb.cpp index bd6dae0f6e..d06639a112 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/util.cpp b/src/util.cpp index 7d748ac3bf..8cfd1c2e03 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/util.h b/src/util.h index d2bb8a4afc..6f7627e090 100644 --- a/src/util.h +++ b/src/util.h @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/wallet.cpp b/src/wallet.cpp index 9648f6f88d..823c96949f 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -18,6 +18,7 @@ using namespace std; // Settings int64_t nTransactionFee = 0; +bool bSpendZeroConfChange = true; ////////////////////////////////////////////////////////////////////////////// // @@ -191,18 +192,6 @@ void CWallet::SetBestChain(const CBlockLocator& loc) walletdb.WriteBestBlock(loc); } -// This class implements an addrIncoming entry that causes pre-0.4 -// clients to crash on startup if reading a private-key-encrypted wallet. -class CCorruptAddress -{ -public: - IMPLEMENT_SERIALIZE - ( - if (nType & SER_DISK) - READWRITE(nVersion); - ) -}; - bool CWallet::SetMinVersion(enum WalletFeature nVersion, CWalletDB* pwalletdbIn, bool fExplicit) { AssertLockHeld(cs_wallet); // nWalletVersion @@ -221,13 +210,6 @@ bool CWallet::SetMinVersion(enum WalletFeature nVersion, CWalletDB* pwalletdbIn, if (fFileBacked) { CWalletDB* pwalletdb = pwalletdbIn ? pwalletdbIn : new CWalletDB(strWalletFile); - if (nWalletVersion >= 40000) - { - // Versions prior to 0.4.0 did not support the "minversion" record. - // Use a CCorruptAddress to make them crash instead. - CCorruptAddress corruptAddress; - pwalletdb->WriteSetting("addrIncoming", corruptAddress); - } if (nWalletVersion > 40000) pwalletdb->WriteMinVersion(nWalletVersion); if (!pwalletdbIn) @@ -249,6 +231,82 @@ bool CWallet::SetMaxVersion(int nVersion) return true; } +set<uint256> CWallet::GetConflicts(const uint256& txid) const +{ + set<uint256> result; + AssertLockHeld(cs_wallet); + + std::map<uint256, CWalletTx>::const_iterator it = mapWallet.find(txid); + if (it == mapWallet.end()) + return result; + const CWalletTx& wtx = it->second; + + std::pair<TxConflicts::const_iterator, TxConflicts::const_iterator> range; + + BOOST_FOREACH(const CTxIn& txin, wtx.vin) + { + range = mapTxConflicts.equal_range(txin.prevout); + for (TxConflicts::const_iterator it = range.first; it != range.second; ++it) + result.insert(it->second); + } + return result; +} + +void CWallet::SyncMetaData(pair<TxConflicts::iterator, TxConflicts::iterator> range) +{ + // We want all the wallet transactions in range to have the same metadata as + // the oldest (smallest nOrderPos). + // So: find smallest nOrderPos: + + int nMinOrderPos = std::numeric_limits<int>::max(); + const CWalletTx* copyFrom = NULL; + for (TxConflicts::iterator it = range.first; it != range.second; ++it) + { + const uint256& hash = it->second; + int n = mapWallet[hash].nOrderPos; + if (n < nMinOrderPos) + { + nMinOrderPos = n; + copyFrom = &mapWallet[hash]; + } + } + // Now copy data from copyFrom to rest: + for (TxConflicts::iterator it = range.first; it != range.second; ++it) + { + const uint256& hash = it->second; + CWalletTx* copyTo = &mapWallet[hash]; + if (copyFrom == 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; + // vfSpent not copied on purpose + // nOrderPos not copied on purpose + // cached members not copied on purpose + } +} + +void CWallet::AddToConflicts(const uint256& wtxhash) +{ + assert(mapWallet.count(wtxhash)); + CWalletTx& thisTx = mapWallet[wtxhash]; + if (thisTx.IsCoinBase()) + return; + + BOOST_FOREACH(const CTxIn& txin, thisTx.vin) + { + mapTxConflicts.insert(make_pair(txin.prevout, wtxhash)); + + pair<TxConflicts::iterator, TxConflicts::iterator> range; + range = mapTxConflicts.equal_range(txin.prevout); + if (range.first != range.second) + SyncMetaData(range); + } +} + bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) { if (IsCrypted()) @@ -403,9 +461,16 @@ void CWallet::MarkDirty() } } -bool CWallet::AddToWallet(const CWalletTx& wtxIn) +bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet) { uint256 hash = wtxIn.GetHash(); + + if (fFromLoadWallet) + { + mapWallet[hash] = wtxIn; + AddToConflicts(hash); + } + else { LOCK(cs_wallet); // Inserts only if not already there, returns tx inserted or tx found @@ -463,6 +528,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) wtxIn.GetHash().ToString(), wtxIn.hashBlock.ToString()); } + AddToConflicts(hash); } bool fUpdated = false; @@ -925,6 +991,18 @@ void CWalletTx::RelayWalletTransaction() } } +set<uint256> CWalletTx::GetConflicts() const +{ + set<uint256> result; + if (pwallet != NULL) + { + uint256 myHash = GetHash(); + result = pwallet->GetConflicts(myHash); + result.erase(myHash); + } + return result; +} + void CWallet::ResendWalletTransactions() { // Do this infrequently and randomly to avoid giving away @@ -982,7 +1060,7 @@ int64_t CWallet::GetBalance() const for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; - if (pcoin->IsConfirmed()) + if (pcoin->IsTrusted()) nTotal += pcoin->GetAvailableCredit(); } } @@ -998,7 +1076,7 @@ int64_t CWallet::GetUnconfirmedBalance() const for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; - if (!IsFinalTx(*pcoin) || !pcoin->IsConfirmed()) + if (!IsFinalTx(*pcoin) || (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0)) nTotal += pcoin->GetAvailableCredit(); } } @@ -1033,17 +1111,21 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const if (!IsFinalTx(*pcoin)) continue; - if (fOnlyConfirmed && !pcoin->IsConfirmed()) + if (fOnlyConfirmed && !pcoin->IsTrusted()) continue; if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0) continue; + int nDepth = pcoin->GetDepthInMainChain(); + if (nDepth < 0) + continue; + for (unsigned int i = 0; i < pcoin->vout.size(); i++) { if (!(pcoin->IsSpent(i)) && IsMine(pcoin->vout[i]) && !IsLockedCoin((*it).first, i) && pcoin->vout[i].nValue > 0 && (!coinControl || !coinControl->HasSelected() || coinControl->IsSelected((*it).first, i))) - vCoins.push_back(COutput(pcoin, i, pcoin->GetDepthInMainChain())); + vCoins.push_back(COutput(pcoin, i, nDepth)); } } } @@ -1211,7 +1293,7 @@ bool CWallet::SelectCoins(int64_t nTargetValue, set<pair<const CWalletTx*,unsign return (SelectCoinsMinConf(nTargetValue, 1, 6, vCoins, setCoinsRet, nValueRet) || SelectCoinsMinConf(nTargetValue, 1, 1, vCoins, setCoinsRet, nValueRet) || - SelectCoinsMinConf(nTargetValue, 0, 1, vCoins, setCoinsRet, nValueRet)); + (bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue, 0, 1, vCoins, setCoinsRet, nValueRet))); } @@ -1515,6 +1597,30 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet) } +DBErrors CWallet::ZapWalletTx() +{ + if (!fFileBacked) + return DB_LOAD_OK; + DBErrors nZapWalletTxRet = CWalletDB(strWalletFile,"cr+").ZapWalletTx(this); + if (nZapWalletTxRet == DB_NEED_REWRITE) + { + if (CDB::Rewrite(strWalletFile, "\x04pool")) + { + LOCK(cs_wallet); + setKeyPool.clear(); + // Note: can't top-up keypool here, because wallet is locked. + // User will be prompted to unlock wallet the next operation + // the requires a new key. + } + } + + if (nZapWalletTxRet != DB_LOAD_OK) + return nZapWalletTxRet; + + return DB_LOAD_OK; +} + + bool CWallet::SetAddressBook(const CTxDestination& address, const string& strName, const string& strPurpose) { AssertLockHeld(cs_wallet); // mapAddressBook @@ -1728,7 +1834,7 @@ std::map<CTxDestination, int64_t> CWallet::GetAddressBalances() { CWalletTx *pcoin = &walletEntry.second; - if (!IsFinalTx(*pcoin) || !pcoin->IsConfirmed()) + if (!IsFinalTx(*pcoin) || !pcoin->IsTrusted()) continue; if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0) diff --git a/src/wallet.h b/src/wallet.h index dc8c007ac8..95fb0ee9de 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -25,6 +25,7 @@ // Settings extern int64_t nTransactionFee; +extern bool bSpendZeroConfChange; class CAccountingEntry; class CCoinControl; @@ -107,6 +108,12 @@ private: int64_t nNextResend; int64_t nLastResend; + // Used to detect and report conflicted transactions: + typedef std::multimap<COutPoint, uint256> TxConflicts; + TxConflicts mapTxConflicts; + void AddToConflicts(const uint256& wtxhash); + void SyncMetaData(std::pair<TxConflicts::iterator, TxConflicts::iterator>); + public: /// Main wallet lock. /// This lock protects all the fields added by CWallet @@ -150,6 +157,7 @@ public: } std::map<uint256, CWalletTx> mapWallet; + int64_t nOrderPosNext; std::map<uint256, int> mapRequestCount; @@ -222,7 +230,7 @@ public: TxItems OrderedTxItems(std::list<CAccountingEntry>& acentries, std::string strAccount = ""); void MarkDirty(); - bool AddToWallet(const CWalletTx& wtxIn); + bool AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet=false); void SyncTransaction(const uint256 &hash, const CTransaction& tx, const CBlock* pblock); bool AddToWalletIfInvolvingMe(const uint256 &hash, const CTransaction& tx, const CBlock* pblock, bool fUpdate); void EraseFromWallet(const uint256 &hash); @@ -322,6 +330,7 @@ public: void SetBestChain(const CBlockLocator& loc); DBErrors LoadWallet(bool& fFirstRunRet); + DBErrors ZapWalletTx(); bool SetAddressBook(const CTxDestination& address, const std::string& strName, const std::string& purpose); @@ -356,6 +365,9 @@ public: // get the current wallet format (the oldest client version guaranteed to understand this wallet) int GetVersion() { AssertLockHeld(cs_wallet); return nWalletVersion; } + // Get wallet transactions that conflict with given transaction (spend same outputs) + std::set<uint256> GetConflicts(const uint256& txid) const; + /** Address book entry changed. * @note called with lock cs_wallet held. */ @@ -694,14 +706,17 @@ public: return (GetDebit() > 0); } - bool IsConfirmed() const + bool IsTrusted() const { // Quick answer in most cases if (!IsFinalTx(*this)) return false; - if (GetDepthInMainChain() >= 1) + int nDepth = GetDepthInMainChain(); + if (nDepth >= 1) return true; - if (!IsFromMe()) // using wtx's cached debit + if (nDepth < 0) + return false; + if (!bSpendZeroConfChange || !IsFromMe()) // using wtx's cached debit return false; // If no confirmations but it's from us, we can still @@ -716,8 +731,11 @@ public: if (!IsFinalTx(*ptx)) return false; - if (ptx->GetDepthInMainChain() >= 1) + int nPDepth = ptx->GetDepthInMainChain(); + if (nPDepth >= 1) continue; + if (nPDepth < 0) + return false; if (!pwallet->IsFromMe(*ptx)) return false; @@ -745,6 +763,8 @@ public: void AddSupportingTransactions(); bool AcceptWalletTransaction(); void RelayWalletTransaction(); + + std::set<uint256> GetConflicts() const; }; diff --git a/src/walletdb.cpp b/src/walletdb.cpp index d912317a55..b3816a54b6 100644 --- a/src/walletdb.cpp +++ b/src/walletdb.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2013 The Bitcoin developers +// Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -154,12 +154,6 @@ bool CWalletDB::ErasePool(int64_t nPool) return Erase(std::make_pair(std::string("pool"), nPool)); } -bool CWalletDB::EraseSetting(const std::string& strKey) -{ - nWalletDBUpdated++; - return Erase(std::make_pair(std::string("setting"), strKey)); -} - bool CWalletDB::WriteMinVersion(int nVersion) { return Write(std::string("minversion"), nVersion); @@ -388,7 +382,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, if (wtx.nOrderPos == -1) wss.fAnyUnordered = true; - pwallet->mapWallet[hash] = wtx; + pwallet->AddToWallet(wtx, true); //// debug print //LogPrintf("LoadWallet %s\n", wtx.GetHash().ToString()); //LogPrintf(" %12"PRId64" %s %s %s\n", @@ -690,6 +684,86 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) return result; } +DBErrors CWalletDB::FindWalletTx(CWallet* pwallet, vector<uint256>& vTxHash) +{ + pwallet->vchDefaultKey = CPubKey(); + CWalletScanState wss; + bool fNoncriticalErrors = false; + DBErrors result = DB_LOAD_OK; + + try { + LOCK(pwallet->cs_wallet); + int nMinVersion = 0; + if (Read((string)"minversion", nMinVersion)) + { + if (nMinVersion > CLIENT_VERSION) + return DB_TOO_NEW; + pwallet->LoadMinVersion(nMinVersion); + } + + // Get cursor + Dbc* pcursor = GetCursor(); + if (!pcursor) + { + LogPrintf("Error getting wallet database cursor\n"); + return DB_CORRUPT; + } + + while (true) + { + // Read next record + CDataStream ssKey(SER_DISK, CLIENT_VERSION); + CDataStream ssValue(SER_DISK, CLIENT_VERSION); + int ret = ReadAtCursor(pcursor, ssKey, ssValue); + if (ret == DB_NOTFOUND) + break; + else if (ret != 0) + { + LogPrintf("Error reading next record from wallet database\n"); + return DB_CORRUPT; + } + + string strType; + ssKey >> strType; + if (strType == "tx") { + uint256 hash; + ssKey >> hash; + + vTxHash.push_back(hash); + } + } + pcursor->close(); + } + catch (boost::thread_interrupted) { + throw; + } + catch (...) { + result = DB_CORRUPT; + } + + if (fNoncriticalErrors && result == DB_LOAD_OK) + result = DB_NONCRITICAL_ERROR; + + return result; +} + +DBErrors CWalletDB::ZapWalletTx(CWallet* pwallet) +{ + // build list of wallet TXs + vector<uint256> vTxHash; + DBErrors err = FindWalletTx(pwallet, vTxHash); + if (err != DB_LOAD_OK) + return err; + + // erase each wallet TX + BOOST_FOREACH (uint256& hash, vTxHash) { + if (!EraseTx(hash)) + return DB_CORRUPT; + } + + return DB_LOAD_OK; +} + void ThreadFlushWalletDB(const string& strFile) { // Make this thread recognisable as the wallet flushing thread diff --git a/src/walletdb.h b/src/walletdb.h index 15af287245..3bfb436050 100644 --- a/src/walletdb.h +++ b/src/walletdb.h @@ -104,22 +104,6 @@ public: bool WritePool(int64_t nPool, const CKeyPool& keypool); bool ErasePool(int64_t nPool); - // Settings are no longer stored in wallet.dat; these are - // used only for backwards compatibility: - template<typename T> - bool ReadSetting(const std::string& strKey, T& value) - { - return Read(std::make_pair(std::string("setting"), strKey), value); - } - template<typename T> - bool WriteSetting(const std::string& strKey, const T& value) - { - nWalletDBUpdated++; - return Write(std::make_pair(std::string("setting"), strKey), value); - } - - bool EraseSetting(const std::string& strKey); - bool WriteMinVersion(int nVersion); bool ReadAccount(const std::string& strAccount, CAccount& account); @@ -138,6 +122,8 @@ public: DBErrors ReorderTransactions(CWallet*); DBErrors LoadWallet(CWallet* pwallet); + DBErrors FindWalletTx(CWallet* pwallet, std::vector<uint256>& vTxHash); + DBErrors ZapWalletTx(CWallet* pwallet); static bool Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys); static bool Recover(CDBEnv& dbenv, std::string filename); }; |