Commit graph

300 commits

Author SHA1 Message Date
Owain G. Ainsworth 75e577c82e RPC TLS Support.
All rpc sockets now listen using TLS by default, and this can not be
turned off. The keys (defauling to the datadirectory) may be provided by
--rpccert and --rpckey. If the keys do not exist we will generate a new
self-signed keypair with some sane defaults (hostname and all current
interface addresses).

Additionally add tls capability to btcctl so that it can still be used.
The certificate to use for verify can be provided on the commandline or
verification can be turned off (this leaves you susceptible to MITM
attacks)

Initial code from dhill (rpc tls support) and jrick (key generation),
cleanup, debugging and polishing from me.
2013-11-19 14:50:31 +00:00
Owain G. Ainsworth 5da5dfe1c4 Add --rpclisten that behaves frighteningly similar to --listen.
Except it works for the rpcserver instead of the main server.

Closes #34
2013-11-19 14:48:58 +00:00
Josh Rickmar 5ec4aaff09 Add importprivkey support to btcctl. 2013-11-18 14:51:31 -05:00
Dave Collins 5bf879dcfc Minor cleanup of some documentation and comments. 2013-11-18 10:38:24 -06:00
Dave Collins 37d3d83ed3 Improve mempool handling.
- Lock the mempool when removing transactions during a notification as
  intended
- When generating the inventory vectors to serve on a mempool request,
  recheck the memory pool for each hash since it's possible another thread
  could have removed an entry after the initial query for available
  hashes
- When a block is connected, remove any transactions which are now double
  spends as a result of the newly connected transactions
2013-11-15 16:23:27 -06:00
David Hill 7b7d4e8555 fix typo - now addresses show up in getrawtransaction 2013-11-15 16:12:08 -05:00
Dave Collins 6b8c10d1fb Don't load default config file in regtest mode.
The regression test mode is special and therefore most likely will not
want to use the same settings that are in the configuration file.  The -C
option can still be used to specify a config file in regression test mode
if desired.
2013-11-15 14:43:36 -06:00
Dave Collins 527a08eb14 Convert chain RuleError to TxRuleError in mempool.
When a transaction is being checked for acceptance into the transation
memory pool, it makes use of a chain function to ensure the invariant rules
for what transactions are allowed into a block are not violated.  That
function returns a btcchain.RuleError if rules are violated.  However,
since this code path is tailored to free-standing transactions, the error
needs to be converted to a TxRuleError so the caller can properly detect
the transaction as a rejected transaction instead of treating it like an
real error.
2013-11-15 11:59:32 -06:00
Dave Collins 166f8c9ae5 Don't relay resurrected transactions.
This commit modifies the transaction memory pool handling so that it does
not relay resurrected transactions.  The other peers on the network will
also be reorganizing to the same block, so they already know about them.
2013-11-15 09:52:47 -06:00
Dave Collins 9fb17c3a6d Improve usage display a little.
This commit makes use of the new default-mask go-flags option in
conjunction with delaying the usage display until after the config file is
parsed.  This has a couple of nice properties such as showing the actual
values that will be used as loaded from the specific config file instead
of the defaults specified in btcd itself, and also allows any config file
parsing errors to be shown prior to displaying the usage.
2013-11-14 20:38:27 -06:00
Dave Collins 50388bcf66 Add more mempool standard checks.
This commit adds a few more checks to restrict what transactions are
allowed into the transaction memory pool and therefore are candidates
to be mined and relayed.

In particular, the following changes were made to what is considered
standard:

- nulldata scripts are now supported and considered standard
- multi-signature transaction are now checked to ensure they only have a
  max of 3 pubkeys and the number of signatures doesn't exceed the number
  of pubkeys
- the number of inputs to a signature script must now match the expected
  number of inputs for the script type (includes support for additional
  pay-to-script-hash inputs)
- the number of inputs pushed onto the stack by a redeeming sig script
  must match the number of inputs consumed by the referenced pk script
