mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
wallet: Avoid use of Chain::Lock in tryGetTxStatus and tryGetBalances
This is a step toward removing the Chain::Lock class and reducing cs_main locking. It also helps ensure the GUI display stays up to date in the case where the node chain height runs ahead of wallet last block processed height.
This commit is contained in:
parent
bf30cd4922
commit
f6da44ccce
2 changed files with 13 additions and 10 deletions
|
@ -14,6 +14,7 @@
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <ui_interface.h>
|
#include <ui_interface.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
|
#include <util/check.h>
|
||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
#include <wallet/feebumper.h>
|
#include <wallet/feebumper.h>
|
||||||
#include <wallet/fees.h>
|
#include <wallet/fees.h>
|
||||||
|
@ -62,7 +63,7 @@ WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
|
||||||
WalletTxStatus MakeWalletTxStatus(interfaces::Chain::Lock& locked_chain, const CWalletTx& wtx)
|
WalletTxStatus MakeWalletTxStatus(interfaces::Chain::Lock& locked_chain, const CWalletTx& wtx)
|
||||||
{
|
{
|
||||||
WalletTxStatus result;
|
WalletTxStatus result;
|
||||||
result.block_height = locked_chain.getBlockHeight(wtx.m_confirm.hashBlock).get_value_or(std::numeric_limits<int>::max());
|
result.block_height = wtx.m_confirm.block_height > 0 ? wtx.m_confirm.block_height : std::numeric_limits<int>::max();
|
||||||
result.blocks_to_maturity = wtx.GetBlocksToMaturity();
|
result.blocks_to_maturity = wtx.GetBlocksToMaturity();
|
||||||
result.depth_in_main_chain = wtx.GetDepthInMainChain();
|
result.depth_in_main_chain = wtx.GetDepthInMainChain();
|
||||||
result.time_received = wtx.nTimeReceived;
|
result.time_received = wtx.nTimeReceived;
|
||||||
|
@ -317,13 +318,9 @@ public:
|
||||||
if (mi == m_wallet->mapWallet.end()) {
|
if (mi == m_wallet->mapWallet.end()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (Optional<int> height = locked_chain->getHeight()) {
|
num_blocks = m_wallet->GetLastBlockHeight();
|
||||||
num_blocks = *height;
|
block_time = -1;
|
||||||
block_time = locked_chain->getBlockTime(*height);
|
CHECK_NONFATAL(m_wallet->chain().findBlock(m_wallet->GetLastBlockHash(), FoundBlock().time(block_time)));
|
||||||
} else {
|
|
||||||
num_blocks = -1;
|
|
||||||
block_time = -1;
|
|
||||||
}
|
|
||||||
tx_status = MakeWalletTxStatus(*locked_chain, mi->second);
|
tx_status = MakeWalletTxStatus(*locked_chain, mi->second);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -372,12 +369,12 @@ public:
|
||||||
{
|
{
|
||||||
auto locked_chain = m_wallet->chain().lock(true /* try_lock */);
|
auto locked_chain = m_wallet->chain().lock(true /* try_lock */);
|
||||||
if (!locked_chain) return false;
|
if (!locked_chain) return false;
|
||||||
num_blocks = locked_chain->getHeight().get_value_or(-1);
|
|
||||||
if (!force && num_blocks == cached_num_blocks) return false;
|
|
||||||
TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
|
TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
|
||||||
if (!locked_wallet) {
|
if (!locked_wallet) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
num_blocks = m_wallet->GetLastBlockHeight();
|
||||||
|
if (!force && num_blocks == cached_num_blocks) return false;
|
||||||
balances = getBalances();
|
balances = getBalances();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1200,6 +1200,12 @@ public:
|
||||||
assert(m_last_block_processed_height >= 0);
|
assert(m_last_block_processed_height >= 0);
|
||||||
return m_last_block_processed_height;
|
return m_last_block_processed_height;
|
||||||
};
|
};
|
||||||
|
uint256 GetLastBlockHash() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
|
||||||
|
{
|
||||||
|
AssertLockHeld(cs_wallet);
|
||||||
|
assert(m_last_block_processed_height >= 0);
|
||||||
|
return m_last_block_processed;
|
||||||
|
}
|
||||||
/** Set last block processed height, currently only use in unit test */
|
/** Set last block processed height, currently only use in unit test */
|
||||||
void SetLastBlockProcessed(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
|
void SetLastBlockProcessed(int block_height, uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue