Commit graph

70 commits

Author SHA1 Message Date
Josh Rickmar f3df6c8bc9 Handle flags explicitly set to defaults.
This prevents treating a flag that was explicitly set to the default
as unchanged, since the explicit set is recorded in the new
*cfgutil.ExplicitString flag type.
2016-05-25 09:37:23 -04:00
Josh Rickmar 7704a6d5c3 Switch from forked to upstream flags package.
In https://github.com/btcsuite/btcwallet/pull/419#issuecomment-212482492
I mentioned that btcwallet should wait until btcd also switches back
to upstream package paths so that duplicate packages are not included
in and bloat the btcwallet binary.  Even while btcd has not yet
switched to the upstream flags package, this change can still be made
now since it is only used by btcd's main package, which is not
included in btcwallet.
2016-05-06 12:41:42 -04:00
Josh Rickmar 4d51f8358f Use -b for deprecated --datadir short option.
When 29f31725ee deprecated the datadir
option, replacing it with --appdata/-A, the short --datadir option was
unintentinally changed from -b to -D.  It was previously changed to -b
in fda2e14b99 for consistency with
btcd's --datadir short option.

This change reverts the unintentional switch back to -D.
2016-05-04 17:45:52 -04:00
Josh Rickmar 5e3613775d Make default config relative to appdata directory.
This modifies the default configuration file to be relative to the
application data directory (configuratble with --appdata).  If there
is no configuration file in this directory, then no additional
configuration options are applied (it does not fallback to
~/.btcwallet/btcwallet.conf).

Fixes #421.
2016-04-28 11:21:44 -04:00
Josh Rickmar 178717341e Expand several more config options.
This adds home directory and OS environment variable expansion for the
following configuration options: configfile, appdatadir, rpccert,
rpckey.
2016-04-28 11:16:17 -04:00
Josh Rickmar f91303f507 Lookup actual home directory when expanding ~.
This fixes home directory expansion on Windows and OS X.  Previously
on these platforms, a leading ~ would expand to %LOCALAPPDATA% on
Windows or ~/Library/Application Support/ on OS X.

While here, add support for ~otheruser expansion to expand to
otheruser's home directory.
2016-04-28 11:16:17 -04:00
Josh Rickmar c82b8bae20 Ignore config in current directory by default.
Fixes #415.
2016-04-20 11:08:14 -04:00
Josh Rickmar 29f31725ee Rename datadir/-b options to appdata/-A.
This removes an inconsistency with the datadir option from btcd, which
only set the directory containing the blockchain data and indexes.
2016-04-15 20:30:05 -04:00
Josh Rickmar cee0411a2e Default to mainnet.
Note that this is a breaking change since it removes the mainnet
config option, replacing it with a testnet option.  Old configuration
files that set mainnet=1 will cause the wallet to error during startup
since extraneous flags are treated as errors.

Because configuration files will have to be updated for the change
regardless, the old deprecated (and unused) options `disallowfree` and
`keypoolsize` have also been removed.

Closes #383.
2016-03-11 09:08:38 -05:00
Josh Rickmar f084802fec Refactor wallet transaction creation code.
This began as a change to improve the fee calculation code and evolved
into a much larger refactor which improves the readability and
modularity of all of the transaction creation code.

Transaction fee calculations have been switched from full increments
of the relay fee to a proportion based on the transaction size.  This
means that for a relay fee of 1e3 satoshis/kB, a 500 byte transaction
is only required to pay a 5e2 satoshi fee and a 1500 byte transaction
only need pay a 1.5e3 fee.  The previous code would end up estimating
these fees to be 1e3 and 2e3 respectively.

Because the previous code would add more fee than needed in almost
every case, the transaction size estimations were optimistic
(best/smallest case) and signing was done in a loop where the fee was
incremented by the relay fee again each time the actual size of the
signed transaction rendered the fee too low.  This has switched to
using worst case transaction size estimates rather than best case, and
signing is only performed once.

