Commit graph

1189 commits

Author SHA1 Message Date
Wilmer Paulino 02b0a7c18d
wallet: fix nil txid in publishTransaction
A nil txid could've been returned from publishTransaction even if it was
successful. This was due to the underlying SendRawTransaction call
"failing", e.g., when the transaction being broadcast has already
confirmed, but publishTranasction interpreting such failure as a
success.
2019-07-10 16:25:01 -07:00
Wilmer Paulino 44d818d813
wtxmgr: prevent adding existing confirmed transactions as unconfirmed
We do this as a sanity check for users of the wallet to ensure the
wallet maintains a correct representation of the chain.
2019-07-10 16:25:00 -07:00
Olaoluwa Osuntokun cd66e82bc8
Merge pull request #631 from wpaulino/dropwtxmgr-max-reorg-depth
cmd/dropwtxmgr+waddrmgr: handle constraint when resetting synced state
2019-07-10 15:45:58 -07:00
Wilmer Paulino f710cd4a92
cmd/dropwtxmgr+waddrmgr: handle constraint when resetting synced state
We update the dropwtxmgr utility tool to take into account that the
wallet only stores MaxReorgDepth blocks, which introduced an additional
constraint when updating the wallet's synced state. The constraint
ensures that the previous block exists when updating the wallet's synced
state, but this does not hold for the birthday block since it's the
first block we'll store.
2019-07-08 13:26:43 -07:00
Olaoluwa Osuntokun 4a9774585e
Merge pull request #628 from cfromknecht/faster-btcd-init
wallet: speed up bare wallet init when using the btcd backend
2019-06-28 15:53:30 -07:00
Olaoluwa Osuntokun 2698f8434e
wallet: speed up bare wallet init when using the btcd backend
In this commit, we speed up creating a fresh wallet when using the btcd
backend. Before this commit, we would need to rescan 10k or so blocks
when creating a new wallet with the btcd backend. btcd will actually
fully scan all the blocks even though we have zero addresses or UTXOs to
look for. As a result, this can take quite some time.

In this commit we modify the starting height of the initial rescan to
start at the birthday height, and only modify it if it's unset, or the
best height of the chain is before this birthday height. As a result, we
won't always have the full 10k block re org safety horizon on disk, but
will tend to this level after we begin to sync forward.
2019-06-28 15:01:09 -07:00
Olaoluwa Osuntokun 46c0cf2a3f
Merge pull request #627 from wpaulino/wallet-recovery-start-height
wallet: start recovery from the wallet's best height
2019-06-20 16:32:57 -07:00
Wilmer Paulino 2ff8e92e37
wallet: remove wallet best height check when checkpointing intial sync
This check is not required since the wallet's best height is the genesis
block.
2019-06-19 20:00:00 -07:00
Wilmer Paulino 426f523475
wallet: start recovery from the wallet's best height
Previously, the wallet would attempt to store the same block it
checkpointed during its initial sync when performing a recovery. This
would cause the previous block existence validation check to be in
place, which would ultimately fail because the previous block was not
stored intentionally.

To address this, we always start/resume our recovery from the wallet's
best height. This also ensures that we do not rescan the same block
again when resuming a recovery after a shutdown.
2019-06-19 19:59:51 -07:00
Olaoluwa Osuntokun de02d6fdfb
Merge pull request #626 from Roasbeef/dust-fix-sendoutputs
wallet: use relay fee to check for dust not fee rate
2019-06-18 17:55:38 -07:00
Olaoluwa Osuntokun 1dccdec1c1
wallet: use relay fee to check for dust not fee rate
In this commit we fix a lingering bug in our output sanity checks that
would only show up during time periods of persistently higher fees.
Before this commit we would incorrectly use the fee rate instead of the
min relay fee when checking an output for dust. This would cause us to
mistakenly reject a transaction for having a dust output.

We fix this by falling back to using the current min-relayfee.
2019-06-18 17:11:01 -07:00
Olaoluwa Osuntokun a335c56614
Merge pull request #618 from wpaulino/instant-wallet-startup
wallet+waddrmgr: sync and store up to MaxReorgDepth blocks
2019-06-14 06:35:44 +02:00
Wilmer Paulino 4a913d02ea
chain: only allow bitcoind block notifications at tip after NotifyBlocks
One could argue that the behavior before this commit was incorrect, as
the ChainClient interface expects a call to NotifyBlocks before
notifying blocks at tip, so we decide to fix this.

