aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet.cpp
AgeCommit message (Collapse)Author
2017-10-04wallet: update stored witness in AddToWalletSuhas Daftuar
Replace witness-stripped wallet transactions with full transactions; this can happen when upgrading from a pre-segwit wallet to a segwit- aware wallet. Github-Pull: #11225 Rebased-From: d01a9682b126a5f83c7311e652e6e62f2c2e1d20
2017-10-03Acquire cs_main lock before cs_wallet during wallet initializationRussell Yanofsky
CWallet::MarkConflicted may acquire the cs_main lock after CWalletDB::LoadWallet acquires the cs_wallet lock during wallet initialization. (CWalletDB::LoadWallet calls ReadKeyValue which calls CWallet::LoadToWallet which calls CWallet::MarkConflicted). This is the opposite order that cs_main and cs_wallet locks are acquired in the rest of the code, and so leads to POTENTIAL DEADLOCK DETECTED errors if bitcoin is built with -DDEBUG_LOCKORDER. This commit changes CWallet::LoadWallet (which calls CWalletDB::LoadWallet) to acquire both locks in the standard order. It also fixes some tests that were acquiring wallet and main locks out of order and failed with the new locking in CWallet::LoadWallet. Error was reported by Luke Dashjr <luke-jr@utopios.org> in https://botbot.me/freenode/bitcoin-core-dev/msg/90244330/ Github-Pull: #11126 Rebased-From: de9a1db2ed14e0c75ffd82dc031f7ad30c56d195
2017-08-28Output a bit more information for fee calculation report.Alex Morcos
Github-Pull: #11145 Rebased-From: 6af49dddeaeec7f134e86d6f8cf839c55870b7ab Tree-SHA512: 7245c6f7ed81cf3913e351ff1df7f74f4be7abe0ae8be312e4862c9875e2943b0b11136bc9999191cdf03468fdac5d41e294bb59b657605c22643b102e37c070
2017-08-28Fix rounding errors in calculation of minimum change sizeAlex Morcos
Github-Pull: #11145 Rebased-From: a54c7b94f8825e9b52fec9066fe7c1d5b6f53482 Tree-SHA512: d9abb9794edbf7e52450c63d183a4f28e9a3621a670b7f21af92407be096363b44a356818f2abbea11c168d123c04852bd0b60f1cd9d423aefbf4ae831f8567d
2017-08-21[wallet] Add logging to MarkReserveKeysAsUsedJohn Newbery
Github-Pull: #11044 Rebased-From: 67ceff4039ae038ae16f06128f868a2e8395b59a Tree-SHA512: 850c5b1010c84e164edf24a83ae36e46309b2eb7a67854bad509265ed590ba67d5f743a8416590da6ecca85fe4bda7f20e8c3152e422638eb7898db11a416af7
2017-08-21[wallet] Remove keypool_topup_cleanupsJohn Newbery
Unused function. Mostly reverts c25d90f125d69e33688288eff439eb7be75012e9 c25d90f... was merged as part of PR 11022 but is not required. Github-Pull: #11044 Rebased-From: 1221f60c94971c0f66abe5fdf086087a173bb0ac Tree-SHA512: da229b128bee5f124c009a1a2adfb4fa879366c81789824c426c9ce5209c835888a7e6cfeb1724551320a98cd08406a605372f84487a0d289cd6e02f9ac3ea21
2017-08-14scripted-diff: stop using the gArgs wrappersMarko Bencun
They were temporary additions to ease the transition. -BEGIN VERIFY SCRIPT- find src/ -name "*.cpp" ! -wholename "src/util.h" ! -wholename "src/util.cpp" | xargs perl -i -pe 's/(?<!\.)(ParseParameters|ReadConfigFile|IsArgSet|(Soft|Force)?(Get|Set)(|Bool|)Arg(s)?)\(/gArgs.\1(/g' -END VERIFY SCRIPT-
2017-08-14Merge #10483: scripted-diff: Use the C++11 keyword nullptr to denote the ↵Wladimir J. van der Laan
pointer literal instead of the macro NULL 90d4d89 scripted-diff: Use the C++11 keyword nullptr to denote the pointer literal instead of the macro NULL (practicalswift) Pull request description: Since C++11 the macro `NULL` may be: * an integer literal with value zero, or * a prvalue of type `std::nullptr_t` By using the C++11 keyword `nullptr` we are guaranteed a prvalue of type `std::nullptr_t`. For a more thorough discussion, see "A name for the null pointer: nullptr" (Sutter & Stroustrup), http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2431.pdf With this patch applied there are no `NULL` macro usages left in the repo: ``` $ git grep NULL -- "*.cpp" "*.h" | egrep -v '(/univalue/|/secp256k1/|/leveldb/|_NULL|NULLDUMMY|torcontrol.*NULL|NULL cert)' | wc -l 0 ``` The road towards `nullptr` (C++11) is split into two PRs: * `NULL` → `nullptr` is handled in PR #10483 (scripted, this PR) * `0` → `nullptr` is handled in PR #10645 (manual) Tree-SHA512: 3c395d66f2ad724a8e6fed74b93634de8bfc0c0eafac94e64e5194c939499fefd6e68f047de3083ad0b4eff37df9a8a3a76349aa17d55eabbd8e0412f140a297
2017-08-14Merge #11022: Basic keypool topupWladimir J. van der Laan
d34957e [wallet] [tests] Add keypool topup functional test (Jonas Schnelli) 095142d [wallet] keypool mark-used and topup (John Newbery) c25d90f [wallet] Add HasUnusedKeys() helper (John Newbery) f2123e3 [wallet] Cache keyid -> keypool id mappings (John Newbery) 83f1ec3 [wallet] Don't hold cs_LastBlockFile while calling setBestChain (John Newbery) 2376bfc [wallet] [moveonly] Move LoadKeyPool to cpp (Matt Corallo) cab8557 [wallet] [moveonly] Move CAffectedKeysVisitor (Jonas Schnelli) Pull request description: This PR contains the first part of #10882 : - if a key from the keypool is used, mark all keys up to that key as used, and then try to top up the keypool - top up the keypool on startup Notably, it does not stop the node or prevent the best block from advancing if the keypool drops below a threshold (which means that transactions may be missed and funds lost if restoring from an old HD wallet backup). Tree-SHA512: ac681fefeaf7ec2aab2fa1da93d12273ea80bd05eb48d7b3b551ea6e5d975dd97ba7de52b7fba52993823280ac4079cc36cf78a27dac708107ebf8fb6326142b
2017-08-10[wallet] keypool mark-used and topupJohn Newbery
This commit adds basic keypool mark-used and topup: - try to topup the keypool on initial load - if a key in the keypool is used, mark all keys before that as used and try to top up
2017-08-07scripted-diff: Use the C++11 keyword nullptr to denote the pointer literal ↵practicalswift
instead of the macro NULL -BEGIN VERIFY SCRIPT- sed -i 's/\<NULL\>/nullptr/g' src/*.cpp src/*.h src/*/*.cpp src/*/*.h src/qt/*/*.cpp src/qt/*/*.h src/wallet/*/*.cpp src/wallet/*/*.h src/support/allocators/*.h sed -i 's/Prefer nullptr, otherwise SAFECOOKIE./Prefer NULL, otherwise SAFECOOKIE./g' src/torcontrol.cpp sed -i 's/tor: Using nullptr authentication/tor: Using NULL authentication/g' src/torcontrol.cpp sed -i 's/METHODS=nullptr/METHODS=NULL/g' src/test/torcontrol_tests.cpp src/torcontrol.cpp sed -i 's/nullptr certificates/NULL certificates/g' src/qt/paymentserver.cpp sed -i 's/"nullptr"/"NULL"/g' src/torcontrol.cpp src/test/torcontrol_tests.cpp -END VERIFY SCRIPT-
2017-08-06Fix resendwallettransactions assert failure if -walletbroadcast=0Matt Corallo
2017-08-04[wallet] Add HasUnusedKeys() helperJohn Newbery
2017-08-04[wallet] Cache keyid -> keypool id mappingsJohn Newbery
2017-08-03Merge #10942: Eliminate fee overpaying edge case when subtracting fee from ↵Wladimir J. van der Laan
recipients 49d903e Eliminate fee overpaying edge case when subtracting fee from recipients (Alex Morcos) Pull request description: I'm not sure if this is the cause of the issue in #10034 , but this was a known edge case. I just didn't realize how simple the fix is. Could use a couple more eyes to make sure nothing silly can go wrong here, but if we all agree it's this simple, we can add this as another 0.15 bug fix. Tree-SHA512: db1dd1e83363a3c231267b626d3a388893ee70ba1972056fe2c339c5c9e4fbfd30f7fe837c30cc7be884d454797fd4c619b9d631a8d5eeb55cdb07402a83acb3
2017-08-02[wallet] [moveonly] Move LoadKeyPool to cppMatt Corallo
2017-08-02[wallet] [moveonly] Move CAffectedKeysVisitorJonas Schnelli
2017-07-28Clarify help message for -discardfeeAlex Morcos
2017-07-28[wallet] Specify wallet name in wallet loading errorsJohn Newbery
2017-07-28Reject invalid wallet filesJoão Barbosa
2017-07-28Reject duplicate wallet filenamesJoão Barbosa
2017-07-27Eliminate fee overpaying edge case when subtracting fee from recipientsAlex Morcos
2017-07-26Merge #10854: Avoid using sizes on non-fixed-width types to derive protocol ↵Wladimir J. van der Laan
constants. 095b917 Avoid using sizes on non-fixed-width types to derive protocol constants. (Gregory Maxwell) Pull request description: Thanks to awemany for pointing this out. This replaces #10172 which appears to be abandoned, but uses the constants as requested on that PR. Tree-SHA512: 032c0d75b3aaf807a7d0c7fb8ff5515acc45ad58bd00fe81413f900fe02bad900534a970403b9bb568e132c9eddea6043e958daf625e8acc84375bd41ee2e2ef
2017-07-20Merge #10862: Remove unused variable int64_t nEnd. Fix typo: "conditon" → ↵Wladimir J. van der Laan
"condition". 5a6671c Fix typo: "conditon" → "condition" (practicalswift) 35aff43 Remove unused variable int64_t nEnd (practicalswift) Pull request description: * Remove unused variable `int64_t nEnd`. Last use of `nEnd` removed in commit 1fc8c3d. * Fix typo: "conditon" → "condition". Typo introduced in commit 439c4e8. Tree-SHA512: 61624e6f70828c485fe46dbe00df76f1a07b7a5849d41bf7d279323b687420e60e9b85192f611a37211f17f3dea8eb3f6f6dc65d90c92e5516404fd81d37785a
2017-07-19Merge #10817: Redefine Dust and add a discard_rateWladimir J. van der Laan
f4d00e6 Add a discard_rate (Alex Morcos) b138585 Remove factor of 3 from definition of dust. (Alex Morcos) Pull request description: The definition of dust is redefined to remove the factor of 3. Dust is redefined to be the value of an output such that it would cost that value in fees to (create and) spend the output at the dust relay rate. The previous definition was that it would cost 1/3 of the value. The default dust relay rate is correspondingly increased to 3000 sat/kB so the actual default dust output value of 546 satoshis for a non-segwit output remains unchanged. This commit is a refactor only unless a dustrelayfee is passed on the commandline in which case that number now needs to be increased by a factor of 3 to get the same behavior. -dustrelayfee is a hidden command line option. Note: It's not exactly a refactor due to edge case changes in rounding as evidenced by the required change to the unit test. A discard_rate is added which defaults to 10,000 sat/kB Any change output which would be dust at the discard_rate you are willing to discard completely and add to fee (as well as continuing to pay the fee that would have been needed for creating the change) This would be a nice addition for 0.15 and I think will remain useful for 0.16 with the new coin selection algorithms in discussion, but its not crucial. It does add translation strings, but we could (should?) avoid that by hiding the option Tree-SHA512: 5b6f655354d0ab6b8b6cac1e8d1fe3136d10beb15c6d948fb15bfb105155a9d03684c6240624039b3eed6428b7e60e54216cc8b2f90c4600701e39f646284a9b
2017-07-18Do not allow users to get keys from keypool without reserving themMatt Corallo
fundrawtransaction allows users to add a change output and then not have it removed from keypool. While it would be nice to have users follow the normal CreateTransaction/CommitTransaction process we use internally, there isnt much benefit in exposing this option, especially with HD wallets, while there is ample room for users to misunderstand or misuse this option. This could be particularly nasty in some use-cases (especially pre-HD-split) - eg a user might fundrawtransaction, then call getnewaddress, hand out the address for someone to pay them, then sendrawtransaction. This may result in the user thinking they have received payment, even though it was really just their own change! This could obviously result in needless key-reuse.
2017-07-18Remove unused variable int64_t nEndpracticalswift
Last use of nEnd removed in commit 1fc8c3de0cff2971cc1f9903bfc3d03a982f2fab.
2017-07-17Add a discard_rateAlex Morcos
Any change output which would be dust at the discard_rate you are willing to discard completely and add to fee (as well as continuing to pay the fee that would have been needed for creating the change).
2017-07-17Avoid using sizes on non-fixed-width types to derive protocol constants.Gregory Maxwell
Thanks to awemany for pointing this out.
2017-07-17No longer ever reuse keypool indexesMatt Corallo
This fixes an issue where you could reserve a keypool entry, then top up the keypool, writing out a new key at the given index, then return they key from the pool. This isnt likely to cause issues, but given there is no reason to ever re-use keypool indexes (they're 64 bits...), best to avoid it alltogether.
2017-07-17Merge #10831: Batch flushing operations to the walletdb during top up and ↵Wladimir J. van der Laan
increase keypool size. b0e8e2d Print one log message per keypool top-up, not one per key. (Gregory Maxwell) 41dc163 Increase wallet default keypool size to 1000. (Gregory Maxwell) 30d8f3a Pushdown walletdb though CWallet::AddKeyPubKey to avoid flushes. (Gregory Maxwell) 3a53f19 Pushdown walletdb object through GenerateNewKey/DeriveNewChildKey. (Gregory Maxwell) Pull request description: This carries the walletdb object from top-up through GenerateNewKey/DeriveNewChildKey/CWallet::AddKeyPubKey, which allows us to avoid the flush on destruction until the top up finishes instead of flushing the wallet for every key. This speeds up adding keys by well over 10x on my laptop (actually something like 17x), I wouldn't be surprised if it were an even bigger speedup on spinning rust. Then it increases the keypool size to 1000. I would have preferred to use 10,000 but in the case where the user creates a new wallet and then turns on encryption it seems kind of dumb to have >400KB of marked-used born unencrypted keys just laying around. (Thanks to Matt for cluesticking me on how to bypass the crypter spaghetti) Tree-SHA512: 868303de38fce4c3f67d7fe133f765f15435c94b39d252d7450b5fee5c607a3cc2f5e531861a69d8c8877bf130e0ff4c539f97500a6bc0ff6d67e4a42c9385c7
2017-07-17Print one log message per keypool top-up, not one per key.Gregory Maxwell
2017-07-17Pushdown walletdb though CWallet::AddKeyPubKey to avoid flushes.Gregory Maxwell
This prevents the wallet from being flushed between each and every key during top-up. This results in a >10x speed-up for the top-up.
2017-07-17Merge #10706: Improve wallet fee logic and fix GUI bugsWladimir J. van der Laan
11590d3 Properly bound check conf_target in wallet RPC calls (Alex Morcos) fd29d3d Remove checking of mempool min fee from estimateSmartFee. (Alex Morcos) 2fffaa9 Make QT fee displays use GetMinimumFee instead of estimateSmartFee (Alex Morcos) 1983ca6 Use CoinControl to pass custom fee setting from QT. (Alex Morcos) 03ee701 Refactor to use CoinControl in GetMinimumFee and FeeBumper (Alex Morcos) ecd81df Make CoinControl a required argument to CreateTransaction (Alex Morcos) Pull request description: This builds on #10589 (first 5 commits from that PR, last 5 commits are new) The first couple commits refactor to use the CCoinControl class to pass fee calculation parameters around. This allows for fixing the buggy interaction in QT between the global payTxFee which can be modified by the RPC call settxfee or temporarily modified by the QT custom fee settings. Before these changes the GUI could sometimes send a transaction with a recently set payTxFee and not respect the settings displayed in the GUI. After these changes, using the GUI does not involve the global transaction confirm target or payTxFee. The prospective fee displays in the smart fee slider and the coin control dialog are changed to use the fee calculation from GetMinimumFee, this simplifies the code and makes them slightly more correct in edge cases. Maxing the fee calculation with the mempool min fee is move from estimateSmartFee to GetMinimumFee. This fixes a long standing bug, and should be tagged for 0.15 as it is holding up finalizing the estimatesmartfee RPC API before release. Tree-SHA512: 4d36a1bd5934aa62f3806d380fcafbef73e9fe5bdf190fc5259a3e3a13349e5ce796e50e7068c46dc630ccf56d061bce5804f0bfe2e082bb01ca725b63efd4c1
2017-07-17Merge #10330: [wallet] fix zapwallettxes interaction with persistent mempoolMarcoFalke
4c3b538 [logs] fix zapwallettxes startup logs (John Newbery) e7a2181 [wallet] fix zapwallettxes interaction with persistent mempool (John Newbery) ff7365e [tests] fix flake8 warnings in zapwallettxes.py (John Newbery) Pull request description: zapwallettxes previously did not interact well with persistent mempool. zapwallettxes would cause wallet transactions to be zapped, but they would then be reloaded from the mempool on startup. This commit softsets persistmempool to false if zapwallettxes is enabled so transactions are actually zapped. This PR also fixes the zapwallettxes.py functional test, which did not properly test this feature. The test line: ```py assert_raises(JSONRPCException, self.nodes[0].gettransaction, [txid3]) #there must be a expection because the unconfirmed wallettx0 must be gone by now ``` is not actually testing the presence of the transaction since the RPC is being called incorrectly (with an array instead of a string). The `assert_raises()` passes since an assert is raised, but it's not the one the test writer had in mind! Fixes #9710 . Tree-SHA512: e3236efc7a2fd2b3bf1d9e2e8a7726d470c57f5d95cf41b7bde264edc8817bd36a6f3feff52f8de8db0ef64b7247c88b24e7ff7cefaa706cba86fe4e2135a508
2017-07-16Pushdown walletdb object through GenerateNewKey/DeriveNewChildKey.Gregory Maxwell
This is needed but not sufficient for batching the wallet flushing when topping up the keypool.
2017-07-15Merge #10235: Track keypool entries as internal vs external in memoryPieter Wuille
d40a72ccb Clarify *(--.end()) iterator semantics in CWallet::TopUpKeyPool (Matt Corallo) 28301b978 Meet code style on lines changed in the previous commit (Matt Corallo) 4a3fc3562 Track keypool entries as internal vs external in memory (Matt Corallo) Pull request description: This is an alternative version of #10184. As @jonasschnelli points out there, the performance regressions are pretty minimal, but given that this is a pretty simple, mechanical change, its probably worth doing. Tree-SHA512: e83f9ebf2998f8164d1b2eebe5e6dcdeadea8c30b7612861f830758c08bf4093cd6a67b3bcfa9cfcb139e5e0b106fc8898a975fc69f334981aefc756568ab613
2017-07-15[logs] fix zapwallettxes startup logsJohn Newbery
2017-07-15[wallet] fix zapwallettxes interaction with persistent mempoolJohn Newbery
zapwallettxes previously did not interact well with persistent mempool. zapwallettxes would cause wallet transactions to be zapped, but they would then be reloaded from the mempool on startup. This commit softsets persistmempool to false if zapwallettxes is enabled so transactions are actually zapped.
2017-07-14Remove checking of mempool min fee from estimateSmartFee.Alex Morcos
This check has been moved to the wallet logic GetMinimumFee. The rpc call to estimatesmartfee will now no longer return a result maxed with the mempool min fee, but automated fee calculations from the wallet will produce the same result as before and coincontrol and sendcoins dialogs in the GUI will correctly display the right prospective fee. changes to policy/fees.cpp include a big whitespace indentation change.
2017-07-14Make QT fee displays use GetMinimumFee instead of estimateSmartFeeAlex Morcos
Remove helper function (CalculateEstimateType) for determining whether estimates should be conservative or not, now that this is only called once from GetMinimumFee and incorporate the logic directly there.
2017-07-14Refactor to use CoinControl in GetMinimumFee and FeeBumperAlex Morcos
Improve parameter precedence in coin_control
2017-07-14Make CoinControl a required argument to CreateTransactionAlex Morcos
2017-07-14Clarify *(--.end()) iterator semantics in CWallet::TopUpKeyPoolMatt Corallo
2017-07-14Meet code style on lines changed in the previous commitMatt Corallo
2017-07-14Track keypool entries as internal vs external in memoryMatt Corallo
This resolves a super minor performance regressions in several keypool-handling functions
2017-07-13Properly forbid -salvagewallet and -zapwallettxes for multi wallet.Alex Morcos
2017-07-11Fix rare edge case of paying too many fees when transaction has no change.Alex Morcos
Due to the iterative process of selecting new coins in each loop a new fee is calculated that needs to be met each time. In the typical case if the most recent iteration of the loop produced a much smaller transaction and we have now gathered inputs with too many fees, we can just reduce the change. However in the case where there is no change output, it is possible to end up with a transaction which drastically overpays fees. This commit addresses that case, by creating a change output if the overpayment is large enough to support it, this is accomplished by rerunning the transaction creation loop without selecting new coins. Thanks to instagibbs for working on this as well
2017-07-11Only reserve key for scriptChange once in CreateTransactionAlex Morcos
This does not affect behavior but allows us to have access to an output to scriptChange even if we currently do not have change in the transaction.
2017-07-11Merge #10589: More economical fee estimates for RBF and RPC options to controlWladimir J. van der Laan
f135923 Add RPC options for RBF, confirmation target, and conservative fee estimation. (Alex Morcos) f0bf33d Change default fee estimation mode. (Alex Morcos) e0738e3 remove default argument from estimateSmartFee (Alex Morcos) d507c30 Introduce a fee estimate mode. (Alex Morcos) cfaef69 remove default argument from GetMinimumFee (Alex Morcos) Tree-SHA512: 49c3a49a6893790a7e8b4e93a48f123dd5307af26c2017800683b76b4df8fc904ba73402917878676242c7440e3e04288d0c1ff3c2c907418724efc03cedab50