Commit graph

247 commits

Author SHA1 Message Date
Wilmer Paulino
c853ceaa60
wallet/wallet: consolidate rollback logic
In this commit, we consolidate the existing rollback logic to carry out
its duties under one database transaction.

Co-authored-by: Roei Erez <roeierez@gmail.com>
2019-01-14 22:42:45 -08:00
Wilmer Paulino
db837f1ba3
wallet/wallet: use new syncToBirthday and recovery methods
In this commit, we refactor the wallet's syncing logic with
syncWithChain to use the newer, simpler methods: syncToBirthday and
recovery. Along the way, we also fix a bug within the wallet where it
was possible to sync past the birthday, but not sync to tip completely
and restart, which would lead to us starting a rescan from the latest
synced height, rather than from the birthday stamp.

This commit slightly changes the wallet's syncing behavior to the
following:

  1. Ensure the wallet is synced to its birthday.
  2. Perform a recovery if requested.
  3. Check for chain reorgs.
  4. Dispatch a rescan from the current synced height.

Co-authored-by: Roei Erez <roeierez@gmail.com>
2019-01-14 22:42:45 -08:00
Wilmer Paulino
29e1f0c4fb
wallet/wallet: add new recovery method
In this commit, we add a new recovery method to the wallet. This method
attempts to recover any unspent outputs which pay to any of the wallet's
addresses. Most of the logic found within it is heavily borrowed from
the existing syncWithChain method. This method is currently unused, but
it will end up replacing some of the existing sync logic in a later
commit.
2019-01-14 22:42:45 -08:00
Wilmer Paulino
089cc747db
wallet/wallet: add new syncToBirthday method
In this commit, we add a new syncToBirthday method to the wallet. This
method intends to sync the wallet's point of the view of the chain until
finding its birthday. Most of the logic found within it is heavily
borrowed from the existing syncWithChain method. This method is
currently unused, but it will end up replacing some of the existing sync
logic in a later commit.

Co-authored-by: Roei Erez <roeierez@gmail.com>
2019-01-14 22:42:45 -08:00
Wilmer Paulino
80450c9033
wallet/chainntfns: make birthdaySanityCheck return ErrBirthdayBlockNotSet 2018-11-20 13:00:45 -08:00
Wilmer Paulino
cc77e41198
wallet/chainntfns: set height for new birthday block candidate
In this commit, we address an issue that would cause users to be stuck
in an infinite loop by fetching the same candidate birthday block due to
its height not being updated if the sanity check was attempting to fix
an estimate in the future. We fix this by setting the new candidate
height so that new candidate blocks can be fetched and tested.
2018-11-19 20:48:14 -08:00
Wilmer Paulino
f92cc4db42
wallet/chainntfns_test: add birthdaySanityCheck tests 2018-11-19 20:48:14 -08:00
Wilmer Paulino
03a818efaa
wallet/chainntfns: remove wallet dependency from birthdaySanityCheck
In this commit, we remove the wallet dependency from the
birthdaySanityCheck function. Every interaction with the wallet is now
backed by two interfaces, birthdayStore and chainConn. These interfaces
will allow us to increase the test coverage of the birthdaySanityCheck
as now we'll only need to mock out only the necessary functionality.
2018-11-19 20:48:14 -08:00
Wilmer Paulino
bd95bfa6fb
wallet/wallet: prompt sanity check upon setting new birthday block within ImportPrivateKey
In this commit, we set the verified bit to false upon setting the new
birthday block to ensure its correctness as it was provided by the caller.
2018-11-15 18:17:56 -08:00
Wilmer Paulino
16ea72e95b
wallet/wallet: update to latest SetBirthdayBlock changes 2018-11-15 18:17:56 -08:00
Wilmer Paulino
f9df4908b3
wallet/chainntfns: prevent sanity check if correctness of birthday block has been verified
In this commit, we prevent any further sanity check attempts by the
wallet if its correctness has previously been verified. We do this to
ensure we don't unnecessarily attempt to find a new candidate.
2018-11-15 18:17:56 -08:00
Wilmer Paulino
4f5baed780
wallet/wallet: prevent always rescanning from birthday block
In this commit, we address an issue with the wallet where it would
always request a rescan from the birthday block. This is very crucial
for older wallets, as it'll potentially go through thousands of blocks.
To address this, we'll now only request a rescan from our birthday if
we're recovering our wallet from our seed, the birthday block was rolled
back, or if we're performing our initial sync. Otherwise, we'll request
a rescan from tip.
2018-11-15 16:34:42 -08:00
Wilmer Paulino
31011de227
wtxmgr+wallet: add wtxmgr sublogger 2018-11-14 18:09:10 -08:00
Wilmer Paulino
ae31984630
wallet: request notification of tx confirmation that pays to relevant addr
In this commit, we address a slight regression within the wallet
that was introduced in a previous commit. When attempting to send coins
on-chain, we would never ask the chain backend to notify us of the
transaction upon confirmation. This, along with the rebroadcast of
unconfirmed transactions logic, would result in the wallet becoming out
of sync with the chain.

