Commit graph

715 commits

Author SHA1 Message Date
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
Nicola 'tekNico' Larosa
7ec4e96c6b Implement listreceivedbyaddress.
Closes #53.
2014-06-10 22:19:50 -05:00
Josh Rickmar
99c986e21f Consistantly create empty bytes.Buffers. 2014-06-04 22:23:32 -05:00
Josh Rickmar
d863c75be7 Fix and simplify RPC server error handling.
This change rewrites much of the error handling for the RPC server
components to match a more idiomatic Go error handling style as well as
fix several issues regarding error equality checks.

Closes #94.
2014-06-03 19:55:48 -05:00
Josh Rickmar
0cba485793 Handle unopenable transaction stores.
If the transaction store cannot be opened and read (i.e. the version
is too old to be deserialized), the wallet is marked unsynced and
rewritten, and a new empty transaction store is written over the
previous.
2014-06-03 12:10:42 -05:00
Josh Rickmar
6597d789b7 Avoid slice out-of-bounds indexing panic.
The gettransaction handler was attempting to lookup the "sent-to"
address of an outgoing transaction from the transaction store (as a
wallet credit).  This is the incorrect address when sending to an
address controlled by another wallet, and panics when there are no
credits (for example, sending to another wallet without any change
address).  Instead, use the first non-change output address is used as
the address of the "send" result.

This fixes the panic reported when debugging issue #91.

While here, fix the category strings used for wallet credits to
support immature and generate (the categories for coinbase outputs).
2014-06-02 11:56:38 -05:00
Josh Rickmar
12c50f9611 Fix typo. 2014-06-02 11:15:27 -05:00
Josh Rickmar
9f7c2d60f7 Do not error opening simnet wallets. 2014-05-30 15:53:19 -05:00
Josh Rickmar
03a45d7aa0 Remove closure over a range iterator. 2014-05-30 15:36:04 -05:00
Josh Rickmar
df18578bc9 Use t.Errorf for test formatting directives. 2014-05-30 15:34:39 -05:00
Josh Rickmar
368204a58a Fix rescans across wallet process restarts.
This change immediately writes a new empty transaction store out to
disk if the old one could not be read.  Since old transaction store
versions are not read in at start, and were previously not written out
until new transaction history was received, it was possible that a
full rescan started and finished without ever marking a synced tx
history for the next wallet start.
2014-05-30 15:29:25 -05:00
Josh Rickmar
c7200659d1 go fmt. 2014-05-30 12:46:41 -05:00
Josh Rickmar
454fc3904a No full rescans after rescan completion.
If the rescan finishes before any progress notifications have been
received, also unset the need to perform a full rescan next btcd
reconnect.
2014-05-30 10:37:34 -05:00
Josh Rickmar
2c3845bbbd Prevent full handshake rescans on btcd reconnect.
If a rescan fails (for example, due to a disconnected btcd) in the
btcd handshake, the last block height from a rescanprogress
notification should be used for the next rescan job on next wallet
connect.  Previously, this rescan would always start at the earliest
block height for any wallet address if the transaction store could not
be read at wallet startup.  This change unsets the boolean flag which
would cause a full rescan at next connect when a rescan progress
notification is received and a partial sync height is written.

Fixes #87.
2014-05-30 10:25:32 -05:00