A secure lbry wallet daemon written in Go
Find a file
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
chain Remove account support, fix races on btcd connect. 2014-07-25 13:26:14 -05:00
keystore Remove account support, fix races on btcd connect. 2014-07-25 13:26:14 -05:00
rename Remove account support, fix races on btcd connect. 2014-07-25 13:26:14 -05:00
txstore Remove account support, fix races on btcd connect. 2014-07-25 13:26:14 -05:00
.gitignore Initial commit. 2013-08-21 10:37:30 -04:00
.travis.yml Update travis 2014-07-22 14:09:04 +03:00
btcwallet.go Remove account support, fix races on btcd connect. 2014-07-25 13:26:14 -05:00
chainntfns.go Remove account support, fix races on btcd connect. 2014-07-25 13:26:14 -05:00
CHANGES Prepare for release 0.4.0. 2014-05-25 19:07:38 -05:00
config.go Remove account support, fix races on btcd connect. 2014-07-25 13:26:14 -05:00
createtx.go Remove account support, fix races on btcd connect. 2014-07-25 13:26:14 -05:00
createtx_test.go Remove account support, fix races on btcd connect. 2014-07-25 13:26:14 -05:00
deps.txt Prepare for release 0.1.0. 2013-11-13 14:08:35 -05:00
disksync.go Remove account support, fix races on btcd connect. 2014-07-25 13:26:14 -05:00
log.go Remove account support, fix races on btcd connect. 2014-07-25 13:26:14 -05:00
params.go Fix simnet RPC port. 2014-05-29 16:32:30 -05:00
README.md Modify websocket endpoint from 'frontend' to 'ws'. 2014-06-12 12:54:58 -05:00
rescan.go Remove account support, fix races on btcd connect. 2014-07-25 13:26:14 -05:00
rpcserver.go Remove account support, fix races on btcd connect. 2014-07-25 13:26:14 -05:00
rpcserver_test.go Throttle RPC and WS concurrent active clients 2014-07-03 13:12:37 -05:00
sample-btcwallet.conf Add support for the simulation test network. 2014-05-29 16:15:32 -05:00
signal.go Implement clean ^C shutdown and add the stop RPC. 2014-06-24 16:00:27 -05:00
version.go Consistantly create empty bytes.Buffers. 2014-06-04 22:23:32 -05:00
wallet.go Remove account support, fix races on btcd connect. 2014-07-25 13:26:14 -05:00

btcwallet

[Build Status] (https://travis-ci.org/conformal/btcwallet)

btcwallet is a daemon handling bitcoin wallet functionality for a single user. It acts as both an RPC client to btcd and an RPC server for wallet clients and legacy RPC applications.

The wallet file format is based on Armory and provides a deterministic wallet where all future generated private keys can be recovered from a previous wallet backup. Unencrypted wallets are unsupported and are never written to disk. This design decision has the consequence of generating new wallets on the fly impossible: a client is required to provide a wallet encryption passphrase.

btcwallet is not an SPV client and requires connecting to a local or remote btcd instance for asynchronous blockchain queries and notifications over websockets. Full btcd installation instructions can be found here.

As a daemon, btcwallet provides no user interface and an additional graphical or command line client is required for normal, personal wallet usage. Conformal has written btcgui as a graphical client to btcwallet.

This project is currently under active development is not production ready yet. Support for creating and using wallets the main Bitcoin network is currently disabled by default.

Installation

Windows - MSI Available

Install the btcd suite MSI here:

https://opensource.conformal.com/packages/windows/btcdsuite/

Linux/BSD/POSIX - Build from Source

  • Install Go according to the installation instructions here: http://golang.org/doc/install

  • Run the following commands to obtain and install btcwallet and all dependencies:

$ go get -u -v github.com/conformal/btcd/...
$ go get -u -v github.com/conformal/btcwallet/...
  • btcd and btcwallet will now be installed in either $GOROOT/bin or $GOPATH/bin depending on your configuration. If you did not already add to your system path during the installation, we recommend you do so now.

Updating

Windows

Install a newer btcd suite MSI here:

https://opensource.conformal.com/packages/windows/btcdsuite/

Linux/BSD/POSIX - Build from Source

  • Run the following commands to update btcwallet, all dependencies, and install it:
$ go get -u -v github.com/conformal/btcd/...
$ go get -u -v github.com/conformal/btcwallet/...

Getting Started

The follow instructions detail how to get started with btcwallet connecting to a localhost btcd.

Windows (Installed from MSI)

Open Btcd Suite from the Btcd Suite menu in the Start Menu. This will also open btcgui, which can be closed if you only want btcd and btcwallet running.

Linux/BSD/POSIX/Source

  • Run the following command to start btcd:
$ btcd --testnet -u rpcuser -P rpcpass
  • Run the following command to start btcwallet:
$ btcwallet -u rpcuser -P rpcpass

If everything appears to be working, it is recommended at this point to copy the sample btcd and btcwallet configurations and update with your RPC username and password.

$ cp $GOPATH/src/github.com/conformal/btcd/sample-btcd.conf ~/.btcd/btcd.conf
$ cp $GOPATH/src/github.com/conformal/btcwallet/sample-btcwallet.conf ~/.btcwallet/btcwallet.conf
$ $EDITOR ~/.btcd/btcd.conf
$ $EDITOR ~/.btcwallet/btcwallet.conf

Client Usage

Clients wishing to use btcwallet must connect to the ws endpoint over a websocket connection. Messages sent to btcwallet over this websocket are expected to follow the standard Bitcoin JSON API (partially documented here). Websocket connections also enable additional API extensions and JSON-RPC notifications (currently undocumented). The btcd packages btcjson and btcws provide types and functions for creating and JSON (un)marshaling these requests and notifications.

Issue Tracker

The integrated github issue tracker is used for this project.

GPG Verification Key

All official release tags are signed by Conformal so users can ensure the code has not been tampered with and is coming from Conformal. To verify the signature perform the following:

  • Download the public key from the Conformal website at https://opensource.conformal.com/GIT-GPG-KEY-conformal.txt

  • Import the public key into your GPG keyring:

    gpg --import GIT-GPG-KEY-conformal.txt
    
  • Verify the release tag with the following command where TAG_NAME is a placeholder for the specific tag:

    git tag -v TAG_NAME
    

License

btcwallet is licensed under the liberal ISC License.