diff options
author | Antoine Riard <ariard@student.42.fr> | 2019-04-20 12:02:52 -0400 |
---|---|---|
committer | Antoine Riard <ariard@student.42.fr> | 2019-11-05 12:59:16 -0500 |
commit | 5aacc3eff15b9b5bdc951f1e274f00d581f63bce (patch) | |
tree | cdfccd67221dfa0ea43311e5fb99f2b74140e4f6 /src/wallet/wallet.h | |
parent | 10b4729e33f76092bd8cfa06d1a5e0a066436f76 (diff) |
Add m_last_block_processed_height field in CWallet
At BlockConnected/BlockDisconnected, we rely on height of block
itself to know current height of wallet
Diffstat (limited to 'src/wallet/wallet.h')
-rw-r--r-- | src/wallet/wallet.h | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index dba8a8cc08..7c22f06e2c 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -679,12 +679,18 @@ private: * The following is used to keep track of how far behind the wallet is * from the chain sync, and to allow clients to block on us being caught up. * - * Note that this is *not* how far we've processed, we may need some rescan - * to have seen all transactions in the chain, but is only used to track - * live BlockConnected callbacks. + * Processed hash is a pointer on node's tip and doesn't imply that the wallet + * has scanned sequentially all blocks up to this one. */ uint256 m_last_block_processed GUARDED_BY(cs_wallet); + /* Height of last block processed is used by wallet to know depth of transactions + * without relying on Chain interface beyond asynchronous updates. For safety, we + * initialize it to -1. Height is a pointer on node's tip and doesn't imply + * that the wallet has scanned sequentially all blocks up to this one. + */ + int m_last_block_processed_height GUARDED_BY(cs_wallet) = -1; + public: /* * Main wallet lock. @@ -1129,6 +1135,21 @@ public: LegacyScriptPubKeyMan::WatchKeyMap& mapWatchKeys GUARDED_BY(cs_KeyStore) = m_spk_man->mapWatchKeys; WalletBatch*& encrypted_batch GUARDED_BY(cs_wallet) = m_spk_man->encrypted_batch; using CryptedKeyMap = LegacyScriptPubKeyMan::CryptedKeyMap; + + /** Get last block processed height */ + int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) + { + AssertLockHeld(cs_wallet); + assert(m_last_block_processed_height >= 0); + return m_last_block_processed_height; + }; + /** Set last block processed height, currently only use in unit test */ + void SetLastBlockProcessed(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) + { + AssertLockHeld(cs_wallet); + m_last_block_processed_height = block_height; + m_last_block_processed = block_hash; + }; }; /** |