Below is an example of how this could have happened:

  1. Send funds on-chain.
  2. Wallet doesn't ask to be notified of the confirmation.
  3. Since the wallet is not notified of the confirmation, the
  transaction remains in the unconfirmed bucket, even though it might
  have already confirmed on-chain.
  4. Restart and trigger the rebroadcast of unconfirmed transactions.
  5. The unconfirmed transaction is removed from the unconfirmed bucket
  due to it already existing on-chain, without it being moved to the
  confirmed bucket. Moving to the confirmed bucket would require the
  block at which it confirmed, which we don't have at this point.
2018-11-14 18:06:26 -08:00
Wilmer Paulino
4976c84f8f
wallet/wallet: prevent logging resend tx error if already accepted into
mempool
2018-11-14 18:06:25 -08:00
Wilmer Paulino
71ead8e3b4
wallet/wallet: commit birthday blockstamp upon initial sync/recovery 2018-11-14 17:24:00 -08:00
Wilmer Paulino
603e03de32
wallet/chainntnfs: add sanity check for birthday block before syncing
In this commit, we add a sanity check for the wallet's birthday block
before syncing as a result of the migration that populated it for
existing wallets. This is done as the second part to the migration to
ensure we do not miss any relevant events throughout rescans.

The sanity check performs two main checks: whether the birthday block
timestamp reflects a time before the birthday timestamp and whether the
delta between these two timestamps is a reasonable amount. The birthday
block is then found as the first candidate that satisfies both of these
conditions.
2018-11-14 17:24:00 -08:00
Wilmer Paulino
709fa17540
waddrmgr+wallet: add waddrmgr log to the wallet 2018-11-12 08:56:31 -08:00
Wilmer Paulino
33629dcfc2
wallet/wallet: set birthday block when importing private key 2018-11-12 08:56:31 -08:00
Olaoluwa Osuntokun
6d43b2e29b
Merge pull request #568 from joostjager/output-indices
wallet: return full tx from SendOutputs
2018-11-07 16:38:07 +11:00
Olaoluwa Osuntokun
ea4b832693
Merge pull request #567 from wpaulino/wtxmgr-migrations
wallet: add atomic migration logic for sub-buckets
2018-11-07 16:36:42 +11:00
Joost Jager
b718296188
wallet: return full tx from SendOutputs 2018-11-06 10:40:37 +01:00
Wilmer Paulino
df36d100e5
wallet/wallet: only set new birthday if before current within
ImportPrivateKey

In this commit, we ensure that when an external private key is imported
into the wallet, that we do not overwrite our existing birthday with the
one provided. If this were to happen and we forced a wallet rescan using
the birthday as our starting point, then we'd miss detecting relevant
on-chain events that occurred between them.
2018-11-05 18:23:15 -08:00
Wilmer Paulino
105faf52cb
wallet/log: use migration logger 2018-11-05 17:58:16 -08:00
Wilmer Paulino
69cb45e3e7
wallet/wallet: use new migration logic for waddrmgr and wtxmgr
In this commit, we modify the wallet to use the new migration logic
provided by the recently introduced migration package. Additionally,
we'll also perform all of our upgrades within the same database
transaction to guarantee fault-tolerance of the wallet.
2018-11-05 17:58:16 -08:00
Johan T. Halseth
d791cb7c30
wallet: always wait for Neutrino IsCurrent during initial sync 2018-10-16 18:18:46 -07:00
Olaoluwa Osuntokun
fd0bac8e18
wallet: add godoc to publishTransaction 2018-09-25 19:19:20 -07:00
Olaoluwa Osuntokun
f7085cf1bf
wallet: relax initial sync detection logic to speed up sync in case of mid restart
In this commit, we relax the initial sync detection logic a bit. We do
this as right now, if a user creates an address during the sync point,
if they restart, then we'll fall back to performing a rescan from that
height as we'll detect that we aren't performing the initial sync, so
won't pick up the birthday timestamp.

