Commit graph

1285 commits

Author SHA1 Message Date
Wilmer Paulino
6568c433fe
waddrmgr/db: store birthday block verification status
In this commit, we add a new key/value pair to the waddrmgr's sync
bucket to store the verification status of the birthday block. This
verification status determines whether the wallet has verified the
correctness of its birthday block through its sanity check on startup.
2018-11-15 18:01:19 -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
Olaoluwa Osuntokun
4c01c0878c
Merge pull request #573 from wpaulino/notify-received
wallet: notify wallet upon relevant transaction confirmation
2018-11-14 18:39:41 -08:00
Wilmer Paulino
31011de227
wtxmgr+wallet: add wtxmgr sublogger 2018-11-14 18:09:10 -08:00
Wilmer Paulino
9d329e111e
wtxmgr/migrations: add drop transaction history migration
In this commit, we follow up our previous migration to reset our synced
block to our birthday block with another migration to drop our
transaction history. We'll need to do this to ensure that the
transaction store matches the exact state of our outputs on-chain to
prevent inadvertently crafting any invalid transactions.
2018-11-14 18:09:10 -08:00
Wilmer Paulino
a0a5e46177
wtxmgr/db: add new createBuckets and deleteBuckets methods 2018-11-14 18:09:10 -08:00
Wilmer Paulino
de4662e5df
wtxmgr: convert unit tests to be package-level
This allows us to reuse some of the existing code to test migrations of
the transaction store.
2018-11-14 18:09:10 -08:00
Wilmer Paulino
0424fd22ec
waddrmgr/migrations: add migration to force rescan from birthday block
In this commit, we add a migration to force a rescan of users' wallets
starting from their birthday block to ensure that their balance is
reflected correctly as it is on-chain. This was inspired by the recent
bug discovered where the wallet would not watch for the confirmation of
a relevant transaction.
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
Olaoluwa Osuntokun
ee93fa9871
Merge pull request #571 from wpaulino/birthday-blockstamp
wallet+waddrmgr: add migration & sanity check to populate birthday block
2018-11-14 18:05:49 -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
a25899eae7
waddrmgr/migrations: add migration to populate birthday block for existing wallets
In this commit, we add a new migration to the waddrmgr to populate the
birthday block for existing wallets. This will deem useful when
performing rescans for whatever reason, as we'll now be able to start
from this point rather than the genesis block, incurring a longer
rescan.

The migration is not as reliable since we do not store block timestamps,
so we'll need to estimate our height by looking at the genesis timestamp
and assuming a block occurs every 10 minutes. This can be unsafe, and
cause us to actually miss on-chain events, so a sanity check will be
added before the wallet attempts to sync itself in a later commit.
2018-11-13 19:37:08 -08:00
Wilmer Paulino
709fa17540
waddrmgr+wallet: add waddrmgr log to the wallet 2018-11-12 08:56:31 -08:00
Wilmer Paulino
61a2a8c391
waddrmgr/db: return ErrBlockNotFound if block doesn't exist 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
Wilmer Paulino
e30cebea1b
waddrmgr/sync: add methods to Manager to get/set birthday block 2018-11-11 17:44:10 -08:00
Wilmer Paulino
e9d24382d6
waddrmgr/db: add birthday block within syncBucket
In this commit, we add a new key/value pair within the waddrmgr's
syncBucket that will represent the birthday block of the wallet. This
can then be used to force rescans from this point, rather than from the
genesis block.
2018-11-11 17:44:08 -08:00
Olaoluwa Osuntokun
9eec895db8
Merge pull request #570 from wpaulino/waddrmgr-package-level-tests
waddrmgr: convert unit tests to package-level tests
2018-11-08 10:48:39 +11:00
Wilmer Paulino
f2432b1a5e
waddrmgr: remove testing work-around for unexported vars
These work-arounds are no longer needed since the tests now have
package-level access.
2018-11-07 04:02:59 -08:00
Wilmer Paulino
fb91894a20
waddrmgr: remove ErrUpgrade check in TestManager in favor of test 2018-11-07 00:44:31 -08:00
Wilmer Paulino
c2d6f1a8b3
waddrmgr: convert unit tests to package-level tests
In this commit, we convert our unit tests to have package-level access.
We do this as an effort to reduce test code duplication when we
introduce migration tests which require access to specific unexported
functions/methods.
2018-11-07 00:44:27 -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
Olaoluwa Osuntokun
69684e9091
Merge pull request #569 from wpaulino/import-priv-key-birthday
wallet/wallet: only set new birthday if before current within ImportPrivateKey
2018-11-06 14:29:38 +11: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
f582eab1fa
waddrmgr: remove old migration logic
In this commit, we remove the old upgrade/migration logic of the address
manager as it's been superseded by the new approach using the
migration.Manager interface.
2018-11-05 17:58:16 -08:00
Wilmer Paulino
2fb234c68f
wtxmgr: remove old migration logic
In this commit, we remove the old upgrade/migration logic of the
transaction manager as it's been superseded by the new approach using
the migration.Manager interface.
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
Wilmer Paulino
c523ccd192
wtxmgr/db: remove LatestVersion const in favor of getLatestVersion
In this commit, we can remove the LatestVersion constant as it's no
longer needed. Instead, we'll now define the latest version as the last
entry in the slice of versions previously defined.
2018-11-05 17:58:16 -08:00
Wilmer Paulino
ec1213aeab
wtxmgr/migrations: add migration.Manager implementation
In this commit, we add an implementation of the recently introduced
migration.Manager interface for the transaction manager. With this,
we'll now be able to only expose the things required for the migration
to happen, but have the actual migration logic live at a much higher
level.

