Commit graph

652 commits

Author SHA1 Message Date
Javed Khan
8759d12617 allow client to disconnect when handlers are done
added a waitgroup on websocketClient to keep track of handler
goroutines specific to the client
2014-08-08 18:33:38 +05:30
Josh Rickmar
8bc6eee32c Begin with root key index when reading keystores.
Instead of using the zero value, explicitly set the last chain index
to -1, which represents the root key.  If no additional keys are read
from the io.Reader, this could result in panics when looking up keys
at index 0, when no additional keys have been created yet.

Fixes #119.
2014-08-06 08:48:17 -05:00
David Hill
9b14cd99f1 Enable ScriptStrictMultiSig when creating or signing txs.
ok @jrick
2014-08-01 14:58:17 -04:00
Josh Rickmar
e7263e48dc Drain chain server connected notifications.
Fixes a possible hang on shutdown.
2014-08-01 11:05:26 -05:00
Guilherme Salgado
ef6aa91b6a Refactor Wallet.txToPairs into smaller functions
Also add a unit test for one of them.
2014-07-31 16:52:52 -03:00
Guilherme Salgado
868625d8c3 Remove a unused channel from chain.NewClient 2014-07-31 14:33:46 -05:00
Josh Rickmar
5e18693d2a Register for ntfns when the RPCS creates wallets.
Previously, registerations for wallet notifications (new txs, changed
account balances) were only passed up to websocket clients if the
wallet was loaded off disk (SetWallet was called with a non-nil
wallet), and not for the case when the RPC server would create the
wallet (if it wasn't created yet, and the user manually created it
with createencryptedwallet).  This change fixes that by registering
for these notifications when this code path is taken.
2014-07-31 08:27:30 -05:00
Josh Rickmar
dd856160aa Save logs to network specific directories.
Fixes #114.
2014-07-30 12:17:19 -05:00
Josh Rickmar
248ea9c08f Send btcdconnected notifications without a wallet.
The notified chain server connection state was being passed through
the wallet and then notified to the RPC server, which prevented this
notification from ever firing if a wallet didn't exist yet.  Instead,
make the RPC server register for these notifications directly from the
chain server RPC client.

I'm not happy with this notification and how it's handled in the code,
but to not break existing clients this change is being made.  Fixing
the notifiation mess and modifying existing clients to use a new
notification API will need to be done sometime later.
2014-07-30 09:47:50 -05:00
Josh Rickmar
400153d7c0 Drain notification registeration channel.
This prevents a hang when attempting to set the wallet (and register
for wallet notifications) when the process is interrupted and the rpc
server begins shutting down.
2014-07-29 08:36:28 -05:00
Josh Rickmar
2b5eefae56 Use btcd-specific RPC user/pass for chain RPC. 2014-07-28 09:52:16 -05:00
Josh Rickmar
549d0920f1 Fix build. 2014-07-28 09:51:49 -05:00
Josh Rickmar
c908a44665 Fix typos from my last commit. 2014-07-28 09:38:44 -05:00
Josh Rickmar
8771664af7 Send btcdconnected ntfns to connected clients.
If a websocket client was already connected and the wallet and/or
chain server is loaded into the rpc server (enabling the handlers
specific to those components), the btcdconnected notifications were
not being sent, and this could break clients that expected the
notification.  I'm not happy with this change, but since this is how
notifications are currently done (unsolicited), and to not break
compatibility yet, I'm adding these back in for now.

Eventually, this notification will require explicit registration
before it is received by a client.  See issue #84.

Closes #115.
2014-07-28 09:33:00 -05:00
Josh Rickmar
cd1aebb68e Remove 'getaddressbalance' extension RPC.
Addresses do no have balances.  In situations where a payment is
required and just a single address was provided, it is better to track
the unspent outputs themselves, rather than watching some artificial
measure of payment.
2014-07-26 10:27:10 -05:00
Josh Rickmar
49b15625b9 Fix sending next queued websocket notification. 2014-07-26 10:15:38 -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
Michalis Kargakis
a4dab8a713 Update travis
Tested on lint.travis-ci.org
2014-07-22 14:09:04 +03:00
Josh Rickmar
7ca16dfe70 Synchronize notifications and client gr shutdown.
The responses chan for a websocket client was being closed by one of
the websocket goroutines, but it was not the only sender to this
channel.  There was also the notification handler, run by the server
to handle notifications to all websocket clients.  It was possible to
hit cases where sends to this channel would still occur (the select
statement doesn't guarantee that the picked channel operation won't
panic, even if there's another that won't).  To fix this, wait on the
client being removed from the notification group, or if the server is
already shutting down, wait on the notification handler completely
closing, to ensure that no more sends to the channel will occur,
before closing the channel.