To fix this, we now declare that if we have no UTXO's, then we're still
performing the initial sync. This solves this issue as when the user
restarts, we'll continue to wait for the backend to sync, and pick up
the proper birthday height before we attempt to scan forward for the
rescan. However, the one tradeoff is that we'll now always start the
rescan from the birthday height until the wallet has gained it's first
UTXO. I don't think this is too bad, as after all, the point of a wallet
is to manage utxos.
2018-09-25 19:19:04 -07:00
Wilmer Paulino
db51e8b8de
wallet/wallet: use publishTransaction within SendOutputs 2018-09-20 19:04:30 -07:00
Wilmer Paulino
c125b59df4
wallet/wallet: refactor PublishTransaction to use unexported method
In this commit, we refactor the logic outside of PublishTransaction into
another unexported method. This will pave the road for unifying the
logic between SendOutputs and PublishTransaction.
2018-09-20 18:59:02 -07:00
Wilmer Paulino
06e70c0f08
wallet/wallet: use addRelevantTx when publishing transactions
In this commit, we simplify the logic when broadcasting transactions to
the greater network. Rather than special casing when running with a
Neutrino backend, we'll always add the transaction to the store as
relevant when attempting to broadcast it. This will properly insert it
into the store and update unconfirmed balances. In the event that the
transaction failed to broadcast, it can be removed from the store with
no side-effects, essentially acting as if the transaction was never
added to the store in the first place.
2018-09-20 18:58:34 -07:00
Olaoluwa Osuntokun
421298df22
Merge pull request #542 from wpaulino/bitcoind-client-birthday
chain+wallet: set bitcoind client birthday after wallet init
2018-09-12 20:41:30 -07:00
Olaoluwa Osuntokun
54a82426c8
Merge pull request #543 from Roasbeef/neutrino-ntfn
wallet: allow SendOutputs to notify new outgoing transactions for neu…
2018-09-12 20:21:40 -07:00
Olaoluwa Osuntokun
0cfe15c0c7
wallet: allow SendOutputs to notify new outgoing transactions for neutrino
In this commit, we modify the SendOutputs method to also notify new
outgoing transctions for neutriino. For the full node backends, they'll
get this notification when the transactino hits the mempool. However,
for neutrino it will only be notified once the transaction has been
confirmed. This commit ensures that we'll notify on send as well.
2018-09-12 19:25:06 -07:00
Wilmer Paulino
ed47296c88
wallet: set chain client birthday after the wallet has been initialized 2018-09-12 14:25:11 -07:00
Wilmer Paulino
aca9bebfab
wallet/chainntfns: avoid notifying txs if not found within the wallet
In this commit, we avoid notifying clients of transactions that we've
received chain.RelevantTx notifications for, but are not found within
the wallet. This can happen as now we'll prevent adding an unconfirmed
transaction to the wallet that already exists as confirmed. Due to this,
UniqueTxDetails will be unable to find the transaction and return nil,
casuing a panic for potential callers.
2018-09-06 19:42:13 -07:00
Olaoluwa Osuntokun
8ae4afc701
Merge pull request #536 from cfromknecht/birthday-block-rescan
wallet: start initial rescan from birthday block
2018-09-03 18:05:40 -07:00
Conner Fromknecht
0c5c8d7f9e
wallet/wallet: start initial rescan from birthday block 2018-08-31 16:49:11 -07:00
Conner Fromknecht
e508a127b6
wallet/wallet: notify addrs+props after db commit
This PR moves any address notifications outside of the
db transaction that creates them. This is known to have
resulted in deadlocks, since chainClient.NotifyReceived
could block the db transaction from committing.

Doing so also prevents the situation where we send
notifications about the new addresses, but the db txn
fails to commit and the addresses are in fact never
created.
2018-08-31 16:30:39 -07:00
Conner Fromknecht
dfa3a88529
wallet/rescan: add rescanWithTarget helper
This commit adds rescanWithTarget, in order to facilitate
rescans beginning a certain height. This is done as a
precursor to fixing a bug in the initial sync, that would
cause us to miss relevant txns if they are confirmed before
starting the initial rescan.
2018-08-30 19:40:06 -07:00
Olaoluwa Osuntokun
7d0d499cd0
wallet: remove txns from store if they're in the chain, or have a negative output 2018-08-22 20:20:54 -07:00
Olaoluwa Osuntokun
1fbdc8c44b
wallet: catch and return error from rollback failure 2018-08-14 18:17:47 -07:00
Wilmer Paulino
dec9978ca2 wallet: stop handling chain notifications once wallet has stopped
In this commit, we alter the behavior for handling chain notifications
within the wallet. The previous code would assume that the channel would
close, but due to now using a ConcurrentQueue to handle notifications,
this assumption no longer stands. Now, we'll stop handling notifications
either once the wallet has or stopped or once the notifications channel
has been closed.
2018-07-30 17:54:08 -07:00
Wilmer Paulino
bbb5a6c058 wallet: remove the need to set the birthday for bitcoind chain clients
Due to the previous commit allowing us to specify the birthday of the
wallet at the time of the BitcoindClient's creation, this is now
unnecessary.
2018-07-30 17:54:08 -07:00
Olaoluwa Osuntokun
8b2629a935
Merge pull request #514 from vapopov/zerobalance
wallet: fix lost balance of unmined transaction for neutrino
2018-07-23 17:58:56 -07:00
Olaoluwa Osuntokun
dbb7ae6668 wallet: remove extraneous err check 2018-07-16 19:47:17 -07:00
Olaoluwa Osuntokun
fb511876c5 wallet: update to use new recovery manager API 2018-07-16 19:47:17 -07:00
Olaoluwa Osuntokun
49e46f3232 wallet: update rescan to take addrs along with their outpoints 2018-07-16 19:47:17 -07:00
Olaoluwa Osuntokun
d6ee9fd0e4 wallet: update HD recovery logic to map outpoints to addresses 2018-07-16 19:47:17 -07:00
Vadym Popov
40ba75dd9d
wallet: fix lost balance of unmined transaction for neutrino 2018-07-13 12:41:02 +03:00