Transaction input signature creation has switched from using
txscript.SignatureScript to txscript.SignTxOutput.  The new API is
able to redeem outputs other than just P2PKH, so the previous
restrictions about P2SH outputs being unspendable (except through the
signrawtransaction RPC) no longer hold.

Several new public packages have been added:

wallet/txauthor - transaction authoring and signing
wallet/txfees - fee estimations and change output inclusion
wallet/txrules - simple consensus and mempool policy rule checks

Along with some internal packages:

wallet/internal/txsizes - transaction size estimation
internal/helpers - context free convenience functions

The txsizes package is internal as the estimations it provides are
specific for the algorithms used by these new packages.
2016-03-08 17:42:27 -05:00
Josh Rickmar 5140086f6e Use LICENSE file and short license headers. 2016-02-28 22:22:34 -05:00
John C. Vernaleo 2808c4fe40 If wallet already exists show path.
This was initially pointed out by davec in
decred/dcrwallet#18
2016-02-11 10:51:25 -05:00
Josh Rickmar 567752ea9b Add option for one time TLS keys.
This option prevents the RPC server TLS key from ever being written to
disk.  This is performed by generating a new certificate pair each
startup and writing (possibly overwriting) the certificate but not the
key.

Closes #359.
2016-02-11 00:15:30 -05:00
Josh Rickmar fda2e14b99 Change datadir short option to -b.
Fixes #339.
2016-02-01 17:39:04 -05:00
Josh Rickmar 497ffc11f0 Modernize the RPC server.
This is a rather monolithic commit that moves the old RPC server to
its own package (rpc/legacyrpc), introduces a new RPC server using
gRPC (rpc/rpcserver), and provides the ability to defer wallet loading
until request at a later time by an RPC (--noinitialload).

The legacy RPC server remains the default for now while the new gRPC
server is not enabled by default.  Enabling the new server requires
setting a listen address (--experimenalrpclisten).  This experimental
flag is used to effectively feature gate the server until it is ready
to use as a default.  Both RPC servers can be run at the same time,
but require binding to different listen addresses.

In theory, with the legacy RPC server now living in its own package it
should become much easier to unit test the handlers.  This will be
useful for any future changes to the package, as compatibility with
Core's wallet is still desired.

Type safety has also been improved in the legacy RPC server.  Multiple
handler types are now used for methods that do and do not require the
RPC client as a dependency.  This can statically help prevent nil
pointer dereferences, and was very useful for catching bugs during
refactoring.

To synchronize the wallet loading process between the main package
(the default) and through the gRPC WalletLoader service (with the
--noinitialload option), as well as increasing the loose coupling of
packages, a new wallet.Loader type has been added.  All creating and
loading of existing wallets is done through a single Loader instance,
and callbacks can be attached to the instance to run after the wallet
has been opened.  This is how the legacy RPC server is associated with
a loaded wallet, even after the wallet is loaded by a gRPC method in a
completely unrelated package.

Documentation for the new RPC server has been added to the
rpc/documentation directory.  The documentation includes a
specification for the new RPC API, addresses how to make changes to
the server implementation, and provides short example clients in
several different languages.

Some of the new RPC methods are not implementated exactly as described
by the specification.  These are considered bugs with the
implementation, not the spec.  Known bugs are commented as such.
2016-01-29 11:18:26 -05:00
Josh Rickmar b0566e09c8 Separate out default ports and utility funcs.
This change moves the chain and network parameter definitions, along
with the default client and server ports, to a package for reuse by
other utilities (most notably, tools in the cmd dir).  Along with it,
functions commonly used for config parsing and validation are moved to
an internal package since they will also be useful for distributed
tools.
2015-11-25 01:02:50 -05:00
Josh Rickmar 5843c0bc66 Move legacy under internal directory.
After Go 1.5, this will prevent consumers from importing these
packages since they are currently unmaintained.