There are no existing migrations for the transaction manager, but since
the latest version was already defined as 1, we'll start from there to
be backwards-compatible.
2018-11-05 17:58:16 -08:00
Wilmer Paulino
3bdfb6cc23
wtxmgr/db: define new helpers to set/get store version 2018-11-05 17:58:16 -08:00
Wilmer Paulino
1e582298b2
waddrmgr/db: remove LatestVersion const in favor of getLatestVersion
In this commit, we can remove the LatestVersion constant as it's no
longer needed. Instead, we'll now define the latest version as the last
entry in the slice of versions previously defined.
2018-11-05 17:58:16 -08:00
Wilmer Paulino
b05148bb8b
waddrmgr/migrations: move migration-related functions
This commit is strictly a code move to keep all migration-related things
within the same file.
2018-11-05 17:58:16 -08:00
Wilmer Paulino
3b4f73272f
waddrmgr/migrations: add migration.Manager implementation
In this commit, we add an implementation of the recently introduced
migration.Manager interface for the address manager. With this, we'll
now be able to only expose the things required for the migration to
happen, but have the actual migration logic live at a much higher level.

The existing versions defined are set up in the same way as the existing
upgrade/migration logic, which will end up being superseded by this and
removed in a later commit.
2018-11-05 17:58:16 -08:00
Wilmer Paulino
c01bbc4758
waddrmgr/db: remove unused pubPassPhrase arg from upgradeToVersion5 2018-11-05 17:58:16 -08:00
Wilmer Paulino
541ad708c7
walletdb/migration: add new migration package with Manager interface
In this commit, we add a new sub-package to the walletdb package:
migration. In this package, we define a new interface, Manager, which
will expose all of the necessary functions required to abstract the
migration logic of different sub-services within the wallet, like the
address and transaction managers. The implementations of this interface
will then be able to use the migration logic within the Upgrade
function with no additional complexity.
2018-11-05 17:58:16 -08:00
Olaoluwa Osuntokun
c4dd27e481
Merge pull request #541 from halseth/neutrino-recovery
Wait for neutrino filter headers
2018-10-16 18:53:32 -07:00
Johan T. Halseth
312baff46a
travis: update golint dep path 2018-10-16 18:43:02 -07:00
Johan T. Halseth
d791cb7c30
wallet: always wait for Neutrino IsCurrent during initial sync 2018-10-16 18:18:46 -07:00
Johan T. Halseth
060361939b
chain/neutrino: use new neutrino API 2018-10-16 18:18:46 -07:00
Johan T. Halseth
8705541e9a
glide: update neutrino dependency 2018-10-16 18:18:29 -07:00
Olaoluwa Osuntokun
29ee9442fe
Merge pull request #551 from wpaulino/fix-initial-sync-catchup
wallet: relax initial sync detection logic to speed up sync in case o…
2018-09-25 19:37:02 -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
Olaoluwa Osuntokun
04340fd158
Merge pull request #549 from wpaulino/unify-send-outputs-publish-tx
wallet: unify SendOutputs + PublishTransaction logic
2018-09-25 19:15:48 -07:00
Olaoluwa Osuntokun
2922e4d37a
Merge pull request #548 from wpaulino/extend-remove-unmined-tx-test
wtxmgr/tx_test: extend TestRemoveUnminedTx to check balances
2018-09-25 19:07:58 -07:00