- there can now only be a max of one nulldata output per transaction
2013-11-14 17:40:12 -06:00
Dave Collins e3eca752da Allow verbose param on btcctl getrawtransaction. 2013-11-14 12:19:20 -06:00
Dave Collins c3a3fbcabf Don't bother parsing listeners if disabled. 2013-11-13 21:16:49 -06:00
Dave Collins 3902a71bee Minor cleanup. 2013-11-13 21:12:41 -06:00
Dave Collins ac375df71f Use the passed addresses in parseListeners.
Also, check the return error on parseListeners to catch invalid IP
addresses.
2013-11-13 21:02:34 -06:00
Dave Collins 50484c5841 Update sample config file with recent changes.
This commit updates the sample config file to add the new listen option
and update the semantics regarding the combination of --proxy and --tor
flags.
2013-11-13 20:20:32 -06:00
Dave Collins 7b86bec825 Comment new parseLiteners function. 2013-11-13 19:43:36 -06:00
Owain G. Ainsworth 6116a6cb02 Support --listen.
This allows the provision of address/port pairs to be listened on instead
of just providing the port. e.g.:
btcd --listen 1.2.3.4:4321 --listen 127.0.0.01 --listen [::1]:5432

When --proxy and --connect are used, we disable listening *unless* any --listen
arguments have been provided, when we will listen on those addresses as
requested.

Initial code by davec, integration by myself.

Closes #33

allow listens to fail, but warn. error if all failed

fmt
2013-11-14 01:15:47 +00:00
Dave Collins 3108b94401 Add 0.3.3 deps to deps.txt. 2013-11-13 10:53:57 -06:00
Dave Collins 58fdcec6e2 Prepare for release 0.3.3. 2013-11-13 10:52:14 -06:00
Owain G. Ainsworth 31a97d5c09 look up tx in mempool first for getrawtransaction
Closes #26
2013-11-12 22:57:27 +00:00
Owain G. Ainsworth bb276b53aa Add support for the verifychain command.
So far we only do level 0 and level 1 checks (precense and basic
sanity). The checks done at higher levels in bitcoind are closely
coupled with their database layout.

arguably Closes #13
2013-11-12 22:57:26 +00:00
Josh Rickmar 31f27cffd5 Safely remove elements from list.Lists. 2013-11-12 16:24:32 -05:00
Josh Rickmar afc520634f Process all tx notifications, then notify new block.
This change allows wallet to record all transactions in a block before
receving the new block notification, and then process them all
together when the blockconnected notification arrives.
2013-11-12 14:50:33 -05:00
Josh Rickmar 77e1af792b Fix mutex handling for removing minedtx requests.
Previously, RemoveMinedTxRequest was being run from a caller which
held a reader lock for the websocket request contexts.  When
RemoveMinedTxRequest tried to grab a writer lock, it would block.
This change creates a new function, removeMinedTxRequest, that does
not grab any locks, and the caller (NotifyBlockConnected) grabs a
writer lock instead of a reader lock.
2013-11-11 14:23:11 -05:00
Josh Rickmar 8b5413a4ac Always release ws context reader lock.
Previously, on a blockconnected notification, the websocket context
reader lock was not always being given up properly.  This change
defers the unlock so it will always happen.

This fixes an issue where wallet will stop responding (due to not
being able to complete its handshake) on reconnect.
2013-11-11 12:54:49 -05:00
Dave Collins dcf2994905 Add some missed imports in last commit. 2013-11-11 11:52:59 -06:00
Dave Collins 89eae6f590 Update utilities to use new btcutil.AppDataDir.
Closes #30.
2013-11-11 10:58:39 -06:00
Dave Collins 72c186f9a9 Migrate to new app data directories.
This commit makes use of the new btcutil.AppDataDir function which chooses
appropriate data directories for each supported operating system.  It also
adds code to the upgrade path to properly migrate existing data from the
old to new locations.

