Commit graph

812 commits

Author SHA1 Message Date
Dave Collins
5ec951f6a7 Rework and improve headers-first mode.
This commit improves how the headers-first mode works in several ways.

The previous headers-first code was an initial implementation that did not
have all of the bells and whistles and a few less than ideal
characteristics.  This commit improves the heaers-first code to resolve
the issues discussed next.

- The previous code only used headers-first mode when starting out from
  block height 0 rather than allowing it to work starting at any height
  before the final checkpoint.  This means if you stopped the chain
  download at any point before the final checkpoint and restarted, it
  would not resume and you therefore would not have the benefit of the
  faster processing offered by headers-first mode.
- Previously all headers (even those after the final checkpoint) were
  downloaded and only the final checkpoint was verified.  This resulted in
  the following issues:
  - As the block chain grew, increasingly larger numbers of headers were
    downloaded and kept in memory
  - If the node the node serving up the headers was serving an invalid
    chain, it wouldn't be detected until downloading a large number of
    headers
  - When an invalid checkpoint was detected, no action was taken to
    recover which meant the chain download would essentially be stalled
- The headers were kept in memory even though they didn't need to be as
  merely keeping track of the hashes and heights is enough to provde they
  properly link together and checkpoints match
- There was no logging when headers were being downloaded so it could
  appear like nothing was happening
- Duplicate requests for the same headers weren't being filtered which
  meant is was possible to inadvertently download the same headers twice
  only to throw them away.

This commit resolves these issues with the following changes:

- The current height is now examined at startup and prior each sync peer
  selection to allow it to resume headers-first mode starting from the
  known height to the next checkpoint
- All checkpoints are now verified and the headers are only downloaded
  from the current known block height up to the next checkpoint.  This has
  several desirable properties:
  - The amount of memory required is bounded by the maximum distance
    between to checkpoints rather than the entire length of the chain
  - A node serving up an invalid chain is detected very quickly and with
    little work
  - When an invalid checkpoint is detected, the headers are simply
    discarded and the peer is disconnected for serving an invalid chain
  - When the sync peer disconnets, all current headers are thrown away
    and, due to the new aforementioned resume code, when a new sync peer
    is selected, headers-first mode will continue from the last known good
    block
- In addition to reduced memory usage from only keeping information about
  headers between two checkpoints, the only information now kept in memory
  about the headers is the hash and height rather than the entire header
