aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore7
-rw-r--r--COPYING2
-rw-r--r--Makefile.am1
-rw-r--r--README.md4
-rwxr-xr-xautogen.sh3
-rw-r--r--configure.ac2
-rw-r--r--contrib/debian/control1
-rw-r--r--contrib/debian/manpages/bitcoin-qt.13
-rw-r--r--contrib/gitian-descriptors/gitian-osx-bitcoin.yml1
-rw-r--r--contrib/verifysfbinaries/README.md2
-rwxr-xr-xcontrib/verifysfbinaries/verify.sh8
-rw-r--r--doc/build-osx.md24
-rw-r--r--doc/build-unix.md11
-rw-r--r--doc/coding.md75
-rw-r--r--doc/gitian-building.md35
-rw-r--r--doc/release-notes.md66
-rw-r--r--doc/release-notes/release-notes-0.9.2.1.md207
-rw-r--r--doc/release-notes/release-notes-0.9.2.md207
-rw-r--r--doc/release-process.md32
-rwxr-xr-xqa/rpc-tests/rpcbind_test.py22
-rw-r--r--src/Makefile.am21
-rw-r--r--src/Makefile.qt.include3
-rw-r--r--src/Makefile.qttest.include3
-rw-r--r--src/Makefile.test.include6
-rw-r--r--src/base58.cpp4
-rw-r--r--src/bitcoin-cli-res.rc1
-rw-r--r--src/bitcoind-res.rc1
-rw-r--r--src/bloom.cpp7
-rw-r--r--src/bloom.h2
-rw-r--r--src/checkpoints.cpp7
-rw-r--r--src/checkpoints.h7
-rw-r--r--src/clientversion.h5
-rw-r--r--src/coins.cpp16
-rw-r--r--src/coins.h11
-rw-r--r--src/core.cpp18
-rw-r--r--src/core.h12
-rw-r--r--src/init.cpp37
-rw-r--r--src/init.h2
-rw-r--r--src/key.cpp133
-rw-r--r--src/main.cpp331
-rw-r--r--src/main.h30
-rw-r--r--src/miner.cpp2
-rw-r--r--src/net.cpp115
-rw-r--r--src/net.h12
-rw-r--r--src/qt/addresstablemodel.cpp6
-rw-r--r--src/qt/bitcoin.cpp8
-rw-r--r--src/qt/bitcoingui.cpp78
-rw-r--r--src/qt/bitcoingui.h37
-rw-r--r--src/qt/bitcoinunits.cpp10
-rw-r--r--src/qt/bitcoinunits.h2
-rw-r--r--src/qt/coincontroldialog.cpp60
-rw-r--r--src/qt/coincontroldialog.h3
-rw-r--r--src/qt/forms/sendcoinsentry.ui2
-rw-r--r--src/qt/forms/signverifymessagedialog.ui4
-rw-r--r--src/qt/guiconstants.h4
-rw-r--r--src/qt/guiutil.cpp7
-rw-r--r--src/qt/optionsdialog.cpp9
-rw-r--r--src/qt/optionsmodel.cpp17
-rw-r--r--src/qt/optionsmodel.h2
-rw-r--r--src/qt/paymentrequestplus.cpp22
-rw-r--r--src/qt/paymentserver.cpp28
-rw-r--r--src/qt/recentrequeststablemodel.cpp27
-rw-r--r--src/qt/recentrequeststablemodel.h6
-rw-r--r--src/qt/res/bitcoin-qt-res.rc1
-rw-r--r--src/qt/signverifymessagedialog.cpp1
-rw-r--r--src/qt/transactionfilterproxy.cpp4
-rw-r--r--src/qt/transactionrecord.cpp10
-rw-r--r--src/qt/transactionrecord.h24
-rw-r--r--src/qt/transactiontablemodel.cpp35
-rw-r--r--src/qt/transactiontablemodel.h2
-rw-r--r--src/qt/transactionview.cpp2
-rw-r--r--src/qt/utilitydialog.cpp1
-rw-r--r--src/qt/walletmodel.cpp8
-rw-r--r--src/qt/winshutdownmonitor.cpp6
-rw-r--r--src/rpcblockchain.cpp2
-rw-r--r--src/rpcclient.cpp183
-rw-r--r--src/rpcmining.cpp2
-rw-r--r--src/rpcmisc.cpp4
-rw-r--r--src/rpcnet.cpp3
-rw-r--r--src/rpcprotocol.cpp39
-rw-r--r--src/rpcprotocol.h6
-rw-r--r--src/rpcserver.cpp155
-rw-r--r--src/rpcserver.h11
-rw-r--r--src/rpcwallet.cpp22
-rw-r--r--src/script.cpp5
-rw-r--r--src/secp256k1/.empty0
-rw-r--r--src/test/bloom_tests.cpp4
-rw-r--r--src/test/script_P2SH_tests.cpp118
-rw-r--r--src/test/skiplist_tests.cpp45
-rw-r--r--src/txdb.cpp4
-rw-r--r--src/txdb.h2
-rw-r--r--src/txmempool.cpp36
-rw-r--r--src/txmempool.h4
-rw-r--r--src/ui_interface.h3
-rw-r--r--src/uint256.cpp292
-rw-r--r--src/uint256.h262
-rw-r--r--src/util.cpp9
-rw-r--r--src/util.h2
-rw-r--r--src/wallet.cpp92
-rw-r--r--src/wallet.h21
100 files changed, 2342 insertions, 909 deletions
diff --git a/.gitignore b/.gitignore
index 564fe68fd9..4169a2d96c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,6 +19,13 @@ src/config/stamp-h1
src/build-aux/
share/setup.nsi
share/qt/Info.plist
+# Libtool
+libtool
+src/m4/libtool.m4
+src/m4/ltoptions.m4
+src/m4/ltsugar.m4
+src/m4/ltversion.m4
+src/m4/lt~obsolete.m4
src/qt/*.moc
src/qt/moc_*.cpp
diff --git a/COPYING b/COPYING
index c410baa6a0..6219bd75a6 100644
--- a/COPYING
+++ b/COPYING
@@ -1,4 +1,4 @@
-Copyright (c) 2009-2013 Bitcoin Developers
+Copyright (c) 2009-2014 Bitcoin Developers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/Makefile.am b/Makefile.am
index 719af42ac7..3a6a6b6d88 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -35,6 +35,7 @@ COVERAGE_INFO = baseline_filtered_combined.info baseline.info block_test.info \
dist-hook:
-$(MAKE) -C $(top_distdir)/src/leveldb clean
+ -$(MAKE) -C $(top_distdir)/src/secp256k1 distclean
-$(GIT) archive --format=tar HEAD -- src/version.cpp | $(AMTAR) -C $(top_distdir) -xf -
distcheck-hook:
diff --git a/README.md b/README.md
index 102aa56201..7c2fe12f3a 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
Bitcoin Core integration/staging tree
=====================================
-http://www.bitcoin.org
+https://www.bitcoin.org
Copyright (c) 2009-2014 Bitcoin Core Developers
@@ -15,7 +15,7 @@ out collectively by the network. Bitcoin Core is the name of open source
software which enables the use of this currency.
For more information, as well as an immediately useable, binary version of
-the Bitcoin Core software, see http://www.bitcoin.org/en/download.
+the Bitcoin Core software, see https://www.bitcoin.org/en/download.
License
-------
diff --git a/autogen.sh b/autogen.sh
index 5b883a6a4c..50b85bcba0 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -2,4 +2,7 @@
set -e
srcdir="$(dirname $0)"
cd "$srcdir"
+if [ -z ${LIBTOOLIZE} ] && GLIBTOOLIZE="`which glibtoolize 2>/dev/null`"; then
+ export LIBTOOLIZE="${GLIBTOOLIZE}"
+fi
autoreconf --install --force
diff --git a/configure.ac b/configure.ac
index 3abf94f136..dcaec0d4b0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -9,6 +9,7 @@ define(_COPYRIGHT_YEAR, 2014)
AC_INIT([Bitcoin Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[info@bitcoin.org],[bitcoin])
AC_CONFIG_AUX_DIR([src/build-aux])
AC_CONFIG_MACRO_DIR([src/m4])
+LT_INIT([disable-shared])
AC_CANONICAL_HOST
AH_TOP([#ifndef BITCOIN_CONFIG_H])
AH_TOP([#define BITCOIN_CONFIG_H])
@@ -681,6 +682,7 @@ AM_CONDITIONAL([USE_LCOV],[test x$use_lcov == xyes])
AM_CONDITIONAL([USE_COMPARISON_TOOL],[test x$use_comparison_tool != xno])
AM_CONDITIONAL([USE_COMPARISON_TOOL_REORG_TESTS],[test x$use_comparison_tool_reorg_test != xno])
AM_CONDITIONAL([GLIBC_BACK_COMPAT],[test x$use_glibc_compat = xyes])
+AM_CONDITIONAL([USE_LIBSECP256K1],[test x$use_libsecp256k1 = xyes])
AC_DEFINE(CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MAJOR, [Major version])
AC_DEFINE(CLIENT_VERSION_MINOR, _CLIENT_VERSION_MINOR, [Minor version])
diff --git a/contrib/debian/control b/contrib/debian/control
index 9e006a7070..a04e88d4e1 100644
--- a/contrib/debian/control
+++ b/contrib/debian/control
@@ -6,6 +6,7 @@ Uploaders: Micah Anderson <micah@debian.org>
Build-Depends: debhelper,
devscripts,
automake,
+ libtool,
bash-completion,
libboost-system-dev (>> 1.35) | libboost-system1.35-dev,
libdb4.8++-dev,
diff --git a/contrib/debian/manpages/bitcoin-qt.1 b/contrib/debian/manpages/bitcoin-qt.1
index cd478b1875..25a423f9c4 100644
--- a/contrib/debian/manpages/bitcoin-qt.1
+++ b/contrib/debian/manpages/bitcoin-qt.1
@@ -139,6 +139,9 @@ Execute command when the best block changes (%s in cmd is replaced by block hash
\fB\-walletnotify=\fR<cmd>
Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)
.TP
+\fB\-respendnotify=\fR<cmd>
+Execute command when a network tx respends wallet tx input (%s=respend TxID, %t=wallet TxID)
+.TP
\fB\-alertnotify=\fR<cmd>
Execute command when a relevant alert is received (%s in cmd is replaced by message)
.TP
diff --git a/contrib/gitian-descriptors/gitian-osx-bitcoin.yml b/contrib/gitian-descriptors/gitian-osx-bitcoin.yml
index 44b5de9be3..bc3d561c35 100644
--- a/contrib/gitian-descriptors/gitian-osx-bitcoin.yml
+++ b/contrib/gitian-descriptors/gitian-osx-bitcoin.yml
@@ -11,6 +11,7 @@ packages:
- "bsdmainutils"
- "pkg-config"
- "p7zip-full"
+- "libtool"
reference_datetime: "2013-06-01 00:00:00"
remotes:
diff --git a/contrib/verifysfbinaries/README.md b/contrib/verifysfbinaries/README.md
index f646d1efd1..8c038865bd 100644
--- a/contrib/verifysfbinaries/README.md
+++ b/contrib/verifysfbinaries/README.md
@@ -1,5 +1,5 @@
### Verify SF Binaries ###
-This script attempts to download the signature file `SHA256SUMS.asc` from SourceForge.
+This script attempts to download the signature file `SHA256SUMS.asc` from https://bitcoin.org.
It first checks if the signature passes, and then downloads the files specified in the file, and checks if the hashes of these files match those that are specified in the signature file.
diff --git a/contrib/verifysfbinaries/verify.sh b/contrib/verifysfbinaries/verify.sh
index e92295661c..3eb4693883 100755
--- a/contrib/verifysfbinaries/verify.sh
+++ b/contrib/verifysfbinaries/verify.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-### This script attempts to download the signature file SHA256SUMS.asc from SourceForge
+### This script attempts to download the signature file SHA256SUMS.asc from bitcoin.org
### It first checks if the signature passes, and then downloads the files specified in
### the file, and checks if the hashes of these files match those that are specified
### in the signature file.
@@ -18,11 +18,11 @@ WORKINGDIR="/tmp/bitcoin"
TMPFILE="hashes.tmp"
#this URL is used if a version number is not specified as an argument to the script
-SIGNATUREFILE="http://downloads.sourceforge.net/project/bitcoin/Bitcoin/bitcoin-0.9.0rc1/SHA256SUMS.asc"
+SIGNATUREFILE="https://bitcoin.org/bin/0.9.2.1/SHA256SUMS.asc"
SIGNATUREFILENAME="SHA256SUMS.asc"
RCSUBDIR="test/"
-BASEDIR="http://downloads.sourceforge.net/project/bitcoin/Bitcoin/"
+BASEDIR="https://bitcoin.org/bin/"
VERSIONPREFIX="bitcoin-"
RCVERSIONSTRING="rc"
@@ -62,7 +62,7 @@ WGETOUT=$(wget -N "$BASEDIR$SIGNATUREFILENAME" 2>&1)
#and then see if wget completed successfully
if [ $? -ne 0 ]; then
echo "Error: couldn't fetch signature file. Have you specified the version number in the following format?"
- echo "[bitcoin-]<version>-[rc[0-9]] (example: bitcoin-0.7.1-rc1)"
+ echo "[bitcoin-]<version>-[rc[0-9]] (example: bitcoin-0.9.2-rc1)"
echo "wget output:"
echo "$WGETOUT"|sed 's/^/\t/g'
exit 2
diff --git a/doc/build-osx.md b/doc/build-osx.md
index 0de5c792e9..bc42723b12 100644
--- a/doc/build-osx.md
+++ b/doc/build-osx.md
@@ -22,7 +22,7 @@ Xcode 4.3 or later, you'll need to install its command line tools. This can
be done in `Xcode > Preferences > Downloads > Components` and generally must
be re-done or updated every time Xcode is updated.
-There's an assumption that you already have `git` installed, as well. If
+There's also an assumption that you already have `git` installed. If
not, it's the path of least resistance to install [Github for Mac](https://mac.github.com/)
(OS X 10.7+) or
[Git for OS X](https://code.google.com/p/git-osx-installer/). It is also
@@ -30,11 +30,8 @@ available via Homebrew or MacPorts.
You will also need to install [Homebrew](http://brew.sh)
or [MacPorts](https://www.macports.org/) in order to install library
-dependencies. It's largely a religious decision which to choose, but, as of
-December 2012, MacPorts is a little easier because you can just install the
-dependencies immediately - no other work required. If you're unsure, read
-the instructions through first in order to assess what you want to do.
-Homebrew is a little more popular among those newer to OS X.
+dependencies. It's largely a religious decision which to choose, however, Homebrew
+is now used for building release versions.
The installation of the actual dependencies is covered in the Instructions
sections below.
@@ -44,9 +41,7 @@ Instructions: MacPorts
### Install dependencies
-Installing the dependencies using MacPorts is very straightforward.
-
- sudo port install boost db48@+no_java openssl miniupnpc autoconf pkgconfig automake
+ sudo port install boost db48@+no_java openssl miniupnpc autoconf pkgconfig automake libtool
Optional: install Qt4
@@ -74,13 +69,13 @@ Instructions: Homebrew
#### Install dependencies using Homebrew
- brew install autoconf automake berkeley-db4 boost miniupnpc openssl pkg-config protobuf qt
+ brew install autoconf automake libtool berkeley-db4 boost miniupnpc openssl pkg-config protobuf qt
Note: After you have installed the dependencies, you should check that the Homebrew installed version of OpenSSL is the one available for compilation. You can check this by typing
openssl version
-into Terminal. You should see OpenSSL 1.0.1f 6 Jan 2014.
+into Terminal. You should see OpenSSL 1.0.1h 5 Jun 2014.
If not, you can ensure that the Homebrew OpenSSL is correctly linked by running
@@ -103,7 +98,7 @@ PATH.
./configure
make
-3. It is a good idea to build and run the unit tests, too:
+3. It is also a good idea to build and run the unit tests:
make check
@@ -131,7 +126,7 @@ For MacPorts, that means editing your macports.conf and setting
... and then uninstalling and re-installing, or simply rebuilding, all ports.
As of December 2012, the `boost` port does not obey `macosx_deployment_target`.
-Download `http://gavinandresen-bitcoin.s3.amazonaws.com/boost_macports_fix.zip`
+Download `https://gavinandresen-bitcoin.s3.amazonaws.com/boost_macports_fix.zip`
for a fix.
Once dependencies are compiled, see release-process.md for how the Bitcoin-Qt.app
@@ -149,13 +144,14 @@ commands:
echo -e "rpcuser=bitcoinrpc\nrpcpassword=$(xxd -l 16 -p /dev/urandom)" > "/Users/${USER}/Library/Application Support/Bitcoin/bitcoin.conf"
chmod 600 "/Users/${USER}/Library/Application Support/Bitcoin/bitcoin.conf"
-When next you run it, it will start downloading the blockchain, but it won't
+The next time you run it, it will start downloading the blockchain, but it won't
output anything while it's doing this. This process may take several hours;
you can monitor its process by looking at the debug.log file, like this:
tail -f $HOME/Library/Application\ Support/Bitcoin/debug.log
Other commands:
+-------
./bitcoind -daemon # to start the bitcoin daemon.
./bitcoin-cli --help # for a list of command-line options.
diff --git a/doc/build-unix.md b/doc/build-unix.md
index 1d75c206e5..0f381d56c5 100644
--- a/doc/build-unix.md
+++ b/doc/build-unix.md
@@ -61,10 +61,8 @@ Dependency Build Instructions: Ubuntu & Debian
----------------------------------------------
Build requirements:
- sudo apt-get install build-essential
- sudo apt-get install libtool autotools-dev autoconf
- sudo apt-get install libssl-dev
-
+ sudo apt-get install build-essential libtool autotools-dev autoconf pkg-config libssl-dev
+
for Ubuntu 12.04 and later:
sudo apt-get install libboost-all-dev
@@ -93,10 +91,9 @@ To enable the change run
sudo apt-get update
-for other Ubuntu & Debian:
+for other Debian & Ubuntu (with ppa):
- sudo apt-get install libdb4.8-dev
- sudo apt-get install libdb4.8++-dev
+ sudo apt-get install libdb4.8-dev libdb4.8++-dev
Optional:
diff --git a/doc/coding.md b/doc/coding.md
index 69388c9ce2..2f332e92f0 100644
--- a/doc/coding.md
+++ b/doc/coding.md
@@ -4,44 +4,65 @@ Coding
Please be consistent with the existing coding style.
Block style:
-
- bool Function(char* psz, int n)
- {
- // Comment summarising what this section of code does
- for (int i = 0; i < n; i++)
- {
- // When something fails, return early
- if (!Something())
- return false;
- ...
- }
-
- // Success return is usually at the end
- return true;
- }
-
+```c++
+ bool Function(char* psz, int n)
+ {
+ // Comment summarising what this section of code does
+ for (int i = 0; i < n; i++)
+ {
+ // When something fails, return early
+ if (!Something())
+ return false;
+ ...
+ }
+
+ // Success return is usually at the end
+ return true;
+ }
+```
- ANSI/Allman block style
- 4 space indenting, no tabs
- No extra spaces inside parenthesis; please don't do ( this )
- No space after function names, one space after if, for and while
+- Includes need to be ordered alphabetically, separate own and foreign headers with a new-line (example key.cpp):
+```c++
+#include "key.h"
+
+#include "crypto/sha2.h"
+#include "util.h"
+#include <openssl/foo.h>
+```
+- Class or struct keywords in header files need to be ordered alphabetically:
+```c++
+class CAlpha;
+class CBeta;
+```
+- When using namespace keyword use the following form:
+```c++
+namespace Foo {
+
+...
+
+} // Foo
+```
Variable names begin with the type in lowercase, like nSomeVariable.
Please don't put the first word of the variable name in lowercase like
someVariable.
Common types:
- n integer number: short, unsigned short, int, unsigned int, int64, uint64, sometimes char if used as a number
- d double, float
- f flag
- hash uint256
- p pointer or array, one p for each level of indirection
- psz pointer to null terminated string
- str string object
- v vector or similar list objects
- map map or multimap
- set set or multiset
- bn CBigNum
+ n integer number: short, unsigned short, int, unsigned int, int64, uint64, sometimes char if used as a number
+ d double, float
+ f flag
+ hash uint256
+ p pointer or array, one p for each level of indirection
+ psz pointer to null terminated string
+ str string object
+ v vector or similar list objects
+ map map or multimap
+ set set or multiset
+ bn CBigNum
Doxygen comments
-----------------
diff --git a/doc/gitian-building.md b/doc/gitian-building.md
index 378a45eda5..b356a5d88d 100644
--- a/doc/gitian-building.md
+++ b/doc/gitian-building.md
@@ -4,8 +4,8 @@ Gitian building
*Setup instructions for a gitian build of Bitcoin using a Debian VM or physical system.*
Gitian is the deterministic build process that is used to build the Bitcoin
-Core executables [1]. It provides a way to be reasonably sure that the
-executables are really built from source on github. It also makes sure that
+Core executables. It provides a way to be reasonably sure that the
+executables are really built from source on GitHub. It also makes sure that
the same, tested dependencies are used and statically built into the executable.
Multiple developers build the source code by following a specific descriptor
@@ -17,9 +17,6 @@ More independent gitian builders are needed, which is why I wrote this
guide. It is preferred to follow these steps yourself instead of using someone else's
VM image to avoid 'contaminating' the build.
-[1] For all platforms except for MacOSX, at this point. Work for deterministic
-builds for Mac is under way here: https://github.com/theuni/osx-cross-depends .
-
Table of Contents
------------------
@@ -38,7 +35,7 @@ Preparing the Gitian builder host
---------------------------------
The first step is to prepare the host environment that will be used to perform the Gitian builds.
-In this guide it is explained how to set up the environment, and how to get the builds started.
+This guide explains how to set up the environment, and how to start the builds.
Debian Linux was chosen as the host distribution because it has a lightweight install (in contrast to Ubuntu) and is readily available.
Any kind of virtualization can be used, for example:
@@ -134,7 +131,7 @@ and proceed, just press `Enter`. To select a different button, press `Tab`.
![](gitian-building/debian_install_5_configure_the_network.png)
-- Choose a root password and enter it twice (and remember it for later)
+- Choose a root password and enter it twice (remember it for later)
![](gitian-building/debian_install_6a_set_up_root_password.png)
@@ -143,7 +140,7 @@ and proceed, just press `Enter`. To select a different button, press `Tab`.
![](gitian-building/debian_install_7_set_up_user_fullname.png)
![](gitian-building/debian_install_8_set_up_username.png)
-- Choose a user password and enter it twice (and remember it for later)
+- Choose a user password and enter it twice (remember it for later)
![](gitian-building/debian_install_9_user_password.png)
@@ -236,7 +233,7 @@ adduser debian sudo
When you get a colorful screen with a question about the 'LXC directory', just
go with the default (`/var/lib/lxc`).
-Then set up LXC and the rest with the following is a complex jumble of settings and workarounds:
+Then set up LXC and the rest with the following, which is a complex jumble of settings and workarounds:
```bash
# the version of lxc-start in Debian 7.4 needs to run as root, so make sure
@@ -280,7 +277,7 @@ cd ..
**Note**: When sudo asks for a password, enter the password for the user *debian* not for *root*.
-Clone the git repositories for bitcoin and gitian and then checkout the bitcoin version that you are willing to build.
+Clone the git repositories for bitcoin and gitian and then checkout the bitcoin version that you want to build.
```bash
git clone https://github.com/devrandom/gitian-builder.git
@@ -319,10 +316,10 @@ you will find a list of `wget` commands that can be executed to get the dependen
I needed to add `--no-check-certificate` to the OpenSSL wget line to make it work.
Likely this is because the ca-certificates in Debian 7.4 is fairly old. This does not create a
-security issue as the gitian descriptors check integrity of the input archives and refuse to work
+security issue as the gitian descriptors check the integrity of the input archives and refuse to work
if any one is corrupted.
-After downloading the archives, execute the `gbuild` commends to build the dependencies.
+After downloading the archives, execute the `gbuild` commands to build the dependencies.
This can take a long time, but only has to be done when the dependencies change, for example
to upgrade the used version.
@@ -339,7 +336,7 @@ tail -f var/build.log
Building Bitcoin
----------------
-To build Bitcoin (for Linux and/or Windows) just follow the steps under 'perform
+To build Bitcoin (for Linux, OSX and Windows) just follow the steps under 'perform
gitian builds' in [doc/release-process.md](release-process.md) in the bitcoin repository.
Output from `gbuild` will look something like
@@ -372,7 +369,7 @@ can be inspected in `var/install.log` and `var/build.log`.
Building an alternative repository
-----------------------------------
-If you want to do a test build of a pull on github it can be useful to point
+If you want to do a test build of a pull on GitHub it can be useful to point
the gitian builder at an alternative repository, using the same descriptors
and inputs.
@@ -382,13 +379,14 @@ URL=https://github.com/laanwj/bitcoin.git
COMMIT=2014_03_windows_unicode_path
./bin/gbuild --commit bitcoin=${COMMIT} --url bitcoin=${URL} ../bitcoin/contrib/gitian-descriptors/gitian-linux.yml
./bin/gbuild --commit bitcoin=${COMMIT} --url bitcoin=${URL} ../bitcoin/contrib/gitian-descriptors/gitian-win.yml
+./bin/gbuild --commit bitcoin=${COMMIT} --url bitcoin=${URL} ../bitcoin/contrib/gitian-descriptors/gitian-osx.yml
```
Signing externally
-------------------
-If you want to do the PGP signing on another device that's possible too; just define `SIGNER` as mentioned
-and follow the steps in the build process as normally.
+If you want to do the PGP signing on another device that's also possible; just define `SIGNER` as mentioned
+and follow the steps in the build process as normal.
gpg: skipped "laanwj": secret key not available
@@ -396,8 +394,9 @@ When you execute `gsign` you will get an error from GPG, which can be ignored. C
in `gitian.sigs` to your signing machine and do
```bash
- gpg --detach-sign ${VERSION}/${SIGNER}/bitcoin-build.assert
+ gpg --detach-sign ${VERSION}-linux/${SIGNER}/bitcoin-build.assert
gpg --detach-sign ${VERSION}-win/${SIGNER}/bitcoin-build.assert
+ gpg --detach-sign ${VERSION}-osx/${SIGNER}/bitcoin-build.assert
```
This will create the `.sig` files that can be committed together with the `.assert` files to assert your
@@ -407,5 +406,5 @@ Uploading signatures
---------------------
After building and signing you can push your signatures (both the `.assert` and `.assert.sig` files) to the
-[bitcoin/gitian.sigs](https://github.com/bitcoin/gitian.sigs/) repository, or if not possible create a pull
+[bitcoin/gitian.sigs](https://github.com/bitcoin/gitian.sigs/) repository, or if that's not possible create a pull
request. You can also mail the files to me (laanwj@gmail.com) and I'll commit them.
diff --git a/doc/release-notes.md b/doc/release-notes.md
index 9272d427cd..66059800b6 100644
--- a/doc/release-notes.md
+++ b/doc/release-notes.md
@@ -1,6 +1,26 @@
(note: this is a temporary file, to be added-to by anybody, and moved to
release-notes at release time)
+Transaction fee changes
+=======================
+
+This release automatically estimates how high a transaction fee (or how
+high a priority) transactions require to be confirmed quickly. The default
+settings will create transactions that confirm quickly; see the new
+'txconfirmtarget' setting to control the tradeoff between fees and
+confirmation times.
+
+Prior releases used hard-coded fees (and priorities), and would
+sometimes create transactions that took a very long time to confirm.
+
+
+New Command Line Options
+========================
+
+-txconfirmtarget=n : create transactions that have enough fees (or priority)
+so they are likely to confirm within n blocks (default: 1). This setting
+is over-ridden by the -paytxfee option.
+
New RPC methods
===============
@@ -19,3 +39,49 @@ estimate.
Statistics used to estimate fees and priorities are saved in the
data directory in the 'fee_estimates.dat' file just before
program shutdown, and are read in at startup.
+
+Double-Spend Relay and Alerts
+=============================
+VERY IMPORTANT: *It has never been safe, and remains unsafe, to rely*
+*on unconfirmed transactions.*
+
+Relay
+-----
+When an attempt is seen on the network to spend the same unspent funds
+more than once, it is no longer ignored. Instead, it is broadcast, to
+serve as an alert. This broadcast is subject to protections against
+denial-of-service attacks.
+
+Wallets and other bitcoin services should alert their users to
+double-spends that affect them. Merchants and other users may have
+enough time to withhold goods or services when payment becomes
+uncertain, until confirmation.
+
+Bitcoin Core Wallet Alerts
+--------------------------
+The Bitcoin Core wallet now makes respend attempts visible in several
+ways.
+
+If you are online, and a respend affecting one of your wallet
+transactions is seen, a notification is immediately issued to the
+command registered with `-respendnotify=<cmd>`. Additionally, if
+using the GUI:
+ - An alert box is immediately displayed.
+ - The affected wallet transaction is highlighted in red until it is
+ confirmed (and it may never be confirmed).
+
+A `respendsobserved` array is added to `gettransaction`, `listtransactions`,
+and `listsinceblock` RPC results.
+
+Warning
+-------
+*If you rely on an unconfirmed transaction, these change do VERY*
+*LITTLE to protect you from a malicious double-spend, because:*
+
+ - You may learn about the respend too late to avoid doing whatever
+ you were being paid for
+ - Using other relay rules, a double-spender can craft his crime to
+ resist broadcast
+ - Miners can choose which conflicting spend to confirm, and some
+ miners may not confirm the first acceptable spend they see
+
diff --git a/doc/release-notes/release-notes-0.9.2.1.md b/doc/release-notes/release-notes-0.9.2.1.md
new file mode 100644
index 0000000000..3168ad1a5a
--- /dev/null
+++ b/doc/release-notes/release-notes-0.9.2.1.md
@@ -0,0 +1,207 @@
+Bitcoin Core version 0.9.2.1 is now available from:
+
+ https://bitcoin.org/bin/0.9.2.1/
+
+This is a new minor version release, bringing mostly bug fixes and some minor
+improvements. OpenSSL has been updated because of a security issue (CVE-2014-0224).
+Upgrading to this release is recommended.
+
+Please report bugs using the issue tracker at github:
+
+ https://github.com/bitcoin/bitcoin/issues
+
+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), 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.2.1 your blockchain files will be re-indexed, which will take anywhere from
+30 minutes to several hours, depending on the speed of your machine.
+
+Downgrading warnings
+--------------------
+
+The 'chainstate' for this release is not always compatible with previous
+releases, so if you run 0.9.x and then decide to switch back to a
+0.8.x release you might get a blockchain validation error when starting the
+old release (due to 'pruned outputs' being omitted from the index of
+unspent transaction outputs).
+
+Running the old release with the -reindex option will rebuild the chainstate
+data structures and correct the problem.
+
+Also, the first time you run a 0.8.x release on a 0.9 wallet it will rescan
+the blockchain for missing spent coins, which will take a long time (tens
+of minutes on a typical machine).
+
+Important changes
+==================
+
+Gitian OSX build
+-----------------
+
+The deterministic build system that was already used for Windows and Linux
+builds is now used for OSX as well. Although the resulting executables have
+been tested quite a bit, there could be possible regressions. Be sure to report
+these on the Github bug tracker mentioned above.
+
+Compatibility of Linux build
+-----------------------------
+
+For Linux we now build against Qt 4.6, and filter the symbols for libstdc++ and glibc.
+This brings back compatibility with
+
+- Debian 6+ / Tails
+- Ubuntu 10.04
+- CentOS 6.5
+
+0.9.2 - 0.9.2.1 Release notes
+=======================
+
+The OpenSSL dependency in the gitian builds has been upgraded to 1.0.1h because of CVE-2014-0224.
+
+RPC:
+
+- Add `getwalletinfo`, `getblockchaininfo` and `getnetworkinfo` calls (will replace hodge-podge `getinfo` at some point)
+- Add a `relayfee` field to `getnetworkinfo`
+- Fix RPC related shutdown hangs and leaks
+- Always show syncnode in `getpeerinfo`
+- `sendrawtransaction`: report the reject code and reason, and make it possible to re-send transactions that are already in the mempool
+- `getmininginfo` show right genproclimit
+
+Command-line options:
+
+- Fix `-printblocktree` output
+- Show error message if ReadConfigFile fails
+
+Block-chain handling and storage:
+
+- Fix for GetBlockValue() after block 13,440,000 (BIP42)
+- Upgrade leveldb to 1.17
+
+Protocol and network code:
+
+- Per-peer block download tracking and stalled download detection
+- Add new DNS seed from bitnodes.io
+- Prevent socket leak in ThreadSocketHandler and correct some proxy related socket leaks
+- Use pnode->nLastRecv as sync score (was the wrong way around)
+
+Wallet:
+
+- Make GetAvailableCredit run GetHash() only once per transaction (performance improvement)
+- Lower paytxfee warning threshold from 0.25 BTC to 0.01 BTC
+- Fix importwallet nTimeFirstKey (trigger necessary rescans)
+- Log BerkeleyDB version at startup
+- CWallet init fix
+
+Build system:
+
+- Add OSX build descriptors to gitian
+- Fix explicit --disable-qt-dbus
+- Don't require db_cxx.h when compiling with wallet disabled and GUI enabled
+- Improve missing boost error reporting
+- Upgrade miniupnpc version to 1.9
+- gitian-linux: --enable-glibc-back-compat for binary compatibility with old distributions
+- gitian: don't export any symbols from executable
+- gitian: build against Qt 4.6
+- devtools: add script to check symbols from Linux gitian executables
+- Remove build-time no-IPv6 setting
+
+GUI:
+
+- Fix various coin control visual issues
+- Show number of in/out connections in debug console
+- Show weeks as well as years behind for long timespans behind
+- Enable and disable the Show and Remove buttons for requested payments history based on whether any entry is selected.
+- Show also value for options overridden on command line in options dialog
+- Fill in label from address book also for URIs
+- Fixes feel when resizing the last column on tables (issue #2862)
+- Fix ESC in disablewallet mode
+- Add expert section to wallet tab in optionsdialog
+- Do proper boost::path conversion (fixes unicode in datadir)
+- Only override -datadir if different from the default (fixes -datadir in config file)
+- Show rescan progress at start-up
+- Show importwallet progress
+- Get required locks upfront in polling functions (avoids hanging on locks)
+- Catch Windows shutdown events while client is running
+- Optionally add third party links to transaction context menu
+- Check for !pixmap() before trying to export QR code (avoids crashes when no QR code could be generated)
+- Fix "Start bitcoin on system login"
+
+Miscellaneous:
+
+- Replace non-threadsafe C functions (gmtime, strerror and setlocale)
+- Add missing cs_main and wallet locks
+- Avoid exception at startup when system locale not recognized
+- Changed bitrpc.py's raw_input to getpass for passwords to conceal characters during command line input
+- devtools: add a script to fetch and postprocess translations
+
+Credits
+--------
+
+Thanks to everyone who contributed to this release:
+
+- Addy Yeow
+- Altoidnerd
+- Andrea D'Amore
+- Andreas Schildbach
+- Bardi Harborow
+- Brandon Dahler
+- Bryan Bishop
+- Chris Beams
+- Christian von Roques
+- Cory Fields
+- Cozz Lovan
+- daniel
+- Daniel Newton
+- David A. Harding
+- ditto-b
+- duanemoody
+- Eric S. Bullington
+- Fabian Raetz
+- Gavin Andresen
+- Gregory Maxwell
+- gubatron
+- Haakon Nilsen
+- harry
+- Hector Jusforgues
+- Isidoro Ghezzi
+- Jeff Garzik
+- Johnathan Corgan
+- jtimon
+- Kamil Domanski
+- langerhans
+- Luke Dashjr
+- Manuel Araoz
+- Mark Friedenbach
+- Matt Corallo
+- Matthew Bogosian
+- Meeh
+- Michael Ford
+- Michagogo
+- Mikael Wikman
+- Mike Hearn
+- olalonde
+- paveljanik
+- peryaudo
+- Philip Kaufmann
+- philsong
+- Pieter Wuille
+- R E Broadley
+- richierichrawr
+- Rune K. Svendsen
+- rxl
+- shshshsh
+- Simon de la Rouviere
+- Stuart Cardall
+- super3
+- Telepatheic
+- Thomas Zander
+- Torstein Husebø
+- Warren Togami
+- Wladimir J. van der Laan
+- Yoichi Hirai
diff --git a/doc/release-notes/release-notes-0.9.2.md b/doc/release-notes/release-notes-0.9.2.md
new file mode 100644
index 0000000000..a2749e549f
--- /dev/null
+++ b/doc/release-notes/release-notes-0.9.2.md
@@ -0,0 +1,207 @@
+Bitcoin Core version 0.9.2 is now available from:
+
+ https://bitcoin.org/bin/0.9.2/
+
+This is a new minor version release, bringing mostly bug fixes and some minor
+improvements. OpenSSL has been updated because of a security issue (CVE-2014-0224).
+Upgrading to this release is recommended.
+
+Please report bugs using the issue tracker at github:
+
+ https://github.com/bitcoin/bitcoin/issues
+
+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), 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.2 your blockchain files will be re-indexed, which will take anywhere from
+30 minutes to several hours, depending on the speed of your machine.
+
+Downgrading warnings
+--------------------
+
+The 'chainstate' for this release is not always compatible with previous
+releases, so if you run 0.9.x and then decide to switch back to a
+0.8.x release you might get a blockchain validation error when starting the
+old release (due to 'pruned outputs' being omitted from the index of
+unspent transaction outputs).
+
+Running the old release with the -reindex option will rebuild the chainstate
+data structures and correct the problem.
+
+Also, the first time you run a 0.8.x release on a 0.9 wallet it will rescan
+the blockchain for missing spent coins, which will take a long time (tens
+of minutes on a typical machine).
+
+Important changes
+==================
+
+Gitian OSX build
+-----------------
+
+The deterministic build system that was already used for Windows and Linux
+builds is now used for OSX as well. Although the resulting executables have
+been tested quite a bit, there could be possible regressions. Be sure to report
+these on the Github bug tracker mentioned above.
+
+Compatibility of Linux build
+-----------------------------
+
+For Linux we now build against Qt 4.6, and filter the symbols for libstdc++ and glibc.
+This brings back compatibility with
+
+- Debian 6+ / Tails
+- Ubuntu 10.04
+- CentOS 6.5
+
+0.9.2 Release notes
+=======================
+
+The OpenSSL dependency in the gitian builds has been upgraded to 1.0.1h because of CVE-2014-0224.
+
+RPC:
+
+- Add `getwalletinfo`, `getblockchaininfo` and `getnetworkinfo` calls (will replace hodge-podge `getinfo` at some point)
+- Add a `relayfee` field to `getnetworkinfo`
+- Fix RPC related shutdown hangs and leaks
+- Always show syncnode in `getpeerinfo`
+- `sendrawtransaction`: report the reject code and reason, and make it possible to re-send transactions that are already in the mempool
+- `getmininginfo` show right genproclimit
+
+Command-line options:
+
+- Fix `-printblocktree` output
+- Show error message if ReadConfigFile fails
+
+Block-chain handling and storage:
+
+- Fix for GetBlockValue() after block 13,440,000 (BIP42)
+- Upgrade leveldb to 1.17
+
+Protocol and network code:
+
+- Per-peer block download tracking and stalled download detection
+- Add new DNS seed from bitnodes.io
+- Prevent socket leak in ThreadSocketHandler and correct some proxy related socket leaks
+- Use pnode->nLastRecv as sync score (was the wrong way around)
+
+Wallet:
+
+- Make GetAvailableCredit run GetHash() only once per transaction (performance improvement)
+- Lower paytxfee warning threshold from 0.25 BTC to 0.01 BTC
+- Fix importwallet nTimeFirstKey (trigger necessary rescans)
+- Log BerkeleyDB version at startup
+- CWallet init fix
+
+Build system:
+
+- Add OSX build descriptors to gitian
+- Fix explicit --disable-qt-dbus
+- Don't require db_cxx.h when compiling with wallet disabled and GUI enabled
+- Improve missing boost error reporting
+- Upgrade miniupnpc version to 1.9
+- gitian-linux: --enable-glibc-back-compat for binary compatibility with old distributions
+- gitian: don't export any symbols from executable
+- gitian: build against Qt 4.6
+- devtools: add script to check symbols from Linux gitian executables
+- Remove build-time no-IPv6 setting
+
+GUI:
+
+- Fix various coin control visual issues
+- Show number of in/out connections in debug console
+- Show weeks as well as years behind for long timespans behind
+- Enable and disable the Show and Remove buttons for requested payments history based on whether any entry is selected.
+- Show also value for options overridden on command line in options dialog
+- Fill in label from address book also for URIs
+- Fixes feel when resizing the last column on tables (issue #2862)
+- Fix ESC in disablewallet mode
+- Add expert section to wallet tab in optionsdialog
+- Do proper boost::path conversion (fixes unicode in datadir)
+- Only override -datadir if different from the default (fixes -datadir in config file)
+- Show rescan progress at start-up
+- Show importwallet progress
+- Get required locks upfront in polling functions (avoids hanging on locks)
+- Catch Windows shutdown events while client is running
+- Optionally add third party links to transaction context menu
+- Check for !pixmap() before trying to export QR code (avoids crashes when no QR code could be generated)
+- Fix "Start bitcoin on system login"
+
+Miscellaneous:
+
+- Replace non-threadsafe C functions (gmtime, strerror and setlocale)
+- Add missing cs_main and wallet locks
+- Avoid exception at startup when system locale not recognized
+- Changed bitrpc.py's raw_input to getpass for passwords to conceal characters during command line input
+- devtools: add a script to fetch and postprocess translations
+
+Credits
+--------
+
+Thanks to everyone who contributed to this release:
+
+- Addy Yeow
+- Altoidnerd
+- Andrea D'Amore
+- Andreas Schildbach
+- Bardi Harborow
+- Brandon Dahler
+- Bryan Bishop
+- Chris Beams
+- Christian von Roques
+- Cory Fields
+- Cozz Lovan
+- daniel
+- Daniel Newton
+- David A. Harding
+- ditto-b
+- duanemoody
+- Eric S. Bullington
+- Fabian Raetz
+- Gavin Andresen
+- Gregory Maxwell
+- gubatron
+- Haakon Nilsen
+- harry
+- Hector Jusforgues
+- Isidoro Ghezzi
+- Jeff Garzik
+- Johnathan Corgan
+- jtimon
+- Kamil Domanski
+- langerhans
+- Luke Dashjr
+- Manuel Araoz
+- Mark Friedenbach
+- Matt Corallo
+- Matthew Bogosian
+- Meeh
+- Michael Ford
+- Michagogo
+- Mikael Wikman
+- Mike Hearn
+- olalonde
+- paveljanik
+- peryaudo
+- Philip Kaufmann
+- philsong
+- Pieter Wuille
+- R E Broadley
+- richierichrawr
+- Rune K. Svendsen
+- rxl
+- shshshsh
+- Simon de la Rouviere
+- Stuart Cardall
+- super3
+- Telepatheic
+- Thomas Zander
+- Torstein Husebø
+- Warren Togami
+- Wladimir J. van der Laan
+- Yoichi Hirai
diff --git a/doc/release-process.md b/doc/release-process.md
index d12b41772e..c588381411 100644
--- a/doc/release-process.md
+++ b/doc/release-process.md
@@ -23,7 +23,7 @@ Release Process
* * *
-##perform gitian builds
+###perform gitian builds
From a directory containing the bitcoin source, gitian-builder and gitian.sigs
@@ -33,16 +33,21 @@ Release Process
git checkout v${VERSION}
popd
pushd ./gitian-builder
- mkdir -p inputs; cd inputs/
- Register and download the Apple SDK (see OSX Readme for details)
- visit https://developer.apple.com/downloads/download.action?path=Developer_Tools/xcode_4.6.3/xcode4630916281a.dmg
+###fetch and build inputs: (first time, or when dependency versions change)
- Using a Mac, create a tarball for the 10.7 SDK
- tar -C /Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ -czf MacOSX10.7.sdk.tar.gz MacOSX10.7.sdk
+ mkdir -p inputs; cd inputs/
- Fetch and build inputs: (first time, or when dependency versions change)
+ Register and download the Apple SDK: (see OSX Readme for details)
+
+ https://developer.apple.com/downloads/download.action?path=Developer_Tools/xcode_4.6.3/xcode4630916281a.dmg
+
+ Using a Mac, create a tarball for the 10.7 SDK and copy it to the inputs directory:
+
+ tar -C /Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ -czf MacOSX10.7.sdk.tar.gz MacOSX10.7.sdk
+ Download remaining inputs, and build everything:
+
wget 'http://miniupnp.free.fr/files/download.php?file=miniupnpc-1.9.tar.gz' -O miniupnpc-1.9.tar.gz
wget 'https://www.openssl.org/source/openssl-1.0.1h.tar.gz'
wget 'http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz'
@@ -87,10 +92,10 @@ Release Process
The expected SHA256 hashes of the intermediate inputs are:
- 46710f673467e367738d8806e45b4cb5931aaeea61f4b6b55a68eea56d5006c5 bitcoin-deps-linux32-gitian-r6.zip
- f03be39fb26670243d3a659e64d18e19d03dec5c11e9912011107768390b5268 bitcoin-deps-linux64-gitian-r6.zip
f29b7d9577417333fb56e023c2977f5726a7c297f320b175a4108cf7cd4c2d29 boost-linux32-1.55.0-gitian-r1.zip
88232451c4104f7eb16e469ac6474fd1231bd485687253f7b2bdf46c0781d535 boost-linux64-1.55.0-gitian-r1.zip
+ 46710f673467e367738d8806e45b4cb5931aaeea61f4b6b55a68eea56d5006c5 bitcoin-deps-linux32-gitian-r6.zip
+ f03be39fb26670243d3a659e64d18e19d03dec5c11e9912011107768390b5268 bitcoin-deps-linux64-gitian-r6.zip
57e57dbdadc818cd270e7e00500a5e1085b3bcbdef69a885f0fb7573a8d987e1 qt-linux32-4.6.4-gitian-r1.tar.gz
60eb4b9c5779580b7d66529efa5b2836ba1a70edde2a0f3f696d647906a826be qt-linux64-4.6.4-gitian-r1.tar.gz
60dc2d3b61e9c7d5dbe2f90d5955772ad748a47918ff2d8b74e8db9b1b91c909 boost-win32-1.55.0-gitian-r6.zip
@@ -106,10 +111,10 @@ Release Process
ec95abef1df2b096a970359787c01d8c45e2a4475b7ae34e12c022634fbdba8a osx-depends-qt-5.2.1-r4.tar.gz
- Build bitcoind and bitcoin-qt on Linux32, Linux64, and Win32:
+ Build Bitcoin Core for Linux, Windows, and OS X:
./bin/gbuild --commit bitcoin=v${VERSION} ../bitcoin/contrib/gitian-descriptors/gitian-linux.yml
- ./bin/gsign --signer $SIGNER --release ${VERSION} --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-linux.yml
+ ./bin/gsign --signer $SIGNER --release ${VERSION}-linux --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-linux.yml
pushd build/out
zip -r bitcoin-${VERSION}-linux-gitian.zip *
mv bitcoin-${VERSION}-linux-gitian.zip ../../../
@@ -132,7 +137,7 @@ Release Process
1. linux 32-bit and 64-bit binaries + source (bitcoin-${VERSION}-linux-gitian.zip)
2. windows 32-bit and 64-bit binaries + installer + source (bitcoin-${VERSION}-win-gitian.zip)
3. OSX installer (Bitcoin-Qt.dmg)
- 4. Gitian signatures (in gitian.sigs/${VERSION}[-win|-osx]/(your gitian key)/
+ 4. Gitian signatures (in gitian.sigs/${VERSION}-<linux|win|osx>/(your gitian key)/
repackage gitian builds for release as stand-alone zip/tar/installer exe
@@ -172,8 +177,9 @@ repackage gitian builds for release as stand-alone zip/tar/installer exe
Commit your signature to gitian.sigs:
pushd gitian.sigs
- git add ${VERSION}/${SIGNER}
+ git add ${VERSION}-linux/${SIGNER}
git add ${VERSION}-win/${SIGNER}
+ git add ${VERSION}-osx/${SIGNER}
git commit -a
git push # Assuming you can push to the gitian.sigs tree
popd
diff --git a/qa/rpc-tests/rpcbind_test.py b/qa/rpc-tests/rpcbind_test.py
index a31f8d98ef..a823404e00 100755
--- a/qa/rpc-tests/rpcbind_test.py
+++ b/qa/rpc-tests/rpcbind_test.py
@@ -39,7 +39,7 @@ def run_bind_test(tmpdir, allow_ips, connect_to, addresses, expected):
stop_nodes(nodes)
wait_bitcoinds()
-def run_allowip_test(tmpdir, allow_ips, rpchost):
+def run_allowip_test(tmpdir, allow_ips, rpchost, rpcport):
'''
Start a node with rpcwallow IP, and request getinfo
at a non-localhost IP.
@@ -48,7 +48,7 @@ def run_allowip_test(tmpdir, allow_ips, rpchost):
nodes = start_nodes(1, tmpdir, [base_args])
try:
# connect to node through non-loopback interface
- url = "http://rt:rt@%s:%d" % (rpchost, START_RPC_PORT,)
+ url = "http://rt:rt@%s:%d" % (rpchost, rpcport,)
node = AuthServiceProxy(url)
node.getinfo()
finally:
@@ -69,15 +69,17 @@ def run_test(tmpdir):
assert(not 'This test requires at least one non-loopback IPv4 interface')
print("Using interface %s for testing" % non_loopback_ip)
+ defaultport = rpc_port(0)
+
# check default without rpcallowip (IPv4 and IPv6 localhost)
run_bind_test(tmpdir, None, '127.0.0.1', [],
- [('127.0.0.1', 11100), ('::1', 11100)])
+ [('127.0.0.1', defaultport), ('::1', defaultport)])
# check default with rpcallowip (IPv6 any)
run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1', [],
- [('::0', 11100)])
+ [('::0', defaultport)])
# check only IPv4 localhost (explicit)
run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1', ['127.0.0.1'],
- [('127.0.0.1', START_RPC_PORT)])
+ [('127.0.0.1', defaultport)])
# check only IPv4 localhost (explicit) with alternative port
run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1:32171', ['127.0.0.1:32171'],
[('127.0.0.1', 32171)])
@@ -86,18 +88,18 @@ def run_test(tmpdir):
[('127.0.0.1', 32171), ('127.0.0.1', 32172)])
# check only IPv6 localhost (explicit)
run_bind_test(tmpdir, ['[::1]'], '[::1]', ['[::1]'],
- [('::1', 11100)])
+ [('::1', defaultport)])
# check both IPv4 and IPv6 localhost (explicit)
run_bind_test(tmpdir, ['127.0.0.1'], '127.0.0.1', ['127.0.0.1', '[::1]'],
- [('127.0.0.1', START_RPC_PORT), ('::1', START_RPC_PORT)])
+ [('127.0.0.1', defaultport), ('::1', defaultport)])
# check only non-loopback interface
run_bind_test(tmpdir, [non_loopback_ip], non_loopback_ip, [non_loopback_ip],
- [(non_loopback_ip, START_RPC_PORT)])
+ [(non_loopback_ip, defaultport)])
# Check that with invalid rpcallowip, we are denied
- run_allowip_test(tmpdir, [non_loopback_ip], non_loopback_ip)
+ run_allowip_test(tmpdir, [non_loopback_ip], non_loopback_ip, defaultport)
try:
- run_allowip_test(tmpdir, ['1.1.1.1'], non_loopback_ip)
+ run_allowip_test(tmpdir, ['1.1.1.1'], non_loopback_ip, defaultport)
assert(not 'Connection not denied by rpcallowip as expected')
except ValueError:
pass
diff --git a/src/Makefile.am b/src/Makefile.am
index 3643e60201..e2a62c9699 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,10 @@
AM_CPPFLAGS = $(INCLUDES)
AM_LDFLAGS = $(PTHREAD_CFLAGS)
+if USE_LIBSECP256K1
+secp256k1/libsecp256k1.la: $(wildcard secp256k1/src/*) $(wildcard secp256k1/include/*)
+ @$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F)
+endif
if EMBEDDED_LEVELDB
LEVELDB_CPPFLAGS += -I$(srcdir)/leveldb/include
@@ -20,6 +24,10 @@ endif
BITCOIN_CONFIG_INCLUDES=-I$(builddir)/config
BITCOIN_INCLUDES=-I$(builddir) -I$(builddir)/obj $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS)
+if USE_LIBSECP256K1
+BITCOIN_INCLUDES += -I$(srcdir)/secp256k1/include
+endif
+
LIBBITCOIN_SERVER=libbitcoin_server.a
LIBBITCOIN_WALLET=libbitcoin_wallet.a
LIBBITCOIN_COMMON=libbitcoin_common.a
@@ -192,6 +200,7 @@ libbitcoin_util_a_SOURCES = \
chainparamsbase.cpp \
rpcprotocol.cpp \
sync.cpp \
+ uint256.cpp \
util.cpp \
version.cpp \
compat/glibc_sanity.cpp \
@@ -219,6 +228,11 @@ bitcoind_LDADD = \
$(LIBBITCOIN_CRYPTO) \
$(LIBLEVELDB) \
$(LIBMEMENV)
+
+if USE_LIBSECP256K1
+ bitcoind_LDADD += secp256k1/libsecp256k1.la
+endif
+
if ENABLE_WALLET
bitcoind_LDADD += libbitcoin_wallet.a
endif
@@ -241,6 +255,10 @@ bitcoin_cli_LDADD = \
$(BOOST_LIBS)
bitcoin_cli_SOURCES = \
bitcoin-cli.cpp
+
+if USE_LIBSECP256K1
+ bitcoin_cli_LDADD += secp256k1/libsecp256k1.la
+endif
bitcoin_cli_CPPFLAGS = $(BITCOIN_INCLUDES)
#
@@ -252,10 +270,11 @@ CLEANFILES = leveldb/libleveldb.a leveldb/libmemenv.a *.gcda *.gcno
DISTCLEANFILES = obj/build.h
-EXTRA_DIST = leveldb
+EXTRA_DIST = leveldb secp256k1
clean-local:
-$(MAKE) -C leveldb clean
+ -$(MAKE) -C secp256k1 clean
rm -f leveldb/*/*.gcno leveldb/helpers/memenv/*.gcno
-rm -f config.h
diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include
index 9df0779ba3..4563bb3565 100644
--- a/src/Makefile.qt.include
+++ b/src/Makefile.qt.include
@@ -357,6 +357,9 @@ qt_bitcoin_qt_LDADD += $(LIBBITCOIN_WALLET)
endif
qt_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBLEVELDB) $(LIBMEMENV) \
$(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS)
+if USE_LIBSECP256K1
+ qt_bitcoin_qt_LDADD += secp256k1/libsecp256k1.la
+endif
qt_bitcoin_qt_LDFLAGS = $(QT_LDFLAGS)
#locale/foo.ts -> locale/foo.qm
diff --git a/src/Makefile.qttest.include b/src/Makefile.qttest.include
index a509f23755..7e10ce5a96 100644
--- a/src/Makefile.qttest.include
+++ b/src/Makefile.qttest.include
@@ -33,6 +33,9 @@ endif
qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBLEVELDB) \
$(LIBMEMENV) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \
$(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS)
+if USE_LIBSECP256K1
+ qt_test_test_bitcoin_qt_LDADD += secp256k1/libsecp256k1.la
+endif
qt_test_test_bitcoin_qt_LDFLAGS = $(QT_LDFLAGS)
CLEAN_BITCOIN_QT_TEST = $(TEST_QT_MOC_CPP) qt/test/*.gcda qt/test/*.gcno
diff --git a/src/Makefile.test.include b/src/Makefile.test.include
index 4dab1773f4..12b90adca3 100644
--- a/src/Makefile.test.include
+++ b/src/Makefile.test.include
@@ -47,6 +47,7 @@ BITCOIN_TESTS =\
test/script_tests.cpp \
test/serialize_tests.cpp \
test/sigopcount_tests.cpp \
+ test/skiplist_tests.cpp \
test/test_bitcoin.cpp \
test/transaction_tests.cpp \
test/uint256_tests.cpp \
@@ -68,6 +69,11 @@ test_test_bitcoin_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_CO
if ENABLE_WALLET
test_test_bitcoin_LDADD += $(LIBBITCOIN_WALLET)
endif
+
+if USE_LIBSECP256K1
+ test_test_bitcoin_LDADD += secp256k1/libsecp256k1.la
+endif
+
test_test_bitcoin_LDADD += $(BDB_LIBS)
nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)
diff --git a/src/base58.cpp b/src/base58.cpp
index 1bd64684e5..c9e91beef1 100644
--- a/src/base58.cpp
+++ b/src/base58.cpp
@@ -186,6 +186,7 @@ int CBase58Data::CompareTo(const CBase58Data& b58) const {
}
namespace {
+
class CBitcoinAddressVisitor : public boost::static_visitor<bool> {
private:
CBitcoinAddress *addr;
@@ -196,7 +197,8 @@ namespace {
bool operator()(const CScriptID &id) const { return addr->Set(id); }
bool operator()(const CNoDestination &no) const { return false; }
};
-};
+
+} // anon namespace
bool CBitcoinAddress::Set(const CKeyID &id) {
SetData(Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS), &id, 20);
diff --git a/src/bitcoin-cli-res.rc b/src/bitcoin-cli-res.rc
index f8bfb3a881..b1aa1b0e16 100644
--- a/src/bitcoin-cli-res.rc
+++ b/src/bitcoin-cli-res.rc
@@ -5,7 +5,6 @@
#define VER_PRODUCTVERSION_STR STRINGIZE(CLIENT_VERSION_MAJOR) "." STRINGIZE(CLIENT_VERSION_MINOR) "." STRINGIZE(CLIENT_VERSION_REVISION) "." STRINGIZE(CLIENT_VERSION_BUILD)
#define VER_FILEVERSION VER_PRODUCTVERSION
#define VER_FILEVERSION_STR VER_PRODUCTVERSION_STR
-#define COPYRIGHT_STR "2009-" STRINGIZE(COPYRIGHT_YEAR) " The Bitcoin Core developers"
VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILEVERSION
diff --git a/src/bitcoind-res.rc b/src/bitcoind-res.rc
index dc5c56b797..2e6d754495 100644
--- a/src/bitcoind-res.rc
+++ b/src/bitcoind-res.rc
@@ -5,7 +5,6 @@
#define VER_PRODUCTVERSION_STR STRINGIZE(CLIENT_VERSION_MAJOR) "." STRINGIZE(CLIENT_VERSION_MINOR) "." STRINGIZE(CLIENT_VERSION_REVISION) "." STRINGIZE(CLIENT_VERSION_BUILD)
#define VER_FILEVERSION VER_PRODUCTVERSION
#define VER_FILEVERSION_STR VER_PRODUCTVERSION_STR
-#define COPYRIGHT_STR "2009-" STRINGIZE(COPYRIGHT_YEAR) " The Bitcoin Core developers"
VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILEVERSION
diff --git a/src/bloom.cpp b/src/bloom.cpp
index 26e366179c..85a2ddc189 100644
--- a/src/bloom.cpp
+++ b/src/bloom.cpp
@@ -94,6 +94,13 @@ bool CBloomFilter::contains(const uint256& hash) const
return contains(data);
}
+void CBloomFilter::clear()
+{
+ vData.assign(vData.size(),0);
+ isFull = false;
+ isEmpty = true;
+}
+
bool CBloomFilter::IsWithinSizeConstraints() const
{
return vData.size() <= MAX_BLOOM_FILTER_SIZE && nHashFuncs <= MAX_HASH_FUNCS;
diff --git a/src/bloom.h b/src/bloom.h
index 956bead87f..d0caf9e9fa 100644
--- a/src/bloom.h
+++ b/src/bloom.h
@@ -78,6 +78,8 @@ public:
bool contains(const COutPoint& outpoint) const;
bool contains(const uint256& hash) const;
+ void clear();
+
// True if the size is <= MAX_BLOOM_FILTER_SIZE and the number of hash functions is <= MAX_HASH_FUNCS
// (catch a filter which was just deserialized which was too big)
bool IsWithinSizeConstraints() const;
diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp
index 75ac418916..80479b47fb 100644
--- a/src/checkpoints.cpp
+++ b/src/checkpoints.cpp
@@ -12,8 +12,8 @@
#include <boost/assign/list_of.hpp> // for 'map_list_of()'
#include <boost/foreach.hpp>
-namespace Checkpoints
-{
+namespace Checkpoints {
+
typedef std::map<int, uint256> MapCheckpoints;
// How many times we expect transactions after the last checkpoint to
@@ -161,4 +161,5 @@ namespace Checkpoints
}
return NULL;
}
-}
+
+} // namespace Checkpoints
diff --git a/src/checkpoints.h b/src/checkpoints.h
index 1b4aacee20..2cf8d41b9d 100644
--- a/src/checkpoints.h
+++ b/src/checkpoints.h
@@ -13,8 +13,8 @@ class uint256;
/** Block-chain checkpoints are compiled-in sanity checks.
* They are updated every release or three.
*/
-namespace Checkpoints
-{
+namespace Checkpoints {
+
// Returns true if block passes checkpoint checks
bool CheckBlock(int nHeight, const uint256& hash);
@@ -27,6 +27,7 @@ namespace Checkpoints
double GuessVerificationProgress(CBlockIndex *pindex, bool fSigchecks = true);
extern bool fEnabled;
-}
+
+} //namespace Checkpoints
#endif
diff --git a/src/clientversion.h b/src/clientversion.h
index a30bbff06b..6c718a9f79 100644
--- a/src/clientversion.h
+++ b/src/clientversion.h
@@ -8,7 +8,7 @@
// client versioning and copyright year
//
-// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
+// These need to be macros, as version.cpp's and bitcoin*-res.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 0
#define CLIENT_VERSION_MINOR 9
#define CLIENT_VERSION_REVISION 99
@@ -28,4 +28,7 @@
#define STRINGIZE(X) DO_STRINGIZE(X)
#define DO_STRINGIZE(X) #X
+// Copyright string used in Windows .rc files
+#define COPYRIGHT_STR "2009-" STRINGIZE(COPYRIGHT_YEAR) " The Bitcoin Core Developers"
+
#endif // CLIENTVERSION_H
diff --git a/src/coins.cpp b/src/coins.cpp
index 86b2a6ef17..13a4ea95cd 100644
--- a/src/coins.cpp
+++ b/src/coins.cpp
@@ -55,7 +55,7 @@ bool CCoinsView::SetCoins(const uint256 &txid, const CCoins &coins) { return fal
bool CCoinsView::HaveCoins(const uint256 &txid) { return false; }
uint256 CCoinsView::GetBestBlock() { return uint256(0); }
bool CCoinsView::SetBestBlock(const uint256 &hashBlock) { return false; }
-bool CCoinsView::BatchWrite(const std::map<uint256, CCoins> &mapCoins, const uint256 &hashBlock) { return false; }
+bool CCoinsView::BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlock) { return false; }
bool CCoinsView::GetStats(CCoinsStats &stats) { return false; }
@@ -66,7 +66,7 @@ bool CCoinsViewBacked::HaveCoins(const uint256 &txid) { return base->HaveCoins(t
uint256 CCoinsViewBacked::GetBestBlock() { return base->GetBestBlock(); }
bool CCoinsViewBacked::SetBestBlock(const uint256 &hashBlock) { return base->SetBestBlock(hashBlock); }
void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { base = &viewIn; }
-bool CCoinsViewBacked::BatchWrite(const std::map<uint256, CCoins> &mapCoins, const uint256 &hashBlock) { return base->BatchWrite(mapCoins, hashBlock); }
+bool CCoinsViewBacked::BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlock) { return base->BatchWrite(mapCoins, hashBlock); }
bool CCoinsViewBacked::GetStats(CCoinsStats &stats) { return base->GetStats(stats); }
CCoinsViewCache::CCoinsViewCache(CCoinsView &baseIn, bool fDummy) : CCoinsViewBacked(baseIn), hashBlock(0) { }
@@ -83,20 +83,20 @@ bool CCoinsViewCache::GetCoins(const uint256 &txid, CCoins &coins) {
return false;
}
-std::map<uint256,CCoins>::iterator CCoinsViewCache::FetchCoins(const uint256 &txid) {
- std::map<uint256,CCoins>::iterator it = cacheCoins.lower_bound(txid);
+CCoinsMap::iterator CCoinsViewCache::FetchCoins(const uint256 &txid) {
+ CCoinsMap::iterator it = cacheCoins.lower_bound(txid);
if (it != cacheCoins.end() && it->first == txid)
return it;
CCoins tmp;
if (!base->GetCoins(txid,tmp))
return cacheCoins.end();
- std::map<uint256,CCoins>::iterator ret = cacheCoins.insert(it, std::make_pair(txid, CCoins()));
+ CCoinsMap::iterator ret = cacheCoins.insert(it, std::make_pair(txid, CCoins()));
tmp.swap(ret->second);
return ret;
}
CCoins &CCoinsViewCache::GetCoins(const uint256 &txid) {
- std::map<uint256,CCoins>::iterator it = FetchCoins(txid);
+ CCoinsMap::iterator it = FetchCoins(txid);
assert(it != cacheCoins.end());
return it->second;
}
@@ -121,8 +121,8 @@ bool CCoinsViewCache::SetBestBlock(const uint256 &hashBlockIn) {
return true;
}
-bool CCoinsViewCache::BatchWrite(const std::map<uint256, CCoins> &mapCoins, const uint256 &hashBlockIn) {
- for (std::map<uint256, CCoins>::const_iterator it = mapCoins.begin(); it != mapCoins.end(); it++)
+bool CCoinsViewCache::BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlockIn) {
+ for (CCoinsMap::const_iterator it = mapCoins.begin(); it != mapCoins.end(); it++)
cacheCoins[it->first] = it->second;
hashBlock = hashBlockIn;
return true;
diff --git a/src/coins.h b/src/coins.h
index 0ad28524a1..c57a5ec722 100644
--- a/src/coins.h
+++ b/src/coins.h
@@ -239,6 +239,7 @@ public:
}
};
+typedef std::map<uint256,CCoins> CCoinsMap;
struct CCoinsStats
{
@@ -275,7 +276,7 @@ public:
virtual bool SetBestBlock(const uint256 &hashBlock);
// Do a bulk modification (multiple SetCoins + one SetBestBlock)
- virtual bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, const uint256 &hashBlock);
+ virtual bool BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlock);
// Calculate statistics about the unspent transaction output set
virtual bool GetStats(CCoinsStats &stats);
@@ -299,7 +300,7 @@ public:
uint256 GetBestBlock();
bool SetBestBlock(const uint256 &hashBlock);
void SetBackend(CCoinsView &viewIn);
- bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, const uint256 &hashBlock);
+ bool BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlock);
bool GetStats(CCoinsStats &stats);
};
@@ -309,7 +310,7 @@ class CCoinsViewCache : public CCoinsViewBacked
{
protected:
uint256 hashBlock;
- std::map<uint256,CCoins> cacheCoins;
+ CCoinsMap cacheCoins;
public:
CCoinsViewCache(CCoinsView &baseIn, bool fDummy = false);
@@ -320,7 +321,7 @@ public:
bool HaveCoins(const uint256 &txid);
uint256 GetBestBlock();
bool SetBestBlock(const uint256 &hashBlock);
- bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, const uint256 &hashBlock);
+ bool BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlock);
// Return a modifiable reference to a CCoins. Check HaveCoins first.
// Many methods explicitly require a CCoinsViewCache because of this method, to reduce
@@ -352,7 +353,7 @@ public:
const CTxOut &GetOutputFor(const CTxIn& input);
private:
- std::map<uint256,CCoins>::iterator FetchCoins(const uint256 &txid);
+ CCoinsMap::iterator FetchCoins(const uint256 &txid);
};
#endif
diff --git a/src/core.cpp b/src/core.cpp
index 6c5ee1c0f8..47f3b2a015 100644
--- a/src/core.cpp
+++ b/src/core.cpp
@@ -80,7 +80,7 @@ CFeeRate::CFeeRate(int64_t nFeePaid, size_t nSize)
nSatoshisPerK = 0;
}
-int64_t CFeeRate::GetFee(size_t nSize)
+int64_t CFeeRate::GetFee(size_t nSize) const
{
return nSatoshisPerK*nSize / 1000;
}
@@ -119,6 +119,22 @@ CTransaction& CTransaction::operator=(const CTransaction &tx) {
return *this;
}
+bool CTransaction::IsEquivalentTo(const CTransaction& tx) const
+{
+ if (nVersion != tx.nVersion ||
+ nLockTime != tx.nLockTime ||
+ vin.size() != tx.vin.size() ||
+ vout != tx.vout)
+ return false;
+ for (unsigned int i = 0; i < vin.size(); i++)
+ {
+ if (vin[i].nSequence != tx.vin[i].nSequence ||
+ vin[i].prevout != tx.vin[i].prevout)
+ return false;
+ }
+ return true;
+}
+
int64_t CTransaction::GetValueOut() const
{
int64_t nValueOut = 0;
diff --git a/src/core.h b/src/core.h
index 27fda95552..0387336c98 100644
--- a/src/core.h
+++ b/src/core.h
@@ -125,13 +125,14 @@ public:
CFeeRate(int64_t nFeePaid, size_t nSize);
CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
- int64_t GetFee(size_t size); // unit returned is satoshis
- int64_t GetFeePerK() { return GetFee(1000); } // satoshis-per-1000-bytes
+ int64_t GetFee(size_t size) const; // unit returned is satoshis
+ int64_t GetFeePerK() const { return GetFee(1000); } // satoshis-per-1000-bytes
friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }
friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; }
friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; }
-
+ friend bool operator<=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK <= b.nSatoshisPerK; }
+ friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
std::string ToString() const;
IMPLEMENT_SERIALIZE( READWRITE(nSatoshisPerK); )
@@ -216,8 +217,6 @@ private:
void UpdateHash() const;
public:
- static CFeeRate minTxFee;
- static CFeeRate minRelayTxFee;
static const int CURRENT_VERSION=1;
// The local variables are made const to prevent unintended modification
@@ -256,6 +255,9 @@ public:
return hash;
}
+ // True if only scriptSigs are different
+ bool IsEquivalentTo(const CTransaction& tx) const;
+
// Return sum of txouts.
int64_t GetValueOut() const;
// GetValueIn() is a method on CCoinsViewCache, because
diff --git a/src/init.cpp b/src/init.cpp
index c7170b0f2d..c514facbbe 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -253,10 +253,13 @@ std::string HelpMessage(HelpMessageMode mode)
#ifdef ENABLE_WALLET
strUsage += "\n" + _("Wallet options:") + "\n";
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 += " -mintxfee=<amt> " + strprintf(_("Fees (in BTC/Kb) smaller than this are considered zero fee for transaction creation (default: %s)"), FormatMoney(CWallet::minTxFee.GetFeePerK())) + "\n";
+ strUsage += " -paytxfee=<amt> " + strprintf(_("Fee (in BTC/kB) to add to transactions you send (default: %s)"), FormatMoney(payTxFee.GetFeePerK())) + "\n";
strUsage += " -rescan " + _("Rescan the block chain for missing wallet transactions") + " " + _("on startup") + "\n";
+ strUsage += " -respendnotify=<cmd> " + _("Execute command when a network tx respends wallet tx input (%s=respend TxID, %t=wallet TxID)") + "\n";
strUsage += " -salvagewallet " + _("Attempt to recover private keys from a corrupt wallet.dat") + " " + _("on startup") + "\n";
strUsage += " -spendzeroconfchange " + _("Spend unconfirmed change when sending transactions (default: 1)") + "\n";
+ strUsage += " -txconfirmtarget=<n> " + _("If paytxfee is not set, include enough fee so transactions are confirmed on average within n blocks (default: 1)") + "\n";
strUsage += " -upgradewallet " + _("Upgrade wallet to latest format") + " " + _("on startup") + "\n";
strUsage += " -wallet=<file> " + _("Specify wallet file (within data directory)") + " " + _("(default: wallet.dat)") + "\n";
strUsage += " -walletnotify=<cmd> " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n";
@@ -287,14 +290,14 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += " -gen " + _("Generate coins (default: 0)") + "\n";
strUsage += " -genproclimit=<n> " + _("Set the processor limit for when generation is on (-1 = unlimited, default: -1)") + "\n";
strUsage += " -help-debug " + _("Show all debugging options (usage: --help -help-debug)") + "\n";
+ strUsage += " -logips " + _("Include IP addresses in debug output (default: 0)") + "\n";
strUsage += " -logtimestamps " + _("Prepend debug output with timestamp (default: 1)") + "\n";
if (GetBoolArg("-help-debug", false))
{
strUsage += " -limitfreerelay=<n> " + _("Continuously rate-limit free transactions to <n>*1000 bytes per minute (default:15)") + "\n";
strUsage += " -maxsigcachesize=<n> " + _("Limit size of signature cache to <n> entries (default: 50000)") + "\n";
}
- strUsage += " -mintxfee=<amt> " + _("Fees smaller than this are considered zero fee (for transaction creation) (default:") + " " + FormatMoney(CTransaction::minTxFee.GetFeePerK()) + ")" + "\n";
- strUsage += " -minrelaytxfee=<amt> " + _("Fees smaller than this are considered zero fee (for relaying) (default:") + " " + FormatMoney(CTransaction::minRelayTxFee.GetFeePerK()) + ")" + "\n";
+ strUsage += " -minrelaytxfee=<amt> " + strprintf(_("Fees (in BTC/Kb) smaller than this are considered zero fee for relaying (default: %s)"), FormatMoney(::minRelayTxFee.GetFeePerK())) + "\n";
strUsage += " -printtoconsole " + _("Send trace/debug info to console instead of debug.log file") + "\n";
if (GetBoolArg("-help-debug", false))
{
@@ -322,7 +325,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += " -rpcuser=<user> " + _("Username for JSON-RPC connections") + "\n";
strUsage += " -rpcpassword=<pw> " + _("Password for JSON-RPC connections") + "\n";
strUsage += " -rpcport=<port> " + _("Listen for JSON-RPC connections on <port> (default: 8332 or testnet: 18332)") + "\n";
- strUsage += " -rpcallowip=<ip> " + _("Allow JSON-RPC connections from specified IP address. This option can be specified multiple times") + "\n";
+ strUsage += " -rpcallowip=<ip> " + _("Allow JSON-RPC connections from specified source. Valid for <ip> are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24). This option can be specified multiple times") + "\n";
strUsage += " -rpcthreads=<n> " + _("Set the number of threads to service RPC calls (default: 4)") + "\n";
strUsage += "\n" + _("RPC SSL options: (see the Bitcoin Wiki for SSL setup instructions)") + "\n";
@@ -584,6 +587,7 @@ bool AppInit2(boost::thread_group& threadGroup)
fServer = GetBoolArg("-server", false);
fPrintToConsole = GetBoolArg("-printtoconsole", false);
fLogTimestamps = GetBoolArg("-logtimestamps", true);
+ fLogIPs = GetBoolArg("-logips", false);
setvbuf(stdout, NULL, _IOLBF, 0);
#ifdef ENABLE_WALLET
bool fDisableWallet = GetBoolArg("-disablewallet", false);
@@ -608,24 +612,24 @@ bool AppInit2(boost::thread_group& threadGroup)
// a transaction spammer can cheaply fill blocks using
// 1-satoshi-fee transactions. It should be set above the real
// cost to you of processing a transaction.
- if (mapArgs.count("-mintxfee"))
- {
- int64_t n = 0;
- if (ParseMoney(mapArgs["-mintxfee"], n) && n > 0)
- CTransaction::minTxFee = CFeeRate(n);
- else
- return InitError(strprintf(_("Invalid amount for -mintxfee=<amount>: '%s'"), mapArgs["-mintxfee"]));
- }
if (mapArgs.count("-minrelaytxfee"))
{
int64_t n = 0;
if (ParseMoney(mapArgs["-minrelaytxfee"], n) && n > 0)
- CTransaction::minRelayTxFee = CFeeRate(n);
+ ::minRelayTxFee = CFeeRate(n);
else
return InitError(strprintf(_("Invalid amount for -minrelaytxfee=<amount>: '%s'"), mapArgs["-minrelaytxfee"]));
}
#ifdef ENABLE_WALLET
+ if (mapArgs.count("-mintxfee"))
+ {
+ int64_t n = 0;
+ if (ParseMoney(mapArgs["-mintxfee"], n) && n > 0)
+ CWallet::minTxFee = CFeeRate(n);
+ else
+ return InitError(strprintf(_("Invalid amount for -mintxfee=<amount>: '%s'"), mapArgs["-mintxfee"]));
+ }
if (mapArgs.count("-paytxfee"))
{
int64_t nFeePerK = 0;
@@ -634,7 +638,13 @@ bool AppInit2(boost::thread_group& threadGroup)
if (nFeePerK > nHighTransactionFeeWarning)
InitWarning(_("Warning: -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction."));
payTxFee = CFeeRate(nFeePerK, 1000);
+ if (payTxFee < ::minRelayTxFee)
+ {
+ return InitError(strprintf(_("Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s)"),
+ mapArgs["-paytxfee"], ::minRelayTxFee.ToString()));
+ }
}
+ nTxConfirmTarget = GetArg("-txconfirmtarget", 1);
bSpendZeroConfChange = GetArg("-spendzeroconfchange", true);
std::string strWalletFile = GetArg("-wallet", "wallet.dat");
@@ -1175,6 +1185,7 @@ bool AppInit2(boost::thread_group& threadGroup)
LogPrintf("mapAddressBook.size() = %u\n", pwalletMain ? pwalletMain->mapAddressBook.size() : 0);
#endif
+ InitRespendFilter();
StartNode(threadGroup);
if (fServer)
StartRPCThreads();
diff --git a/src/init.h b/src/init.h
index 52daa47616..626525c9ad 100644
--- a/src/init.h
+++ b/src/init.h
@@ -12,7 +12,7 @@ class CWallet;
namespace boost {
class thread_group;
-};
+} // namespace boost
extern CWallet* pwalletMain;
diff --git a/src/key.cpp b/src/key.cpp
index 96b1ac439c..3c4fa77e72 100644
--- a/src/key.cpp
+++ b/src/key.cpp
@@ -5,15 +5,34 @@
#include "key.h"
#include "crypto/sha2.h"
+#include <openssl/rand.h>
+#ifdef USE_SECP256K1
+#include <secp256k1.h>
+#else
#include <openssl/bn.h>
#include <openssl/ecdsa.h>
#include <openssl/obj_mac.h>
-#include <openssl/rand.h>
+#endif
// anonymous namespace with local implementation code (OpenSSL interaction)
namespace {
+#ifdef USE_SECP256K1
+#include <secp256k1.h>
+class CSecp256k1Init {
+public:
+ CSecp256k1Init() {
+ secp256k1_start();
+ }
+ ~CSecp256k1Init() {
+ secp256k1_stop();
+ }
+};
+static CSecp256k1Init instance_of_csecp256k1;
+
+#else
+
// Generate a private key from just the secret parameter
int EC_KEY_regenerate_key(EC_KEY *eckey, BIGNUM *priv_key)
{
@@ -334,6 +353,8 @@ public:
}
};
+#endif
+
int CompareBigEndian(const unsigned char *c1, size_t c1len, const unsigned char *c2, size_t c2len) {
while (c1len > c2len) {
if (*c1)
@@ -377,8 +398,7 @@ const unsigned char vchMaxModHalfOrder[32] = {
const unsigned char vchZero[0] = {};
-
-}; // end of anonymous namespace
+} // anon namespace
bool CKey::Check(const unsigned char *vch) {
return CompareBigEndian(vch, 32, vchZero, 0) > 0 &&
@@ -399,10 +419,15 @@ void CKey::MakeNewKey(bool fCompressedIn) {
}
bool CKey::SetPrivKey(const CPrivKey &privkey, bool fCompressedIn) {
+#ifdef USE_SECP256K1
+ if (!secp256k1_ecdsa_privkey_import((unsigned char*)begin(), &privkey[0], privkey.size()))
+ return false;
+#else
CECKey key;
if (!key.SetPrivKey(privkey))
return false;
key.GetSecretBytes(vch);
+#endif
fCompressed = fCompressedIn;
fValid = true;
return true;
@@ -410,99 +435,167 @@ bool CKey::SetPrivKey(const CPrivKey &privkey, bool fCompressedIn) {
CPrivKey CKey::GetPrivKey() const {
assert(fValid);
+ CPrivKey privkey;
+#ifdef USE_SECP256K1
+ privkey.resize(279);
+ int privkeylen = 279;
+ int ret = secp256k1_ecdsa_privkey_export(begin(), (unsigned char*)&privkey[0], &privkeylen, fCompressed);
+ assert(ret);
+ privkey.resize(privkeylen);
+#else
CECKey key;
key.SetSecretBytes(vch);
- CPrivKey privkey;
key.GetPrivKey(privkey, fCompressed);
+#endif
return privkey;
}
CPubKey CKey::GetPubKey() const {
assert(fValid);
+ CPubKey pubkey;
+#ifdef USE_SECP256K1
+ int clen = 65;
+ int ret = secp256k1_ecdsa_pubkey_create((unsigned char*)pubkey.begin(), &clen, begin(), fCompressed);
+ assert(ret);
+ assert(pubkey.IsValid());
+ assert((int)pubkey.size() == clen);
+#else
CECKey key;
key.SetSecretBytes(vch);
- CPubKey pubkey;
key.GetPubKey(pubkey, fCompressed);
+#endif
return pubkey;
}
bool CKey::Sign(const uint256 &hash, std::vector<unsigned char>& vchSig) const {
if (!fValid)
return false;
+#ifdef USE_SECP256K1
+ vchSig.resize(72);
+ int nSigLen = 72;
+ CKey nonce;
+ do {
+ nonce.MakeNewKey(true);
+ if (secp256k1_ecdsa_sign((const unsigned char*)&hash, 32, (unsigned char*)&vchSig[0], &nSigLen, begin(), nonce.begin()))
+ break;
+ } while(true);
+ vchSig.resize(nSigLen);
+ return true;
+#else
CECKey key;
key.SetSecretBytes(vch);
return key.Sign(hash, vchSig);
+#endif
}
bool CKey::SignCompact(const uint256 &hash, std::vector<unsigned char>& vchSig) const {
if (!fValid)
return false;
- CECKey key;
- key.SetSecretBytes(vch);
vchSig.resize(65);
int rec = -1;
+#ifdef USE_SECP256K1
+ CKey nonce;
+ do {
+ nonce.MakeNewKey(true);
+ if (secp256k1_ecdsa_sign_compact((const unsigned char*)&hash, 32, &vchSig[1], begin(), nonce.begin(), &rec))
+ break;
+ } while(true);
+#else
+ CECKey key;
+ key.SetSecretBytes(vch);
if (!key.SignCompact(hash, &vchSig[1], rec))
return false;
+#endif
assert(rec != -1);
vchSig[0] = 27 + rec + (fCompressed ? 4 : 0);
return true;
}
bool CKey::Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck=false) {
+#ifdef USE_SECP256K1
+ if (!secp256k1_ecdsa_privkey_import((unsigned char*)begin(), &privkey[0], privkey.size()))
+ return false;
+#else
CECKey key;
if (!key.SetPrivKey(privkey, fSkipCheck))
return false;
-
key.GetSecretBytes(vch);
+#endif
fCompressed = vchPubKey.IsCompressed();
fValid = true;
-
+
if (fSkipCheck)
return true;
-
+
if (GetPubKey() != vchPubKey)
return false;
-
+
return true;
}
bool CPubKey::Verify(const uint256 &hash, const std::vector<unsigned char>& vchSig) const {
if (!IsValid())
return false;
+#ifdef USE_SECP256K1
+ if (secp256k1_ecdsa_verify((const unsigned char*)&hash, 32, &vchSig[0], vchSig.size(), begin(), size()) != 1)
+ return false;
+#else
CECKey key;
if (!key.SetPubKey(*this))
return false;
if (!key.Verify(hash, vchSig))
return false;
+#endif
return true;
}
bool CPubKey::RecoverCompact(const uint256 &hash, const std::vector<unsigned char>& vchSig) {
if (vchSig.size() != 65)
return false;
+ int recid = (vchSig[0] - 27) & 3;
+ bool fComp = (vchSig[0] - 27) & 4;
+#ifdef USE_SECP256K1
+ int pubkeylen = 65;
+ if (!secp256k1_ecdsa_recover_compact((const unsigned char*)&hash, 32, &vchSig[1], (unsigned char*)begin(), &pubkeylen, fComp, recid))
+ return false;
+ assert((int)size() == pubkeylen);
+#else
CECKey key;
- if (!key.Recover(hash, &vchSig[1], (vchSig[0] - 27) & ~4))
+ if (!key.Recover(hash, &vchSig[1], recid))
return false;
- key.GetPubKey(*this, (vchSig[0] - 27) & 4);
+ key.GetPubKey(*this, fComp);
+#endif
return true;
}
bool CPubKey::IsFullyValid() const {
if (!IsValid())
return false;
+#ifdef USE_SECP256K1
+ if (!secp256k1_ecdsa_pubkey_verify(begin(), size()))
+ return false;
+#else
CECKey key;
if (!key.SetPubKey(*this))
return false;
+#endif
return true;
}
bool CPubKey::Decompress() {
if (!IsValid())
return false;
+#ifdef USE_SECP256K1
+ int clen = size();
+ int ret = secp256k1_ecdsa_pubkey_decompress((unsigned char*)begin(), &clen);
+ assert(ret);
+ assert(clen == (int)size());
+#else
CECKey key;
if (!key.SetPubKey(*this))
return false;
key.GetPubKey(*this, false);
+#endif
return true;
}
@@ -532,7 +625,12 @@ bool CKey::Derive(CKey& keyChild, unsigned char ccChild[32], unsigned int nChild
BIP32Hash(cc, nChild, 0, begin(), out);
}
memcpy(ccChild, out+32, 32);
+#ifdef USE_SECP256K1
+ memcpy((unsigned char*)keyChild.begin(), begin(), 32);
+ bool ret = secp256k1_ecdsa_privkey_tweak_add((unsigned char*)keyChild.begin(), out);
+#else
bool ret = CECKey::TweakSecret((unsigned char*)keyChild.begin(), begin(), out);
+#endif
UnlockObject(out);
keyChild.fCompressed = true;
keyChild.fValid = ret;
@@ -546,10 +644,15 @@ bool CPubKey::Derive(CPubKey& pubkeyChild, unsigned char ccChild[32], unsigned i
unsigned char out[64];
BIP32Hash(cc, nChild, *begin(), begin()+1, out);
memcpy(ccChild, out+32, 32);
+#ifdef USE_SECP256K1
+ pubkeyChild = *this;
+ bool ret = secp256k1_ecdsa_pubkey_tweak_add((unsigned char*)pubkeyChild.begin(), pubkeyChild.size(), out);
+#else
CECKey key;
bool ret = key.SetPubKey(*this);
ret &= key.TweakPublic(out);
key.GetPubKey(pubkeyChild, true);
+#endif
return ret;
}
@@ -630,6 +733,9 @@ bool CExtPubKey::Derive(CExtPubKey &out, unsigned int nChild) const {
}
bool ECC_InitSanityCheck() {
+#ifdef USE_SECP256K1
+ return true;
+#else
EC_KEY *pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
if(pkey == NULL)
return false;
@@ -637,6 +743,7 @@ bool ECC_InitSanityCheck() {
// TODO Is there more EC functionality that could be missing?
return true;
+#endif
}
diff --git a/src/main.cpp b/src/main.cpp
index e06c519ee2..b2773953d1 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,6 +7,7 @@
#include "addrman.h"
#include "alert.h"
+#include "bloom.h"
#include "chainparams.h"
#include "checkpoints.h"
#include "checkqueue.h"
@@ -37,8 +38,6 @@ using namespace boost;
CCriticalSection cs_main;
-CTxMemPool mempool;
-
map<uint256, CBlockIndex*> mapBlockIndex;
CChain chainActive;
int64_t nTimeBestReceived = 0;
@@ -49,10 +48,10 @@ bool fBenchmark = false;
bool fTxIndex = false;
unsigned int nCoinCacheSize = 5000;
-/** Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) */
-CFeeRate CTransaction::minTxFee = CFeeRate(10000); // Override with -mintxfee
/** Fees smaller than this (in satoshi) are considered zero fee (for relaying and mining) */
-CFeeRate CTransaction::minRelayTxFee = CFeeRate(1000);
+CFeeRate minRelayTxFee = CFeeRate(1000);
+
+CTxMemPool mempool(::minRelayTxFee);
struct COrphanBlock {
uint256 hashBlock;
@@ -72,6 +71,7 @@ const string strMessageMagic = "Bitcoin Signed Message:\n";
// Internal stuff
namespace {
+
struct CBlockIndexWorkComparator
{
bool operator()(CBlockIndex *pa, CBlockIndex *pb) {
@@ -120,8 +120,18 @@ namespace {
};
map<uint256, pair<NodeId, list<QueuedBlock>::iterator> > mapBlocksInFlight;
map<uint256, pair<NodeId, list<uint256>::iterator> > mapBlocksToDownload;
+
+} // anon namespace
+
+// Bloom filter to limit respend relays to one
+static const unsigned int MAX_DOUBLESPEND_BLOOM = 1000;
+static CBloomFilter doubleSpendFilter;
+void InitRespendFilter() {
+ seed_insecure_rand();
+ doubleSpendFilter = CBloomFilter(MAX_DOUBLESPEND_BLOOM, 0.01, insecure_rand(), BLOOM_UPDATE_NONE);
}
+
//////////////////////////////////////////////////////////////////////////////
//
// dispatching functions
@@ -130,6 +140,7 @@ namespace {
// These functions dispatch to one or all registered wallets
namespace {
+
struct CMainSignals {
// Notifies listeners of updated transaction data (transaction, and optionally the block it is found in.
boost::signals2::signal<void (const CTransaction &, const CBlock *)> SyncTransaction;
@@ -144,7 +155,9 @@ struct CMainSignals {
// Tells listeners to broadcast their data.
boost::signals2::signal<void ()> Broadcast;
} g_signals;
-}
+
+} // anon namespace
+
void RegisterWallet(CWalletInterface* pwalletIn) {
g_signals.SyncTransaction.connect(boost::bind(&CWalletInterface::SyncTransaction, pwalletIn, _1, _2));
@@ -203,6 +216,10 @@ struct CNodeState {
std::string name;
// List of asynchronously-determined block rejections to notify this peer about.
std::vector<CBlockReject> rejects;
+ // The best known block we know this peer has announced.
+ CBlockIndex *pindexBestKnownBlock;
+ // The hash of the last unknown block this peer has announced.
+ uint256 hashLastUnknownBlock;
list<QueuedBlock> vBlocksInFlight;
int nBlocksInFlight;
list<uint256> vBlocksToDownload;
@@ -213,6 +230,8 @@ struct CNodeState {
CNodeState() {
nMisbehavior = 0;
fShouldBan = false;
+ pindexBestKnownBlock = NULL;
+ hashLastUnknownBlock = uint256(0);
nBlocksToDownload = 0;
nBlocksInFlight = 0;
nLastBlockReceive = 0;
@@ -274,7 +293,6 @@ void MarkBlockAsReceived(const uint256 &hash, NodeId nodeFrom = -1) {
state->nLastBlockReceive = GetTimeMicros();
mapBlocksInFlight.erase(itInFlight);
}
-
}
// Requires cs_main.
@@ -310,14 +328,48 @@ void MarkBlockAsInFlight(NodeId nodeid, const uint256 &hash) {
mapBlocksInFlight[hash] = std::make_pair(nodeid, it);
}
+/** Check whether the last unknown block a peer advertized is not yet known. */
+void ProcessBlockAvailability(NodeId nodeid) {
+ CNodeState *state = State(nodeid);
+ assert(state != NULL);
+
+ if (state->hashLastUnknownBlock != 0) {
+ map<uint256, CBlockIndex*>::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock);
+ if (itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) {
+ if (state->pindexBestKnownBlock == NULL || itOld->second->nChainWork >= state->pindexBestKnownBlock->nChainWork)
+ state->pindexBestKnownBlock = itOld->second;
+ state->hashLastUnknownBlock = uint256(0);
+ }
+ }
}
+/** Update tracking information about which blocks a peer is assumed to have. */
+void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) {
+ CNodeState *state = State(nodeid);
+ assert(state != NULL);
+
+ ProcessBlockAvailability(nodeid);
+
+ map<uint256, CBlockIndex*>::iterator it = mapBlockIndex.find(hash);
+ if (it != mapBlockIndex.end() && it->second->nChainWork > 0) {
+ // An actually better block was announced.
+ if (state->pindexBestKnownBlock == NULL || it->second->nChainWork >= state->pindexBestKnownBlock->nChainWork)
+ state->pindexBestKnownBlock = it->second;
+ } else {
+ // An unknown block was announced; just assume that the latest one is the best one.
+ state->hashLastUnknownBlock = hash;
+ }
+}
+
+} // anon namespace
+
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) {
LOCK(cs_main);
CNodeState *state = State(nodeid);
if (state == NULL)
return false;
stats.nMisbehavior = state->nMisbehavior;
+ stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1;
return true;
}
@@ -371,8 +423,11 @@ CBlockLocator CChain::GetLocator(const CBlockIndex *pindex) const {
break;
// Exponentially larger steps back, plus the genesis block.
int nHeight = std::max(pindex->nHeight - nStep, 0);
+ // Jump back quickly to the same height as the chain.
+ if (pindex->nHeight > nHeight)
+ pindex = pindex->GetAncestor(nHeight);
// In case pindex is not in this chain, iterate pindex->pprev to find blocks.
- while (pindex->nHeight > nHeight && !Contains(pindex))
+ while (!Contains(pindex))
pindex = pindex->pprev;
// If pindex is in this chain, use direct height-based access.
if (pindex->nHeight > nHeight)
@@ -399,6 +454,8 @@ CBlockIndex *CChain::FindFork(const CBlockLocator &locator) const {
}
CBlockIndex *CChain::FindFork(CBlockIndex *pindex) const {
+ if (pindex->nHeight > Height())
+ pindex = pindex->GetAncestor(Height());
while (pindex && !Contains(pindex))
pindex = pindex->pprev;
return pindex;
@@ -488,7 +545,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason)
// Treat non-final transactions as non-standard to prevent a specific type
// of double-spend attack, as well as DoS attacks. (if the transaction
// can't be mined, the attacker isn't expending resources broadcasting it)
- // Basically we don't want to propagate transactions that can't included in
+ // Basically we don't want to propagate transactions that can't be included in
// the next block.
//
// However, IsFinalTx() is confusing... Without arguments, it uses
@@ -521,7 +578,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason)
{
// Biggest 'standard' txin is a 15-of-15 P2SH multisig with compressed
// keys. (remember the 520 byte limit on redeemScript size) That works
- // out to a (15*(33+1))+3=513 byte redeemScript, 513+1+15*(73+1)=1624
+ // out to a (15*(33+1))+3=513 byte redeemScript, 513+1+15*(73+1)+3=1627
// bytes of scriptSig, which we round off to 1650 bytes for some minor
// future-proofing. That's also enough to spend a 20-of-20
// CHECKMULTISIG scriptPubKey, though such a scriptPubKey is not
@@ -549,7 +606,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason)
}
if (whichType == TX_NULL_DATA)
nDataOut++;
- else if (txout.IsDust(CTransaction::minRelayTxFee)) {
+ else if (txout.IsDust(::minRelayTxFee)) {
reason = "dust";
return false;
}
@@ -583,15 +640,13 @@ bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
}
//
-// Check transaction inputs, and make sure any
-// pay-to-script-hash transactions are evaluating IsStandard scripts
+// Check transaction inputs to mitigate two
+// potential denial-of-service attacks:
//
-// Why bother? To avoid denial-of-service attacks; an attacker
-// can submit a standard HASH... OP_EQUAL transaction,
-// which will get accepted into blocks. The redemption
-// script can be anything; an attacker could use a very
-// expensive-to-check-upon-redemption script like:
-// DUP CHECKSIG DROP ... repeated 100 times... OP_1
+// 1. scriptSigs with extra data stuffed into them,
+// not consumed by scriptPubKey (or P2SH script)
+// 2. P2SH scripts with a crazy number of expensive
+// CHECKSIG/CHECKMULTISIG operations
//
bool AreInputsStandard(const CTransaction& tx, CCoinsViewCache& mapInputs)
{
@@ -615,8 +670,9 @@ bool AreInputsStandard(const CTransaction& tx, CCoinsViewCache& mapInputs)
// Transactions with extra stuff in their scriptSigs are
// non-standard. Note that this EvalScript() call will
// be quick, because if there are any operations
- // beside "push data" in the scriptSig the
- // IsStandard() call returns false
+ // beside "push data" in the scriptSig
+ // IsStandard() will have already returned false
+ // and this method isn't called.
vector<vector<unsigned char> > stack;
if (!EvalScript(stack, tx.vin[i].scriptSig, tx, i, false, 0))
return false;
@@ -628,16 +684,20 @@ bool AreInputsStandard(const CTransaction& tx, CCoinsViewCache& mapInputs)
CScript subscript(stack.back().begin(), stack.back().end());
vector<vector<unsigned char> > vSolutions2;
txnouttype whichType2;
- if (!Solver(subscript, whichType2, vSolutions2))
- return false;
- if (whichType2 == TX_SCRIPTHASH)
- return false;
-
- int tmpExpected;
- tmpExpected = ScriptSigArgsExpected(whichType2, vSolutions2);
- if (tmpExpected < 0)
- return false;
- nArgsExpected += tmpExpected;
+ if (Solver(subscript, whichType2, vSolutions2))
+ {
+ int tmpExpected = ScriptSigArgsExpected(whichType2, vSolutions2);
+ if (tmpExpected < 0)
+ return false;
+ nArgsExpected += tmpExpected;
+ }
+ else
+ {
+ // Any other Script with less than 15 sigops OK:
+ unsigned int sigops = subscript.GetSigOpCount(true);
+ // ... extra data left on the stack after execution is OK, too:
+ return (sigops <= MAX_P2SH_SIGOPS);
+ }
}
if (stack.size() != (unsigned int)nArgsExpected)
@@ -787,7 +847,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state)
return true;
}
-int64_t GetMinFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree, enum GetMinFee_mode mode)
+int64_t GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree)
{
{
LOCK(mempool.cs);
@@ -799,10 +859,7 @@ int64_t GetMinFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree,
return 0;
}
- // Base fee is either minTxFee or minRelayTxFee
- CFeeRate baseFeeRate = (mode == GMF_RELAY) ? tx.minRelayTxFee : tx.minTxFee;
-
- int64_t nMinFee = baseFeeRate.GetFee(nBytes);
+ int64_t nMinFee = ::minRelayTxFee.GetFee(nBytes);
if (fAllowFree)
{
@@ -810,9 +867,7 @@ int64_t GetMinFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree,
// * If we are relaying we allow transactions up to DEFAULT_BLOCK_PRIORITY_SIZE - 1000
// to be considered to fall into this category. We don't want to encourage sending
// multiple transactions instead of one big transaction to avoid fees.
- // * If we are creating a transaction we allow transactions up to 1,000 bytes
- // to be considered safe and assume they can likely make it into this section.
- if (nBytes < (mode == GMF_SEND ? 1000 : (DEFAULT_BLOCK_PRIORITY_SIZE - 1000)))
+ if (nBytes < (DEFAULT_BLOCK_PRIORITY_SIZE - 1000))
nMinFee = 0;
}
@@ -821,6 +876,60 @@ int64_t GetMinFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree,
return nMinFee;
}
+// Exponentially limit the rate of nSize flow to nLimit. nLimit unit is thousands-per-minute.
+bool RateLimitExceeded(double& dCount, int64_t& nLastTime, int64_t nLimit, unsigned int nSize)
+{
+ static CCriticalSection csLimiter;
+ int64_t nNow = GetTime();
+
+ LOCK(csLimiter);
+
+ dCount *= pow(1.0 - 1.0/600.0, (double)(nNow - nLastTime));
+ nLastTime = nNow;
+ if (dCount >= nLimit*10*1000)
+ return true;
+ dCount += nSize;
+ return false;
+}
+
+static bool RelayableRespend(const COutPoint& outPoint, const CTransaction& doubleSpend, bool fInBlock, CBloomFilter& filter)
+{
+ // Relaying double-spend attempts to our peers lets them detect when
+ // somebody might be trying to cheat them. However, blindly relaying
+ // every double-spend across the entire network gives attackers
+ // a denial-of-service attack: just generate a stream of double-spends
+ // re-spending the same (limited) set of outpoints owned by the attacker.
+ // So, we use a bloom filter and only relay (at most) the first double
+ // spend for each outpoint. False-positives ("we have already relayed")
+ // are OK, because if the peer doesn't hear about the double-spend
+ // from us they are very likely to hear about it from another peer, since
+ // each peer uses a different, randomized bloom filter.
+
+ if (fInBlock || filter.contains(outPoint)) return false;
+
+ // Apply an independent rate limit to double-spend relays
+ static double dRespendCount;
+ static int64_t nLastRespendTime;
+ static int64_t nRespendLimit = GetArg("-limitrespendrelay", 100);
+ unsigned int nSize = ::GetSerializeSize(doubleSpend, SER_NETWORK, PROTOCOL_VERSION);
+
+ if (RateLimitExceeded(dRespendCount, nLastRespendTime, nRespendLimit, nSize))
+ {
+ LogPrint("mempool", "Double-spend relay rejected by rate limiter\n");
+ return false;
+ }
+
+ LogPrint("mempool", "Rate limit dRespendCount: %g => %g\n", dRespendCount, dRespendCount+nSize);
+
+ // Clear the filter on average every MAX_DOUBLE_SPEND_BLOOM
+ // insertions
+ if (insecure_rand()%MAX_DOUBLESPEND_BLOOM == 0)
+ filter.clear();
+
+ filter.insert(outPoint);
+
+ return true;
+}
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,
bool* pfMissingInputs, bool fRejectInsaneFee)
@@ -850,15 +959,18 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
return false;
// Check for conflicts with in-memory transactions
+ bool relayableRespend = false;
{
LOCK(pool.cs); // protect pool.mapNextTx
for (unsigned int i = 0; i < tx.vin.size(); i++)
{
COutPoint outpoint = tx.vin[i].prevout;
- if (pool.mapNextTx.count(outpoint))
+ // Does tx conflict with a member of the pool, and is it not equivalent to that member?
+ if (pool.mapNextTx.count(outpoint) && !tx.IsEquivalentTo(*pool.mapNextTx[outpoint].ptx))
{
- // Disable replacement feature for now
- return false;
+ relayableRespend = RelayableRespend(outpoint, tx, false, doubleSpendFilter);
+ if (!relayableRespend)
+ return false;
}
}
}
@@ -918,7 +1030,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
unsigned int nSize = entry.GetTxSize();
// Don't accept it if it can't get into a block
- int64_t txMinFee = GetMinFee(tx, nSize, true, GMF_RELAY);
+ int64_t txMinFee = GetMinRelayFee(tx, nSize, true);
if (fLimitFree && nFees < txMinFee)
return state.DoS(0, error("AcceptToMemoryPool : not enough fees %s, %d < %d",
hash.ToString(), nFees, txMinFee),
@@ -927,31 +1039,23 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
// Continuously rate-limit free (really, very-low-fee)transactions
// This mitigates 'penny-flooding' -- sending thousands of free transactions just to
// be annoying or make others' transactions take longer to confirm.
- if (fLimitFree && nFees < CTransaction::minRelayTxFee.GetFee(nSize))
+ if (fLimitFree && nFees < ::minRelayTxFee.GetFee(nSize))
{
- static CCriticalSection csFreeLimiter;
static double dFreeCount;
- static int64_t nLastTime;
- int64_t nNow = GetTime();
-
- LOCK(csFreeLimiter);
+ static int64_t nLastFreeTime;
+ static int64_t nFreeLimit = GetArg("-limitfreerelay", 15);
- // Use an exponentially decaying ~10-minute window:
- dFreeCount *= pow(1.0 - 1.0/600.0, (double)(nNow - nLastTime));
- nLastTime = nNow;
- // -limitfreerelay unit is thousand-bytes-per-minute
- // At default rate it would take over a month to fill 1GB
- if (dFreeCount >= GetArg("-limitfreerelay", 15)*10*1000)
+ if (RateLimitExceeded(dFreeCount, nLastFreeTime, nFreeLimit, nSize))
return state.DoS(0, error("AcceptToMemoryPool : free transaction rejected by rate limiter"),
REJECT_INSUFFICIENTFEE, "insufficient priority");
+
LogPrint("mempool", "Rate limit dFreeCount: %g => %g\n", dFreeCount, dFreeCount+nSize);
- dFreeCount += nSize;
}
- if (fRejectInsaneFee && nFees > CTransaction::minRelayTxFee.GetFee(nSize) * 10000)
+ if (fRejectInsaneFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000)
return error("AcceptToMemoryPool: : insane fees %s, %d > %d",
hash.ToString(),
- nFees, CTransaction::minRelayTxFee.GetFee(nSize) * 10000);
+ nFees, ::minRelayTxFee.GetFee(nSize) * 10000);
// Check against previous transactions
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
@@ -959,13 +1063,21 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
{
return error("AcceptToMemoryPool: : ConnectInputs failed %s", hash.ToString());
}
- // Store transaction in memory
- pool.addUnchecked(hash, entry);
+
+ if (relayableRespend)
+ {
+ RelayTransaction(tx);
+ }
+ else
+ {
+ // Store transaction in memory
+ pool.addUnchecked(hash, entry);
+ }
}
g_signals.SyncTransaction(tx, NULL);
- return true;
+ return !relayableRespend;
}
@@ -1013,10 +1125,10 @@ int CMerkleTx::GetBlocksToMaturity() const
}
-bool CMerkleTx::AcceptToMemoryPool(bool fLimitFree)
+bool CMerkleTx::AcceptToMemoryPool(bool fLimitFree, bool fRejectInsaneFee)
{
CValidationState state;
- return ::AcceptToMemoryPool(mempool, state, *this, fLimitFree, NULL);
+ return ::AcceptToMemoryPool(mempool, state, *this, fLimitFree, NULL, fRejectInsaneFee);
}
@@ -2105,6 +2217,7 @@ CBlockIndex* AddToBlockIndex(CBlockHeader& block)
{
pindexNew->pprev = (*miPrev).second;
pindexNew->nHeight = pindexNew->pprev->nHeight + 1;
+ pindexNew->BuildSkip();
}
pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + pindexNew->GetBlockWork();
pindexNew->RaiseValidity(BLOCK_VALID_TREE);
@@ -2462,6 +2575,55 @@ bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, uns
return (nFound >= nRequired);
}
+/** Turn the lowest '1' bit in the binary representation of a number into a '0'. */
+int static inline InvertLowestOne(int n) { return n & (n - 1); }
+
+/** Compute what height to jump back to with the CBlockIndex::pskip pointer. */
+int static inline GetSkipHeight(int height) {
+ if (height < 2)
+ return 0;
+
+ // Determine which height to jump back to. Any number strictly lower than height is acceptable,
+ // but the following expression seems to perform well in simulations (max 110 steps to go back
+ // up to 2**18 blocks).
+ return (height & 1) ? InvertLowestOne(InvertLowestOne(height - 1)) + 1 : InvertLowestOne(height);
+}
+
+CBlockIndex* CBlockIndex::GetAncestor(int height)
+{
+ if (height > nHeight || height < 0)
+ return NULL;
+
+ CBlockIndex* pindexWalk = this;
+ int heightWalk = nHeight;
+ while (heightWalk > height) {
+ int heightSkip = GetSkipHeight(heightWalk);
+ int heightSkipPrev = GetSkipHeight(heightWalk - 1);
+ if (heightSkip == height ||
+ (heightSkip > height && !(heightSkipPrev < heightSkip - 2 &&
+ heightSkipPrev >= height))) {
+ // Only follow pskip if pprev->pskip isn't better than pskip->pprev.
+ pindexWalk = pindexWalk->pskip;
+ heightWalk = heightSkip;
+ } else {
+ pindexWalk = pindexWalk->pprev;
+ heightWalk--;
+ }
+ }
+ return pindexWalk;
+}
+
+const CBlockIndex* CBlockIndex::GetAncestor(int height) const
+{
+ return const_cast<CBlockIndex*>(this)->GetAncestor(height);
+}
+
+void CBlockIndex::BuildSkip()
+{
+ if (pprev)
+ pskip = pprev->GetAncestor(GetSkipHeight(nHeight));
+}
+
void PushGetBlocks(CNode* pnode, CBlockIndex* pindexBegin, uint256 hashEnd)
{
AssertLockHeld(cs_main);
@@ -2812,6 +2974,8 @@ bool static LoadBlockIndexDB()
setBlockIndexValid.insert(pindex);
if (pindex->nStatus & BLOCK_FAILED_MASK && (!pindexBestInvalid || pindex->nChainWork > pindexBestInvalid->nChainWork))
pindexBestInvalid = pindex;
+ if (pindex->pprev)
+ pindex->BuildSkip();
}
// Load block file info
@@ -3374,7 +3538,7 @@ void static ProcessGetData(CNode* pfrom)
bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{
RandAddSeedPerfmon();
- LogPrint("net", "received: %s (%u bytes)\n", strCommand, vRecv.size());
+ LogPrint("net", "received: %s (%u bytes) peer=%d\n", strCommand, vRecv.size(), pfrom->id);
if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
{
LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n");
@@ -3406,7 +3570,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
if (pfrom->nVersion < MIN_PEER_PROTO_VERSION)
{
// disconnect from peers older than this proto version
- LogPrintf("partner %s using obsolete version %i; disconnecting\n", pfrom->addr.ToString(), pfrom->nVersion);
+ LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion);
pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE,
strprintf("Version must be %d or greater", MIN_PEER_PROTO_VERSION));
pfrom->fDisconnect = true;
@@ -3487,7 +3651,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
pfrom->fSuccessfullyConnected = true;
- LogPrintf("receive version message: %s: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", pfrom->cleanSubVer, pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString(), addrFrom.ToString(), pfrom->addr.ToString());
+ LogPrintf("receive version message: %s: version %d, blocks=%d, us=%s, peer=%d\n", pfrom->cleanSubVer, pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString(), pfrom->id);
AddTimeData(pfrom->addr, nTime);
}
@@ -3594,7 +3758,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
pfrom->AddInventoryKnown(inv);
bool fAlreadyHave = AlreadyHave(inv);
- LogPrint("net", " got inventory: %s %s\n", inv.ToString(), fAlreadyHave ? "have" : "new");
+ LogPrint("net", "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom->id);
if (!fAlreadyHave) {
if (!fImporting && !fReindex) {
@@ -3607,6 +3771,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
PushGetBlocks(pfrom, chainActive.Tip(), GetOrphanRoot(inv.hash));
}
+ if (inv.type == MSG_BLOCK)
+ UpdateBlockAvailability(pfrom->GetId(), inv.hash);
+
// Track requests for our stuff
g_signals.Inventory(inv.hash);
}
@@ -3624,10 +3791,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
}
if (fDebug || (vInv.size() != 1))
- LogPrint("net", "received getdata (%u invsz)\n", vInv.size());
+ LogPrint("net", "received getdata (%u invsz) peer=%d\n", vInv.size(), pfrom->id);
if ((fDebug && vInv.size() > 0) || (vInv.size() == 1))
- LogPrint("net", "received getdata for: %s\n", vInv[0].ToString());
+ LogPrint("net", "received getdata for: %s peer=%d\n", vInv[0].ToString(), pfrom->id);
pfrom->vRecvGetData.insert(pfrom->vRecvGetData.end(), vInv.begin(), vInv.end());
ProcessGetData(pfrom);
@@ -3649,7 +3816,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
if (pindex)
pindex = chainActive.Next(pindex);
int nLimit = 500;
- LogPrint("net", "getblocks %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString(), nLimit);
+ LogPrint("net", "getblocks %d to %s limit %d from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop==uint256(0) ? "end" : hashStop.ToString(), nLimit, pfrom->id);
for (; pindex; pindex = chainActive.Next(pindex))
{
if (pindex->GetBlockHash() == hashStop)
@@ -3732,8 +3899,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
vEraseQueue.push_back(inv.hash);
- LogPrint("mempool", "AcceptToMemoryPool: %s %s : accepted %s (poolsz %u)\n",
- pfrom->addr.ToString(), pfrom->cleanSubVer,
+ LogPrint("mempool", "AcceptToMemoryPool: peer=%d %s : accepted %s (poolsz %u)\n",
+ pfrom->id, pfrom->cleanSubVer,
tx.GetHash().ToString(),
mempool.mapTx.size());
@@ -3786,8 +3953,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
int nDoS = 0;
if (state.IsInvalid(nDoS))
{
- LogPrint("mempool", "%s from %s %s was not accepted into the memory pool: %s\n", tx.GetHash().ToString(),
- pfrom->addr.ToString(), pfrom->cleanSubVer,
+ LogPrint("mempool", "%s from peer=%d %s was not accepted into the memory pool: %s\n", tx.GetHash().ToString(),
+ pfrom->id, pfrom->cleanSubVer,
state.GetRejectReason());
pfrom->PushMessage("reject", strCommand, state.GetRejectCode(),
state.GetRejectReason(), inv.hash);
@@ -3802,7 +3969,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
CBlock block;
vRecv >> block;
- LogPrint("net", "received block %s\n", block.GetHash().ToString());
+ LogPrint("net", "received block %s peer=%d\n", block.GetHash().ToString(), pfrom->id);
// block.print();
CInv inv(MSG_BLOCK, block.GetHash());
@@ -3919,8 +4086,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
}
if (!(sProblem.empty())) {
- LogPrint("net", "pong %s %s: %s, %x expected, %x received, %u bytes\n",
- pfrom->addr.ToString(),
+ LogPrint("net", "pong peer=%d %s: %s, %x expected, %x received, %u bytes\n",
+ pfrom->id,
pfrom->cleanSubVer,
sProblem,
pfrom->nPingNonceSent,
@@ -4038,6 +4205,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
else
{
// Ignore unknown commands for extensibility
+ LogPrint("net", "Unknown command \"%s\" from peer=%d\n", SanitizeString(strCommand), pfrom->id);
}
@@ -4159,7 +4327,7 @@ bool ProcessMessages(CNode* pfrom)
}
if (!fRet)
- LogPrintf("ProcessMessage(%s, %u bytes) FAILED\n", strCommand, nMessageSize);
+ LogPrintf("ProcessMessage(%s, %u bytes) FAILED peer=%d\n", strCommand, nMessageSize, pfrom->id);
break;
}
@@ -4352,6 +4520,9 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
pto->fDisconnect = true;
}
+ // Update knowledge of peer's block availability.
+ ProcessBlockAvailability(pto->GetId());
+
//
// Message: getdata (blocks)
//
@@ -4360,7 +4531,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
uint256 hash = state.vBlocksToDownload.front();
vGetData.push_back(CInv(MSG_BLOCK, hash));
MarkBlockAsInFlight(pto->GetId(), hash);
- LogPrint("net", "Requesting block %s from %s\n", hash.ToString(), state.name);
+ LogPrint("net", "Requesting block %s peer=%d\n", hash.ToString(), pto->id);
if (vGetData.size() >= 1000)
{
pto->PushMessage("getdata", vGetData);
@@ -4377,7 +4548,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
if (!AlreadyHave(inv))
{
if (fDebug)
- LogPrint("net", "sending getdata: %s\n", inv.ToString());
+ LogPrint("net", "Requesting %s peer=%d\n", inv.ToString(), pto->id);
vGetData.push_back(inv);
if (vGetData.size() >= 1000)
{
diff --git a/src/main.h b/src/main.h
index 9858bcfd69..33b00a7b50 100644
--- a/src/main.h
+++ b/src/main.h
@@ -43,6 +43,8 @@ static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = 50000;
static const unsigned int MAX_STANDARD_TX_SIZE = 100000;
/** The maximum allowed number of signature check operations in a block (network rule) */
static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
+/** Maxiumum number of signature check operations in an IsStandard() P2SH script */
+static const unsigned int MAX_P2SH_SIGOPS = 15;
/** The maximum number of orphan transactions kept in memory */
static const unsigned int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100;
/** Default for -maxorphanblocks, maximum number of orphan blocks kept in memory */
@@ -91,6 +93,7 @@ extern bool fBenchmark;
extern int nScriptCheckThreads;
extern bool fTxIndex;
extern unsigned int nCoinCacheSize;
+extern CFeeRate minRelayTxFee;
// Minimum disk space required - used in CheckDiskSpace()
static const uint64_t nMinDiskSpace = 52428800;
@@ -106,6 +109,9 @@ struct CNodeStateStats;
struct CBlockTemplate;
+/** Initialize respend bloom filter **/
+void InitRespendFilter();
+
/** Register a wallet to receive updates from core */
void RegisterWallet(CWalletInterface* pwalletIn);
/** Unregister a wallet from core */
@@ -183,6 +189,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
struct CNodeStateStats {
int nMisbehavior;
+ int nSyncHeight;
};
struct CDiskBlockPos
@@ -239,14 +246,7 @@ struct CDiskTxPos : public CDiskBlockPos
};
-
-enum GetMinFee_mode
-{
- GMF_RELAY,
- GMF_SEND,
-};
-
-int64_t GetMinFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree, enum GetMinFee_mode mode);
+int64_t GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree);
//
// Check transaction inputs, and make sure any
@@ -453,7 +453,7 @@ public:
int GetDepthInMainChain() const { CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet); }
bool IsInMainChain() const { CBlockIndex *pindexRet; return GetDepthInMainChainINTERNAL(pindexRet) > 0; }
int GetBlocksToMaturity() const;
- bool AcceptToMemoryPool(bool fLimitFree=true);
+ bool AcceptToMemoryPool(bool fLimitFree=true, bool fRejectInsaneFee=true);
};
@@ -674,6 +674,9 @@ public:
// pointer to the index of the predecessor of this block
CBlockIndex* pprev;
+ // pointer to the index of some further predecessor of this block
+ CBlockIndex* pskip;
+
// height of the entry in the chain. The genesis block has height 0
int nHeight;
@@ -713,6 +716,7 @@ public:
{
phashBlock = NULL;
pprev = NULL;
+ pskip = NULL;
nHeight = 0;
nFile = 0;
nDataPos = 0;
@@ -734,6 +738,7 @@ public:
{
phashBlock = NULL;
pprev = NULL;
+ pskip = NULL;
nHeight = 0;
nFile = 0;
nDataPos = 0;
@@ -866,9 +871,14 @@ public:
}
return false;
}
-};
+ // Build the skiplist pointer for this entry.
+ void BuildSkip();
+ // Efficiently find an ancestor of this block.
+ CBlockIndex* GetAncestor(int height);
+ const CBlockIndex* GetAncestor(int height) const;
+};
/** Used to marshal pointers into hashes for db storage. */
class CDiskBlockIndex : public CBlockIndex
diff --git a/src/miner.cpp b/src/miner.cpp
index 69e53756e0..17918a1280 100644
--- a/src/miner.cpp
+++ b/src/miner.cpp
@@ -236,7 +236,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
double dPriorityDelta = 0;
int64_t nFeeDelta = 0;
mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta);
- if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < CTransaction::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize))
+ if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize))
continue;
// Prioritise by fee once past the priority size or we run out of high-priority
diff --git a/src/net.cpp b/src/net.cpp
index 811df43334..c7bdb83aad 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -36,6 +36,17 @@
#define MSG_NOSIGNAL 0
#endif
+// Fix for ancient MinGW versions, that don't have defined these in ws2tcpip.h.
+// Todo: Can be removed when our pull-tester is upgraded to a modern MinGW version.
+#ifdef WIN32
+#ifndef PROTECTION_LEVEL_UNRESTRICTED
+#define PROTECTION_LEVEL_UNRESTRICTED 10
+#endif
+#ifndef IPV6_PROTECTION_LEVEL
+#define IPV6_PROTECTION_LEVEL 23
+#endif
+#endif
+
using namespace std;
using namespace boost;
@@ -480,8 +491,6 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
{
addrman.Attempt(addrConnect);
- LogPrint("net", "connected %s\n", pszDest ? pszDest : addrConnect.ToString());
-
// Set to non-blocking
#ifdef WIN32
u_long nOne = 1;
@@ -502,6 +511,7 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
}
pnode->nTimeConnected = GetTime();
+
return pnode;
}
@@ -513,7 +523,7 @@ void CNode::CloseSocketDisconnect()
fDisconnect = true;
if (hSocket != INVALID_SOCKET)
{
- LogPrint("net", "disconnecting node %s\n", addrName);
+ LogPrint("net", "disconnecting peer=%d\n", id);
closesocket(hSocket);
hSocket = INVALID_SOCKET;
}
@@ -537,7 +547,10 @@ void CNode::PushVersion()
CAddress addrYou = (addr.IsRoutable() && !IsProxy(addr) ? addr : CAddress(CService("0.0.0.0",0)));
CAddress addrMe = GetLocalAddress(&addr);
RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce));
- LogPrint("net", "send version message: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), addrYou.ToString(), addr.ToString());
+ if (fLogIPs)
+ LogPrint("net", "send version message: version %d, blocks=%d, us=%s, them=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), addrYou.ToString(), id);
+ else
+ LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id);
PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe,
nLocalHostNonce, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<string>()), nBestHeight, true);
}
@@ -816,7 +829,6 @@ void ThreadSocketHandler()
uiInterface.NotifyNumConnectionsChanged(nPrevNodeCount);
}
-
//
// Find which sockets have data to receive
//
@@ -838,6 +850,7 @@ void ThreadSocketHandler()
hSocketMax = max(hSocketMax, hListenSocket);
have_fds = true;
}
+
{
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
@@ -898,58 +911,58 @@ void ThreadSocketHandler()
MilliSleep(timeout.tv_usec/1000);
}
-
//
// Accept new connections
//
BOOST_FOREACH(SOCKET hListenSocket, vhListenSocket)
- if (hListenSocket != INVALID_SOCKET && FD_ISSET(hListenSocket, &fdsetRecv))
{
- struct sockaddr_storage sockaddr;
- socklen_t len = sizeof(sockaddr);
- SOCKET hSocket = accept(hListenSocket, (struct sockaddr*)&sockaddr, &len);
- CAddress addr;
- int nInbound = 0;
-
- if (hSocket != INVALID_SOCKET)
- if (!addr.SetSockAddr((const struct sockaddr*)&sockaddr))
- LogPrintf("Warning: Unknown socket family\n");
-
+ if (hListenSocket != INVALID_SOCKET && FD_ISSET(hListenSocket, &fdsetRecv))
{
- LOCK(cs_vNodes);
- BOOST_FOREACH(CNode* pnode, vNodes)
- if (pnode->fInbound)
- nInbound++;
- }
+ struct sockaddr_storage sockaddr;
+ socklen_t len = sizeof(sockaddr);
+ SOCKET hSocket = accept(hListenSocket, (struct sockaddr*)&sockaddr, &len);
+ CAddress addr;
+ int nInbound = 0;
+
+ if (hSocket != INVALID_SOCKET)
+ if (!addr.SetSockAddr((const struct sockaddr*)&sockaddr))
+ LogPrintf("Warning: Unknown socket family\n");
- if (hSocket == INVALID_SOCKET)
- {
- int nErr = WSAGetLastError();
- if (nErr != WSAEWOULDBLOCK)
- LogPrintf("socket error accept failed: %s\n", NetworkErrorString(nErr));
- }
- else if (nInbound >= nMaxConnections - MAX_OUTBOUND_CONNECTIONS)
- {
- closesocket(hSocket);
- }
- else if (CNode::IsBanned(addr))
- {
- LogPrintf("connection from %s dropped (banned)\n", addr.ToString());
- closesocket(hSocket);
- }
- else
- {
- LogPrint("net", "accepted connection %s\n", addr.ToString());
- CNode* pnode = new CNode(hSocket, addr, "", true);
- pnode->AddRef();
{
LOCK(cs_vNodes);
- vNodes.push_back(pnode);
+ BOOST_FOREACH(CNode* pnode, vNodes)
+ if (pnode->fInbound)
+ nInbound++;
+ }
+
+ if (hSocket == INVALID_SOCKET)
+ {
+ int nErr = WSAGetLastError();
+ if (nErr != WSAEWOULDBLOCK)
+ LogPrintf("socket error accept failed: %s\n", NetworkErrorString(nErr));
+ }
+ else if (nInbound >= nMaxConnections - MAX_OUTBOUND_CONNECTIONS)
+ {
+ closesocket(hSocket);
+ }
+ else if (CNode::IsBanned(addr))
+ {
+ LogPrintf("connection from %s dropped (banned)\n", addr.ToString());
+ closesocket(hSocket);
+ }
+ else
+ {
+ CNode* pnode = new CNode(hSocket, addr, "", true);
+ pnode->AddRef();
+
+ {
+ LOCK(cs_vNodes);
+ vNodes.push_back(pnode);
+ }
}
}
}
-
//
// Service each socket
//
@@ -1028,7 +1041,7 @@ void ThreadSocketHandler()
{
if (pnode->nLastRecv == 0 || pnode->nLastSend == 0)
{
- LogPrint("net", "socket no message in first 60 seconds, %d %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0);
+ LogPrint("net", "socket no message in first 60 seconds, %d %d from %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0, pnode->id);
pnode->fDisconnect = true;
}
else if (nTime - pnode->nLastSend > TIMEOUT_INTERVAL)
@@ -1587,18 +1600,16 @@ bool BindListenPort(const CService &addrBind, string& strError)
return false;
}
+#ifndef WIN32
#ifdef SO_NOSIGPIPE
// Different way of disabling SIGPIPE on BSD
setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&nOne, sizeof(int));
#endif
-
-#ifndef WIN32
// Allow binding if the port is still in TIME_WAIT state after
- // the program was closed and restarted. Not an issue on windows.
+ // the program was closed and restarted. Not an issue on windows!
setsockopt(hListenSocket, SOL_SOCKET, SO_REUSEADDR, (void*)&nOne, sizeof(int));
#endif
-
#ifdef WIN32
// Set to non-blocking, incoming connections will also inherit this
if (ioctlsocket(hListenSocket, FIONBIO, (u_long*)&nOne) == SOCKET_ERROR)
@@ -1622,10 +1633,8 @@ bool BindListenPort(const CService &addrBind, string& strError)
#endif
#endif
#ifdef WIN32
- int nProtLevel = 10 /* PROTECTION_LEVEL_UNRESTRICTED */;
- int nParameterId = 23 /* IPV6_PROTECTION_LEVEl */;
- // this call is allowed to fail
- setsockopt(hListenSocket, IPPROTO_IPV6, nParameterId, (const char*)&nProtLevel, sizeof(int));
+ int nProtLevel = PROTECTION_LEVEL_UNRESTRICTED;
+ setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, (const char*)&nProtLevel, sizeof(int));
#endif
}
diff --git a/src/net.h b/src/net.h
index 41dc618571..3b169f442f 100644
--- a/src/net.h
+++ b/src/net.h
@@ -28,14 +28,13 @@
#include <boost/signals2/signal.hpp>
#include <openssl/rand.h>
-
class CAddrMan;
class CBlockIndex;
class CNode;
namespace boost {
class thread_group;
-}
+} // namespace boost
/** Time between pings automatically sent out for latency probing and keepalive (in seconds). */
static const int PING_INTERVAL = 2 * 60;
@@ -331,6 +330,11 @@ public:
id = nLastNodeId++;
}
+ if (fLogIPs)
+ LogPrint("net", "Added connection to %s peer=%d\n", addrName, id);
+ else
+ LogPrint("net", "Added connection peer=%d\n", id);
+
// Be shy and don't send version until we hear
if (hSocket != INVALID_SOCKET && !fInbound)
PushVersion();
@@ -447,7 +451,7 @@ public:
nRequestTime = it->second;
else
nRequestTime = 0;
- LogPrint("net", "askfor %s %d (%s)\n", inv.ToString(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str());
+ LogPrint("net", "askfor %s %d (%s) peer=%d\n", inv.ToString(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str(), id);
// Make sure not to reuse time indexes to keep things in the same order
int64_t nNow = GetTimeMicros() - 1000000;
@@ -515,7 +519,7 @@ public:
assert(ssSend.size () >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum));
memcpy((char*)&ssSend[CMessageHeader::CHECKSUM_OFFSET], &nChecksum, sizeof(nChecksum));
- LogPrint("net", "(%d bytes)\n", nSize);
+ LogPrint("net", "(%d bytes) peer=%d\n", nSize, id);
std::deque<CSerializeData>::iterator it = vSendMsg.insert(vSendMsg.end(), CSerializeData());
ssSend.GetAndClear(*it);
diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp
index dfbd445ce3..8d5284d5e9 100644
--- a/src/qt/addresstablemodel.cpp
+++ b/src/qt/addresstablemodel.cpp
@@ -114,7 +114,7 @@ public:
case CT_NEW:
if(inModel)
{
- qDebug() << "AddressTablePriv::updateEntry : Warning: Got CT_NEW, but entry is already in model";
+ qWarning() << "AddressTablePriv::updateEntry : Warning: Got CT_NEW, but entry is already in model";
break;
}
parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);
@@ -124,7 +124,7 @@ public:
case CT_UPDATED:
if(!inModel)
{
- qDebug() << "AddressTablePriv::updateEntry : Warning: Got CT_UPDATED, but entry is not in model";
+ qWarning() << "AddressTablePriv::updateEntry : Warning: Got CT_UPDATED, but entry is not in model";
break;
}
lower->type = newEntryType;
@@ -134,7 +134,7 @@ public:
case CT_DELETED:
if(!inModel)
{
- qDebug() << "AddressTablePriv::updateEntry : Warning: Got CT_DELETED, but entry is not in model";
+ qWarning() << "AddressTablePriv::updateEntry : Warning: Got CT_DELETED, but entry is not in model";
break;
}
parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index 89305e9f35..7c4af25edf 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -126,15 +126,15 @@ static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTrans
#if QT_VERSION < 0x050000
void DebugMessageHandler(QtMsgType type, const char *msg)
{
- Q_UNUSED(type);
- LogPrint("qt", "GUI: %s\n", msg);
+ const char *category = (type == QtDebugMsg) ? "qt" : NULL;
+ LogPrint(category, "GUI: %s\n", msg);
}
#else
void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString &msg)
{
- Q_UNUSED(type);
Q_UNUSED(context);
- LogPrint("qt", "GUI: %s\n", qPrintable(msg));
+ const char *category = (type == QtDebugMsg) ? "qt" : NULL;
+ LogPrint(category, "GUI: %s\n", msg.toStdString());
}
#endif
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index 30f5ec8939..f2fb8c877e 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -28,6 +28,7 @@
#include <iostream>
+#include <QAction>
#include <QApplication>
#include <QDateTime>
#include <QDesktopWidget>
@@ -39,6 +40,7 @@
#include <QMenuBar>
#include <QMessageBox>
#include <QMimeData>
+#include <QPoint>
#include <QProgressBar>
#include <QProgressDialog>
#include <QSettings>
@@ -49,6 +51,8 @@
#include <QToolBar>
#include <QVBoxLayout>
+
+
#if QT_VERSION < 0x050000
#include <QUrl>
#include <QTextDocument>
@@ -156,10 +160,13 @@ BitcoinGUI::BitcoinGUI(bool fIsTestnet, QWidget *parent) :
QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
frameBlocksLayout->setContentsMargins(3,0,3,0);
frameBlocksLayout->setSpacing(3);
+ unitDisplayControl = new UnitDisplayStatusBarControl();
labelEncryptionIcon = new QLabel();
labelConnectionsIcon = new QLabel();
labelBlocksIcon = new QLabel();
frameBlocksLayout->addStretch();
+ frameBlocksLayout->addWidget(unitDisplayControl);
+ frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelEncryptionIcon);
frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelConnectionsIcon);
@@ -420,6 +427,8 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
walletFrame->setClientModel(clientModel);
}
#endif
+
+ this->unitDisplayControl->setOptionsModel(clientModel->getOptionsModel());
}
}
@@ -1000,3 +1009,72 @@ void BitcoinGUI::unsubscribeFromCoreSignals()
// Disconnect signals from client
uiInterface.ThreadSafeMessageBox.disconnect(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3));
}
+
+UnitDisplayStatusBarControl::UnitDisplayStatusBarControl():QLabel()
+{
+ optionsModel = 0;
+ createContextMenu();
+ setStyleSheet("font:11pt; color: #333333");
+ setToolTip(tr("Unit to show amounts in. Click to select another unit."));
+}
+
+/** So that it responds to left-button clicks */
+void UnitDisplayStatusBarControl::mousePressEvent(QMouseEvent *event)
+{
+ onDisplayUnitsClicked(event->pos());
+}
+
+/** Creates context menu, its actions, and wires up all the relevant signals for mouse events. */
+void UnitDisplayStatusBarControl::createContextMenu()
+{
+ menu = new QMenu();
+ foreach(BitcoinUnits::Unit u, BitcoinUnits::availableUnits())
+ {
+ QAction *menuAction = new QAction(QString(BitcoinUnits::name(u)), this);
+ menuAction->setData(QVariant(u));
+ menu->addAction(menuAction);
+ }
+ connect(menu,SIGNAL(triggered(QAction*)),this,SLOT(onMenuSelection(QAction*)));
+
+ // what happens on right click.
+ setContextMenuPolicy(Qt::CustomContextMenu);
+ connect(this,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(onDisplayUnitsClicked(const QPoint&)));
+}
+
+/** Lets the control know about the Options Model (and its signals) */
+void UnitDisplayStatusBarControl::setOptionsModel(OptionsModel *optionsModel)
+{
+ if (optionsModel)
+ {
+ this->optionsModel = optionsModel;
+
+ // be aware of a display unit change reported by the OptionsModel object.
+ connect(optionsModel,SIGNAL(displayUnitChanged(int)),this,SLOT(updateDisplayUnit(int)));
+
+ // initialize the display units label with the current value in the model.
+ updateDisplayUnit(optionsModel->getDisplayUnit());
+ }
+}
+
+/** When Display Units are changed on OptionsModel it will refresh the display text of the control on the status bar */
+void UnitDisplayStatusBarControl::updateDisplayUnit(int newUnits)
+{
+ setText(BitcoinUnits::name(newUnits));
+}
+
+/** Shows context menu with Display Unit options by the mouse coordinates */
+void UnitDisplayStatusBarControl::onDisplayUnitsClicked(const QPoint& point)
+{
+ QPoint globalPos = mapToGlobal(point);
+ menu->exec(globalPos);
+}
+
+/** Tells underlying optionsModel to update its current display unit. */
+void UnitDisplayStatusBarControl::onMenuSelection(QAction* action)
+{
+ if (action)
+ {
+ optionsModel->setDisplayUnit(action->data());
+ }
+}
+
diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h
index e7a842df99..705e629a69 100644
--- a/src/qt/bitcoingui.h
+++ b/src/qt/bitcoingui.h
@@ -9,12 +9,16 @@
#include "config/bitcoin-config.h"
#endif
+#include <QLabel>
#include <QMainWindow>
#include <QMap>
+#include <QMenu>
+#include <QPoint>
#include <QSystemTrayIcon>
class ClientModel;
class Notificator;
+class OptionsModel;
class RPCConsole;
class SendCoinsRecipient;
class WalletFrame;
@@ -22,9 +26,13 @@ class WalletModel;
class CWallet;
+class UnitDisplayStatusBarControl;
+
QT_BEGIN_NAMESPACE
class QAction;
class QLabel;
+class QMenu;
+class QPoint;
class QProgressBar;
class QProgressDialog;
QT_END_NAMESPACE
@@ -69,6 +77,7 @@ private:
ClientModel *clientModel;
WalletFrame *walletFrame;
+ UnitDisplayStatusBarControl *unitDisplayControl;
QLabel *labelEncryptionIcon;
QLabel *labelConnectionsIcon;
QLabel *labelBlocksIcon;
@@ -198,4 +207,32 @@ private slots:
void showProgress(const QString &title, int nProgress);
};
+class UnitDisplayStatusBarControl : public QLabel
+{
+ Q_OBJECT
+
+public:
+ explicit UnitDisplayStatusBarControl();
+ /** Lets the control know about the Options Model (and its signals) */
+ void setOptionsModel(OptionsModel *optionsModel);
+
+protected:
+ /** So that it responds to left-button clicks */
+ void mousePressEvent(QMouseEvent *event);
+
+private:
+ OptionsModel *optionsModel;
+ QMenu* menu;
+ /** Shows context menu with Display Unit options by the mouse coordinates */
+ void onDisplayUnitsClicked(const QPoint& point);
+ /** Creates context menu, its actions, and wires up all the relevant signals for mouse events. */
+ void createContextMenu();
+
+private slots:
+ /** When Display Units are changed on OptionsModel it will refresh the display text of the control on the status bar */
+ void updateDisplayUnit(int newUnits);
+ /** Tells underlying optionsModel to update its current display unit. */
+ void onMenuSelection(QAction* action);
+};
+
#endif // BITCOINGUI_H
diff --git a/src/qt/bitcoinunits.cpp b/src/qt/bitcoinunits.cpp
index 2fed443cf2..4ba6aba551 100644
--- a/src/qt/bitcoinunits.cpp
+++ b/src/qt/bitcoinunits.cpp
@@ -169,6 +169,16 @@ bool BitcoinUnits::parse(int unit, const QString &value, qint64 *val_out)
return ok;
}
+QString BitcoinUnits::getAmountColumnTitle(int unit)
+{
+ QString amountTitle = QObject::tr("Amount");
+ if (BitcoinUnits::valid(unit))
+ {
+ amountTitle += " ("+BitcoinUnits::name(unit) + ")";
+ }
+ return amountTitle;
+}
+
int BitcoinUnits::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
diff --git a/src/qt/bitcoinunits.h b/src/qt/bitcoinunits.h
index 46517fc07b..451b52ee21 100644
--- a/src/qt/bitcoinunits.h
+++ b/src/qt/bitcoinunits.h
@@ -54,6 +54,8 @@ public:
static QString formatWithUnit(int unit, qint64 amount, bool plussign=false);
//! Parse string to coin amount
static bool parse(int unit, const QString &value, qint64 *val_out);
+ //! Gets title for amount column including current display unit if optionsModel reference available */
+ static QString getAmountColumnTitle(int unit);
///@}
//! @name AbstractListModel implementation
diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp
index c6a6150392..e0a524a55e 100644
--- a/src/qt/coincontroldialog.cpp
+++ b/src/qt/coincontroldialog.cpp
@@ -16,6 +16,8 @@
#include "main.h"
#include "wallet.h"
+#include <boost/assign/list_of.hpp> // for 'map_list_of()'
+
#include <QApplication>
#include <QCheckBox>
#include <QCursor>
@@ -400,23 +402,24 @@ void CoinControlDialog::viewItemChanged(QTreeWidgetItem* item, int column)
}
// return human readable label for priority number
-QString CoinControlDialog::getPriorityLabel(double dPriority)
+QString CoinControlDialog::getPriorityLabel(const CTxMemPool& pool, double dPriority)
{
- if (AllowFree(dPriority)) // at least medium
+ // confirmations -> textual description
+ typedef std::map<unsigned int, QString> PriorityDescription;
+ const static PriorityDescription priorityDescriptions = boost::assign::map_list_of
+ (1, tr("highest"))(2, tr("higher"))(3, tr("high"))
+ (5, tr("medium-high"))(6, tr("medium"))
+ (10, tr("low-medium"))(15, tr("low"))
+ (20, tr("lower"));
+
+ BOOST_FOREACH(const PriorityDescription::value_type& i, priorityDescriptions)
{
- if (AllowFree(dPriority / 1000000)) return tr("highest");
- else if (AllowFree(dPriority / 100000)) return tr("higher");
- else if (AllowFree(dPriority / 10000)) return tr("high");
- else if (AllowFree(dPriority / 1000)) return tr("medium-high");
- else return tr("medium");
- }
- else
- {
- if (AllowFree(dPriority * 10)) return tr("low-medium");
- else if (AllowFree(dPriority * 100)) return tr("low");
- else if (AllowFree(dPriority * 1000)) return tr("lower");
- else return tr("lowest");
+ double p = mempool.estimatePriority(i.first);
+ if (p > 0 && dPriority >= p) return i.second;
}
+ // Note: if mempool hasn't accumulated enough history (estimatePriority
+ // returns -1) we're conservative and classify as "lowest"
+ return tr("lowest");
}
// shows count of locked unspent outputs
@@ -449,7 +452,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
{
CTxOut txout(amount, (CScript)vector<unsigned char>(24, 0));
txDummy.vout.push_back(txout);
- if (txout.IsDust(CTransaction::minRelayTxFee))
+ if (txout.IsDust(::minRelayTxFee))
fDust = true;
}
}
@@ -518,15 +521,20 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
// Priority
dPriority = dPriorityInputs / (nBytes - nBytesInputs + (nQuantityUncompressed * 29)); // 29 = 180 - 151 (uncompressed public keys are over the limit. max 151 bytes of the input are ignored for priority)
- sPriorityLabel = CoinControlDialog::getPriorityLabel(dPriority);
+ sPriorityLabel = CoinControlDialog::getPriorityLabel(mempool, dPriority);
// Fee
int64_t nFee = payTxFee.GetFee(max((unsigned int)1000, nBytes));
// Min Fee
- int64_t nMinFee = GetMinFee(txDummy, nBytes, AllowFree(dPriority), GMF_SEND);
+ nPayFee = CWallet::GetMinimumFee(nBytes, nTxConfirmTarget, mempool);
+
+ double dPriorityNeeded = mempool.estimatePriority(nTxConfirmTarget);
+ if (dPriorityNeeded <= 0) // Not enough mempool history: never send free
+ dPriorityNeeded = std::numeric_limits<double>::max();
- nPayFee = max(nFee, nMinFee);
+ if (nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE && dPriority >= dPriorityNeeded)
+ nPayFee = 0;
if (nPayAmount > 0)
{
@@ -536,7 +544,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
if (nChange > 0 && nChange < CENT)
{
CTxOut txout(nChange, (CScript)vector<unsigned char>(24, 0));
- if (txout.IsDust(CTransaction::minRelayTxFee))
+ if (txout.IsDust(::minRelayTxFee))
{
nPayFee += nChange;
nChange = 0;
@@ -591,23 +599,23 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
}
// turn labels "red"
- l5->setStyleSheet((nBytes >= 1000) ? "color:red;" : ""); // Bytes >= 1000
+ l5->setStyleSheet((nBytes >= MAX_FREE_TRANSACTION_CREATE_SIZE) ? "color:red;" : "");// Bytes >= 1000
l6->setStyleSheet((dPriority > 0 && !AllowFree(dPriority)) ? "color:red;" : ""); // Priority < "medium"
l7->setStyleSheet((fDust) ? "color:red;" : ""); // Dust = "yes"
// tool tips
QString toolTip1 = tr("This label turns red, if the transaction size is greater than 1000 bytes.") + "<br /><br />";
- toolTip1 += tr("This means a fee of at least %1 per kB is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CTransaction::minTxFee.GetFeePerK())) + "<br /><br />";
+ toolTip1 += tr("This means a fee of at least %1 per kB is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CWallet::minTxFee.GetFeePerK())) + "<br /><br />";
toolTip1 += tr("Can vary +/- 1 byte per input.");
QString toolTip2 = tr("Transactions with higher priority are more likely to get included into a block.") + "<br /><br />";
toolTip2 += tr("This label turns red, if the priority is smaller than \"medium\".") + "<br /><br />";
- toolTip2 += tr("This means a fee of at least %1 per kB is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CTransaction::minTxFee.GetFeePerK()));
+ toolTip2 += tr("This means a fee of at least %1 per kB is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CWallet::minTxFee.GetFeePerK()));
- QString toolTip3 = tr("This label turns red, if any recipient receives an amount smaller than %1.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CTransaction::minRelayTxFee.GetFee(546)));
+ QString toolTip3 = tr("This label turns red, if any recipient receives an amount smaller than %1.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, ::minRelayTxFee.GetFee(546)));
// how many satoshis the estimated fee can vary per byte we guess wrong
- double dFeeVary = (double)std::max(CTransaction::minTxFee.GetFeePerK(), payTxFee.GetFeePerK()) / 1000;
+ double dFeeVary = (double)std::max(CWallet::minTxFee.GetFeePerK(), payTxFee.GetFeePerK()) / 1000;
QString toolTip4 = tr("Can vary +/- %1 satoshi(s) per input.").arg(dFeeVary);
l3->setToolTip(toolTip4);
@@ -732,7 +740,7 @@ void CoinControlDialog::updateView()
// priority
double dPriority = ((double)out.tx->vout[out.i].nValue / (nInputSize + 78)) * (out.nDepth+1); // 78 = 2 * 34 + 10
- itemOutput->setText(COLUMN_PRIORITY, CoinControlDialog::getPriorityLabel(dPriority));
+ itemOutput->setText(COLUMN_PRIORITY, CoinControlDialog::getPriorityLabel(mempool, dPriority));
itemOutput->setText(COLUMN_PRIORITY_INT64, strPad(QString::number((int64_t)dPriority), 20, " "));
dPrioritySum += (double)out.tx->vout[out.i].nValue * (out.nDepth+1);
nInputSum += nInputSize;
@@ -765,7 +773,7 @@ void CoinControlDialog::updateView()
itemWalletAddress->setText(COLUMN_CHECKBOX, "(" + QString::number(nChildren) + ")");
itemWalletAddress->setText(COLUMN_AMOUNT, BitcoinUnits::format(nDisplayUnit, nSum));
itemWalletAddress->setText(COLUMN_AMOUNT_INT64, strPad(QString::number(nSum), 15, " "));
- itemWalletAddress->setText(COLUMN_PRIORITY, CoinControlDialog::getPriorityLabel(dPrioritySum));
+ itemWalletAddress->setText(COLUMN_PRIORITY, CoinControlDialog::getPriorityLabel(mempool, dPrioritySum));
itemWalletAddress->setText(COLUMN_PRIORITY_INT64, strPad(QString::number((int64_t)dPrioritySum), 20, " "));
}
}
diff --git a/src/qt/coincontroldialog.h b/src/qt/coincontroldialog.h
index 465e2a009d..4f7422642f 100644
--- a/src/qt/coincontroldialog.h
+++ b/src/qt/coincontroldialog.h
@@ -19,6 +19,7 @@ namespace Ui {
}
class WalletModel;
class CCoinControl;
+class CTxMemPool;
class CoinControlDialog : public QDialog
{
@@ -32,7 +33,7 @@ public:
// static because also called from sendcoinsdialog
static void updateLabels(WalletModel*, QDialog*);
- static QString getPriorityLabel(double);
+ static QString getPriorityLabel(const CTxMemPool& pool, double);
static QList<qint64> payAmounts;
static CCoinControl *coinControl;
diff --git a/src/qt/forms/sendcoinsentry.ui b/src/qt/forms/sendcoinsentry.ui
index e77de0d9b8..9d829970f0 100644
--- a/src/qt/forms/sendcoinsentry.ui
+++ b/src/qt/forms/sendcoinsentry.ui
@@ -51,7 +51,7 @@
<item>
<widget class="QValidatedLineEdit" name="payTo">
<property name="toolTip">
- <string>The address to send the payment to (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)</string>
+ <string>The Bitcoin address to send the payment to</string>
</property>
</widget>
</item>
diff --git a/src/qt/forms/signverifymessagedialog.ui b/src/qt/forms/signverifymessagedialog.ui
index aa271b4f2a..53573ec821 100644
--- a/src/qt/forms/signverifymessagedialog.ui
+++ b/src/qt/forms/signverifymessagedialog.ui
@@ -45,7 +45,7 @@
<item>
<widget class="QValidatedLineEdit" name="addressIn_SM">
<property name="toolTip">
- <string>The address to sign the message with (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)</string>
+ <string>The Bitcoin address to sign the message with</string>
</property>
</widget>
</item>
@@ -255,7 +255,7 @@
<item>
<widget class="QValidatedLineEdit" name="addressIn_VM">
<property name="toolTip">
- <string>The address the message was signed with (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)</string>
+ <string>The Bitcoin address the message was signed with</string>
</property>
</widget>
</item>
diff --git a/src/qt/guiconstants.h b/src/qt/guiconstants.h
index 5ae4bc833d..696761e234 100644
--- a/src/qt/guiconstants.h
+++ b/src/qt/guiconstants.h
@@ -23,6 +23,10 @@ static const int STATUSBAR_ICONSIZE = 16;
#define COLOR_NEGATIVE QColor(255, 0, 0)
/* Transaction list -- bare address (without label) */
#define COLOR_BAREADDRESS QColor(140, 140, 140)
+/* Transaction list -- has conflicting transactions */
+#define COLOR_HASCONFLICTING QColor(255, 255, 255)
+/* Transaction list -- has conflicting transactions - background */
+#define COLOR_HASCONFLICTING_BG QColor(192, 0, 0)
/* Tooltips longer than this (in characters) are converted into rich text,
so that they can be word-wrapped.
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index 4fe98251d9..60a131df7e 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -11,6 +11,7 @@
#include "core.h"
#include "init.h"
+#include "main.h"
#include "protocol.h"
#include "util.h"
@@ -91,7 +92,9 @@ void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
widget->setFont(bitcoinAddressFont());
#if QT_VERSION >= 0x040700
- widget->setPlaceholderText(QObject::tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
+ // We don't want translators to use own addresses in translations
+ // and this is the only place, where this address is supplied.
+ widget->setPlaceholderText(QObject::tr("Enter a Bitcoin address (e.g. %1)").arg("1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L"));
#endif
widget->setValidator(new BitcoinAddressEntryValidator(parent));
widget->setCheckValidator(new BitcoinAddressCheckValidator(parent));
@@ -210,7 +213,7 @@ bool isDust(const QString& address, qint64 amount)
CTxDestination dest = CBitcoinAddress(address.toStdString()).Get();
CScript script; script.SetDestination(dest);
CTxOut txOut(amount, script);
- return txOut.IsDust(CTransaction::minRelayTxFee);
+ return txOut.IsDust(::minRelayTxFee);
}
QString HtmlEscape(const QString& str, bool fMultiLine)
diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp
index 12d54dff64..9502dba904 100644
--- a/src/qt/optionsdialog.cpp
+++ b/src/qt/optionsdialog.cpp
@@ -14,7 +14,10 @@
#include "monitoreddatamapper.h"
#include "optionsmodel.h"
-#include "main.h" // for CTransaction::minTxFee and MAX_SCRIPTCHECK_THREADS
+#include "main.h" // for MAX_SCRIPTCHECK_THREADS
+#ifdef ENABLE_WALLET
+#include "wallet.h" // for CWallet::minTxFee
+#endif
#include "netbase.h"
#include "txdb.h" // for -dbcache defaults
@@ -101,7 +104,9 @@ OptionsDialog::OptionsDialog(QWidget *parent) :
#endif
ui->unit->setModel(new BitcoinUnits(this));
- ui->transactionFee->setSingleStep(CTransaction::minTxFee.GetFeePerK());
+#ifdef ENABLE_WALLET
+ ui->transactionFee->setSingleStep(CWallet::minTxFee.GetFeePerK());
+#endif
/* Widget-to-option mapper */
mapper = new MonitoredDataMapper(this);
diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp
index 6d985abaf8..09553a2587 100644
--- a/src/qt/optionsmodel.cpp
+++ b/src/qt/optionsmodel.cpp
@@ -308,9 +308,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
break;
#endif
case DisplayUnit:
- nDisplayUnit = value.toInt();
- settings.setValue("nDisplayUnit", nDisplayUnit);
- emit displayUnitChanged(nDisplayUnit);
+ setDisplayUnit(value);
break;
case DisplayAddresses:
bDisplayAddresses = value.toBool();
@@ -356,11 +354,24 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
break;
}
}
+
emit dataChanged(index, index);
return successful;
}
+/** Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal */
+void OptionsModel::setDisplayUnit(const QVariant &value)
+{
+ if (!value.isNull())
+ {
+ QSettings settings;
+ nDisplayUnit = value.toInt();
+ settings.setValue("nDisplayUnit", nDisplayUnit);
+ emit displayUnitChanged(nDisplayUnit);
+ }
+}
+
bool OptionsModel::getProxySettings(QNetworkProxy& proxy) const
{
// Directly query current base proxy, because
diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h
index 2596682d07..89c2ec7453 100644
--- a/src/qt/optionsmodel.h
+++ b/src/qt/optionsmodel.h
@@ -52,6 +52,8 @@ public:
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);
+ /** Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal */
+ void setDisplayUnit(const QVariant &value);
/* Explicit getters */
bool getMinimizeToTray() { return fMinimizeToTray; }
diff --git a/src/qt/paymentrequestplus.cpp b/src/qt/paymentrequestplus.cpp
index 464f995eb6..acce42e203 100644
--- a/src/qt/paymentrequestplus.cpp
+++ b/src/qt/paymentrequestplus.cpp
@@ -29,18 +29,18 @@ bool PaymentRequestPlus::parse(const QByteArray& data)
{
bool parseOK = paymentRequest.ParseFromArray(data.data(), data.size());
if (!parseOK) {
- qDebug() << "PaymentRequestPlus::parse : Error parsing payment request";
+ qWarning() << "PaymentRequestPlus::parse : Error parsing payment request";
return false;
}
if (paymentRequest.payment_details_version() > 1) {
- qDebug() << "PaymentRequestPlus::parse : Received up-version payment details, version=" << paymentRequest.payment_details_version();
+ qWarning() << "PaymentRequestPlus::parse : Received up-version payment details, version=" << paymentRequest.payment_details_version();
return false;
}
parseOK = details.ParseFromString(paymentRequest.serialized_payment_details());
if (!parseOK)
{
- qDebug() << "PaymentRequestPlus::parse : Error parsing payment details";
+ qWarning() << "PaymentRequestPlus::parse : Error parsing payment details";
paymentRequest.Clear();
return false;
}
@@ -80,17 +80,17 @@ bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) c
digestAlgorithm = EVP_sha1();
}
else if (paymentRequest.pki_type() == "none") {
- qDebug() << "PaymentRequestPlus::getMerchant : Payment request: pki_type == none";
+ qWarning() << "PaymentRequestPlus::getMerchant : Payment request: pki_type == none";
return false;
}
else {
- qDebug() << "PaymentRequestPlus::getMerchant : Payment request: unknown pki_type " << QString::fromStdString(paymentRequest.pki_type());
+ qWarning() << "PaymentRequestPlus::getMerchant : Payment request: unknown pki_type " << QString::fromStdString(paymentRequest.pki_type());
return false;
}
payments::X509Certificates certChain;
if (!certChain.ParseFromString(paymentRequest.pki_data())) {
- qDebug() << "PaymentRequestPlus::getMerchant : Payment request: error parsing pki_data";
+ qWarning() << "PaymentRequestPlus::getMerchant : Payment request: error parsing pki_data";
return false;
}
@@ -100,12 +100,12 @@ bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) c
QByteArray certData(certChain.certificate(i).data(), certChain.certificate(i).size());
QSslCertificate qCert(certData, QSsl::Der);
if (currentTime < qCert.effectiveDate() || currentTime > qCert.expiryDate()) {
- qDebug() << "PaymentRequestPlus::getMerchant : Payment request: certificate expired or not yet active: " << qCert;
+ qWarning() << "PaymentRequestPlus::getMerchant : Payment request: certificate expired or not yet active: " << qCert;
return false;
}
#if QT_VERSION >= 0x050000
if (qCert.isBlacklisted()) {
- qDebug() << "PaymentRequestPlus::getMerchant : Payment request: certificate blacklisted: " << qCert;
+ qWarning() << "PaymentRequestPlus::getMerchant : Payment request: certificate blacklisted: " << qCert;
return false;
}
#endif
@@ -115,7 +115,7 @@ bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) c
certs.push_back(cert);
}
if (certs.empty()) {
- qDebug() << "PaymentRequestPlus::getMerchant : Payment request: empty certificate chain";
+ qWarning() << "PaymentRequestPlus::getMerchant : Payment request: empty certificate chain";
return false;
}
@@ -131,7 +131,7 @@ bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) c
// load the signing cert into it and verify.
X509_STORE_CTX *store_ctx = X509_STORE_CTX_new();
if (!store_ctx) {
- qDebug() << "PaymentRequestPlus::getMerchant : Payment request: error creating X509_STORE_CTX";
+ qWarning() << "PaymentRequestPlus::getMerchant : Payment request: error creating X509_STORE_CTX";
return false;
}
@@ -183,7 +183,7 @@ bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) c
catch (SSLVerifyError& err)
{
fResult = false;
- qDebug() << "PaymentRequestPlus::getMerchant : SSL error: " << err.what();
+ qWarning() << "PaymentRequestPlus::getMerchant : SSL error: " << err.what();
}
if (website)
diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp
index fbb11617fe..53db2c5cd9 100644
--- a/src/qt/paymentserver.cpp
+++ b/src/qt/paymentserver.cpp
@@ -90,7 +90,7 @@ static QList<QString> savedPaymentRequests;
static void ReportInvalidCertificate(const QSslCertificate& cert)
{
- qDebug() << "ReportInvalidCertificate : Payment server found an invalid certificate: " << cert.subjectInfo(QSslCertificate::CommonName);
+ qWarning() << "ReportInvalidCertificate : Payment server found an invalid certificate: " << cert.subjectInfo(QSslCertificate::CommonName);
}
//
@@ -161,7 +161,7 @@ void PaymentServer::LoadRootCAs(X509_STORE* _store)
continue;
}
}
- qDebug() << "PaymentServer::LoadRootCAs : Loaded " << nRootCerts << " root certificates";
+ qWarning() << "PaymentServer::LoadRootCAs : Loaded " << nRootCerts << " root certificates";
// Project for another day:
// Fetch certificate revocation lists, and add them to certStore.
@@ -195,7 +195,7 @@ bool PaymentServer::ipcParseCommandLine(int argc, char* argv[])
savedPaymentRequests.append(arg);
SendCoinsRecipient r;
- if (GUIUtil::parseBitcoinURI(arg, &r))
+ if (GUIUtil::parseBitcoinURI(arg, &r) && !r.address.isEmpty())
{
CBitcoinAddress address(r.address.toStdString());
@@ -223,7 +223,7 @@ bool PaymentServer::ipcParseCommandLine(int argc, char* argv[])
{
// Printing to debug.log is about the best we can do here, the
// GUI hasn't started yet so we can't pop up a message box.
- qDebug() << "PaymentServer::ipcSendCommandLine : Payment request file does not exist: " << arg;
+ qWarning() << "PaymentServer::ipcSendCommandLine : Payment request file does not exist: " << arg;
}
}
return true;
@@ -403,7 +403,7 @@ void PaymentServer::handleURIOrFile(const QString& s)
}
else
{
- qDebug() << "PaymentServer::handleURIOrFile : Invalid URL: " << fetchUrl;
+ qWarning() << "PaymentServer::handleURIOrFile : Invalid URL: " << fetchUrl;
emit message(tr("URI handling"),
tr("Payment request fetch URL is invalid: %1").arg(fetchUrl.toString()),
CClientUIInterface::ICON_WARNING);
@@ -476,13 +476,13 @@ bool PaymentServer::readPaymentRequest(const QString& filename, PaymentRequestPl
QFile f(filename);
if (!f.open(QIODevice::ReadOnly))
{
- qDebug() << "PaymentServer::readPaymentRequest : Failed to open " << filename;
+ qWarning() << "PaymentServer::readPaymentRequest : Failed to open " << filename;
return false;
}
if (f.size() > MAX_PAYMENT_REQUEST_SIZE)
{
- qDebug() << "PaymentServer::readPaymentRequest : " << filename << " too large";
+ qWarning() << "PaymentServer::readPaymentRequest : " << filename << " too large";
return false;
}
@@ -551,7 +551,7 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoins
// Extract and check amounts
CTxOut txOut(sendingTo.second, sendingTo.first);
- if (txOut.IsDust(CTransaction::minRelayTxFee)) {
+ if (txOut.IsDust(::minRelayTxFee)) {
emit message(tr("Payment request error"), tr("Requested payment amount of %1 is too small (considered dust).")
.arg(BitcoinUnits::formatWithUnit(optionsModel->getDisplayUnit(), sendingTo.second)),
CClientUIInterface::MSG_ERROR);
@@ -624,7 +624,7 @@ void PaymentServer::fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipien
else {
// This should never happen, because sending coins should have
// just unlocked the wallet and refilled the keypool.
- qDebug() << "PaymentServer::fetchPaymentACK : Error getting refund key, refund_to not set";
+ qWarning() << "PaymentServer::fetchPaymentACK : Error getting refund key, refund_to not set";
}
}
@@ -636,7 +636,7 @@ void PaymentServer::fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipien
}
else {
// This should never happen, either.
- qDebug() << "PaymentServer::fetchPaymentACK : Error serializing payment message";
+ qWarning() << "PaymentServer::fetchPaymentACK : Error serializing payment message";
}
}
@@ -649,7 +649,7 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
.arg(reply->request().url().toString())
.arg(reply->errorString());
- qDebug() << "PaymentServer::netRequestFinished : " << msg;
+ qWarning() << "PaymentServer::netRequestFinished : " << msg;
emit message(tr("Payment request error"), msg, CClientUIInterface::MSG_ERROR);
return;
}
@@ -663,7 +663,7 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
SendCoinsRecipient recipient;
if (!request.parse(data))
{
- qDebug() << "PaymentServer::netRequestFinished : Error parsing payment request";
+ qWarning() << "PaymentServer::netRequestFinished : Error parsing payment request";
emit message(tr("Payment request error"),
tr("Payment request can not be parsed!"),
CClientUIInterface::MSG_ERROR);
@@ -681,7 +681,7 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
QString msg = tr("Bad response from server %1")
.arg(reply->request().url().toString());
- qDebug() << "PaymentServer::netRequestFinished : " << msg;
+ qWarning() << "PaymentServer::netRequestFinished : " << msg;
emit message(tr("Payment request error"), msg, CClientUIInterface::MSG_ERROR);
}
else
@@ -697,7 +697,7 @@ void PaymentServer::reportSslErrors(QNetworkReply* reply, const QList<QSslError>
QString errString;
foreach (const QSslError& err, errs) {
- qDebug() << "PaymentServer::reportSslErrors : " << err;
+ qWarning() << "PaymentServer::reportSslErrors : " << err;
errString += err.errorString() + "\n";
}
emit message(tr("Network request error"), errString, CClientUIInterface::MSG_ERROR);
diff --git a/src/qt/recentrequeststablemodel.cpp b/src/qt/recentrequeststablemodel.cpp
index 844d62518c..b5a998f9f5 100644
--- a/src/qt/recentrequeststablemodel.cpp
+++ b/src/qt/recentrequeststablemodel.cpp
@@ -21,7 +21,9 @@ RecentRequestsTableModel::RecentRequestsTableModel(CWallet *wallet, WalletModel
addNewRequest(request);
/* These columns must match the indices in the ColumnIndex enumeration */
- columns << tr("Date") << tr("Label") << tr("Message") << tr("Amount");
+ columns << tr("Date") << tr("Label") << tr("Message") << getAmountTitle();
+
+ connect(walletModel->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
}
RecentRequestsTableModel::~RecentRequestsTableModel()
@@ -101,6 +103,24 @@ QVariant RecentRequestsTableModel::headerData(int section, Qt::Orientation orien
return QVariant();
}
+/** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
+void RecentRequestsTableModel::updateAmountColumnTitle()
+{
+ columns[Amount] = getAmountTitle();
+ emit headerDataChanged(Qt::Horizontal,Amount,Amount);
+}
+
+/** Gets title for amount column including current display unit if optionsModel reference available. */
+QString RecentRequestsTableModel::getAmountTitle()
+{
+ QString amountTitle = tr("Amount");
+ if (this->walletModel->getOptionsModel() != NULL)
+ {
+ amountTitle += " ("+BitcoinUnits::name(this->walletModel->getOptionsModel()->getDisplayUnit()) + ")";
+ }
+ return amountTitle;
+}
+
QModelIndex RecentRequestsTableModel::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent);
@@ -185,6 +205,11 @@ void RecentRequestsTableModel::sort(int column, Qt::SortOrder order)
emit dataChanged(index(0, 0, QModelIndex()), index(list.size() - 1, NUMBER_OF_COLUMNS - 1, QModelIndex()));
}
+void RecentRequestsTableModel::updateDisplayUnit()
+{
+ updateAmountColumnTitle();
+}
+
bool RecentRequestEntryLessThan::operator()(RecentRequestEntry &left, RecentRequestEntry &right) const
{
RecentRequestEntry *pLeft = &left;
diff --git a/src/qt/recentrequeststablemodel.h b/src/qt/recentrequeststablemodel.h
index d4cc5078aa..4f0b241259 100644
--- a/src/qt/recentrequeststablemodel.h
+++ b/src/qt/recentrequeststablemodel.h
@@ -91,12 +91,18 @@ public:
public slots:
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
+ void updateDisplayUnit();
private:
WalletModel *walletModel;
QStringList columns;
QList<RecentRequestEntry> list;
int64_t nReceiveRequestsMaxId;
+
+ /** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
+ void updateAmountColumnTitle();
+ /** Gets title for amount column including current display unit if optionsModel reference available. */
+ QString getAmountTitle();
};
#endif
diff --git a/src/qt/res/bitcoin-qt-res.rc b/src/qt/res/bitcoin-qt-res.rc
index ee23ae9b78..809235be5f 100644
--- a/src/qt/res/bitcoin-qt-res.rc
+++ b/src/qt/res/bitcoin-qt-res.rc
@@ -8,7 +8,6 @@ IDI_ICON2 ICON DISCARDABLE "icons/bitcoin_testnet.ico"
#define VER_PRODUCTVERSION_STR STRINGIZE(CLIENT_VERSION_MAJOR) "." STRINGIZE(CLIENT_VERSION_MINOR) "." STRINGIZE(CLIENT_VERSION_REVISION) "." STRINGIZE(CLIENT_VERSION_BUILD)
#define VER_FILEVERSION VER_PRODUCTVERSION
#define VER_FILEVERSION_STR VER_PRODUCTVERSION_STR
-#define COPYRIGHT_STR "2009-" STRINGIZE(COPYRIGHT_YEAR) " The Bitcoin developers"
VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILEVERSION
diff --git a/src/qt/signverifymessagedialog.cpp b/src/qt/signverifymessagedialog.cpp
index 3e56412c7c..d4d021e21c 100644
--- a/src/qt/signverifymessagedialog.cpp
+++ b/src/qt/signverifymessagedialog.cpp
@@ -27,7 +27,6 @@ SignVerifyMessageDialog::SignVerifyMessageDialog(QWidget *parent) :
#if QT_VERSION >= 0x040700
ui->signatureOut_SM->setPlaceholderText(tr("Click \"Sign Message\" to generate signature"));
- ui->addressIn_VM->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
#endif
GUIUtil::setupAddressWidget(ui->addressIn_SM, this);
diff --git a/src/qt/transactionfilterproxy.cpp b/src/qt/transactionfilterproxy.cpp
index f9546fddb5..7293029787 100644
--- a/src/qt/transactionfilterproxy.cpp
+++ b/src/qt/transactionfilterproxy.cpp
@@ -24,7 +24,7 @@ TransactionFilterProxy::TransactionFilterProxy(QObject *parent) :
typeFilter(ALL_TYPES),
minAmount(0),
limitRows(-1),
- showInactive(true)
+ showInactive(false)
{
}
@@ -39,7 +39,7 @@ bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &
qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
int status = index.data(TransactionTableModel::StatusRole).toInt();
- if(!showInactive && status == TransactionStatus::Conflicted)
+ if(!showInactive && status == TransactionStatus::Conflicted && type == TransactionRecord::Other)
return false;
if(!(TYPE(type) & typeFilter))
return false;
diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp
index eec2b57e8c..21f1b7356f 100644
--- a/src/qt/transactionrecord.cpp
+++ b/src/qt/transactionrecord.cpp
@@ -170,6 +170,8 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
status.depth = wtx.GetDepthInMainChain();
status.cur_num_blocks = chainActive.Height();
+ status.hasConflicting = false;
+
if (!IsFinalTx(wtx, chainActive.Height() + 1))
{
if (wtx.nLockTime < LOCKTIME_THRESHOLD)
@@ -213,6 +215,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
if (status.depth < 0)
{
status.status = TransactionStatus::Conflicted;
+ status.hasConflicting = !(wtx.GetConflicts(false).empty());
}
else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
{
@@ -221,6 +224,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
else if (status.depth == 0)
{
status.status = TransactionStatus::Unconfirmed;
+ status.hasConflicting = !(wtx.GetConflicts(false).empty());
}
else if (status.depth < RecommendedNumConfirmations)
{
@@ -231,13 +235,13 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
status.status = TransactionStatus::Confirmed;
}
}
-
}
-bool TransactionRecord::statusUpdateNeeded()
+bool TransactionRecord::statusUpdateNeeded(int64_t nConflictsReceived)
{
AssertLockHeld(cs_main);
- return status.cur_num_blocks != chainActive.Height();
+ return (status.cur_num_blocks != chainActive.Height() ||
+ status.cur_num_conflicts != nConflictsReceived);
}
QString TransactionRecord::getTxID() const
diff --git a/src/qt/transactionrecord.h b/src/qt/transactionrecord.h
index af6fd403b3..37679cebfa 100644
--- a/src/qt/transactionrecord.h
+++ b/src/qt/transactionrecord.h
@@ -19,9 +19,17 @@ class TransactionStatus
{
public:
TransactionStatus():
- countsForBalance(false), sortKey(""),
- matures_in(0), status(Offline), depth(0), open_for(0), cur_num_blocks(-1)
- { }
+ countsForBalance(false),
+ sortKey(""),
+ matures_in(0),
+ status(Offline),
+ hasConflicting(false),
+ depth(0),
+ open_for(0),
+ cur_num_blocks(-1),
+ cur_num_conflicts(-1)
+ {
+ }
enum Status {
Confirmed, /**< Have 6 or more confirmations (normal tx) or fully mature (mined tx) **/
@@ -51,6 +59,10 @@ public:
/** @name Reported status
@{*/
Status status;
+
+ // Has conflicting transactions spending same prevout
+ bool hasConflicting;
+
qint64 depth;
qint64 open_for; /**< Timestamp if status==OpenUntilDate, otherwise number
of additional blocks that need to be mined before
@@ -59,6 +71,10 @@ public:
/** Current number of blocks (to know whether cached status is still valid) */
int cur_num_blocks;
+
+ /** Number of conflicts received into wallet as of last status update */
+ int64_t cur_num_conflicts;
+
};
/** UI model for a transaction. A core transaction can be represented by multiple UI transactions if it has
@@ -133,7 +149,7 @@ public:
/** Return whether a status update is needed.
*/
- bool statusUpdateNeeded();
+ bool statusUpdateNeeded(int64_t nConflictsReceived);
};
#endif // TRANSACTIONRECORD_H
diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp
index b9fcd0d6b0..6c1a6c3579 100644
--- a/src/qt/transactiontablemodel.cpp
+++ b/src/qt/transactiontablemodel.cpp
@@ -130,12 +130,12 @@ public:
case CT_NEW:
if(inModel)
{
- qDebug() << "TransactionTablePriv::updateWallet : Warning: Got CT_NEW, but transaction is already in model";
+ qWarning() << "TransactionTablePriv::updateWallet : Warning: Got CT_NEW, but transaction is already in model";
break;
}
if(!inWallet)
{
- qDebug() << "TransactionTablePriv::updateWallet : Warning: Got CT_NEW, but transaction is not in wallet";
+ qWarning() << "TransactionTablePriv::updateWallet : Warning: Got CT_NEW, but transaction is not in wallet";
break;
}
if(showTransaction)
@@ -159,7 +159,7 @@ public:
case CT_DELETED:
if(!inModel)
{
- qDebug() << "TransactionTablePriv::updateWallet : Warning: Got CT_DELETED, but transaction is not in model";
+ qWarning() << "TransactionTablePriv::updateWallet : Warning: Got CT_DELETED, but transaction is not in model";
break;
}
// Removed -- remove entire transaction from table
@@ -168,8 +168,7 @@ public:
parent->endRemoveRows();
break;
case CT_UPDATED:
- // Miscellaneous updates -- nothing to do, status update will take care of this, and is only computed for
- // visible transactions.
+ emit parent->dataChanged(parent->index(lowerIndex, parent->Status), parent->index(upperIndex-1, parent->Amount));
break;
}
}
@@ -190,20 +189,21 @@ public:
// stuck if the core is holding the locks for a longer time - for
// example, during a wallet rescan.
//
- // If a status update is needed (blocks came in since last check),
- // update the status of this transaction from the wallet. Otherwise,
+ // If a status update is needed (blocks or conflicts came in since last check),
+ // update the status of this transaction from the wallet. Otherwise,
// simply re-use the cached status.
TRY_LOCK(cs_main, lockMain);
if(lockMain)
{
TRY_LOCK(wallet->cs_wallet, lockWallet);
- if(lockWallet && rec->statusUpdateNeeded())
+ if(lockWallet && rec->statusUpdateNeeded(wallet->nConflictsReceived))
{
std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash);
if(mi != wallet->mapWallet.end())
{
rec->updateStatus(mi->second);
+ rec->status.cur_num_conflicts = wallet->nConflictsReceived;
}
}
}
@@ -235,8 +235,7 @@ TransactionTableModel::TransactionTableModel(CWallet* wallet, WalletModel *paren
walletModel(parent),
priv(new TransactionTablePriv(wallet, this))
{
- columns << QString() << tr("Date") << tr("Type") << tr("Address") << tr("Amount");
-
+ columns << QString() << tr("Date") << tr("Type") << tr("Address") << BitcoinUnits::getAmountColumnTitle(walletModel->getOptionsModel()->getDisplayUnit());
priv->refreshWallet();
connect(walletModel->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
@@ -247,6 +246,13 @@ TransactionTableModel::~TransactionTableModel()
delete priv;
}
+/** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
+void TransactionTableModel::updateAmountColumnTitle()
+{
+ columns[Amount] = BitcoinUnits::getAmountColumnTitle(walletModel->getOptionsModel()->getDisplayUnit());
+ emit headerDataChanged(Qt::Horizontal,Amount,Amount);
+}
+
void TransactionTableModel::updateTransaction(const QString &hash, int status)
{
uint256 updated;
@@ -363,6 +369,8 @@ QString TransactionTableModel::formatTxType(const TransactionRecord *wtx) const
return tr("Payment to yourself");
case TransactionRecord::Generated:
return tr("Mined");
+ case TransactionRecord::Other:
+ return tr("Other");
default:
return QString();
}
@@ -535,7 +543,13 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
return formatTooltip(rec);
case Qt::TextAlignmentRole:
return column_alignments[index.column()];
+ case Qt::BackgroundColorRole:
+ if (rec->status.hasConflicting)
+ return COLOR_HASCONFLICTING_BG;
+ break;
case Qt::ForegroundRole:
+ if (rec->status.hasConflicting)
+ return COLOR_HASCONFLICTING;
// Non-confirmed (but not immature) as transactions are grey
if(!rec->status.countsForBalance && rec->status.status != TransactionStatus::Immature)
{
@@ -624,5 +638,6 @@ QModelIndex TransactionTableModel::index(int row, int column, const QModelIndex
void TransactionTableModel::updateDisplayUnit()
{
// emit dataChanged to update Amount column with the current unit
+ updateAmountColumnTitle();
emit dataChanged(index(0, Amount), index(priv->size()-1, Amount));
}
diff --git a/src/qt/transactiontablemodel.h b/src/qt/transactiontablemodel.h
index 333e6bc6ed..e8b6ed065d 100644
--- a/src/qt/transactiontablemodel.h
+++ b/src/qt/transactiontablemodel.h
@@ -87,6 +87,8 @@ public slots:
void updateTransaction(const QString &hash, int status);
void updateConfirmations();
void updateDisplayUnit();
+ /** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
+ void updateAmountColumnTitle();
friend class TransactionTablePriv;
};
diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp
index d4d29416ca..d6d210a561 100644
--- a/src/qt/transactionview.cpp
+++ b/src/qt/transactionview.cpp
@@ -309,7 +309,7 @@ void TransactionView::exportClicked()
writer.addColumn(tr("Type"), TransactionTableModel::Type, Qt::EditRole);
writer.addColumn(tr("Label"), 0, TransactionTableModel::LabelRole);
writer.addColumn(tr("Address"), 0, TransactionTableModel::AddressRole);
- writer.addColumn(tr("Amount"), 0, TransactionTableModel::FormattedAmountRole);
+ writer.addColumn(BitcoinUnits::getAmountColumnTitle(model->getOptionsModel()->getDisplayUnit()), 0, TransactionTableModel::FormattedAmountRole);
writer.addColumn(tr("ID"), 0, TransactionTableModel::TxIDRole);
if(!writer.write()) {
diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp
index eb647d0170..5fb0da145d 100644
--- a/src/qt/utilitydialog.cpp
+++ b/src/qt/utilitydialog.cpp
@@ -117,6 +117,7 @@ void ShutdownWindow::showShutdownWindow(BitcoinGUI *window)
tr("Bitcoin Core is shutting down...") + "<br /><br />" +
tr("Do not shut down the computer until this window disappears.")));
shutdownWindow->setLayout(layout);
+ shutdownWindow->setWindowTitle(window->windowTitle());
// Center shutdown window at where main window was
const QPoint global = window->mapToGlobal(window->rect().center());
diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp
index 2f633a26c8..defc815def 100644
--- a/src/qt/walletmodel.cpp
+++ b/src/qt/walletmodel.cpp
@@ -138,6 +138,14 @@ void WalletModel::checkBalanceChanged()
void WalletModel::updateTransaction(const QString &hash, int status)
{
+ if (status == CT_GOT_CONFLICT)
+ {
+ emit message(tr("Conflict Received"),
+ tr("WARNING: Transaction may never be confirmed. Its input was seen being spent by another transaction on the network. Wait for confirmation!"),
+ CClientUIInterface::MSG_WARNING);
+ return;
+ }
+
if(transactionTableModel)
transactionTableModel->updateTransaction(hash, status);
diff --git a/src/qt/winshutdownmonitor.cpp b/src/qt/winshutdownmonitor.cpp
index b7526f0ae4..f8f9bf45b3 100644
--- a/src/qt/winshutdownmonitor.cpp
+++ b/src/qt/winshutdownmonitor.cpp
@@ -45,13 +45,13 @@ void WinShutdownMonitor::registerShutdownBlockReason(const QString& strReason, c
typedef BOOL (WINAPI *PSHUTDOWNBRCREATE)(HWND, LPCWSTR);
PSHUTDOWNBRCREATE shutdownBRCreate = (PSHUTDOWNBRCREATE)GetProcAddress(GetModuleHandleA("User32.dll"), "ShutdownBlockReasonCreate");
if (shutdownBRCreate == NULL) {
- qDebug() << "registerShutdownBlockReason : GetProcAddress for ShutdownBlockReasonCreate failed";
+ qWarning() << "registerShutdownBlockReason : GetProcAddress for ShutdownBlockReasonCreate failed";
return;
}
if (shutdownBRCreate(mainWinId, strReason.toStdWString().c_str()))
- qDebug() << "registerShutdownBlockReason : Successfully registered: " + strReason;
+ qWarning() << "registerShutdownBlockReason : Successfully registered: " + strReason;
else
- qDebug() << "registerShutdownBlockReason : Failed to register: " + strReason;
+ qWarning() << "registerShutdownBlockReason : Failed to register: " + strReason;
}
#endif
diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp
index 580c6bd5ba..a67f266a13 100644
--- a/src/rpcblockchain.cpp
+++ b/src/rpcblockchain.cpp
@@ -66,7 +66,7 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex)
result.push_back(Pair("tx", txs));
result.push_back(Pair("time", block.GetBlockTime()));
result.push_back(Pair("nonce", (uint64_t)block.nNonce));
- result.push_back(Pair("bits", HexBits(block.nBits)));
+ result.push_back(Pair("bits", strprintf("%08x", block.nBits)));
result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp
index 30881b9b1a..501940a730 100644
--- a/src/rpcclient.cpp
+++ b/src/rpcclient.cpp
@@ -3,6 +3,7 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include <set>
#include "rpcclient.h"
#include "rpcprotocol.h"
@@ -15,94 +16,118 @@
using namespace std;
using namespace json_spirit;
-template<typename T>
-void ConvertTo(Value& value, bool fAllowNull=false)
+class CRPCConvertParam
{
- if (fAllowNull && value.type() == null_type)
- return;
- if (value.type() == str_type)
- {
- // reinterpret string as unquoted json value
- Value value2;
- string strJSON = value.get_str();
- if (!read_string(strJSON, value2))
- throw runtime_error(string("Error parsing JSON:")+strJSON);
- ConvertTo<T>(value2, fAllowNull);
- value = value2;
+public:
+ std::string methodName; // method whose params want conversion
+ int paramIdx; // 0-based idx of param to convert
+};
+
+static const CRPCConvertParam vRPCConvertParams[] =
+{
+ { "stop", 0 },
+ { "getaddednodeinfo", 0 },
+ { "setgenerate", 0 },
+ { "setgenerate", 1 },
+ { "getnetworkhashps", 0 },
+ { "getnetworkhashps", 1 },
+ { "sendtoaddress", 1 },
+ { "settxfee", 0 },
+ { "getreceivedbyaddress", 1 },
+ { "getreceivedbyaccount", 1 },
+ { "listreceivedbyaddress", 0 },
+ { "listreceivedbyaddress", 1 },
+ { "listreceivedbyaccount", 0 },
+ { "listreceivedbyaccount", 1 },
+ { "getbalance", 1 },
+ { "getblockhash", 0 },
+ { "move", 2 },
+ { "move", 3 },
+ { "sendfrom", 2 },
+ { "sendfrom", 3 },
+ { "listtransactions", 1 },
+ { "listtransactions", 2 },
+ { "listaccounts", 0 },
+ { "walletpassphrase", 1 },
+ { "getblocktemplate", 0 },
+ { "listsinceblock", 1 },
+ { "sendmany", 1 },
+ { "sendmany", 2 },
+ { "addmultisigaddress", 0 },
+ { "addmultisigaddress", 1 },
+ { "createmultisig", 0 },
+ { "createmultisig", 1 },
+ { "listunspent", 0 },
+ { "listunspent", 1 },
+ { "listunspent", 2 },
+ { "getblock", 1 },
+ { "getrawtransaction", 1 },
+ { "createrawtransaction", 0 },
+ { "createrawtransaction", 1 },
+ { "signrawtransaction", 1 },
+ { "signrawtransaction", 2 },
+ { "sendrawtransaction", 1 },
+ { "gettxout", 1 },
+ { "gettxout", 2 },
+ { "lockunspent", 0 },
+ { "lockunspent", 1 },
+ { "importprivkey", 2 },
+ { "verifychain", 0 },
+ { "verifychain", 1 },
+ { "keypoolrefill", 0 },
+ { "getrawmempool", 0 },
+ { "estimatefee", 0 },
+ { "estimatepriority", 0 },
+};
+
+class CRPCConvertTable
+{
+private:
+ std::set<std::pair<std::string, int> > members;
+
+public:
+ CRPCConvertTable();
+
+ bool convert(const std::string& method, int idx) {
+ return (members.count(std::make_pair(method, idx)) > 0);
}
- else
- {
- value = value.get_value<T>();
+};
+
+CRPCConvertTable::CRPCConvertTable()
+{
+ const unsigned int n_elem =
+ (sizeof(vRPCConvertParams) / sizeof(vRPCConvertParams[0]));
+
+ for (unsigned int i = 0; i < n_elem; i++) {
+ members.insert(std::make_pair(vRPCConvertParams[i].methodName,
+ vRPCConvertParams[i].paramIdx));
}
}
+static CRPCConvertTable rpcCvtTable;
+
// Convert strings to command-specific RPC representation
Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)
{
Array params;
- BOOST_FOREACH(const std::string &param, strParams)
- params.push_back(param);
-
- int n = params.size();
-
- //
- // Special case non-string parameter types
- //
- if (strMethod == "stop" && n > 0) ConvertTo<bool>(params[0]);
- if (strMethod == "getaddednodeinfo" && n > 0) ConvertTo<bool>(params[0]);
- if (strMethod == "setgenerate" && n > 0) ConvertTo<bool>(params[0]);
- if (strMethod == "setgenerate" && n > 1) ConvertTo<int64_t>(params[1]);
- if (strMethod == "getnetworkhashps" && n > 0) ConvertTo<int64_t>(params[0]);
- if (strMethod == "getnetworkhashps" && n > 1) ConvertTo<int64_t>(params[1]);
- if (strMethod == "sendtoaddress" && n > 1) ConvertTo<double>(params[1]);
- if (strMethod == "settxfee" && n > 0) ConvertTo<double>(params[0]);
- if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo<int64_t>(params[1]);
- if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo<int64_t>(params[1]);
- if (strMethod == "listreceivedbyaddress" && n > 0) ConvertTo<int64_t>(params[0]);
- if (strMethod == "listreceivedbyaddress" && n > 1) ConvertTo<bool>(params[1]);
- if (strMethod == "listreceivedbyaccount" && n > 0) ConvertTo<int64_t>(params[0]);
- if (strMethod == "listreceivedbyaccount" && n > 1) ConvertTo<bool>(params[1]);
- if (strMethod == "getbalance" && n > 1) ConvertTo<int64_t>(params[1]);
- if (strMethod == "getblockhash" && n > 0) ConvertTo<int64_t>(params[0]);
- if (strMethod == "move" && n > 2) ConvertTo<double>(params[2]);
- if (strMethod == "move" && n > 3) ConvertTo<int64_t>(params[3]);
- if (strMethod == "sendfrom" && n > 2) ConvertTo<double>(params[2]);
- if (strMethod == "sendfrom" && n > 3) ConvertTo<int64_t>(params[3]);
- if (strMethod == "listtransactions" && n > 1) ConvertTo<int64_t>(params[1]);
- if (strMethod == "listtransactions" && n > 2) ConvertTo<int64_t>(params[2]);
- if (strMethod == "listaccounts" && n > 0) ConvertTo<int64_t>(params[0]);
- if (strMethod == "walletpassphrase" && n > 1) ConvertTo<int64_t>(params[1]);
- if (strMethod == "prioritisetransaction" && n > 1) ConvertTo<double>(params[1]);
- if (strMethod == "prioritisetransaction" && n > 2) ConvertTo<int64_t>(params[2]);
- if (strMethod == "getblocktemplate" && n > 0) ConvertTo<Object>(params[0]);
- if (strMethod == "listsinceblock" && n > 1) ConvertTo<int64_t>(params[1]);
- if (strMethod == "sendmany" && n > 1) ConvertTo<Object>(params[1]);
- if (strMethod == "sendmany" && n > 2) ConvertTo<int64_t>(params[2]);
- if (strMethod == "addmultisigaddress" && n > 0) ConvertTo<int64_t>(params[0]);
- if (strMethod == "addmultisigaddress" && n > 1) ConvertTo<Array>(params[1]);
- if (strMethod == "createmultisig" && n > 0) ConvertTo<int64_t>(params[0]);
- if (strMethod == "createmultisig" && n > 1) ConvertTo<Array>(params[1]);
- if (strMethod == "listunspent" && n > 0) ConvertTo<int64_t>(params[0]);
- if (strMethod == "listunspent" && n > 1) ConvertTo<int64_t>(params[1]);
- if (strMethod == "listunspent" && n > 2) ConvertTo<Array>(params[2]);
- if (strMethod == "getblock" && n > 1) ConvertTo<bool>(params[1]);
- if (strMethod == "getrawtransaction" && n > 1) ConvertTo<int64_t>(params[1]);
- if (strMethod == "createrawtransaction" && n > 0) ConvertTo<Array>(params[0]);
- if (strMethod == "createrawtransaction" && n > 1) ConvertTo<Object>(params[1]);
- if (strMethod == "signrawtransaction" && n > 1) ConvertTo<Array>(params[1], true);
- if (strMethod == "signrawtransaction" && n > 2) ConvertTo<Array>(params[2], true);
- if (strMethod == "sendrawtransaction" && n > 1) ConvertTo<bool>(params[1], true);
- if (strMethod == "gettxout" && n > 1) ConvertTo<int64_t>(params[1]);
- if (strMethod == "gettxout" && n > 2) ConvertTo<bool>(params[2]);
- if (strMethod == "lockunspent" && n > 0) ConvertTo<bool>(params[0]);
- if (strMethod == "lockunspent" && n > 1) ConvertTo<Array>(params[1]);
- if (strMethod == "importprivkey" && n > 2) ConvertTo<bool>(params[2]);
- if (strMethod == "verifychain" && n > 0) ConvertTo<int64_t>(params[0]);
- if (strMethod == "verifychain" && n > 1) ConvertTo<int64_t>(params[1]);
- if (strMethod == "keypoolrefill" && n > 0) ConvertTo<int64_t>(params[0]);
- if (strMethod == "getrawmempool" && n > 0) ConvertTo<bool>(params[0]);
- if (strMethod == "estimatefee" && n > 0) ConvertTo<boost::int64_t>(params[0]);
- if (strMethod == "estimatepriority" && n > 0) ConvertTo<boost::int64_t>(params[0]);
+
+ for (unsigned int idx = 0; idx < strParams.size(); idx++) {
+ const std::string& strVal = strParams[idx];
+
+ // insert string value directly
+ if (!rpcCvtTable.convert(strMethod, idx)) {
+ params.push_back(strVal);
+ }
+
+ // parse string as JSON, insert bool/number/object/etc. value
+ else {
+ Value jVal;
+ if (!read_string(strVal, jVal))
+ throw runtime_error(string("Error parsing JSON:")+strVal);
+ params.push_back(jVal);
+ }
+
+ }
return params;
}
diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp
index 98caf704ee..db60ef3592 100644
--- a/src/rpcmining.cpp
+++ b/src/rpcmining.cpp
@@ -443,7 +443,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
result.push_back(Pair("sigoplimit", (int64_t)MAX_BLOCK_SIGOPS));
result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SIZE));
result.push_back(Pair("curtime", (int64_t)pblock->nTime));
- result.push_back(Pair("bits", HexBits(pblock->nBits)));
+ result.push_back(Pair("bits", strprintf("%08x", pblock->nBits)));
result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));
return result;
diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp
index a300de2680..9ed6b52513 100644
--- a/src/rpcmisc.cpp
+++ b/src/rpcmisc.cpp
@@ -22,10 +22,10 @@
#include "json/json_spirit_utils.h"
#include "json/json_spirit_value.h"
-using namespace std;
using namespace boost;
using namespace boost::assign;
using namespace json_spirit;
+using namespace std;
Value getinfo(const Array& params, bool fHelp)
{
@@ -84,7 +84,7 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("unlocked_until", nWalletUnlockTime));
obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
#endif
- obj.push_back(Pair("relayfee", ValueFromAmount(CTransaction::minRelayTxFee.GetFeePerK())));
+ obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
return obj;
}
diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp
index a54872ccc4..cd3bd59f8f 100644
--- a/src/rpcnet.cpp
+++ b/src/rpcnet.cpp
@@ -134,6 +134,7 @@ Value getpeerinfo(const Array& params, bool fHelp)
obj.push_back(Pair("startingheight", stats.nStartingHeight));
if (fStateStats) {
obj.push_back(Pair("banscore", statestats.nMisbehavior));
+ obj.push_back(Pair("syncheight", statestats.nSyncHeight));
}
obj.push_back(Pair("syncnode", stats.fSyncNode));
@@ -371,7 +372,7 @@ Value getnetworkinfo(const Array& params, bool fHelp)
obj.push_back(Pair("timeoffset", GetTimeOffset()));
obj.push_back(Pair("connections", (int)vNodes.size()));
obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string())));
- obj.push_back(Pair("relayfee", ValueFromAmount(CTransaction::minRelayTxFee.GetFeePerK())));
+ obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));
Array localAddresses;
{
LOCK(cs_mapLocalHost);
diff --git a/src/rpcprotocol.cpp b/src/rpcprotocol.cpp
index 2718f81783..dd8692e802 100644
--- a/src/rpcprotocol.cpp
+++ b/src/rpcprotocol.cpp
@@ -54,7 +54,19 @@ static string rfc1123Time()
return DateTimeStrFormat("%a, %d %b %Y %H:%M:%S +0000", GetTime());
}
-string HTTPReply(int nStatus, const string& strMsg, bool keepalive)
+static const char *httpStatusDescription(int nStatus)
+{
+ switch (nStatus) {
+ case HTTP_OK: return "OK";
+ case HTTP_BAD_REQUEST: return "Bad Request";
+ case HTTP_FORBIDDEN: return "Forbidden";
+ case HTTP_NOT_FOUND: return "Not Found";
+ case HTTP_INTERNAL_SERVER_ERROR: return "Internal Server Error";
+ default: return "";
+ }
+}
+
+string HTTPError(int nStatus, bool keepalive, bool headersOnly)
{
if (nStatus == HTTP_UNAUTHORIZED)
return strprintf("HTTP/1.0 401 Authorization Required\r\n"
@@ -73,29 +85,32 @@ string HTTPReply(int nStatus, const string& strMsg, bool keepalive)
"</HEAD>\r\n"
"<BODY><H1>401 Unauthorized.</H1></BODY>\r\n"
"</HTML>\r\n", rfc1123Time(), FormatFullVersion());
- const char *cStatus;
- if (nStatus == HTTP_OK) cStatus = "OK";
- else if (nStatus == HTTP_BAD_REQUEST) cStatus = "Bad Request";
- else if (nStatus == HTTP_FORBIDDEN) cStatus = "Forbidden";
- else if (nStatus == HTTP_NOT_FOUND) cStatus = "Not Found";
- else if (nStatus == HTTP_INTERNAL_SERVER_ERROR) cStatus = "Internal Server Error";
- else cStatus = "";
+
+ return HTTPReply(nStatus, httpStatusDescription(nStatus), keepalive,
+ headersOnly, "text/plain");
+}
+
+string HTTPReply(int nStatus, const string& strMsg, bool keepalive,
+ bool headersOnly, const char *contentType)
+{
return strprintf(
"HTTP/1.1 %d %s\r\n"
"Date: %s\r\n"
"Connection: %s\r\n"
"Content-Length: %u\r\n"
- "Content-Type: application/json\r\n"
+ "Content-Type: %s\r\n"
"Server: bitcoin-json-rpc/%s\r\n"
"\r\n"
"%s",
nStatus,
- cStatus,
+ httpStatusDescription(nStatus),
rfc1123Time(),
keepalive ? "keep-alive" : "close",
- strMsg.size(),
+ (headersOnly ? 0 : strMsg.size()),
+ contentType,
FormatFullVersion(),
- strMsg);
+ (headersOnly ? "" : strMsg.c_str())
+ );
}
bool ReadHTTPRequestLine(std::basic_istream<char>& stream, int &proto,
diff --git a/src/rpcprotocol.h b/src/rpcprotocol.h
index 11bdd171d9..5627077bfb 100644
--- a/src/rpcprotocol.h
+++ b/src/rpcprotocol.h
@@ -141,7 +141,11 @@ private:
};
std::string HTTPPost(const std::string& strMsg, const std::map<std::string,std::string>& mapRequestHeaders);
-std::string HTTPReply(int nStatus, const std::string& strMsg, bool keepalive);
+std::string HTTPError(int nStatus, bool keepalive,
+ bool headerOnly = false);
+std::string HTTPReply(int nStatus, const std::string& strMsg, bool keepalive,
+ bool headerOnly = false,
+ const char *contentType = "application/json");
bool ReadHTTPRequestLine(std::basic_istream<char>& stream, int &proto,
std::string& http_method, std::string& http_uri);
int ReadHTTPStatus(std::basic_istream<char>& stream, int &proto);
diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp
index 6552de8c49..5c4d307497 100644
--- a/src/rpcserver.cpp
+++ b/src/rpcserver.cpp
@@ -25,10 +25,10 @@
#include <boost/shared_ptr.hpp>
#include "json/json_spirit_writer_template.h"
-using namespace std;
using namespace boost;
using namespace boost::asio;
using namespace json_spirit;
+using namespace std;
static std::string strRPCUserColonPass;
@@ -97,16 +97,6 @@ Value ValueFromAmount(int64_t amount)
return (double)amount / (double)COIN;
}
-std::string HexBits(unsigned int nBits)
-{
- union {
- int32_t nBits;
- char cBits[4];
- } uBits;
- uBits.nBits = htonl((int32_t)nBits);
- return HexStr(BEGIN(uBits.cBits), END(uBits.cBits));
-}
-
uint256 ParseHashV(const Value& v, string strName)
{
string strHex;
@@ -393,16 +383,6 @@ bool ClientAllowed(const boost::asio::ip::address& address)
return false;
}
-class AcceptedConnection
-{
-public:
- virtual ~AcceptedConnection() {}
-
- virtual std::iostream& stream() = 0;
- virtual std::string peer_address_to_string() const = 0;
- virtual void close() = 0;
-};
-
template <typename Protocol>
class AcceptedConnectionImpl : public AcceptedConnection
{
@@ -501,7 +481,7 @@ static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptor<Protocol,
{
// Only send a 403 if we're not using SSL to prevent a DoS during the SSL handshake.
if (!fUseSSL)
- conn->stream() << HTTPReply(HTTP_FORBIDDEN, "", false) << std::flush;
+ conn->stream() << HTTPError(HTTP_FORBIDDEN, false) << std::flush;
conn->close();
}
else {
@@ -532,7 +512,7 @@ void StartRPCThreads()
if(!subnet.IsValid())
{
uiInterface.ThreadSafeMessageBox(
- strprintf("Invalid -rpcallowip subnet specification: %s", strAllow),
+ strprintf("Invalid -rpcallowip subnet specification: %s. Valid are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24).", strAllow),
"", CClientUIInterface::MSG_ERROR);
StartShutdown();
return;
@@ -819,6 +799,71 @@ static string JSONRPCExecBatch(const Array& vReq)
return write_string(Value(ret), false) + "\n";
}
+static bool HTTPReq_JSONRPC(AcceptedConnection *conn,
+ string& strRequest,
+ map<string, string>& mapHeaders,
+ bool fRun)
+{
+ // Check authorization
+ if (mapHeaders.count("authorization") == 0)
+ {
+ conn->stream() << HTTPError(HTTP_UNAUTHORIZED, false) << std::flush;
+ return false;
+ }
+
+ if (!HTTPAuthorized(mapHeaders))
+ {
+ LogPrintf("ThreadRPCServer incorrect password attempt from %s\n", conn->peer_address_to_string());
+ /* Deter brute-forcing short passwords.
+ If this results in a DoS the user really
+ shouldn't have their RPC port exposed. */
+ if (mapArgs["-rpcpassword"].size() < 20)
+ MilliSleep(250);
+
+ conn->stream() << HTTPError(HTTP_UNAUTHORIZED, false) << std::flush;
+ return false;
+ }
+
+ JSONRequest jreq;
+ try
+ {
+ // Parse request
+ Value valRequest;
+ if (!read_string(strRequest, valRequest))
+ throw JSONRPCError(RPC_PARSE_ERROR, "Parse error");
+
+ string strReply;
+
+ // singleton request
+ if (valRequest.type() == obj_type) {
+ jreq.parse(valRequest);
+
+ Value result = tableRPC.execute(jreq.strMethod, jreq.params);
+
+ // Send reply
+ strReply = JSONRPCReply(result, Value::null, jreq.id);
+
+ // array of requests
+ } else if (valRequest.type() == array_type)
+ strReply = JSONRPCExecBatch(valRequest.get_array());
+ else
+ throw JSONRPCError(RPC_PARSE_ERROR, "Top-level object parse error");
+
+ conn->stream() << HTTPReply(HTTP_OK, strReply, fRun) << std::flush;
+ }
+ catch (Object& objError)
+ {
+ ErrorReply(conn->stream(), objError, jreq.id);
+ return false;
+ }
+ catch (std::exception& e)
+ {
+ ErrorReply(conn->stream(), JSONRPCError(RPC_PARSE_ERROR, e.what()), jreq.id);
+ return false;
+ }
+ return true;
+}
+
void ServiceConnection(AcceptedConnection *conn)
{
bool fRun = true;
@@ -835,67 +880,15 @@ void ServiceConnection(AcceptedConnection *conn)
// Read HTTP message headers and body
ReadHTTPMessage(conn->stream(), mapHeaders, strRequest, nProto);
- if (strURI != "/") {
- conn->stream() << HTTPReply(HTTP_NOT_FOUND, "", false) << std::flush;
- break;
- }
-
- // Check authorization
- if (mapHeaders.count("authorization") == 0)
- {
- conn->stream() << HTTPReply(HTTP_UNAUTHORIZED, "", false) << std::flush;
- break;
- }
- if (!HTTPAuthorized(mapHeaders))
- {
- LogPrintf("ThreadRPCServer incorrect password attempt from %s\n", conn->peer_address_to_string());
- /* Deter brute-forcing short passwords.
- If this results in a DoS the user really
- shouldn't have their RPC port exposed. */
- if (mapArgs["-rpcpassword"].size() < 20)
- MilliSleep(250);
-
- conn->stream() << HTTPReply(HTTP_UNAUTHORIZED, "", false) << std::flush;
- break;
- }
+ // HTTP Keep-Alive is false; close connection immediately
if (mapHeaders["connection"] == "close")
fRun = false;
- JSONRequest jreq;
- try
- {
- // Parse request
- Value valRequest;
- if (!read_string(strRequest, valRequest))
- throw JSONRPCError(RPC_PARSE_ERROR, "Parse error");
-
- string strReply;
-
- // singleton request
- if (valRequest.type() == obj_type) {
- jreq.parse(valRequest);
-
- Value result = tableRPC.execute(jreq.strMethod, jreq.params);
-
- // Send reply
- strReply = JSONRPCReply(result, Value::null, jreq.id);
-
- // array of requests
- } else if (valRequest.type() == array_type)
- strReply = JSONRPCExecBatch(valRequest.get_array());
- else
- throw JSONRPCError(RPC_PARSE_ERROR, "Top-level object parse error");
-
- conn->stream() << HTTPReply(HTTP_OK, strReply, fRun) << std::flush;
- }
- catch (Object& objError)
- {
- ErrorReply(conn->stream(), objError, jreq.id);
- break;
- }
- catch (std::exception& e)
- {
- ErrorReply(conn->stream(), JSONRPCError(RPC_PARSE_ERROR, e.what()), jreq.id);
+ if (strURI == "/") {
+ if (!HTTPReq_JSONRPC(conn, strRequest, mapHeaders, fRun))
+ break;
+ } else {
+ conn->stream() << HTTPError(HTTP_NOT_FOUND, false) << std::flush;
break;
}
}
diff --git a/src/rpcserver.h b/src/rpcserver.h
index 1966a65b50..01e77163c4 100644
--- a/src/rpcserver.h
+++ b/src/rpcserver.h
@@ -21,6 +21,16 @@
class CBlockIndex;
class CNetAddr;
+class AcceptedConnection
+{
+public:
+ virtual ~AcceptedConnection() {}
+
+ virtual std::iostream& stream() = 0;
+ virtual std::string peer_address_to_string() const = 0;
+ virtual void close() = 0;
+};
+
/* Start RPC threads */
void StartRPCThreads();
/* Alternative to StartRPCThreads for the GUI, when no server is
@@ -106,7 +116,6 @@ extern int64_t nWalletUnlockTime;
extern int64_t AmountFromValue(const json_spirit::Value& value);
extern json_spirit::Value ValueFromAmount(int64_t amount);
extern double GetDifficulty(const CBlockIndex* blockindex = NULL);
-extern std::string HexBits(unsigned int nBits);
extern std::string HelpRequiringPassphrase();
extern std::string HelpExampleCli(std::string methodname, std::string args);
extern std::string HelpExampleRpc(std::string methodname, std::string args);
diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp
index 4f27cef087..38e96133b4 100644
--- a/src/rpcwallet.cpp
+++ b/src/rpcwallet.cpp
@@ -58,6 +58,10 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry)
BOOST_FOREACH(const uint256& conflict, wtx.GetConflicts())
conflicts.push_back(conflict.GetHex());
entry.push_back(Pair("walletconflicts", conflicts));
+ Array respends;
+ BOOST_FOREACH(const uint256& respend, wtx.GetConflicts(false))
+ respends.push_back(respend.GetHex());
+ entry.push_back(Pair("respendsobserved", respends));
entry.push_back(Pair("time", wtx.GetTxTime()));
entry.push_back(Pair("timereceived", (int64_t)wtx.nTimeReceived));
BOOST_FOREACH(const PAIRTYPE(string,string)& item, wtx.mapValue)
@@ -1211,6 +1215,12 @@ Value listtransactions(const Array& params, bool fHelp)
" \"blockindex\": n, (numeric) The block index containing the transaction. Available for 'send' and 'receive'\n"
" category of transactions.\n"
" \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
+ " \"walletconflicts\" : [\n"
+ " \"conflictid\", (string) Ids of transactions, including equivalent clones, that re-spend a txid input.\n"
+ " ],\n"
+ " \"respendsobserved\" : [\n"
+ " \"respendid\", (string) Ids of transactions, NOT equivalent clones, that re-spend a txid input. \"Double-spends.\"\n"
+ " ],\n"
" \"time\": xxx, (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).\n"
" \"timereceived\": xxx, (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT). Available \n"
" for 'send' and 'receive' category of transactions.\n"
@@ -1376,6 +1386,12 @@ Value listsinceblock(const Array& params, bool fHelp)
" \"blockindex\": n, (numeric) The block index containing the transaction. Available for 'send' and 'receive' category of transactions.\n"
" \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n"
" \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n"
+ " \"walletconflicts\" : [\n"
+ " \"conflictid\", (string) Ids of transactions, including equivalent clones, that re-spend a txid input.\n"
+ " ],\n"
+ " \"respendsobserved\" : [\n"
+ " \"respendid\", (string) Ids of transactions, NOT equivalent clones, that re-spend a txid input. \"Double-spends.\"\n"
+ " ],\n"
" \"time\": xxx, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT).\n"
" \"timereceived\": xxx, (numeric) The time received in seconds since epoch (Jan 1 1970 GMT). Available for 'send' and 'receive' category of transactions.\n"
" \"comment\": \"...\", (string) If a comment is associated with the transaction.\n"
@@ -1448,6 +1464,12 @@ Value gettransaction(const Array& params, bool fHelp)
" \"blockindex\" : xx, (numeric) The block index\n"
" \"blocktime\" : ttt, (numeric) The time in seconds since epoch (1 Jan 1970 GMT)\n"
" \"txid\" : \"transactionid\", (string) The transaction id.\n"
+ " \"walletconflicts\" : [\n"
+ " \"conflictid\", (string) Ids of transactions, including equivalent clones, that re-spend a txid input.\n"
+ " ],\n"
+ " \"respendsobserved\" : [\n"
+ " \"respendid\", (string) Ids of transactions, NOT equivalent clones, that re-spend a txid input. \"Double-spends.\"\n"
+ " ],\n"
" \"time\" : ttt, (numeric) The transaction time in seconds since epoch (1 Jan 1970 GMT)\n"
" \"timereceived\" : ttt, (numeric) The time received in seconds since epoch (1 Jan 1970 GMT)\n"
" \"details\" : [\n"
diff --git a/src/script.cpp b/src/script.cpp
index bc4705abe7..e1b6985408 100644
--- a/src/script.cpp
+++ b/src/script.cpp
@@ -974,6 +974,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
namespace {
+
/** Wrapper that serializes like CTransaction, but with the modifications
* required for the signature hash done in-place
*/
@@ -1066,7 +1067,8 @@ public:
::Serialize(s, txTo.nLockTime, nType, nVersion);
}
};
-}
+
+} // anon namespace
uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType)
{
@@ -1092,7 +1094,6 @@ uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsig
return ss.GetHash();
}
-
// Valid signature cache, to avoid doing expensive ECDSA signature checking
// twice for every transaction (once when accepted into memory pool, and
// again when accepted into the block chain)
diff --git a/src/secp256k1/.empty b/src/secp256k1/.empty
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/src/secp256k1/.empty
diff --git a/src/test/bloom_tests.cpp b/src/test/bloom_tests.cpp
index b56d998be2..5c6c7d8588 100644
--- a/src/test/bloom_tests.cpp
+++ b/src/test/bloom_tests.cpp
@@ -45,6 +45,10 @@ BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize)
expected[i] = (char)vch[i];
BOOST_CHECK_EQUAL_COLLECTIONS(stream.begin(), stream.end(), expected.begin(), expected.end());
+
+ BOOST_CHECK_MESSAGE( filter.contains(ParseHex("99108ad8ed9bb6274d3980bab5a85c048f0950c8")), "BloomFilter doesn't contain just-inserted object!");
+ filter.clear();
+ BOOST_CHECK_MESSAGE( !filter.contains(ParseHex("99108ad8ed9bb6274d3980bab5a85c048f0950c8")), "BloomFilter should be empty!");
}
BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize_with_tweak)
diff --git a/src/test/script_P2SH_tests.cpp b/src/test/script_P2SH_tests.cpp
index a75593a8b2..a1dc17ba36 100644
--- a/src/test/script_P2SH_tests.cpp
+++ b/src/test/script_P2SH_tests.cpp
@@ -256,46 +256,61 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
CCoinsView coinsDummy;
CCoinsViewCache coins(coinsDummy);
CBasicKeyStore keystore;
- CKey key[3];
+ CKey key[6];
vector<CPubKey> keys;
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 6; i++)
{
key[i].MakeNewKey(true);
keystore.AddKey(key[i]);
- keys.push_back(key[i].GetPubKey());
}
+ for (int i = 0; i < 3; i++)
+ keys.push_back(key[i].GetPubKey());
CMutableTransaction txFrom;
- txFrom.vout.resize(6);
+ txFrom.vout.resize(7);
// First three are standard:
CScript pay1; pay1.SetDestination(key[0].GetPubKey().GetID());
keystore.AddCScript(pay1);
- CScript payScriptHash1; payScriptHash1.SetDestination(pay1.GetID());
CScript pay1of3; pay1of3.SetMultisig(1, keys);
- txFrom.vout[0].scriptPubKey = payScriptHash1;
+ txFrom.vout[0].scriptPubKey.SetDestination(pay1.GetID()); // P2SH (OP_CHECKSIG)
txFrom.vout[0].nValue = 1000;
- txFrom.vout[1].scriptPubKey = pay1;
+ txFrom.vout[1].scriptPubKey = pay1; // ordinary OP_CHECKSIG
txFrom.vout[1].nValue = 2000;
- txFrom.vout[2].scriptPubKey = pay1of3;
+ txFrom.vout[2].scriptPubKey = pay1of3; // ordinary OP_CHECKMULTISIG
txFrom.vout[2].nValue = 3000;
- // Last three non-standard:
- CScript empty;
- keystore.AddCScript(empty);
- txFrom.vout[3].scriptPubKey = empty;
+ // vout[3] is complicated 1-of-3 AND 2-of-3
+ // ... that is OK if wrapped in P2SH:
+ CScript oneAndTwo;
+ oneAndTwo << OP_1 << key[0].GetPubKey() << key[1].GetPubKey() << key[2].GetPubKey();
+ oneAndTwo << OP_3 << OP_CHECKMULTISIGVERIFY;
+ oneAndTwo << OP_2 << key[3].GetPubKey() << key[4].GetPubKey() << key[5].GetPubKey();
+ oneAndTwo << OP_3 << OP_CHECKMULTISIG;
+ keystore.AddCScript(oneAndTwo);
+ txFrom.vout[3].scriptPubKey.SetDestination(oneAndTwo.GetID());
txFrom.vout[3].nValue = 4000;
- // Can't use SetPayToScriptHash, it checks for the empty Script. So:
- txFrom.vout[4].scriptPubKey << OP_HASH160 << Hash160(empty) << OP_EQUAL;
+
+ // vout[4] is max sigops:
+ CScript fifteenSigops; fifteenSigops << OP_1;
+ for (unsigned i = 0; i < MAX_P2SH_SIGOPS; i++)
+ fifteenSigops << key[i%3].GetPubKey();
+ fifteenSigops << OP_15 << OP_CHECKMULTISIG;
+ keystore.AddCScript(fifteenSigops);
+ txFrom.vout[4].scriptPubKey.SetDestination(fifteenSigops.GetID());
txFrom.vout[4].nValue = 5000;
- CScript oneOfEleven;
- oneOfEleven << OP_1;
- for (int i = 0; i < 11; i++)
- oneOfEleven << key[0].GetPubKey();
- oneOfEleven << OP_11 << OP_CHECKMULTISIG;
- txFrom.vout[5].scriptPubKey.SetDestination(oneOfEleven.GetID());
- txFrom.vout[5].nValue = 6000;
+
+ // vout[5/6] are non-standard because they exceed MAX_P2SH_SIGOPS
+ CScript sixteenSigops; sixteenSigops << OP_16 << OP_CHECKMULTISIG;
+ keystore.AddCScript(sixteenSigops);
+ txFrom.vout[5].scriptPubKey.SetDestination(fifteenSigops.GetID());
+ txFrom.vout[5].nValue = 5000;
+ CScript twentySigops; twentySigops << OP_CHECKMULTISIG;
+ keystore.AddCScript(twentySigops);
+ txFrom.vout[6].scriptPubKey.SetDestination(twentySigops.GetID());
+ txFrom.vout[6].nValue = 6000;
+
coins.SetCoins(txFrom.GetHash(), CCoins(txFrom, 0));
@@ -303,19 +318,24 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
txTo.vout.resize(1);
txTo.vout[0].scriptPubKey.SetDestination(key[1].GetPubKey().GetID());
- txTo.vin.resize(3);
- txTo.vin[0].prevout.n = 0;
- txTo.vin[0].prevout.hash = txFrom.GetHash();
+ txTo.vin.resize(5);
+ for (int i = 0; i < 5; i++)
+ {
+ txTo.vin[i].prevout.n = i;
+ txTo.vin[i].prevout.hash = txFrom.GetHash();
+ }
BOOST_CHECK(SignSignature(keystore, txFrom, txTo, 0));
- txTo.vin[1].prevout.n = 1;
- txTo.vin[1].prevout.hash = txFrom.GetHash();
BOOST_CHECK(SignSignature(keystore, txFrom, txTo, 1));
- txTo.vin[2].prevout.n = 2;
- txTo.vin[2].prevout.hash = txFrom.GetHash();
BOOST_CHECK(SignSignature(keystore, txFrom, txTo, 2));
+ // SignSignature doesn't know how to sign these. We're
+ // not testing validating signatures, so just create
+ // dummy signatures that DO include the correct P2SH scripts:
+ txTo.vin[3].scriptSig << OP_11 << OP_11 << static_cast<vector<unsigned char> >(oneAndTwo);
+ txTo.vin[4].scriptSig << static_cast<vector<unsigned char> >(fifteenSigops);
BOOST_CHECK(::AreInputsStandard(txTo, coins));
- BOOST_CHECK_EQUAL(GetP2SHSigOpCount(txTo, coins), 1U);
+ // 22 P2SH sigops for all inputs (1 for vin[0], 6 for vin[3], 15 for vin[4]
+ BOOST_CHECK_EQUAL(GetP2SHSigOpCount(txTo, coins), 22U);
// Make sure adding crap to the scriptSigs makes them non-standard:
for (int i = 0; i < 3; i++)
@@ -326,23 +346,29 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
txTo.vin[i].scriptSig = t;
}
- CMutableTransaction txToNonStd;
- txToNonStd.vout.resize(1);
- txToNonStd.vout[0].scriptPubKey.SetDestination(key[1].GetPubKey().GetID());
- txToNonStd.vout[0].nValue = 1000;
- txToNonStd.vin.resize(2);
- txToNonStd.vin[0].prevout.n = 4;
- txToNonStd.vin[0].prevout.hash = txFrom.GetHash();
- txToNonStd.vin[0].scriptSig << Serialize(empty);
- txToNonStd.vin[1].prevout.n = 5;
- txToNonStd.vin[1].prevout.hash = txFrom.GetHash();
- txToNonStd.vin[1].scriptSig << OP_0 << Serialize(oneOfEleven);
-
- BOOST_CHECK(!::AreInputsStandard(txToNonStd, coins));
- BOOST_CHECK_EQUAL(GetP2SHSigOpCount(txToNonStd, coins), 11U);
-
- txToNonStd.vin[0].scriptSig.clear();
- BOOST_CHECK(!::AreInputsStandard(txToNonStd, coins));
+ CMutableTransaction txToNonStd1;
+ txToNonStd1.vout.resize(1);
+ txToNonStd1.vout[0].scriptPubKey.SetDestination(key[1].GetPubKey().GetID());
+ txToNonStd1.vout[0].nValue = 1000;
+ txToNonStd1.vin.resize(1);
+ txToNonStd1.vin[0].prevout.n = 5;
+ txToNonStd1.vin[0].prevout.hash = txFrom.GetHash();
+ txToNonStd1.vin[0].scriptSig << static_cast<vector<unsigned char> >(sixteenSigops);
+
+ BOOST_CHECK(!::AreInputsStandard(txToNonStd1, coins));
+ BOOST_CHECK_EQUAL(GetP2SHSigOpCount(txToNonStd1, coins), 16U);
+
+ CMutableTransaction txToNonStd2;
+ txToNonStd2.vout.resize(1);
+ txToNonStd2.vout[0].scriptPubKey.SetDestination(key[1].GetPubKey().GetID());
+ txToNonStd2.vout[0].nValue = 1000;
+ txToNonStd2.vin.resize(1);
+ txToNonStd2.vin[0].prevout.n = 6;
+ txToNonStd2.vin[0].prevout.hash = txFrom.GetHash();
+ txToNonStd2.vin[0].scriptSig << static_cast<vector<unsigned char> >(twentySigops);
+
+ BOOST_CHECK(!::AreInputsStandard(txToNonStd2, coins));
+ BOOST_CHECK_EQUAL(GetP2SHSigOpCount(txToNonStd2, coins), 20U);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/test/skiplist_tests.cpp b/src/test/skiplist_tests.cpp
new file mode 100644
index 0000000000..ea301685c9
--- /dev/null
+++ b/src/test/skiplist_tests.cpp
@@ -0,0 +1,45 @@
+// Copyright (c) 2014 The Bitcoin Core developers
+// Distributed under the MIT/X11 software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <boost/test/unit_test.hpp>
+#include <vector>
+#include "main.h"
+#include "util.h"
+
+
+#define SKIPLIST_LENGTH 300000
+
+BOOST_AUTO_TEST_SUITE(skiplist_tests)
+
+BOOST_AUTO_TEST_CASE(skiplist_test)
+{
+ std::vector<CBlockIndex> vIndex(SKIPLIST_LENGTH);
+
+ for (int i=0; i<SKIPLIST_LENGTH; i++) {
+ vIndex[i].nHeight = i;
+ vIndex[i].pprev = (i == 0) ? NULL : &vIndex[i - 1];
+ vIndex[i].BuildSkip();
+ }
+
+ for (int i=0; i<SKIPLIST_LENGTH; i++) {
+ if (i > 0) {
+ BOOST_CHECK(vIndex[i].pskip == &vIndex[vIndex[i].pskip->nHeight]);
+ BOOST_CHECK(vIndex[i].pskip->nHeight < i);
+ } else {
+ BOOST_CHECK(vIndex[i].pskip == NULL);
+ }
+ }
+
+ for (int i=0; i < 1000; i++) {
+ int from = insecure_rand() % (SKIPLIST_LENGTH - 1);
+ int to = insecure_rand() % (from + 1);
+
+ BOOST_CHECK(vIndex[SKIPLIST_LENGTH - 1].GetAncestor(from) == &vIndex[from]);
+ BOOST_CHECK(vIndex[from].GetAncestor(to) == &vIndex[to]);
+ BOOST_CHECK(vIndex[from].GetAncestor(0) == &vIndex[0]);
+ }
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
diff --git a/src/txdb.cpp b/src/txdb.cpp
index 92137f71ff..52cd96283e 100644
--- a/src/txdb.cpp
+++ b/src/txdb.cpp
@@ -54,11 +54,11 @@ bool CCoinsViewDB::SetBestBlock(const uint256 &hashBlock) {
return db.WriteBatch(batch);
}
-bool CCoinsViewDB::BatchWrite(const std::map<uint256, CCoins> &mapCoins, const uint256 &hashBlock) {
+bool CCoinsViewDB::BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlock) {
LogPrint("coindb", "Committing %u changed transactions to coin database...\n", (unsigned int)mapCoins.size());
CLevelDBBatch batch;
- for (std::map<uint256, CCoins>::const_iterator it = mapCoins.begin(); it != mapCoins.end(); it++)
+ for (CCoinsMap::const_iterator it = mapCoins.begin(); it != mapCoins.end(); it++)
BatchWriteCoins(batch, it->first, it->second);
if (hashBlock != uint256(0))
BatchWriteHashBestChain(batch, hashBlock);
diff --git a/src/txdb.h b/src/txdb.h
index 7257b0dd21..7d670c2542 100644
--- a/src/txdb.h
+++ b/src/txdb.h
@@ -37,7 +37,7 @@ public:
bool HaveCoins(const uint256 &txid);
uint256 GetBestBlock();
bool SetBestBlock(const uint256 &hashBlock);
- bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, const uint256 &hashBlock);
+ bool BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlock);
bool GetStats(CCoinsStats &stats);
};
diff --git a/src/txmempool.cpp b/src/txmempool.cpp
index 52f82ef040..a852de5da8 100644
--- a/src/txmempool.cpp
+++ b/src/txmempool.cpp
@@ -80,13 +80,13 @@ public:
// Used as belt-and-suspenders check when reading to detect
// file corruption
- bool AreSane(const std::vector<CFeeRate>& vecFee)
+ bool AreSane(const std::vector<CFeeRate>& vecFee, const CFeeRate& minRelayFee)
{
BOOST_FOREACH(CFeeRate fee, vecFee)
{
if (fee < CFeeRate(0))
return false;
- if (fee.GetFee(1000) > CTransaction::minRelayTxFee.GetFee(1000) * 10000)
+ if (fee.GetFeePerK() > minRelayFee.GetFeePerK() * 10000)
return false;
}
return true;
@@ -109,10 +109,10 @@ public:
fileout << vecPriority;
}
- void Read(CAutoFile& filein) {
+ void Read(CAutoFile& filein, const CFeeRate& minRelayFee) {
std::vector<CFeeRate> vecFee;
filein >> vecFee;
- if (AreSane(vecFee))
+ if (AreSane(vecFee, minRelayFee))
feeSamples.insert(feeSamples.end(), vecFee.begin(), vecFee.end());
else
throw runtime_error("Corrupt fee value in estimates file.");
@@ -141,7 +141,7 @@ private:
// nBlocksAgo is 0 based, i.e. transactions that confirmed in the highest seen block are
// nBlocksAgo == 0, transactions in the block before that are nBlocksAgo == 1 etc.
- void seenTxConfirm(CFeeRate feeRate, double dPriority, int nBlocksAgo)
+ void seenTxConfirm(const CFeeRate& feeRate, const CFeeRate& minRelayFee, double dPriority, int nBlocksAgo)
{
// Last entry records "everything else".
int nBlocksTruncated = min(nBlocksAgo, (int) history.size() - 1);
@@ -149,7 +149,7 @@ private:
// We need to guess why the transaction was included in a block-- either
// because it is high-priority or because it has sufficient fees.
- bool sufficientFee = (feeRate > CTransaction::minRelayTxFee);
+ bool sufficientFee = (feeRate > minRelayFee);
bool sufficientPriority = AllowFree(dPriority);
const char* assignedTo = "unassigned";
if (sufficientFee && !sufficientPriority)
@@ -177,7 +177,7 @@ public:
history.resize(nEntries);
}
- void seenBlock(const std::vector<CTxMemPoolEntry>& entries, int nBlockHeight)
+ void seenBlock(const std::vector<CTxMemPoolEntry>& entries, int nBlockHeight, const CFeeRate minRelayFee)
{
if (nBlockHeight <= nBestSeenHeight)
{
@@ -222,7 +222,7 @@ public:
// Fees are stored and reported as BTC-per-kb:
CFeeRate feeRate(entry->GetFee(), entry->GetTxSize());
double dPriority = entry->GetPriority(entry->GetHeight()); // Want priority when it went IN
- seenTxConfirm(feeRate, dPriority, i);
+ seenTxConfirm(feeRate, minRelayFee, dPriority, i);
}
}
for (size_t i = 0; i < history.size(); i++) {
@@ -251,8 +251,13 @@ public:
std::sort(sortedFeeSamples.begin(), sortedFeeSamples.end(),
std::greater<CFeeRate>());
}
- if (sortedFeeSamples.size() == 0)
+ if (sortedFeeSamples.size() < 11)
+ {
+ // Eleven is Gavin's Favorite Number
+ // ... but we also take a maximum of 10 samples per block so eleven means
+ // we're getting samples from at least two different blocks
return CFeeRate(0);
+ }
int nBucketSize = history.at(nBlocksToConfirm).FeeSamples();
@@ -281,7 +286,7 @@ public:
std::sort(sortedPrioritySamples.begin(), sortedPrioritySamples.end(),
std::greater<double>());
}
- if (sortedPrioritySamples.size() == 0)
+ if (sortedPrioritySamples.size() < 11)
return -1.0;
int nBucketSize = history.at(nBlocksToConfirm).PrioritySamples();
@@ -308,7 +313,7 @@ public:
}
}
- void Read(CAutoFile& filein)
+ void Read(CAutoFile& filein, const CFeeRate& minRelayFee)
{
filein >> nBestSeenHeight;
size_t numEntries;
@@ -317,14 +322,14 @@ public:
for (size_t i = 0; i < numEntries; i++)
{
CBlockAverage entry;
- entry.Read(filein);
+ entry.Read(filein, minRelayFee);
history.push_back(entry);
}
}
};
-CTxMemPool::CTxMemPool()
+CTxMemPool::CTxMemPool(const CFeeRate& _minRelayFee) : minRelayFee(_minRelayFee)
{
// Sanity checks off by default for performance, because otherwise
// accepting transactions becomes O(N^2) where N is the number
@@ -415,7 +420,6 @@ void CTxMemPool::remove(const CTransaction &tx, std::list<CTransaction>& removed
void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>& removed)
{
// Remove transactions which depend on inputs of tx, recursively
- list<CTransaction> result;
LOCK(cs);
BOOST_FOREACH(const CTxIn &txin, tx.vin) {
std::map<COutPoint, CInPoint>::iterator it = mapNextTx.find(txin.prevout);
@@ -441,7 +445,7 @@ void CTxMemPool::removeForBlock(const std::vector<CTransaction>& vtx, unsigned i
if (mapTx.count(hash))
entries.push_back(mapTx[hash]);
}
- minerPolicyEstimator->seenBlock(entries, nBlockHeight);
+ minerPolicyEstimator->seenBlock(entries, nBlockHeight, minRelayFee);
BOOST_FOREACH(const CTransaction& tx, vtx)
{
std::list<CTransaction> dummy;
@@ -556,7 +560,7 @@ CTxMemPool::ReadFeeEstimates(CAutoFile& filein)
return error("CTxMemPool::ReadFeeEstimates() : up-version (%d) fee estimate file", nVersionRequired);
LOCK(cs);
- minerPolicyEstimator->Read(filein);
+ minerPolicyEstimator->Read(filein, minRelayFee);
}
catch (std::exception &e) {
LogPrintf("CTxMemPool::ReadFeeEstimates() : unable to read policy estimator data (non-fatal)");
diff --git a/src/txmempool.h b/src/txmempool.h
index f7dbb126a0..41b2c52f39 100644
--- a/src/txmempool.h
+++ b/src/txmempool.h
@@ -67,13 +67,15 @@ private:
unsigned int nTransactionsUpdated;
CMinerPolicyEstimator* minerPolicyEstimator;
+ CFeeRate minRelayFee; // Passed to constructor to avoid dependency on main
+
public:
mutable CCriticalSection cs;
std::map<uint256, CTxMemPoolEntry> mapTx;
std::map<COutPoint, CInPoint> mapNextTx;
std::map<uint256, std::pair<double, int64_t> > mapDeltas;
- CTxMemPool();
+ CTxMemPool(const CFeeRate& _minRelayFee);
~CTxMemPool();
/*
diff --git a/src/ui_interface.h b/src/ui_interface.h
index e1a3e04e12..e9fcd91d41 100644
--- a/src/ui_interface.h
+++ b/src/ui_interface.h
@@ -21,7 +21,8 @@ enum ChangeType
{
CT_NEW,
CT_UPDATED,
- CT_DELETED
+ CT_DELETED,
+ CT_GOT_CONFLICT
};
/** Signals for UI communication. */
diff --git a/src/uint256.cpp b/src/uint256.cpp
new file mode 100644
index 0000000000..3392f1e9bc
--- /dev/null
+++ b/src/uint256.cpp
@@ -0,0 +1,292 @@
+// Copyright (c) 2009-2010 Satoshi Nakamoto
+// 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.
+
+#include "uint256.h"
+#include "util.h"
+
+#include <stdio.h>
+#include <string.h>
+
+template<unsigned int BITS>
+base_uint<BITS>::base_uint(const std::string& str)
+{
+ SetHex(str);
+}
+
+template<unsigned int BITS>
+base_uint<BITS>::base_uint(const std::vector<unsigned char>& vch)
+{
+ if (vch.size() != sizeof(pn))
+ throw uint_error("Converting vector of wrong size to base_uint");
+ memcpy(pn, &vch[0], sizeof(pn));
+}
+
+template<unsigned int BITS>
+base_uint<BITS>& base_uint<BITS>::operator<<=(unsigned int shift)
+{
+ base_uint<BITS> a(*this);
+ for (int i = 0; i < WIDTH; i++)
+ pn[i] = 0;
+ int k = shift / 32;
+ shift = shift % 32;
+ for (int i = 0; i < WIDTH; i++) {
+ if (i+k+1 < WIDTH && shift != 0)
+ pn[i+k+1] |= (a.pn[i] >> (32-shift));
+ if (i+k < WIDTH)
+ pn[i+k] |= (a.pn[i] << shift);
+ }
+ return *this;
+}
+
+template<unsigned int BITS>
+base_uint<BITS>& base_uint<BITS>::operator>>=(unsigned int shift)
+{
+ base_uint<BITS> a(*this);
+ for (int i = 0; i < WIDTH; i++)
+ pn[i] = 0;
+ int k = shift / 32;
+ shift = shift % 32;
+ for (int i = 0; i < WIDTH; i++) {
+ if (i-k-1 >= 0 && shift != 0)
+ pn[i-k-1] |= (a.pn[i] << (32-shift));
+ if (i-k >= 0)
+ pn[i-k] |= (a.pn[i] >> shift);
+ }
+ return *this;
+}
+
+template<unsigned int BITS>
+base_uint<BITS>& base_uint<BITS>::operator*=(uint32_t b32)
+{
+ uint64_t carry = 0;
+ for (int i = 0; i < WIDTH; i++) {
+ uint64_t n = carry + (uint64_t)b32 * pn[i];
+ pn[i] = n & 0xffffffff;
+ carry = n >> 32;
+ }
+ return *this;
+}
+
+template<unsigned int BITS>
+base_uint<BITS>& base_uint<BITS>::operator*=(const base_uint& b)
+{
+ base_uint<BITS> a = *this;
+ *this = 0;
+ for (int j = 0; j < WIDTH; j++) {
+ uint64_t carry = 0;
+ for (int i = 0; i + j < WIDTH; i++) {
+ uint64_t n = carry + pn[i + j] + (uint64_t)a.pn[j] * b.pn[i];
+ pn[i + j] = n & 0xffffffff;
+ carry = n >> 32;
+ }
+ }
+ return *this;
+}
+
+template<unsigned int BITS>
+base_uint<BITS>& base_uint<BITS>::operator/=(const base_uint& b)
+{
+ base_uint<BITS> div = b; // make a copy, so we can shift.
+ base_uint<BITS> num = *this; // make a copy, so we can subtract.
+ *this = 0; // the quotient.
+ int num_bits = num.bits();
+ int div_bits = div.bits();
+ if (div_bits == 0)
+ throw uint_error("Division by zero");
+ if (div_bits > num_bits) // the result is certainly 0.
+ return *this;
+ int shift = num_bits - div_bits;
+ div <<= shift; // shift so that div and nun align.
+ while (shift >= 0) {
+ if (num >= div) {
+ num -= div;
+ pn[shift / 32] |= (1 << (shift & 31)); // set a bit of the result.
+ }
+ div >>= 1; // shift back.
+ shift--;
+ }
+ // num now contains the remainder of the division.
+ return *this;
+}
+
+template<unsigned int BITS>
+int base_uint<BITS>::CompareTo(const base_uint<BITS>& b) const {
+ for (int i = WIDTH-1; i >= 0; i--) {
+ if (pn[i] < b.pn[i])
+ return -1;
+ if (pn[i] > b.pn[i])
+ return 1;
+ }
+ return 0;
+}
+
+template<unsigned int BITS>
+bool base_uint<BITS>::EqualTo(uint64_t b) const {
+ for (int i = WIDTH-1; i >= 2; i--) {
+ if (pn[i])
+ return false;
+ }
+ if (pn[1] != (b >> 32))
+ return false;
+ if (pn[0] != (b & 0xfffffffful))
+ return false;
+ return true;
+}
+
+template<unsigned int BITS>
+double base_uint<BITS>::getdouble() const
+{
+ double ret = 0.0;
+ double fact = 1.0;
+ for (int i = 0; i < WIDTH; i++) {
+ ret += fact * pn[i];
+ fact *= 4294967296.0;
+ }
+ return ret;
+}
+
+template<unsigned int BITS>
+std::string base_uint<BITS>::GetHex() const
+{
+ char psz[sizeof(pn)*2 + 1];
+ for (unsigned int i = 0; i < sizeof(pn); i++)
+ sprintf(psz + i*2, "%02x", ((unsigned char*)pn)[sizeof(pn) - i - 1]);
+ return std::string(psz, psz + sizeof(pn)*2);
+}
+
+template<unsigned int BITS>
+void base_uint<BITS>::SetHex(const char* psz)
+{
+ memset(pn,0,sizeof(pn));
+
+ // skip leading spaces
+ while (isspace(*psz))
+ psz++;
+
+ // skip 0x
+ if (psz[0] == '0' && tolower(psz[1]) == 'x')
+ psz += 2;
+
+ // hex string to uint
+ const char* pbegin = psz;
+ while (::HexDigit(*psz) != -1)
+ psz++;
+ psz--;
+ unsigned char* p1 = (unsigned char*)pn;
+ unsigned char* pend = p1 + WIDTH * 4;
+ while (psz >= pbegin && p1 < pend) {
+ *p1 = ::HexDigit(*psz--);
+ if (psz >= pbegin) {
+ *p1 |= ((unsigned char)::HexDigit(*psz--) << 4);
+ p1++;
+ }
+ }
+}
+
+template<unsigned int BITS>
+void base_uint<BITS>::SetHex(const std::string& str)
+{
+ SetHex(str.c_str());
+}
+
+template<unsigned int BITS>
+std::string base_uint<BITS>::ToString() const
+{
+ return (GetHex());
+}
+
+template<unsigned int BITS>
+unsigned int base_uint<BITS>::bits() const
+{
+ for (int pos = WIDTH-1; pos >= 0; pos--) {
+ if (pn[pos]) {
+ for (int bits = 31; bits > 0; bits--) {
+ if (pn[pos] & 1<<bits)
+ return 32*pos + bits + 1;
+ }
+ return 32*pos + 1;
+ }
+ }
+ return 0;
+}
+
+// Explicit instantiations for base_uint<160>
+template base_uint<160>::base_uint(const std::string&);
+template base_uint<160>::base_uint(const std::vector<unsigned char>&);
+template base_uint<160>& base_uint<160>::operator<<=(unsigned int);
+template base_uint<160>& base_uint<160>::operator>>=(unsigned int);
+template base_uint<160>& base_uint<160>::operator*=(uint32_t b32);
+template base_uint<160>& base_uint<160>::operator*=(const base_uint<160>& b);
+template base_uint<160>& base_uint<160>::operator/=(const base_uint<160>& b);
+template int base_uint<160>::CompareTo(const base_uint<160>&) const;
+template bool base_uint<160>::EqualTo(uint64_t) const;
+template double base_uint<160>::getdouble() const;
+template std::string base_uint<160>::GetHex() const;
+template std::string base_uint<160>::ToString() const;
+template void base_uint<160>::SetHex(const char*);
+template void base_uint<160>::SetHex(const std::string&);
+template unsigned int base_uint<160>::bits() const;
+
+// Explicit instantiations for base_uint<256>
+template base_uint<256>::base_uint(const std::string&);
+template base_uint<256>::base_uint(const std::vector<unsigned char>&);
+template base_uint<256>& base_uint<256>::operator<<=(unsigned int);
+template base_uint<256>& base_uint<256>::operator>>=(unsigned int);
+template base_uint<256>& base_uint<256>::operator*=(uint32_t b32);
+template base_uint<256>& base_uint<256>::operator*=(const base_uint<256>& b);
+template base_uint<256>& base_uint<256>::operator/=(const base_uint<256>& b);
+template int base_uint<256>::CompareTo(const base_uint<256>&) const;
+template bool base_uint<256>::EqualTo(uint64_t) const;
+template double base_uint<256>::getdouble() const;
+template std::string base_uint<256>::GetHex() const;
+template std::string base_uint<256>::ToString() const;
+template void base_uint<256>::SetHex(const char*);
+template void base_uint<256>::SetHex(const std::string&);
+template unsigned int base_uint<256>::bits() const;
+
+// This implementation directly uses shifts instead of going
+// through an intermediate MPI representation.
+uint256& uint256::SetCompact(uint32_t nCompact, bool *pfNegative, bool *pfOverflow)
+{
+ int nSize = nCompact >> 24;
+ uint32_t nWord = nCompact & 0x007fffff;
+ if (nSize <= 3) {
+ nWord >>= 8*(3-nSize);
+ *this = nWord;
+ } else {
+ *this = nWord;
+ *this <<= 8*(nSize-3);
+ }
+ if (pfNegative)
+ *pfNegative = nWord != 0 && (nCompact & 0x00800000) != 0;
+ if (pfOverflow)
+ *pfOverflow = nWord != 0 && ((nSize > 34) ||
+ (nWord > 0xff && nSize > 33) ||
+ (nWord > 0xffff && nSize > 32));
+ return *this;
+}
+
+uint32_t uint256::GetCompact(bool fNegative) const
+{
+ int nSize = (bits() + 7) / 8;
+ uint32_t nCompact = 0;
+ if (nSize <= 3) {
+ nCompact = GetLow64() << 8*(3-nSize);
+ } else {
+ uint256 bn = *this >> 8*(nSize-3);
+ nCompact = bn.GetLow64();
+ }
+ // The 0x00800000 bit denotes the sign.
+ // Thus, if it is already set, divide the mantissa by 256 and increase the exponent.
+ if (nCompact & 0x00800000) {
+ nCompact >>= 8;
+ nSize++;
+ }
+ assert((nCompact & ~0x007fffff) == 0);
+ assert(nSize < 256);
+ nCompact |= nSize << 24;
+ nCompact |= (fNegative && (nCompact & 0x007fffff) ? 0x00800000 : 0);
+ return nCompact;
+}
diff --git a/src/uint256.h b/src/uint256.h
index 1acedd14bf..82db7758c9 100644
--- a/src/uint256.h
+++ b/src/uint256.h
@@ -9,18 +9,9 @@
#include <assert.h>
#include <stdexcept>
#include <stdint.h>
-#include <stdio.h>
#include <string>
-#include <string.h>
#include <vector>
-extern const signed char p_util_hexdigit[256]; // defined in util.cpp
-
-inline signed char HexDigit(char c)
-{
- return p_util_hexdigit[(unsigned char)c];
-}
-
class uint_error : public std::runtime_error {
public:
explicit uint_error(const std::string& str) : std::runtime_error(str) {}
@@ -62,17 +53,8 @@ public:
pn[i] = 0;
}
- explicit base_uint(const std::string& str)
- {
- SetHex(str);
- }
-
- explicit base_uint(const std::vector<unsigned char>& vch)
- {
- if (vch.size() != sizeof(pn))
- throw uint_error("Converting vector of wrong size to base_uint");
- memcpy(pn, &vch[0], sizeof(pn));
- }
+ explicit base_uint(const std::string& str);
+ explicit base_uint(const std::vector<unsigned char>& vch);
bool operator!() const
{
@@ -99,16 +81,7 @@ public:
return ret;
}
- double getdouble() const
- {
- double ret = 0.0;
- double fact = 1.0;
- for (int i = 0; i < WIDTH; i++) {
- ret += fact * pn[i];
- fact *= 4294967296.0;
- }
- return ret;
- }
+ double getdouble() const;
base_uint& operator=(uint64_t b)
{
@@ -154,39 +127,8 @@ public:
return *this;
}
- base_uint& operator<<=(unsigned int shift)
- {
- base_uint a(*this);
- for (int i = 0; i < WIDTH; i++)
- pn[i] = 0;
- int k = shift / 32;
- shift = shift % 32;
- for (int i = 0; i < WIDTH; i++)
- {
- if (i+k+1 < WIDTH && shift != 0)
- pn[i+k+1] |= (a.pn[i] >> (32-shift));
- if (i+k < WIDTH)
- pn[i+k] |= (a.pn[i] << shift);
- }
- return *this;
- }
-
- base_uint& operator>>=(unsigned int shift)
- {
- base_uint a(*this);
- for (int i = 0; i < WIDTH; i++)
- pn[i] = 0;
- int k = shift / 32;
- shift = shift % 32;
- for (int i = 0; i < WIDTH; i++)
- {
- if (i-k-1 >= 0 && shift != 0)
- pn[i-k-1] |= (a.pn[i] << (32-shift));
- if (i-k >= 0)
- pn[i-k] |= (a.pn[i] >> shift);
- }
- return *this;
- }
+ base_uint& operator<<=(unsigned int shift);
+ base_uint& operator>>=(unsigned int shift);
base_uint& operator+=(const base_uint& b)
{
@@ -222,57 +164,9 @@ public:
return *this;
}
- base_uint& operator*=(uint32_t b32)
- {
- uint64_t carry = 0;
- for (int i = 0; i < WIDTH; i++)
- {
- uint64_t n = carry + (uint64_t)b32 * pn[i];
- pn[i] = n & 0xffffffff;
- carry = n >> 32;
- }
- return *this;
- }
-
- base_uint& operator*=(const base_uint& b)
- {
- base_uint a = *this;
- *this = 0;
- for (int j = 0; j < WIDTH; j++) {
- uint64_t carry = 0;
- for (int i = 0; i + j < WIDTH; i++) {
- uint64_t n = carry + pn[i + j] + (uint64_t)a.pn[j] * b.pn[i];
- pn[i + j] = n & 0xffffffff;
- carry = n >> 32;
- }
- }
- return *this;
- }
-
- base_uint& operator/=(const base_uint& b)
- {
- base_uint div = b; // make a copy, so we can shift.
- base_uint num = *this; // make a copy, so we can subtract.
- *this = 0; // the quotient.
- int num_bits = num.bits();
- int div_bits = div.bits();
- if (div_bits == 0)
- throw uint_error("Division by zero");
- if (div_bits > num_bits) // the result is certainly 0.
- return *this;
- int shift = num_bits - div_bits;
- div <<= shift; // shift so that div and nun align.
- while (shift >= 0) {
- if (num >= div) {
- num -= div;
- pn[shift / 32] |= (1 << (shift & 31)); // set a bit of the result.
- }
- div >>= 1; // shift back.
- shift--;
- }
- // num now contains the remainder of the division.
- return *this;
- }
+ base_uint& operator*=(uint32_t b32);
+ base_uint& operator*=(const base_uint& b);
+ base_uint& operator/=(const base_uint& b);
base_uint& operator++()
{
@@ -308,27 +202,8 @@ public:
return ret;
}
- int CompareTo(const base_uint& b) const {
- for (int i = base_uint::WIDTH-1; i >= 0; i--) {
- if (pn[i] < b.pn[i])
- return -1;
- if (pn[i] > b.pn[i])
- return 1;
- }
- return 0;
- }
-
- bool EqualTo(uint64_t b) const {
- for (int i = base_uint::WIDTH-1; i >= 2; i--) {
- if (pn[i])
- return false;
- }
- if (pn[1] != (b >> 32))
- return false;
- if (pn[0] != (b & 0xfffffffful))
- return false;
- return true;
- }
+ int CompareTo(const base_uint& b) const;
+ bool EqualTo(uint64_t b) const;
friend inline const base_uint operator+(const base_uint& a, const base_uint& b) { return base_uint(a) += b; }
friend inline const base_uint operator-(const base_uint& a, const base_uint& b) { return base_uint(a) -= b; }
@@ -349,53 +224,10 @@ public:
friend inline bool operator==(const base_uint& a, uint64_t b) { return a.EqualTo(b); }
friend inline bool operator!=(const base_uint& a, uint64_t b) { return !a.EqualTo(b); }
- std::string GetHex() const
- {
- char psz[sizeof(pn)*2 + 1];
- for (unsigned int i = 0; i < sizeof(pn); i++)
- sprintf(psz + i*2, "%02x", ((unsigned char*)pn)[sizeof(pn) - i - 1]);
- return std::string(psz, psz + sizeof(pn)*2);
- }
-
- void SetHex(const char* psz)
- {
- memset(pn,0,sizeof(pn));
-
- // skip leading spaces
- while (isspace(*psz))
- psz++;
-
- // skip 0x
- if (psz[0] == '0' && tolower(psz[1]) == 'x')
- psz += 2;
-
- // hex string to uint
- const char* pbegin = psz;
- while (::HexDigit(*psz) != -1)
- psz++;
- psz--;
- unsigned char* p1 = (unsigned char*)pn;
- unsigned char* pend = p1 + WIDTH * 4;
- while (psz >= pbegin && p1 < pend)
- {
- *p1 = ::HexDigit(*psz--);
- if (psz >= pbegin)
- {
- *p1 |= ((unsigned char)::HexDigit(*psz--) << 4);
- p1++;
- }
- }
- }
-
- void SetHex(const std::string& str)
- {
- SetHex(str.c_str());
- }
-
- std::string ToString() const
- {
- return (GetHex());
- }
+ std::string GetHex() const;
+ void SetHex(const char* psz);
+ void SetHex(const std::string& str);
+ std::string ToString() const;
unsigned char* begin()
{
@@ -424,19 +256,7 @@ public:
// Returns the position of the highest bit set plus one, or zero if the
// value is zero.
- unsigned int bits() const
- {
- for (int pos = WIDTH-1; pos >= 0; pos--) {
- if (pn[pos]) {
- for (int bits = 31; bits > 0; bits--) {
- if (pn[pos] & 1<<bits)
- return 32*pos + bits + 1;
- }
- return 32*pos + 1;
- }
- }
- return 0;
- }
+ unsigned int bits() const;
uint64_t GetLow64() const
{
@@ -500,56 +320,8 @@ public:
// targets, which are unsigned 256bit quantities. Thus, all the
// complexities of the sign bit and using base 256 are probably an
// implementation accident.
- //
- // This implementation directly uses shifts instead of going
- // through an intermediate MPI representation.
- uint256& SetCompact(uint32_t nCompact, bool *pfNegative = NULL, bool *pfOverflow = NULL)
- {
- int nSize = nCompact >> 24;
- uint32_t nWord = nCompact & 0x007fffff;
- if (nSize <= 3)
- {
- nWord >>= 8*(3-nSize);
- *this = nWord;
- }
- else
- {
- *this = nWord;
- *this <<= 8*(nSize-3);
- }
- if (pfNegative)
- *pfNegative = nWord != 0 && (nCompact & 0x00800000) != 0;
- if (pfOverflow)
- *pfOverflow = nWord != 0 && ((nSize > 34) ||
- (nWord > 0xff && nSize > 33) ||
- (nWord > 0xffff && nSize > 32));
- return *this;
- }
-
- uint32_t GetCompact(bool fNegative = false) const
- {
- int nSize = (bits() + 7) / 8;
- uint32_t nCompact = 0;
- if (nSize <= 3)
- nCompact = GetLow64() << 8*(3-nSize);
- else
- {
- uint256 bn = *this >> 8*(nSize-3);
- nCompact = bn.GetLow64();
- }
- // The 0x00800000 bit denotes the sign.
- // Thus, if it is already set, divide the mantissa by 256 and increase the exponent.
- if (nCompact & 0x00800000)
- {
- nCompact >>= 8;
- nSize++;
- }
- assert((nCompact & ~0x007fffff) == 0);
- assert(nSize < 256);
- nCompact |= nSize << 24;
- nCompact |= (fNegative && (nCompact & 0x007fffff) ? 0x00800000 : 0);
- return nCompact;
- }
+ uint256& SetCompact(uint32_t nCompact, bool *pfNegative = NULL, bool *pfOverflow = NULL);
+ uint32_t GetCompact(bool fNegative = false) const;
};
#endif
diff --git a/src/util.cpp b/src/util.cpp
index 9e4b2b787e..081484c37d 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -77,11 +77,12 @@
// See also: http://stackoverflow.com/questions/10020179/compilation-fail-in-boost-librairies-program-options
// http://clang.debian.net/status.php?version=3.0&key=CANNOT_FIND_FUNCTION
namespace boost {
+
namespace program_options {
std::string to_internal(const std::string&);
}
-}
+} // namespace boost
using namespace std;
@@ -94,6 +95,7 @@ bool fDaemon = false;
bool fServer = false;
string strMiscWarning;
bool fLogTimestamps = false;
+bool fLogIPs = false;
volatile bool fReopenDebugLog = false;
CClientUIInterface uiInterface;
@@ -419,6 +421,11 @@ const signed char p_util_hexdigit[256] =
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, };
+signed char HexDigit(char c)
+{
+ return p_util_hexdigit[(unsigned char)c];
+}
+
bool IsHex(const string& str)
{
BOOST_FOREACH(char c, str)
diff --git a/src/util.h b/src/util.h
index 6057c72e66..60db71bfd0 100644
--- a/src/util.h
+++ b/src/util.h
@@ -100,6 +100,7 @@ extern bool fPrintToDebugLog;
extern bool fServer;
extern std::string strMiscWarning;
extern bool fLogTimestamps;
+extern bool fLogIPs;
extern volatile bool fReopenDebugLog;
void RandAddSeed();
@@ -156,6 +157,7 @@ bool ParseMoney(const char* pszIn, int64_t& nRet);
std::string SanitizeString(const std::string& str);
std::vector<unsigned char> ParseHex(const char* psz);
std::vector<unsigned char> ParseHex(const std::string& str);
+signed char HexDigit(char c);
bool IsHex(const std::string& str);
std::vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid = NULL);
std::string DecodeBase64(const std::string& str);
diff --git a/src/wallet.cpp b/src/wallet.cpp
index f6fd6e958d..318a1388d2 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -18,8 +18,12 @@ using namespace std;
// Settings
CFeeRate payTxFee(DEFAULT_TRANSACTION_FEE);
+unsigned int nTxConfirmTarget = 1;
bool bSpendZeroConfChange = true;
+/** Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) */
+CFeeRate CWallet::minTxFee = CFeeRate(10000); // Override with -mintxfee
+
//////////////////////////////////////////////////////////////////////////////
//
// mapWallet
@@ -256,7 +260,7 @@ bool CWallet::SetMaxVersion(int nVersion)
return true;
}
-set<uint256> CWallet::GetConflicts(const uint256& txid) const
+set<uint256> CWallet::GetConflicts(const uint256& txid, bool includeEquivalent) const
{
set<uint256> result;
AssertLockHeld(cs_wallet);
@@ -274,7 +278,8 @@ set<uint256> CWallet::GetConflicts(const uint256& txid) const
continue; // No conflict if zero or one spends
range = mapTxSpends.equal_range(txin.prevout);
for (TxSpends::const_iterator it = range.first; it != range.second; ++it)
- result.insert(it->second);
+ if (includeEquivalent || !wtx.IsEquivalentTo(mapWallet.at(it->second)))
+ result.insert(it->second);
}
return result;
}
@@ -303,6 +308,7 @@ void CWallet::SyncMetaData(pair<TxSpends::iterator, TxSpends::iterator> range)
const uint256& hash = it->second;
CWalletTx* copyTo = &mapWallet[hash];
if (copyFrom == copyTo) continue;
+ if (!copyFrom->IsEquivalentTo(*copyTo)) continue;
copyTo->mapValue = copyFrom->mapValue;
copyTo->vOrderForm = copyFrom->vOrderForm;
// fTimeReceivedIsTxTime not copied on purpose
@@ -588,6 +594,28 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet)
// Notify UI of new or updated transaction
NotifyTransactionChanged(this, hash, fInsertedNew ? CT_NEW : CT_UPDATED);
+ // Notifications for existing transactions that now have conflicts with this one
+ if (fInsertedNew)
+ {
+ BOOST_FOREACH(const uint256& conflictHash, wtxIn.GetConflicts(false))
+ {
+ CWalletTx& txConflict = mapWallet[conflictHash];
+ NotifyTransactionChanged(this, conflictHash, CT_UPDATED); //Updates UI table
+ if (IsFromMe(txConflict) || IsMine(txConflict))
+ {
+ NotifyTransactionChanged(this, conflictHash, CT_GOT_CONFLICT); //Throws dialog
+ // external respend notify
+ std::string strCmd = GetArg("-respendnotify", "");
+ if (!strCmd.empty())
+ {
+ boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex());
+ boost::replace_all(strCmd, "%t", conflictHash.GetHex());
+ boost::thread t(runCommand, strCmd); // thread runs free
+ }
+ }
+ }
+ }
+
// notify an external script when a wallet transaction comes in or is updated
std::string strCmd = GetArg("-walletnotify", "");
@@ -610,7 +638,12 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
AssertLockHeld(cs_wallet);
bool fExisted = mapWallet.count(tx.GetHash());
if (fExisted && !fUpdate) return false;
- if (fExisted || IsMine(tx) || IsFromMe(tx))
+
+ bool fIsConflicting = IsConflicting(tx);
+ if (fIsConflicting)
+ nConflictsReceived++;
+
+ if (fExisted || IsMine(tx) || IsFromMe(tx) || fIsConflicting)
{
CWalletTx wtx(this,tx);
// Get merkle branch if transaction was found in a block
@@ -896,7 +929,7 @@ void CWallet::ReacceptWalletTransactions()
int nDepth = wtx.GetDepthInMainChain();
- if (!wtx.IsCoinBase() && nDepth < 0)
+ if (!wtx.IsCoinBase() && nDepth < 0 && (IsMine(wtx) || IsFromMe(wtx)))
{
// Try to add to memory pool
LOCK(mempool.cs);
@@ -916,13 +949,13 @@ void CWalletTx::RelayWalletTransaction()
}
}
-set<uint256> CWalletTx::GetConflicts() const
+set<uint256> CWalletTx::GetConflicts(bool includeEquivalent) const
{
set<uint256> result;
if (pwallet != NULL)
{
uint256 myHash = GetHash();
- result = pwallet->GetConflicts(myHash);
+ result = pwallet->GetConflicts(myHash, includeEquivalent);
result.erase(myHash);
}
return result;
@@ -1244,6 +1277,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
return false;
}
+ wtxNew.fTimeReceivedIsTxTime = true;
wtxNew.BindWallet(this);
CMutableTransaction txNew;
@@ -1263,7 +1297,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend)
{
CTxOut txout(s.second, s.first);
- if (txout.IsDust(CTransaction::minRelayTxFee))
+ if (txout.IsDust(::minRelayTxFee))
{
strFailReason = _("Transaction amount too small");
return false;
@@ -1324,7 +1358,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
// Never create dust outputs; if we would, just
// add the dust to the fee.
- if (newTxOut.IsDust(CTransaction::minRelayTxFee))
+ if (newTxOut.IsDust(::minRelayTxFee))
{
nFeeRet += nChange;
reservekey.ReturnKey();
@@ -1364,19 +1398,31 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
}
dPriority = wtxNew.ComputePriority(dPriority, nBytes);
- // Check that enough fee is included
- int64_t nPayFee = payTxFee.GetFee(nBytes);
- bool fAllowFree = AllowFree(dPriority);
- int64_t nMinFee = GetMinFee(wtxNew, nBytes, fAllowFree, GMF_SEND);
- if (nFeeRet < max(nPayFee, nMinFee))
+ int64_t nFeeNeeded = GetMinimumFee(nBytes, nTxConfirmTarget, mempool);
+
+ if (nFeeRet >= nFeeNeeded)
+ break; // Done, enough fee included.
+
+ // Too big to send for free? Include more fee and try again:
+ if (nBytes > MAX_FREE_TRANSACTION_CREATE_SIZE)
{
- nFeeRet = max(nPayFee, nMinFee);
+ nFeeRet = nFeeNeeded;
continue;
}
- wtxNew.fTimeReceivedIsTxTime = true;
+ // Not enough fee: enough priority?
+ double dPriorityNeeded = mempool.estimatePriority(nTxConfirmTarget);
+ // Not enough mempool history to estimate: use hard-coded AllowFree.
+ if (dPriorityNeeded <= 0 && AllowFree(dPriority))
+ break;
- break;
+ // Small enough, and priority high enough, to send for free
+ if (dPriority >= dPriorityNeeded)
+ break;
+
+ // Include more fee and try again.
+ nFeeRet = nFeeNeeded;
+ continue;
}
}
}
@@ -1484,6 +1530,20 @@ string CWallet::SendMoneyToDestination(const CTxDestination& address, int64_t nV
return SendMoney(scriptPubKey, nValue, wtxNew);
}
+int64_t CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool)
+{
+ // payTxFee is user-set "I want to pay this much"
+ int64_t nFeeNeeded = payTxFee.GetFee(nTxBytes);
+ // User didn't set: use -txconfirmtarget to estimate...
+ if (nFeeNeeded == 0)
+ nFeeNeeded = pool.estimateFee(nConfirmTarget).GetFee(nTxBytes);
+ // ... unless we don't have enough mempool data, in which case fall
+ // back to a hard-coded fee
+ if (nFeeNeeded == 0)
+ nFeeNeeded = minTxFee.GetFee(nTxBytes);
+ return nFeeNeeded;
+}
+
diff --git a/src/wallet.h b/src/wallet.h
index 8494ce9a34..a5162bb838 100644
--- a/src/wallet.h
+++ b/src/wallet.h
@@ -25,12 +25,15 @@
// Settings
extern CFeeRate payTxFee;
+extern unsigned int nTxConfirmTarget;
extern bool bSpendZeroConfChange;
// -paytxfee default
static const int64_t DEFAULT_TRANSACTION_FEE = 0;
// -paytxfee will warn if called with a higher fee than this amount (in satoshis) per KB
static const int nHighTransactionFeeWarning = 0.01 * COIN;
+// Largest (in bytes) free transaction we're willing to create
+static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000;
class CAccountingEntry;
class CCoinControl;
@@ -141,6 +144,9 @@ public:
MasterKeyMap mapMasterKeys;
unsigned int nMasterKeyMaxID;
+ // Increment to cause UI refresh, similar to new block
+ int64_t nConflictsReceived;
+
CWallet()
{
SetNull();
@@ -163,6 +169,7 @@ public:
nNextResend = 0;
nLastResend = 0;
nTimeFirstKey = 0;
+ nConflictsReceived = 0;
}
std::map<uint256, CWalletTx> mapWallet;
@@ -261,6 +268,9 @@ public:
std::string SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew);
std::string SendMoneyToDestination(const CTxDestination &address, int64_t nValue, CWalletTx& wtxNew);
+ static CFeeRate minTxFee;
+ static int64_t GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool);
+
bool NewKeyPool();
bool TopUpKeyPool(unsigned int kpSize = 0);
void ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool);
@@ -305,6 +315,13 @@ public:
{
return (GetDebit(tx) > 0);
}
+ bool IsConflicting(const CTransaction& tx) const
+ {
+ BOOST_FOREACH(const CTxIn& txin, tx.vin)
+ if (mapTxSpends.count(txin.prevout))
+ return true;
+ return false;
+ }
int64_t GetDebit(const CTransaction& tx) const
{
int64_t nDebit = 0;
@@ -377,7 +394,7 @@ public:
int GetVersion() { LOCK(cs_wallet); return nWalletVersion; }
// Get wallet transactions that conflict with given transaction (spend same outputs)
- std::set<uint256> GetConflicts(const uint256& txid) const;
+ std::set<uint256> GetConflicts(const uint256& txid, bool includeEquivalent) const;
/** Address book entry changed.
* @note called with lock cs_wallet held.
@@ -699,7 +716,7 @@ public:
void RelayWalletTransaction();
- std::set<uint256> GetConflicts() const;
+ std::set<uint256> GetConflicts(bool includeEquivalent=true) const;
};