This is part of work toward issue #30.
2013-11-11 10:58:38 -06:00
Josh Rickmar 41838b83b0 Use btcws package for wallet notifications. 2013-11-08 12:44:00 -05:00
Dave Collins af311078b4 Correct btcctl getblockhash.
Also run gofmt while here.
2013-11-07 17:07:26 -06:00
Owain G. Ainsworth d81a2c9067 Check for 0 shas before dereferencing list 2013-11-07 22:26:43 +00:00
Josh Rickmar ced24946a4 Rework JSON handlers to take a btcjson.Cmd.
This change reworks where the command parsing occurs to be done before
handlers are checked.  Before, the websocket extension handler called
the standard handler with the same message, and if it was unhandled,
would unmarshal it a second time for checking extension handlers.
2013-11-07 13:53:41 -05:00
Josh Rickmar d403863e2b Don't marshal a function for getbestblockhash replies. 2013-11-07 13:53:22 -05:00
Josh Rickmar b97a2145d8 Try to match bitcoind sendrawtransaction RPC errors. 2013-11-07 10:34:55 -05:00
Owain G. Ainsworth c1a1e6b6b2 keep track of connected groups as we gain and lose outbound peers.
Instead of recalculating every time we go to look for more peers. Should
save a few cycles.
2013-11-06 19:08:06 +00:00
Owain G. Ainsworth 6949a4f940 Have a list per class of peer instead of just one.
persistentpeers and outbound(nonpersistent) peers get their own lists,
so iterating over them can be much simpler (and quicker when you have
125 peer of which 8 are outbound).
2013-11-06 19:08:06 +00:00
Owain G. Ainsworth 4d80750afe Move all local data to peerhandler into a peerState structure
Pass peerstate around instead of indivdual bits.
2013-11-06 18:52:58 +00:00
Owain G. Ainsworth d8c5222474 Rework the way we send notifications over the websocket
Redo the datastructures we search so that we only do one lookup per txin and
txout instead of doing a loop per wallet connection.

Don't send spent data on tx notifications, this can be worked out in wallet and
it is expensiveish to calculate. However we DO check upon getting a notification
request if the output is already spent, and in which case we send an immediate
notification to force a rescan.

MinedTxNotfications are handled separately to the connected block messages
largely to enable this to scale rather better.

Tested by jrick (who found one bug i had introduced, thanks!)

Additionally (accidentally squashed in):

Add handlers for all known commands.

We have handlers for all wallet-requiring commands that will return a suitable
error.

Unimplemented commands temporarily return an error stating so.
2013-11-06 18:47:06 +00:00
Josh Rickmar 8c2b9ae06e Begin using btcws.
This change adds support for the unmarshaling custom commands sent by
btcwallet and supported in the btcws package.
2013-11-06 11:20:36 -05:00
John C. Vernaleo b72f0c6474 Make peerinfo output match bitcoind a bit better.
Add long option for username in btcctl.
2013-11-04 16:25:13 -05:00
Josh Rickmar 1f087adf15 Separate ws command handlers into separate funcs. 2013-11-04 14:15:05 -05:00
Josh Rickmar 53e1c2d6bd Stringify the address hash for txRequests map.
This change allows map lookups using address hashes (which are
returned as []byte) instead of either copying the hash into an array,
or doing a bytes.Equal().

A stupid range over a map until the right key is found was also just
changed to a single map lookup.
2013-11-04 14:11:39 -05:00
Josh Rickmar 2511fee152 Complete rescan extension.
This adds to the initial rescan implementation, but switches it to
rescan based on a group of addresses, rather than just one.  Due to
how expensive database lookups are during a rescan, wallets should
take advantage of this to rescan once for all needed addresses for all
accounts.
2013-11-01 09:35:52 -04:00
Dave Collins 5a46de5103 Add support for min required fees in tx mempool.
This commit adds checks to the memory pool to restrict allowed
transactions based on minimum required fees.
2013-10-31 12:24:28 -05:00
Dave Collins a4794798d4 Make use of new btcwire SerializeSize API.
This commit changes the various cases that were serializing transactions
into a buffer and taking the length to use the new faster SerializeSize
API.  It also completes a TODO since the serialized size of a transaction
output is now available.
2013-10-31 00:28:37 -05:00
Dave Collins 470ef8c58e Use correct calls to tx.Sha() in RPC server. 2013-10-30 18:40:55 -05:00
Dave Collins 70094fcee8 Minor cleanup.
Fix a couple of comments and call tx.Sha directly in a couple of places.
2013-10-30 14:13:29 -05:00
Dave Collins b866e9f14c Improve RPC server log of rejected transactions.
Rather than showing all errors from ProcessTransaction as an error, check
if the error is a TxRuleError meaning the transaction was rejected as
opposed to something actually going wrong and log it accordingly.
2013-10-30 14:11:45 -05:00
Dave Collins e76fada2d2 Optimize NotifyNewTxListener.
Looking up transactions from the database is an expensive operation.
This commit modifies the NotifyNewTxListener code to simply iterate the
transactions in the block instead of looking them up from the db.

Currently the wallet code needs a spent flag which ultimately shouldn't be
required.  For now, the spent data is simply created on the fly which is
still significantly faster than doing database transaction lookups.

Closes #24.
2013-10-30 10:54:03 -05:00