- There is now logging information about what is happening with headers
- Duplicate header requests are now filtered
2014-02-01 16:33:00 -06:00
Dave Collins
c6d865f3b5 Cleanup and slightly optimize the progress logging.
Previously the logging function which reports on progress was called for
every block, regardless of whether it was an orphan or not.  This could be
confusing since it could show a different number of blocks processed as
compared to the old versus new heights reported (orphans do not add to the
block height since they aren't extending the main chain).  Further, the
database had to be consulted for the latest block since the block we just
processed might not be the latest one if it was an orphan.  This is quite
a bit more time conusming than it should've been for progress reporting.

This commit modifies that to only include non-orphan blocks.  As a result,
the latest height shown will match the number of blocks processed (even
when there are orphans) and the additional block lookup from the database
is avoided.
2014-01-30 12:40:37 -06:00
David Hill
79ff9b76ee add verifymessage to btcctl 2014-01-30 13:26:15 -05:00
David Hill
bd0c799e2f add validateaddress to btcctl 2014-01-30 13:14:28 -05:00
David Hill
9c2abd1fa1 add listreceivedbyaccount and listreceivedbyaddress to btcctl 2014-01-30 13:10:43 -05:00
David Hill
1a64f33fca add listunspent to btcctl 2014-01-30 12:59:26 -05:00
David Hill
ed4ffc44a1 add listlockunspent to btcctl 2014-01-30 12:31:56 -05:00
David Hill
0951ffa1c7 add listaddressgroupings to btcctl 2014-01-30 12:29:21 -05:00
David Hill
ea689489d3 add gettxoutsetinfo to btcctl 2014-01-30 12:23:38 -05:00
David Hill
46709bda08 add getrawchangeaddress to btcctl 2014-01-30 12:19:04 -05:00
David Hill
8749cde081 add getreceivedbyaccount and getreceivedbyaddress to btcctl 2014-01-30 12:08:50 -05:00
David Hill
2b9f5b8932 in getrawmempool verbose mode, initialize depends to an empty array.
this matches bitcoind.

from jrick
ok davec
2014-01-29 22:22:07 -05:00
David Hill
b532860477 sync with btcjson changes to getrawtransaction.
ok oga@
2014-01-29 21:21:58 -05:00
Owain G. Ainsworth
82fca37eae implement the getinfo rpc command.
This contains some wallet inforamtion, but bitcoind if wallet is
disabled returns just the non wallet information. we do the same.
2014-01-29 18:31:33 +00:00
Owain G. Ainsworth
042d9206a1 change some more code over to using newer btcdb apis. 2014-01-29 18:31:33 +00:00
Owain G. Ainsworth
8d930ceed1 convert getdifficulty to getBlockHeaderBySha to save some cycles. 2014-01-29 18:31:33 +00:00
Dave Collins
970c0cdb30 Misc cleanup.
This commit contains various code cleanup such as comment fixes and
function ordering consistency.
2014-01-28 18:57:07 -06:00
David Hill
112525bd7a cleanup sendfrom and sendmany 2014-01-27 21:31:33 -05:00
David Hill
6c9a206709 add keypoolrefill to btcctl 2014-01-27 21:11:59 -05:00
David Hill
34849a181c add listaccounts to btcctl 2014-01-27 21:05:27 -05:00
Owain G. Ainsworth
5cef5bc05c add support for listsinceblock to btcctl 2014-01-27 23:22:09 +00:00
David Hill
2697a0a9ea add settxfee to btcctl 2014-01-27 16:31:48 -05:00
David Hill
c0d6180685 add sendmany to btcctl 2014-01-27 15:57:44 -05:00
David Hill
b354015426 add sendfrom to btcctl 2014-01-27 15:19:39 -05:00
Dave Collins
72afc787e6 Move getinfo RPC method to askwallet list.
The getinfo RPC method requires access to information only available in
the wallet.  Therefore, it has been moved to the list of methods which
return an error information the caller to send the request to the wallet
instead.
2014-01-27 13:52:59 -06:00
David Hill
a5e5903caf add walletlock to btcctl 2014-01-27 13:44:31 -05:00
Josh Rickmar
36e5aa8e92 Add walletpassphrasechange support to btcctl. 2014-01-27 13:39:01 -05:00
David Hill
ffe767c679 add getaddressesbyaccount to btcctl 2014-01-27 13:32:36 -05:00
David Hill
82552e4465 add walletpassphrase to btcctl 2014-01-27 12:49:54 -05:00
David Hill
221352586b add getnewaddress to btcctl 2014-01-27 12:35:20 -05:00
Dave Collins
b9a641ab79 Move getnewaddress RPC method to askwallet list.
The getnewaddress RPC method deals with wallet-related functionality and
therefore has been moved to the list of methods which return an error
information the caller to send the request to the wallet instead.
2014-01-27 10:58:24 -06:00
Dave Collins
0bf4e0e097 Move getblocktemplate/getwork to askwallet list.
Both of these RPC methods require access to information ony available in
the wallet.  Therefore they have been moved to the list of methods which
return an error information the caller to send the request to the wallet
instead.
2014-01-25 22:58:38 -06:00
Dave Collins
d58af1c3cf Make peer state iterator funcs receivers.
Rather than having the iterator functions a separate entities that access
the state to iterate, just expose the iterators as receivers on the state
itself.  This is more consistent with the style used throughout the code
and the other receivers on the state such as Count, OutboundCount, etc.
2014-01-25 22:51:28 -06:00
Dave Collins
fea4109eb2 Add getaddednodeinfo support to btcctl. 2014-01-25 22:50:34 -06:00
Dave Collins
dcef4128b8 Add support for getaddednodeinfo RPC command.
This commit adds full support for the getaddednodeinfo RPC command
including DNS lookups which abide by proxy/onion/tor rules when the DNS
flag is specified.  Note that it returns an array of strings when the DNS
flag is not set which is different than the current version of bitcoind
which is bugged and scheduled to be fixed per issue 3581 on the bitcoind
issue tracker.
2014-01-25 22:50:32 -06:00
David Hill
5736dc05ae add getwork support to btcctl 2014-01-23 15:57:15 -05:00
David Hill
109ca258af sort commands and fix typos 2014-01-23 14:21:41 -05:00
David Hill
136aa95446 add getblocktemplate support to btcctl. 2014-01-23 13:44:28 -05:00
Dave Collins
5859deea7e Improve RPC authentication failure responses.
This commit improves how the legacy RPC server responds to authentication
failures so things like web browsers can react better.  The following
changes have been made:

First, authentication failures were only printing the 401 error response
in the body instead of setting the http status code.  This means the
response had a 200 OK header with a body of 401 Unauthorized.  Therefore
the client would think everything was ok, but see the response as
malformed JSON.

Second, the spec for 401 Unauthorized responses state they must include a
WWW-Authenticate header to instruct the client how to authenticate.
Without this, browsers won't prompt the user for credentials.
2014-01-23 11:27:48 -06:00
Josh Rickmar
8f43dc758e Fix build. 2014-01-22 21:21:05 -05:00
Dave Collins
0d40bf901d Implement alternative auth for websockets.
The previous websocket code required HTTP auth headers to be sent in order
to use the websocket.  While this makes sense for most applications, some
use cases such as javascript-based websockets from browsers do no have the
ability to send headers.

This commit modifies the authentication logic to allow an alternative
authentication mechanism when HTTP auth headers can't be sent.  In
particular, it introduces a new JSON-RPC command named authenticate which
accepts the username and passphrase for the RPC server.  The command is
only required if the connetion has not already been authenticated via HTTP
auth headers and it must be the first command to be received.  Sending any
other command will immediately disconnect the websocket.

ok from @owainga and @jrick.

This closes #77.
2014-01-22 17:40:14 -06:00
Owain G. Ainsworth
9cb5190ac2 add support for the ping rpc command.
And the pingtime and pingwait fields of getpeerinfo.
2014-01-22 16:21:08 +00:00
Owain G. Ainsworth
1487a352da add basic support for the help rpc command. 2014-01-22 16:20:38 +00:00
Josh Rickmar
d3e4bcdcf5 Fix sendrawtransaction for websockets.
This fixes two issues: first, the sendrawtransaction handler had an
extra character in the key in the websocket handler map, preventing
the handler from never running.  Second, a nil pointer dereference was
removed from the handler.

This change fixes the minedtx notifications for btcwallet, since the
websocket-handler now runs instead of falling back to the legacy RPC
handler.
2014-01-20 18:27:27 -05:00
Dave Collins
f12ca20372 Enable memdb support.
This commit adds the btcdb memdb backend as a supported database type.
Note that users will NOT want to run in this mode because, being memory
only, it obviously does not persist the database when shutdown.

It is being added for testing purposes to help prevent constant abuse to
developer's hard drive when churning the block database multiple times a
day.
2014-01-19 20:44:06 -06:00
Dave Collins
f309e899f3 Make use of the new btcdb functions.
This commit switches the handleGetHeadersMsg function to make use of the
new FetchBlockHeightBySha and FetchBlockHeaderBySha functions in btcdb.

Also, while here, nuke the header copy which is no longer required due to
the recent btcwire changes.
2014-01-19 03:05:02 -06:00
Dave Collins
33bb455365 Update for recent btcwire API changes. 2014-01-18 21:15:09 -06:00
Dave Collins
7ad6e235ad Reduce the initial idle timeout to 30 seconds.
This commit reduces the initial idle timeout before version negotiation
has happened on a new peer to 30 seconds.  Previously it could take 5
minutes due to the general idle timeout.
2014-01-18 01:44:34 -06:00
Dave Collins
8c7d44c8dc Add authentication deadline to RPC server cnxns.
Previously it was possible to open a connection to the RPC server, never
authenticate, and idle forever.

This is work toward #68.
2014-01-18 00:08:39 -06:00
Dave Collins
0fbd962f8a Use our own websocket.Server instance.
The websocket.Server used the by websocket.Handler type automatically adds
a handshake function which prevents connections when the Origin header is
not set.  Not all clients send this information and we already require
authentication headers as the auth mechanism anyways.
2014-01-17 16:30:29 -06:00