Commit graph

1028 commits

Author SHA1 Message Date
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
Josh Rickmar
3ebc4f3600 InsufficientFundsError -> InsufficientFunds 2014-06-20 12:20:47 -05:00
Josh Rickmar
1163b3065e Include amounts with insufficient funds errors.
Closes #102.
2014-06-20 11:58:21 -05:00
Josh Rickmar
938dfa1517 Only log rollbacks for detached txstore blocks.
Instead of logging whenever there is a chain fork + reorg, only log if
a detached block affects the wallet in some manner.
2014-06-20 08:36:28 -05: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
3b436402e0 Search unconfirmed txs when finding prev credits.
If a transaction is added that debits from previous transaction
outputs, and those outputs are still unconfirmed, it is possible that
if the credits were not already known (as is the case with
transactions notified after a sendrawtransaction), only mined unspent
transaction outputs would be searched and the unconfirmed unspent
credits would be missed.  This results in spent outputs still being
marked unspent.

This change fixes the above by also searching through unconfirmed
transactions when the previous credits must be lookup up, rather than
being pass from an AddDebits call.

Fixes issue #91.
2014-06-19 11:49:52 -05:00
Josh Rickmar
632148ed55 Fix various issues found by profiling.
This commit is the result of inspecting the results of both cpu and
memory profiling, to improve areas where wallet can be more efficient
on transaction inserts.

One problem that's very evident by profiling is how much waiting there
is for file (txstore, wallet) writes.  This commit does not attempt to
fix this yet, but focuses on the easier-to-fix memory allocation
issues which can slow down the rest of wallet due to excessive garbage
collection scanning.

While here, fix a race where a closure run as a goroutine was closing
over a range iterator.
2014-06-18 17:08:02 -05:00
Josh Rickmar
a87f827fb9 Remove unneeded check of closed channel. 2014-06-18 09:16:14 -05:00
Josh Rickmar
6a72a0ad4d Pass txstore.Credit/Debits directly, not pointers.
The Credit and Debits structures are simple wrappers around an
embedded *txstore.TxRecord, as well as an output index in the case of
Credit.  This means that a Credit is at most two words, while a Debits
struct is just one.  To avoid the unnecessary garbage of creating
Credit and Debits structures on the heap (where the underlying
TxRecord likely already is), simply pass around everywhere as
non-pointer types, and modify the receivers for all Credit and Debits
methods to non-pointer receivers since none of them ever modify the
value.
2014-06-18 00:16:08 -05:00
Josh Rickmar
9153a342e4 Improve txstore unspent output bookkeeping.
This change "reverses" the mapping used by the transaction store to
reference and lookup unspent credits.  Rather than mapping slice
indexes of a block, and then another block map for slice indexes of
transactions with unspent credits, and requiring a lookup through each
credit for whether it is spent or unspent, keep a simple map of
outpoints to a lookup key to find the transaction in a block.

This has a positive effect on performance when searching for previous
transaction outputs that have been spent by a newly-inserted
transaction.  Rather than iterating through every block with an
unspent credit, and then every transaction with unspent credits, a
simple map lookup can be done to check whether a transaction input's
previous outpoint is marked as unspent by wallet, and then access the
transaction record itself by the lookup key.  While transactions
created by wallet with the sendfrom/many RPCs may mark debits with the
previous credits already known, the previous outputs may still not be
known if a debiting transaction was added by rescan, or notified as a
result of a create+sendrawtransaction.
2014-06-17 22:50:34 -05:00
Josh Rickmar
cb717455c7 Use an unbounded queue for waiting notifications.
Fixes a hang where a send on the notification chan can block due to
the queue being filled, and the current running notification making a
blocking call to the rpc client.

Fixes #100.
2014-06-17 11:49:17 -05:00
Josh Rickmar
83e27ae7db Remove unused goroutine. 2014-06-17 08:38:34 -05:00
Josh Rickmar
0f808dc00f Remove unnecessary uint32 type conversions. 2014-06-16 16:25:04 -05:00
Josh Rickmar
f418fe3772 Remove tx send/recv write order synchronization.
This was only necessary for a very old version of the transaction
store.  The current implementation stores both sent (debit) and
received (credit) records for individual transactions.
2014-06-16 15:47:05 -05:00
Josh Rickmar
afee3e2ca7 No need to check map before removing a key. 2014-06-16 15:32:20 -05:00
Josh Rickmar
aa6892a32a Mark finished rescan from notification.
Fixes #99.
2014-06-16 14:19:32 -05:00
Josh Rickmar
23dca5edfd Fix bug returning unconfirmed txstore records.
The incorrect slice was being appended to, causing some unconfirmedg
records to be dropped from the return result.
2014-06-13 16:17:17 -05:00
Josh Rickmar
145ac3e592 Fix unmined transaction resend logging. 2014-06-13 15:53:05 -05:00
Josh Rickmar
83b70e6c7e Improve tx creation performance.
Unspent inputs were being sorted multiple times in an inner loop.
This change moves the sort outside the loop so it is only performed
once.  While here, also move the transaction confirmation filter
outside the inner loop, as these can be calculated just once.
2014-06-13 14:52:52 -05:00
Josh Rickmar
c0e990fb3f Only use P2PKH outputs as sendfrom/many inputs.
Closes #89.
2014-06-13 13:29:57 -05:00
Josh Rickmar
e7b1fc7e9f Randomize change transaction output index.
Based on a diff created by @dajohi.
2014-06-12 22:30:58 -05:00
Josh Rickmar
e4c0fc81dd Return non-nil RPC results for 0 length slices.
If a JSON array result was successfully calculated, but the
slice/array is empty, the result must be marshaled as '[]' rather than
the JSON null value.  To do this in go, the RPC handlers should never
return nil slices for non-error returns, but return a non-nil slice
header with 0 length.

For example, an empty listtransactions result should be returned as
[]btcjson.ListTransactionsResult{}, rather than nil.
2014-06-12 13:58:23 -05:00
Josh Rickmar
3ff16d7539 Modify websocket endpoint from 'frontend' to 'ws'. 2014-06-12 12:54:58 -05:00
Josh Rickmar
ec92578194 Switch to gorilla websocket and btcrpcclient.
Closes #96.
2014-06-12 11:39:26 -05:00