Since we now wait for the chain backend to be considered "current"
before proceeding to sync the wallet with it, any blocks that were
processed while waiting would result in being notified and scanned
twice, once by processing it at tip, and another while rescanning the
wallet, which is not desirable.
2019-06-13 18:09:06 -07:00
Wilmer Paulino a9847c28b6
wallet: improve error logging for unsuccessful notification handling
If a block arrives while the wallet is rescanning, users would be shown
a log message that is confusing and not very helpful.
2019-06-13 18:09:05 -07:00
Wilmer Paulino fd8aa5d541
wallet: use locateBirthdayBlock within birthdaySanityCheck
We use the recently introduced locateBirthdayBlock function within
birthdaySanityCheck as it serves as a more optimized alternative that
achieves the same purpose.
2019-06-13 18:09:04 -07:00
Wilmer Paulino 26bc5ab104
wallet: remove unused function scanChain 2019-06-13 18:09:03 -07:00
Wilmer Paulino fa65c1b5f7
wallet: store reorg safe height upon initial sync
Currently, wallet rescans start from its known tip of the chain. Since
we no longer store blocks all the way from genesis to the tip of the
chain, performing a rescan would cause us to scan blocks all the way
from genesis, which we want to avoid. To prevent this, we set the
wallet's tip to be the current reorg safe height. This ensures that
we're unable to scan any blocks before it, and that we maintain
MaxReorgDepth blocks stored.
2019-06-13 18:09:02 -07:00
Wilmer Paulino e754478496
wallet: modify recovery logic to not start from genesis
This commit serves as another building point to allow the wallet to not
store blocks all the way from genesis to the tip of chain. We modify the
wallet's recovery logic to now start from either its birthday block, or
the current reorg safe height if it's before the birthday, to ensure the
wallet properly only stores MaxReorgDepth blocks.

We also refactor things a bit in hopes of making the logic a bit more
readable.
2019-06-13 18:09:02 -07:00
Wilmer Paulino 2a6f24c61b
wallet: locate birthday block without scanning chain from genesis
We do this as the wallet will no longer store blocks all the way from
genesis to the tip of the chain. Instead, in order to find a reasonable
birthday block, we resort to performing a binary search for a block
timestamp that's within +/-2 hours of the birthday timestamp.
2019-06-13 18:09:01 -07:00
Wilmer Paulino 17efcdba2f
wallet: wait until chain backend is current to begin wallet sync
This serves as groundwork for only storing up to MaxReorgDepth blocks
upon initial sync. To do so, we want to make sure the chain backend
considers itself current so that we can only fetch the latest
MaxReorgDepth blocks from it.
2019-06-13 18:09:00 -07:00
Wilmer Paulino 39f81c630b
chain: add IsCurrent method to chain.Interface
IsCurrent allows us to determine if the chain backend considers itself
"current" with the chain.
2019-06-13 18:08:59 -07:00
Wilmer Paulino 1ee2a239de
wallet: make wallet initial sync synchronous
This ensures the wallet can properly do an initial sync, a recovery, or
detect if it's on a stale branch before attempting to process new blocks
at tip.

Since the rescan will be triggered synchronously as well, we'll need to
catch the wallet's quit chan when handling rescan batches in order to
allow for clean shutdowns.
2019-06-13 18:08:58 -07:00
Wilmer Paulino f2f46b674d
waddrmgr: add migration to maintain MaxReorgDepth block hashes stored
In this commit, we add a migration that will be used by existing wallets
to ensure they can adhere to the new requirement of storing up to
MaxReorgDepth entries within the block hash index.
2019-06-11 12:02:42 -07:00
Wilmer Paulino e548e76684
waddrmgr: maintain a maximum of MaxReorgDepth block hashes stored
In this commit, we modify the wallet's block hash index to only store up
to MaxReorgDepth blocks. This allows us to reduce consumed storage, as
we'd be mostly storing duplicate data. We choose to store up to
MaxReorgDepth to ensure we can recover from a potential long reorg.
2019-06-11 12:02:41 -07:00
Olaoluwa Osuntokun 66a95921c0
Merge pull request #624 from wpaulino/neutrino-rescan-finished-deadlock
chain: prevent deadlock while notifying RescanFinished for NeutrinoClient
2019-06-11 04:59:59 +02:00
Wilmer Paulino eedd5ce1b6
chain: prevent deadlock while notifying RescanFinished for NeutrinoClient 2019-06-07 13:00:09 -07:00
Olaoluwa Osuntokun 2c05240dff
Merge pull request #620 from wpaulino/waddrmgr-rlock-sync
waddrmgr: use RLock when retrieving sync info
2019-05-23 17:35:33 -07:00
Olaoluwa Osuntokun 192de4ec84
Merge pull request #617 from wpaulino/bitcoind-client-misc-fixes
chain: misc BitcoindClient fixes
2019-05-23 17:34:18 -07:00
Wilmer Paulino 8ae8071c54
waddrmgr: use RLock when retrieving sync info 2019-05-23 14:04:02 -07:00
Wilmer Paulino bf9cc20045
wallet: check RPC error code for rejected confirmed transactions
This unifies the logic of receiving an error when broadcasting a
confirmed transaction through btcd's/bitcoind's RPC interface. The btcd
dependency update is required in order for it to match bitcoind's
behavior. For older nodes that have yet to update, the confirmed
transaction will still be caught by the "transaction already exists"
case. This is not needed for bitcoind however, because its been sending
the same RPC error code for several major releases now.
2019-05-22 17:06:37 -07:00
Wilmer Paulino 0efe836773
chain: avoid using defer for BitcoindClient onRescanFinished notification
Since defer will copy the function with the parameters evaluated at its
invocation, the RescanFinished notification would be dispatched with the
incorrect block. To fix this, we'll just send the notification at the
end ourselves manually.
2019-05-11 13:06:25 -07:00
Wilmer Paulino 28161bee42
chain: improve error logging within BitcoindClient.reorg 2019-05-11 13:05:27 -07:00
Wilmer Paulino ecfebcea03
chain: remove unnecessary returned error from BitcoindClient.filterBlock 2019-05-11 13:05:23 -07:00
Wilmer Paulino 8d6dd92706
chain: fix Fatalf format verb error 2019-05-11 13:05:17 -07:00
Olaoluwa Osuntokun 9d95f76e99
Merge pull request #614 from wpaulino/on-block-connected-panic
chain: prevent panic if onBlockConnected is called before onFilteredBlockConnected
2019-04-24 15:40:17 -07:00
Wilmer Paulino e0f82255c7
chain: prevent panic if onBlockConnected is called before onFilteredBlockConnected 2019-04-19 12:27:33 -07:00
Olaoluwa Osuntokun b386e6385e
Merge pull request #505 from cfromknecht/nuke-votingpool
votingpool: nuke package
2019-04-18 21:36:24 -07:00
Olaoluwa Osuntokun 9e694e2bfc
Merge pull request #613 from wpaulino/neutrino-rescan-finished
chain: dispatch RescanFinished notification after BlockConnected
2019-04-18 20:15:46 -07:00
Wilmer Paulino b3643ed7a9
chain: dispatch RescanFinished notification after BlockConnected
In this commit, we address a bug within the wallet when running with
Neutrino where it wouldn't be able to mark it as synced with the chain
due to not receiving a RescanFinished notification if it was a block
behind the chain. This happened because of the order in which the
notifications are delivered within the underlying Neutrino ChainService,
FilteredBlockConnected gets dispatched before BlockConnected. This
doesn't always work however because there is an implicit dependency
between them in which BlockConnected must occur first.