Closes #232.
2015-05-27 10:12:24 -04:00
Dave Collins c820c8a015 Relicense to the btcsuite developers. 2015-05-01 12:20:05 -05:00
Manan Patel dfe617e05d create wallet package
This a refactor of the btcwallet main package to create a new wallet
package.
The main feature of this package is the integration of all the other
wallet components (waddrmgr, txstore, and chain) and the Wallet type is
'runnable', so it will be continuously updating itself against changes
notified by the remote btcd instance.

It also includes several methods which provide access to information
necessary to run a wallet RPC server.
2015-04-02 11:17:45 -07:00
cjepson cec3dc3e83 Add new --createtemp flag to btcwallet.
The createtemp flag is used to create a temporary simnet wallet for
use with btcsim or other testing suites.

The flag only works if the datadir and network to use it on (simnet)
are specified.

After starting btcwallet with the flag, the wallet immediately opens
and is functional.
2015-03-05 23:03:10 -05:00
Dave Collins 8f9f53a618 Switch to new waddrmgr package
This commit converts the wallet to use the new secure hierarchical
deterministic wallet address manager package as well as the walletdb
package.

The following is an overview of modified functionality:

- The wallet must now be created before starting the executable
- A new flag --create has been added to create the new wallet using wizard
  style question and answer prompts
- Starting the process without an existing wallet will instruct now
  display a message to run it with --create
- Providing the --create flag with an existing wallet will simply show an
  error and return

In addition the snacl package has been modified to return the memory after
performing scrypt operations to the OS.

Previously a runtime.GC was being invoked which forced it to release the
memory as far as the garbage collector is concerned, but the memory was
not released back to the OS immediatley.  This modification allows the
memory to be released immedately since it won't be needed again until the
next wallet unlock.
2015-03-02 11:55:42 -06:00
Dave Collins 23c9dc423e Update btcwire path import paths to new location. 2015-02-05 15:41:38 -06:00
Dave Collins 283aa28be5 Update btcwire import paths to new location. 2015-01-16 16:03:04 -06:00
Dave Collins f7b4b5e71d Update go-flags import paths to new location. 2015-01-16 01:01:04 -06:00
Dave Collins afeb509c45 Update btcutil import paths to new location. 2015-01-15 10:48:58 -06:00
Javed Khan edaddb0d95 Allow disabling RPC client TLS for localhost only.
This commit introduces a new flag, --noclienttls, which can be used to disable
TLS for the RPC client.  However, the flag can only be used when the RPC
client is connecting to localhost interfaces.  This is intended to prevent
accidentally leaking sensitive data when switching between local and
remote servers.
2015-01-09 21:36:48 +05:30
Javed Khan 469a6f86eb Allow disabling RPC server TLS for localhost only.
This commit introduces a new flag, --noservertls, which can be used to disable
TLS for the RPC server.  However, the flag can only be used when the RPC
server is bound to localhost interfaces.  This is intended to prevent the
situation where someone decides they want to expose the RPC server to the
web for remote management/access, but forgot they have TLS disabled.
2015-01-09 15:07:06 +05:30
Josh Rickmar dd856160aa Save logs to network specific directories.
Fixes #114.
2014-07-30 12:17:19 -05:00
Josh Rickmar b9fd527d33 Remove account support, fix races on btcd connect.
This commit is the result of several big changes being made to the
wallet.  In particular, the "handshake" (initial sync to the chain
server) was quite racy and required proper synchronization.  To make
fixing this race easier, several other changes were made to the
internal wallet data structures and much of the RPC server ended up
being rewritten.

First, all account support has been removed.  The previous Account
struct has been replaced with a Wallet structure, which includes a
keystore for saving keys, and a txstore for storing relevant
transactions.  This decision has been made since it is the opinion of
myself and other developers that bitcoind accounts are fundamentally
broken (as accounts implemented by bitcoind support both arbitrary
address groupings as well as moving balances between accounts -- these
are fundamentally incompatible features), and since a BIP0032 keystore
is soon planned to be implemented (at which point, "accounts" can
return as HD extended keys).  With the keystore handling the grouping
of related keys, there is no reason have many different Account
structs, and the AccountManager has been removed as well.  All RPC
handlers that take an account option will only work with "" (the
default account) or "*" if the RPC allows specifying all accounts.