Fixes #110.
2014-07-14 09:24:41 -05:00
Josh Rickmar
b42ab5b743 Handle *btcjson.Error errors from RPC handlers.
The btcrpcclient package returns RPC errors as *btcjson.Error, but
wallet was only handling btcjson.Error (no pointer) as special.
Handle both.
2014-07-08 15:41:59 -05:00
Josh Rickmar
35b929aa6b go fmt 2014-07-08 14:09:58 -05:00
Josh Rickmar
3dba4ba87d Rename wallet package to keystore.
This package is used solely for the storage of private and public
keys, and the addresses they represent.  Since "wallet" is an
overloaded term and a working wallet requires transaction history as
well, rename this package and its data structures to more clearly
reflect what it is for.
2014-07-08 14:04:31 -05:00
Josh Rickmar
2d9fb71afd Move fee increment to Account structure.
When a BIP0032 wallet is implemented and multiple address chains can
be supported by a single keystore, the Account structure will
represent a single wallet (and be renamed to reflect that change),
rather than keeping the collection of Account structs as currently
managed by the AccountManager.  In preperation for this, and to remove
a global variable, move the fee increment for created transactions to
this structure.  When setting the fee, look it up from the default
account.
2014-07-08 11:33:19 -05:00
Josh Rickmar
0abe6e32bf Updates for untyped btcutil consts. 2014-07-08 11:22:09 -05:00
Javed Khan
9036d36e68 Fix hang during shutdown when client is connected.
Closes #108.
2014-07-08 09:03:03 -05:00
Josh Rickmar
061a220354 Move last seen block to RPC client structure.
Pass the RPC client to the notification handlers.  Update the last
seen block for blockconnected notifications in the client structure
directly, protecting access with a mutex.
2014-07-07 16:57:00 -05:00
Josh Rickmar
770384be12 Write imported multisig addresses to disk.
When the addmultisigaddress RPC was called, the wallet with the
imported address was not being written to disk, and if no more writes
were scheduled, the address could be lost.  This change immediately
writes the updated keystore to disk before the RPC returns.

Closes #98.
2014-07-07 11:23:53 -05:00
Josh Rickmar
ff7ecf5e54 Test active addresses including script addrs. 2014-07-07 10:58:04 -05:00
Josh Rickmar
5a3be85bf4 Mark imported script addresses for their account.
Spotted by @tuxcanfly.
2014-07-07 10:38: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
f8f7eed4ae Pass even byte length strings to hex.DecodeString.
ok @davecgh
2014-07-01 21:05:02 -05:00
Josh Rickmar
e64d948093 Synchronize locking/unlocking of all keystores.
This change fixes the asynchronous deferred locking that used to be
performed after some timeout after a call to walletpassphrase by
managing the locked state of each account in a new account manager
goroutine.  The timeouts for new unlock requests replace any running
timeouts for older requests, rather than allowing previous timeouts to
expire before the most recent one.

Fixes #105.
2014-07-01 10:09:50 -05:00
Dave Collins
478a7ec867 Update for recent btcjson changes.
This commit updates the types to match the recent changes to the btcjson
result types.
2014-06-29 17:48:07 -05:00
Josh Rickmar
2a006cc83a Clean up interface pointer ID handling. 2014-06-27 16:05:01 -05:00
Josh Rickmar
6909e0dc68 Remove stray fmt.Printf. 2014-06-27 16:03:08 -05:00
Josh Rickmar
8cc066b8f3 Exclude locked outputs for listunspent.
Fixes #104.
2014-06-27 15:05:00 -05:00
Josh Rickmar
3ab6db5c7d Exclude immature coinbase outputs for listunspent.
Fixes #103.
2014-06-26 14:59:41 -05:00
David Hill
206d5526b0 Warn on Sync() failure instead of erroring. 2014-06-25 14:52:55 -04:00
Josh Rickmar
c824f2dc74 Shutdown rpc client even if attempting reconnects.
Instead of checking whether the chain server client is currently
connected (as opposed to in a reconnect loop), always shutdown the
client connection so other rpc calls begin erroring.
2014-06-25 12:01:40 -05:00
Josh Rickmar
c0e77b3e2d Add additional server shutdown checking. 2014-06-25 11:40:40 -05:00
Josh Rickmar
72c7d05159 Sync temporary files before closing and renaming. 2014-06-25 09:47:03 -05:00
Josh Rickmar
cb6969843b Remove gettxout and gettxoutsetinfo handlers.
These RPCs should be implemented by btcd (see conformal/btcd#141 and
conformal/btcd#142), so remove them from the RPC handlers map.
2014-06-24 16:59:15 -05:00
Josh Rickmar
5155ea1b28 Wait for account manager shutdown during server shutdown. 2014-06-24 16:11:06 -05:00
Josh Rickmar
b145868a4b Implement clean ^C shutdown and add the stop RPC.
Closes #69.
2014-06-24 16:00:27 -05:00
Josh Rickmar
85af882c13 Implement lockunspent and listlockunspent.
Closes #50.

Closes #55.
2014-06-23 16:59:57 -05:00
Josh Rickmar
879d2cb27f Do not save to disk whether UTXOs are locked.
The lockunspent RPC is volatile, that is, it only locks unspent
transaction outputs from being used as inputs for the duration of the
wallet process, or until the UTXO is unlocked with a later call to
lockunspent.  Therefore, remove the serialization of the lockedness
when writing txstore Credits.

The space which used to contain the locked flag is now unused and may
be used for other flags in the future.
2014-06-23 10:09:42 -05:00
Josh Rickmar
0439cdfab5 Flush logs and run other defers before os.Exit.
As calls os.Exit do not run deferred functions (such as log flushing),
the real main function should simply run a main helper function that,
rather than exiting the program, runs all defers and returns a
possibly non-nil error.  The real main function can then check the
error and close the program with an error exit status when a fatal
error occured.
2014-06-21 10:39:27 -05:00
Josh Rickmar
cf92f1e5df Remove getwork and getblocktemplate handlers.
These are being implemented by btcd, so there's no reason to have
handlers here as well.
2014-06-20 16:08:16 -05:00
Josh Rickmar
43e3652eb1 Fix InsufficientFunds comment.
Apparently gofmt -r doesn't rewrite comments.
2014-06-20 12:22:33 -05:00