Commit Graph

722 Commits

Author SHA1 Message Date
Daniel Cousens 65fd8eb134
torcontrol: only output disconnect if -debug=tor 2017-03-25 20:25:35 +13:00
Wladimir J. van der Laan 975dc649af
torcontrol improvements and fixes
- Force AUTHCOOKIE size to be 32 bytes: This provides protection against
  an attack where a process pretends to be Tor and uses the cookie
  authentication method to nab arbitrary files such as the
  wallet
- torcontrol logging
- fix cookie auth
- add HASHEDPASSWORD auth, fix fd leak when fwrite() fails
- better error reporting when cookie file is not ok
- better init/shutdown flow
- stop advertizing service when disconnected from tor control port
- COOKIE->SAFECOOKIE auth
2017-03-25 20:22:12 +13:00
Wladimir J. van der Laan eb5f63fe58
net: Automatically create hidden service, listen on Tor
Starting with Tor version 0.2.7.1 it is possible, through Tor's control socket
API, to create and destroy 'ephemeral' hidden services programmatically.
https://stem.torproject.org/api/control.html#stem.control.Controller.create_ephemeral_hidden_service

This means that if Tor is running (and proper authorization is available),
bitcoin automatically creates a hidden service to listen on, without user
manual configuration. This will positively affect the number of available
.onion nodes.

- When the node is started, connect to Tor through control socket
- Send `ADD_ONION` command
- First time:
    - Make it create a hidden service key
    - Save the key in the data directory for later usage