Second, much of the RPC server has been cleaned up.  The global
variables for the RPC server and chain server client have been moved
to part of the rpcServer struct, and the handlers for each RPC method
that are looked up change depending on which components have been set.
Passthrough requests are also no longer handled specially, but when
the chain server is set, a handler to perform the passthrough will be
returned if the method is not otherwise a wallet RPC.  The
notification system for websocket clients has also been rewritten so
wallet components can send notifications through channels, rather than
requiring direct access to the RPC server itself, or worse still,
sending directly to a websocket client's send channel.  In the future,
this will enable proper registration of notifications, rather than
unsolicited broadcasts to every connected websocket client (see
issue #84).

Finally, and the main reason why much of this cleanup was necessary,
the races during intial sync with the chain server have been fixed.
Previously, when the 'Handshake' was run, a rescan would occur which
would perform modifications to Account data structures as
notifications were received.  Synchronization was provided with a
single binary semaphore which serialized all access to wallet and
account data.  However, the Handshake itself was not able to run with
this lock (or else notifications would block), and many data races
would occur as both notifications were being handled.  If GOMAXPROCS
was ever increased beyond 1, btcwallet would always immediately crash
due to invalid addresses caused by the data races on startup.  To fix
this, the single lock for all wallet access has been replaced with
mutexes for both the keystore and txstore.  Handling of btcd
notifications and client requests may now occur simultaneously.
GOMAXPROCS has also been set to the number of logical CPUs at the
beginning of main, since with the data races fixed, there's no reason
to prevent the extra parallelism gained by increasing it.

Closes #78.

Closes #101.

Closes #110.
2014-07-25 13:26:14 -05:00
Tomás Senart 9f4bfeb056 Throttle RPC and WS concurrent active clients
This change set implements tunable concurrent active clients throttling.
2014-07-03 13:12:37 -05:00
Tomás Senart def3543ba6 goimports -w . 2014-07-03 13:45:40 +02:00
Josh Rickmar d75a3fc4e7 Fix logdir config struct tag. 2014-06-20 08:29:54 -05:00
Josh Rickmar ad72d3a400 Add basic transaction store logging.
The info log level (default) will produce output about confirmed and
unconfirmed transactions being inserted into the store, as well as
unconfirmed transactions which have been mined into blocks.  By
enabling the debug log level (-d TXST=debug), additional information
about transaction inputs and outputs is logged.  This includes the
total amount of previously-unspent outputs which have been marked
spent by the inserted transaction, and the output indexes and amounts
for each spendable output.  Additionally, the debug log level will log
whenever transactions are removed due to being a double spend of
another inserted transaction.
2014-06-19 18:16:13 -05:00
Josh Rickmar 12c50f9611 Fix typo. 2014-06-02 11:15:27 -05:00
Josh Rickmar 55564dc31f Fix simnet RPC port.
18555 is the network port, and wallet cannot listen on this port.
Instead, follow the pattern laid out by mainnet, testnet3, and regtest
by listening on 18554 (one less than the network port).
2014-05-29 16:32:30 -05:00
Josh Rickmar 6398dc098e Add support for the simulation test network. 2014-05-29 16:15:32 -05:00
Josh Rickmar 04338d31c9 Handle alternate data directories.
If the data directory is modified on the command line or from the
config file, all paths relative to the directory, if unmodified, must
be changed to reference it.
2014-05-28 12:55:37 -05:00
Josh Rickmar c3224f4fbc Begin update to use btcnet.Params.
This is an intial pass at converting the btcwallet and deps codebases
to pass a network by their parameters, rather than by a magic number
to identify the network.  The parameters in params.go have been
updated to embed a *btcnet.Params, and all previous uses of cfg.Net()
have been replaced with activeNet.{Params,Net} (where activeNet is
the global var for the active network).

Although dependancy packages have not yet been updated from using
btcwire.BitcoinNet to btcnet.Params, the parameters are now accessible
at all callsites, and individual packages can be updated to use btcnet
without requiring updates in each external btc* package at once.

While here, the exported API for btcwallet internal library packages
(txstore and wallet) have been updated to pass full network parameters
rather than the btcwire definition of a network.
2014-05-22 21:24:08 -05:00
Josh Rickmar 461111cadf Allow alternative btcd RPC server auth.
This change adds the new btcdusername and btcdpassword options which,
if set, are used instead of the username and password when
authenticating to a btcd RPC server.  If these new options are unset,
the btcd user and password settings are shared with the client auth
settings.
2014-05-16 12:58:33 -05:00
Josh Rickmar 17ebf9461f Rename connect option to rpcconnect.
The connect option is already used by btcd to force a connection to
other full node peers.  Wallet does not talk directly with these
peers, so the connect option is being renamed to something unique for
an RPC client connection.
2014-05-06 13:25:56 -05:00
Josh Rickmar 361a74fcaf Rename listen option to rpclisten.
This matches the use of the rpclisten option in btcd to specify the
listening interfaces and ports for an RPC server.
2014-05-06 12:50:39 -05:00
Josh Rickmar 00403c7839 Use []Type{} instead of make([]Type, 0). 2014-04-11 13:58:04 -05:00
Josh Rickmar 0d903a5a29 Invert allowfree option.
Boolean options cannot be unset from a default true value on the
command line, so invert the allowfree option, renaming it
disallowfree, so attaching fees may always be forced by specifying
disallowfree = true in the configuration file, or --disallowfree on
the command line.
2014-01-28 12:55:42 -05:00
Josh Rickmar 845d54da55 Add allowfree configuration option.
It may be desirable to never allow free transactions, even if the
calculated priority is high enough that a fee would not be required,
so this change adds a global configuration option to remove this check
and always attach a fee.
2014-01-27 16:58:49 -05:00
Josh Rickmar f0c649b7ac Make maximum keypool size a config option. 2014-01-15 17:29:01 -05:00
Josh Rickmar ebcaa95b35 Use smarter btcd cert path logic.
If ~/.btcwallet/btcd.cert does not exist and the CA file has not been
explicitly set using the config file or command line flags, it's
possible that the cert can be found in ~/.btcd.  If connecting to a
localhost btcd and the previous statements are true, the default CA
file config option is updated for the certificate in them btcd
homedir.

If ~/.btcwallet/btcd.cert does exist and the CA file has not been set,
it is used without checking for a cert in the btcd homedir.
2014-01-10 11:39:03 -05:00
Josh Rickmar a6e0f3bc2a Update copyright years on remaining files. 2014-01-09 14:13:26 -05:00
Josh Rickmar 42055d5b7c Fix sample listen address in config. 2014-01-09 10:51:33 -05:00
Josh Rickmar 5f1fb8b874 Enable --mainnet flag.
This change enables the --mainnet flag to connect to a mainnet btcd
instance and open and create mainnet wallets.  Attempting to connect
to a testnet btcd, or opening a testnet wallet when running in mainnet
mode will result in an error printed to the logging output.

Testnet (version 3) remains the default network for now.  btcwallet
will continue to receive fixes and new features, but at the moment we
believe that early adopters familar with using btcwallet on testnet
can safely use it for mainnet now as well.

Reminder: when dealing with mainnet coins, it is always a good idea to
keep backups of your wallet.  btcwallet uses a deterministic wallet,
and any later addresses for an account can be recreated with just the
account's original wallet file (this does *not* include imported
addresses).  Might we recommend Cyphertite for a backup solution?
2013-12-09 17:44:19 -05:00
Josh Rickmar 9be84e3489 Set connect option based on active net params. 2013-12-09 16:46:38 -05:00