To address it, rather than switching the order in which the
notifications are dispatched, we just check if we can dispatch the final
RescanFinished notification after dispatching BlockConnected.

Co-Authored-By: Roei Erez <roeierez@gmail.com>
2019-04-18 19:32:37 -07:00
Wilmer Paulino 767a7a95cf
chain: extract RescanFinished notification dispatch into method
Co-Authored-By: Roei Erez <roeierez@gmail.com>
2019-04-18 19:30:40 -07:00
Wilmer Paulino 8f25b8b4ef
chain: keep track of lastFilteredBlockHeader within NeutrinoClient
Co-Authored-By: Roei Erez <roeierez@gmail.com>
2019-04-18 19:23:05 -07:00
Olaoluwa Osuntokun 8b90263a61
Merge pull request #609 from wpaulino/utxos-after-remove
wtxmgr: only remove entry for specified spending transaction
2019-03-26 20:45:48 -07:00
Wilmer Paulino 0ae78b1f56
wtxmgr: only remove entry for specified spending transaction
In this commit, we address an issue with the wallet store where it'd be
possible for us to keep lingering unconfirmed transaction entries for an
output that has been spent by a different, confirmed transaction. This
was caused due to us removing all spending transaction entries for a
given output when removing conflicts. Since all of the entries would be
removed, we weren't able to retrieve the hashes of the remaining
spending transactions to remove their records as well. Instead, we
propose to only remove the entry for the specified spending transaction.
2019-03-22 16:59:04 -07:00
Olaoluwa Osuntokun 89ab2044f9
Merge pull request #608 from wpaulino/manager-oncommit-lock
waddrmgr: use methods that do not hold the manager's lock
2019-03-18 18:05:15 -07:00
Wilmer Paulino 3cf41c92b5
waddrmgr: use methods that do not hold the manager's lock 2019-03-18 15:47:48 -07:00
Olaoluwa Osuntokun 68fc7c82e1
Merge pull request #607 from Roasbeef/new-neutrino-rescan
build+chain: update to latest version of neutrino
2019-03-12 21:11:34 -07:00
Olaoluwa Osuntokun d9a9f4176b
build+chain: update to latest version of neutrino
The latest version also includes a change to the way we need to
initialize the rescan object.
2019-03-12 21:05:42 -07:00
Olaoluwa Osuntokun acf3b04b02
Merge pull request #604 from wpaulino/scan-chain-bug-fix
wallet: ensure bestHeight is updated before isCurrent check
2019-03-12 20:26:08 -07:00
Olaoluwa Osuntokun ecfdd888dd
Merge pull request #602 from wpaulino/wallet-sync-dev-env
wallet/wallet: accept 0 bestHeight in developer environments
2019-03-12 20:17:22 -07:00
Wilmer Paulino 06bf42c746
wallet: use last synced block as birthday in development environments
In this commit, we address an issue with chains that are not current,
like in the often case of regtest and simnet chains. Syncing the wallet
would fail due to the chain not being current and not finding a suitable
birthday block. We fix this by just using the last synced block as the
birthday block to ensure we can properly sync to the chain.
2019-03-12 18:33:45 -07:00