- Make it redirect port 8333 to the local port 8333 (or whatever port we're listening on).
- Keep control socket connection open for as long node is running. The hidden service will
  (by default) automatically go away when the connection is closed.
2017-03-25 20:22:09 +13:00
Matt Quinn 8a5ae3c7a9
Consolidate individual references to the current maximum peer connection
value of 125 into a single constant declaration.
2017-03-25 20:22:07 +13:00
Wladimir J. van der Laan 89bccddcd8
rpc: Split option -rpctimeout into -rpcservertimeout and -rpcclienttimeout
The two timeouts for the server and client, are essentially different:

- In the case of the server it should be a lower value to avoid clients
clogging up connection slots

- In the case of the client it should be a high value to accomedate slow
  responses from the server, for example for slow queries or when the
  lock is contended

Split the options into `-rpcservertimeout` and `-rpcclienttimeout` with
respective defaults of 30 and 900.
2017-03-24 09:03:59 +13:00
Wladimir J. van der Laan a659991a2c
http: Disable libevent debug logging, if not explicitly enabled
Add a option "-debug=libevent" to enable libevent debugging for troubleshooting.
Libevent logging is redirected to our own log.
2017-03-24 09:03:59 +13:00
Wladimir J. van der Laan 7ed4d40c61
init: Ignore SIGPIPE
Ignore SIGPIPE on all non-win32 OSes, otherwise an unexpectedly disconnecting
RPC client will terminate the application. This problem was introduced
with the libhttp-based RPC server.

Fixes #6660.
2017-03-24 09:03:59 +13:00
Wladimir J. van der Laan 167b6231c9
Move windows socket init to utility function 2017-03-24 09:03:59 +13:00
Wladimir J. van der Laan 116503c0b8
Fix race condition between starting HTTP server thread and setting EventBase()
Split StartHTTPServer into InitHTTPServer and StartHTTPServer to give
clients a window to register their handlers without race conditions.

Thanks @ajweiss for figuring this out.
2017-03-24 09:03:59 +13:00
Wladimir J. van der Laan 9fb5b94e64
Document options for new HTTP/RPC server in --help 2017-03-24 09:03:59 +13:00
Wladimir J. van der Laan afd64f76ea
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.

- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.

- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral

- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.

- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.

By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.

What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.

Configuration options:

- `-rpcthreads`: repurposed as "number of  work handler threads". Still
defaults to 4.

- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.

- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.

- `-debug=http`: low-level http activity logging
2017-03-24 09:03:59 +13:00
Jack Grigg bec25c91cb
Revert "Closes #1680, temporary fix for rpc deadlock inherited from upstream."
This reverts commit f4404d7b5b.
2017-03-24 09:03:59 +13:00
Simon 07cf426404 Remove stale Qt comments and dead code 2017-03-09 17:04:59 -08:00
zkbot dadb1ab74c Auto merge of #2101 - str4d:2074-tests, r=arcalinea
Bitcoin 0.12 test PRs 1

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6337
- bitcoin/bitcoin#6390
- bitcoin/bitcoin#5515
- bitcoin/bitcoin#6287 (partial, remainder included in bitcoin/bitcoin#6703)
- bitcoin/bitcoin#6465

Part of #2074.
2017-03-03 21:25:03 +00:00
Gavin Andresen abb0e8cced
Testing infrastructure: mocktime fixes
New, undocumented-on-purpose -mocktime=timestamp command-line
argument to startup with mocktime set. Needed because
time-related blockchain sanity checks are done on startup, before a
test has a chance to make a setmocktime RPC call.

And changed the setmocktime RPC call so calling it will not result in
currently connected peers being disconnected due to inactivity timeouts.
2017-03-03 11:46:59 -08:00
Adam Weiss 8550bcfeca
Buffer log messages and explicitly open logs
Prevents stomping on debug logs in datadirs that are locked by other
instances and lost parameter interaction messages that can get wiped by
ShrinkDebugFile().

The log is now opened explicitly and all emitted messages are buffered
until this open occurs.  The version message and log cut have also been
moved to the earliest possible sensible location.
2017-03-03 10:57:23 -08:00
Wladimir J. van der Laan 8d9719e0ef
Improve proxy initialization
Simplify and make the code in AppInit2 more clear.

This provides a straightforward flow, gets rid of .count() (which makes
it possible to override an earlier provided proxy option to nothing), as
well as comments the different cases.
2017-03-03 10:57:12 -08:00
Philip Kaufmann fbbd3cc638
[init] add -blockversion help and extend -upnp help 2017-03-03 10:57:08 -08:00
Pieter Wuille bfa832c7ed
Reduce checkpoints' effect on consensus.
Instead of only checking height to decide whether to disable script checks,
actually check whether a block is an ancestor of a checkpoint, up to which
headers have been validated. This means that we don't have to prevent
accepting a side branch anymore - it will be safe, just less fast to
do.

We still need to prevent being fed a multitude of low-difficulty headers
filling up our memory. The mechanism for that is unchanged for now: once
a checkpoint is reached with headers, no headers chain branching off before
that point are allowed anymore.
2017-03-03 10:57:07 -08:00
Philip Kaufmann db954a65ac
use const references where appropriate 2017-03-03 10:57:05 -08:00
Jack Grigg f42cde3c30
Remove reference to -reindex-chainstate
Revert this when bitcoin/bitcoin#7917 is merged.
2017-02-23 12:42:28 +00:00
Pieter Wuille 5d66d0a11e
Do not ask a UI question from bitcoind 2017-02-23 12:40:45 +00:00
zkbot 93baaeee3e Auto merge of #2081 - daira:1955-single-address-mining, r=bitcartel
Address @str4d's comment on #1965 about the case where -gen is not set

https://github.com/zcash/zcash/pull/1965#discussion_r100414069

Note that the case of calling the ``setgenerate true`` RPC with the wallet disabled was already handled correctly.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2017-02-10 08:58:19 +00:00
Daira Hopwood 3df7c4c8c0 Address @str4d's comment about the case where -gen is not set.
Also avoid shadowing mineToLocalWallet variable.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2017-02-10 00:15:12 +00:00
Jack Grigg b8eb37757b
Require -experimentalmode for wallet encryption 2017-02-09 22:10:58 +00:00
Jack Grigg 1f015f6afa
Add a flag for enabling experimental features 2017-02-09 22:10:58 +00:00
zkbot 0c78782662 Auto merge of #1965 - str4d:1955-single-address-mining, r=bitcartel
Switch miner to P2PKH, add -mineraddress option

Closes #945 and #1955.
2017-02-09 20:58:00 +00:00
zkbot 253c610783 Auto merge of #2050 - str4d:2020-zmq, r=bitcartel
Add ZeroMQ notifications

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6103
- bitcoin/bitcoin#6684
- bitcoin/bitcoin#6686
- bitcoin/bitcoin#6736
- bitcoin/bitcoin#6739
- bitcoin/bitcoin#6743
- bitcoin/bitcoin#6768
- bitcoin/bitcoin#6779
- bitcoin/bitcoin#6810
- bitcoin/bitcoin#6927
- bitcoin/bitcoin#6980 (only upgrading zeromq)
- bitcoin/bitcoin#6680
- bitcoin/bitcoin#7058
- bitcoin/bitcoin#7621
- bitcoin/bitcoin#7335 (only parts affecting `zmq_test.py`)
- bitcoin/bitcoin#7853 (only parts affecting `zmq_test.py`)
- bitcoin/bitcoin#7762
- bitcoin/bitcoin#7993 (only upgrading zeromq)
- bitcoin/bitcoin#8238
- bitcoin/bitcoin#8701
- bitcoin/bitcoin#6685

Closes #2020.
2017-02-09 20:08:15 +00:00
Daira Hopwood 9bba9b37c8 Better error reporting for the !ENABLE_WALLET && ENABLE_MINING case.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2017-02-09 19:31:47 +00:00
zkbot 80a32b2845 Auto merge of #1863 - str4d:1795-config-flag-disable-miner, r=bitcartel
Add compile flag to disable compilation of mining code

Closes #1795
2017-02-09 17:43:43 +00:00
Jack Grigg f49bcdf92b
Add -minetolocalwallet flag, enforced on -mineraddress 2017-02-08 23:37:45 +00:00
Daniel Cousens 6550e97224
init: add zmq to debug categories 2017-02-08 22:11:53 +00:00
Daniel Cousens 57c6ef01d9
init: amend ZMQ flag names 2017-02-08 22:10:42 +00:00
João Barbosa 5015d2b27f
Fix ZMQ Notification initialization and shutdown
Moves the call Initialize() from init.cpp to CreateWithArguments() and handles the
return value. Moves the call Shutdown() from init.cpp to destructor.
Changes Initialize() and Shutdown() to protected members.
2017-02-08 22:10:42 +00:00
Jeff Garzik f200002cf3
Add ZeroMQ support. Notify blocks and transactions via ZeroMQ
Continues Johnathan Corgan's work.
Publishing multipart messages

Bugfix: Add missing zmq header includes

Bugfix: Adjust build system to link ZeroMQ code for Qt binaries
2017-02-08 22:10:42 +00:00
Simon 43b6753782 Update zrpc vs zrpcunsafe logging in z_sendmany operation 2017-02-08 10:50:40 -08:00
Simon 3307124a2b Add parameter interaction, where zrpcunsafe implies zrpc 2017-02-06 23:29:07 -08:00
Jack Grigg 78ba3472d2
Update help text for mining options 2017-02-06 11:55:05 +00:00
Jack Grigg 8e8b6d701b
Switch miner to P2PKH, add -mineraddress option
Closes #945 and #1955.
2017-02-06 11:54:58 +00:00
Jack Grigg 2cc0a252ad
Add compile flag to disable compilation of mining code 2017-01-30 21:14:46 +01:00
Jack Grigg 207924a1d5
Remove OpenSSL PRNG reseeding
Per https://download.libsodium.org/doc/generating_random_data/ reseeding the
default libsodium PRNG is not required.
2017-01-23 17:06:54 +01:00
zkbot c2c7998c2e Auto merge of #1979 - str4d:1786-inform-users-to-fetch-params, r=bitcartel
Instruct users to run zcash-fetch-params if network params aren't available

Closes #1786.
2017-01-19 21:47:26 +00:00
zkbot 78674ca79e Auto merge of #2007 - bitcartel:1097_copyright_notice_and_date, r=bitcartel
Closes #1097 so that zcash-cli displays license info like zcashd.

LicenseInfo is refactored from init.cpp to util.cpp so that the
bitcoin-cli makefile target does not need to be modified.
2017-01-19 00:56:47 +00:00
zkbot 63e0e895a5 Auto merge of #2006 - bitcartel:1497_destination_path_validation_when_exporting, r=bitcartel
Fixes #1497 ZCA-009 by restricting export to a user defined folder and sanitizing filenames
2017-01-18 18:19:50 +00:00
Simon 9064d73bf8 Fixes #1497 ZCA-009 by restricting data exporting to user defined folder.
Previously the RPC interface allowed z_exportwallet, backupwallet and
dumpwallet to write data to an arbitrary filename.  ZCA-009 demonstrates
how this is vulnerable.  The resolution is to only allow data to
written when the -exportdir has been configured.  Also filenames are
restricted to alphanumeric characters.
2017-01-16 10:56:06 -08:00
Simon af02114469 Closes #1097 so zcash-cli now displays license info like zcashd.
LicenseInfo is refactored from init.cpp to util.cpp so that the
bitcoin-cli makefile target does not need to be modified.
2017-01-16 09:38:09 -08:00
Jack Grigg 53e9a6a0e2
Update debug categories
Closes #1954.
2017-01-05 11:56:42 +01:00
Jack Grigg 0b0a48c881
Suggest ./zcutil/fetch-params.sh as well
Once we improve the from-source installation docs to use 'make install', we can
revert this commit.
2017-01-05 11:38:38 +01:00
Jack Grigg bddf4079fd
Instruct users to run zcash-fetch-params if network params aren't available
Closes #1786.
2017-01-04 17:58:07 +01:00
zkbot 9f7bc6cba5 Auto merge of #1904 - str4d:1749-write-witness-cache-with-best-block, r=ebfull
Write witness caches when writing the best block

For steady-state operation, this reduces the average time between wallet disk
writes from once per block to once per hour.

On -rescan, witness caches are only written out at the end along with the best
block, increasing speed while ensuring that on-disk state is kept consistent.

Witness caches are now never recreated during a -reindex, on the assumption that
the blocks themselves are not changing (the chain is just being reconstructed),
and so the witnesses will remain valid.

Part of #1749.
2016-12-09 21:11:15 +00:00