mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-15 12:40:41 +02:00
wallet: Add asserts to detect unset transaction height values
Also document GetTxDepthInMainChain preconditions better
This commit is contained in:
parent
262a78b133
commit
f06016d77d
@ -3303,8 +3303,10 @@ int CWallet::GetTxDepthInMainChain(const CWalletTx& wtx) const
|
|||||||
{
|
{
|
||||||
AssertLockHeld(cs_wallet);
|
AssertLockHeld(cs_wallet);
|
||||||
if (auto* conf = wtx.state<TxStateConfirmed>()) {
|
if (auto* conf = wtx.state<TxStateConfirmed>()) {
|
||||||
|
assert(conf->confirmed_block_height >= 0);
|
||||||
return GetLastBlockHeight() - conf->confirmed_block_height + 1;
|
return GetLastBlockHeight() - conf->confirmed_block_height + 1;
|
||||||
} else if (auto* conf = wtx.state<TxStateConflicted>()) {
|
} else if (auto* conf = wtx.state<TxStateConflicted>()) {
|
||||||
|
assert(conf->conflicting_block_height >= 0);
|
||||||
return -1 * (GetLastBlockHeight() - conf->conflicting_block_height + 1);
|
return -1 * (GetLastBlockHeight() - conf->conflicting_block_height + 1);
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -503,6 +503,13 @@ public:
|
|||||||
* <0 : conflicts with a transaction this deep in the blockchain
|
* <0 : conflicts with a transaction this deep in the blockchain
|
||||||
* 0 : in memory pool, waiting to be included in a block
|
* 0 : in memory pool, waiting to be included in a block
|
||||||
* >=1 : this many blocks deep in the main chain
|
* >=1 : this many blocks deep in the main chain
|
||||||
|
*
|
||||||
|
* Preconditions: it is only valid to call this function when the wallet is
|
||||||
|
* online and the block index is loaded. So this cannot be called by
|
||||||
|
* bitcoin-wallet tool code or by wallet migration code. If this is called
|
||||||
|
* without the wallet being online, it won't be able able to determine the
|
||||||
|
* the height of the last block processed, or the heights of blocks
|
||||||
|
* referenced in transaction, and might cause assert failures.
|
||||||
*/
|
*/
|
||||||
int GetTxDepthInMainChain(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
int GetTxDepthInMainChain(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
bool IsTxInMainChain(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
|
bool IsTxInMainChain(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
|
||||||
|
Loading…
Reference in New Issue
Block a user