Commit graph

748 commits

Author SHA1 Message Date
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
Josh Rickmar
733677433d Use btcjson.ErrWallet for createencryptedwallet.
If an unexpected error is encounted when creating the encrypted
wallet, rather than using btcjson.ErrInternal, wrap the error message
using btcjson.ErrWallet.Code.
2014-05-30 09:31:42 -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
242cb22719 Check every error.
This change is the result of using the errcheck tool
(https://github.com/kisielk/errcheck) to find all unchecked errors,
both unassigned and those assigned to the blank identifier.

Every returned error is now handled in some manner.  These include:

  - Logging errors that would otherwise be missed
  - Returning errors to the caller for further processing
  - Checking error values to determine what to do next
  - Panicking for truely exceptional "impossible" errors

On the subject of panics, they are a sharp tool and should be used
sparingly.  That being said, I have added them to check errors that
were previously explicitly ignored, because they were expected to
always return without failure.  This could be due to fake error paths
(i.e. writing to a bytes.Buffer panics for OOM and should never return
an error) or previous logic asserts that an error case is impossible.
Rather than leaving these unhandled and letting code fail later,
either with incorrect results or a nil pointer dereference, it now
produces a stack trace at the error emit site, which I find far more
useful when debugging.

While here, a bunch of dead code was removed, including code to move
pre-0.1.1 uxto and transaction history account files to the new
directory (as they would be unreadable anyways) and a big chunk of
commented out rpcclient code.
2014-05-28 00:10:35 -05:00
Josh Rickmar
55cf6c3b22 Fix tests. 2014-05-27 18:22:03 -05:00
Josh Rickmar
4495a523d8 Updates for btcutil and btcscript's btcnet conversion. 2014-05-27 17:49:36 -05:00
Owain G. Ainsworth
2c4ea4e4bc hashtype is not flag based despite having a flag embedded.
So (SigHashAll & SigHashSingle)!= 0, which is not the intention here. fix up
that check to only match SigHashSingle.

Found by drahn, debugged together, fix by me.
2014-05-27 23:46:21 +01:00
Josh Rickmar
c53ada2f71 Prepare for release 0.4.0. 2014-05-25 19:07:38 -05:00
Dave Collins
873cf749f1 Update README.md.
The TODO list was out of date and the issue tracker captures the accurate
information, so replace the TODO list with an Issue Tracker section.
2014-05-25 01:48:11 -05:00
Josh Rickmar
1c0701bb59 Return listunspent results sorted.
Fixes #88.
2014-05-23 10:31:05 -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
987dc8f1c4 Updates for btcutil WIF API changes. 2014-05-21 17:50:47 -05:00
Josh Rickmar
813e1b19e9 go fmt. 2014-05-20 20:09:33 -05:00
Geert-Johan Riemer
3fb569e73d btcec is changed, this fixes btcwallet to work with the new changes. 2014-05-20 10:48:09 -05:00
Josh Rickmar
14a9653d73 Use btcec consts for serialized pubkey lengths. 2014-05-20 08:12:43 -05:00
Josh Rickmar
c9b476e940 Remove useless if branch. 2014-05-16 22:19:48 -05:00