mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-21 04:09:09 +02:00
[wallet] Move methods from Chain::Lock interface to simple Chain
Remove findPruned and findFork, no more used after 17954.
This commit is contained in:
@@ -55,58 +55,6 @@ bool FillBlock(const CBlockIndex* index, const FoundBlock& block, UniqueLock<Rec
|
||||
|
||||
class LockImpl : public Chain::Lock, public UniqueLock<RecursiveMutex>
|
||||
{
|
||||
bool haveBlockOnDisk(int height) override
|
||||
{
|
||||
LockAssertion lock(::cs_main);
|
||||
CBlockIndex* block = ::ChainActive()[height];
|
||||
return block && ((block->nStatus & BLOCK_HAVE_DATA) != 0) && block->nTx > 0;
|
||||
}
|
||||
Optional<int> findFirstBlockWithTimeAndHeight(int64_t time, int height, uint256* hash) override
|
||||
{
|
||||
LockAssertion lock(::cs_main);
|
||||
CBlockIndex* block = ::ChainActive().FindEarliestAtLeast(time, height);
|
||||
if (block) {
|
||||
if (hash) *hash = block->GetBlockHash();
|
||||
return block->nHeight;
|
||||
}
|
||||
return nullopt;
|
||||
}
|
||||
Optional<int> findFork(const uint256& hash, Optional<int>* height) override
|
||||
{
|
||||
LockAssertion lock(::cs_main);
|
||||
const CBlockIndex* block = LookupBlockIndex(hash);
|
||||
const CBlockIndex* fork = block ? ::ChainActive().FindFork(block) : nullptr;
|
||||
if (height) {
|
||||
if (block) {
|
||||
*height = block->nHeight;
|
||||
} else {
|
||||
height->reset();
|
||||
}
|
||||
}
|
||||
if (fork) {
|
||||
return fork->nHeight;
|
||||
}
|
||||
return nullopt;
|
||||
}
|
||||
CBlockLocator getTipLocator() override
|
||||
{
|
||||
LockAssertion lock(::cs_main);
|
||||
return ::ChainActive().GetLocator();
|
||||
}
|
||||
Optional<int> findLocatorFork(const CBlockLocator& locator) override
|
||||
{
|
||||
LockAssertion lock(::cs_main);
|
||||
if (CBlockIndex* fork = FindForkInGlobalIndex(::ChainActive(), locator)) {
|
||||
return fork->nHeight;
|
||||
}
|
||||
return nullopt;
|
||||
}
|
||||
bool checkFinalTx(const CTransaction& tx) override
|
||||
{
|
||||
LockAssertion lock(::cs_main);
|
||||
return CheckFinalTx(tx);
|
||||
}
|
||||
|
||||
using UniqueLock::UniqueLock;
|
||||
};
|
||||
|
||||
@@ -234,6 +182,40 @@ public:
|
||||
assert(block);
|
||||
return block->GetBlockHash();
|
||||
}
|
||||
bool haveBlockOnDisk(int height) override
|
||||
{
|
||||
LOCK(cs_main);
|
||||
CBlockIndex* block = ::ChainActive()[height];
|
||||
return block && ((block->nStatus & BLOCK_HAVE_DATA) != 0) && block->nTx > 0;
|
||||
}
|
||||
Optional<int> findFirstBlockWithTimeAndHeight(int64_t time, int height, uint256* hash) override
|
||||
{
|
||||
LOCK(cs_main);
|
||||
CBlockIndex* block = ::ChainActive().FindEarliestAtLeast(time, height);
|
||||
if (block) {
|
||||
if (hash) *hash = block->GetBlockHash();
|
||||
return block->nHeight;
|
||||
}
|
||||
return nullopt;
|
||||
}
|
||||
CBlockLocator getTipLocator() override
|
||||
{
|
||||
LOCK(cs_main);
|
||||
return ::ChainActive().GetLocator();
|
||||
}
|
||||
bool checkFinalTx(const CTransaction& tx) override
|
||||
{
|
||||
LOCK(cs_main);
|
||||
return CheckFinalTx(tx);
|
||||
}
|
||||
Optional<int> findLocatorFork(const CBlockLocator& locator) override
|
||||
{
|
||||
LOCK(cs_main);
|
||||
if (CBlockIndex* fork = FindForkInGlobalIndex(::ChainActive(), locator)) {
|
||||
return fork->nHeight;
|
||||
}
|
||||
return nullopt;
|
||||
}
|
||||
bool findBlock(const uint256& hash, const FoundBlock& block) override
|
||||
{
|
||||
WAIT_LOCK(cs_main, lock);
|
||||
|
||||
@@ -86,36 +86,6 @@ public:
|
||||
{
|
||||
public:
|
||||
virtual ~Lock() {}
|
||||
|
||||
//! Check that the block is available on disk (i.e. has not been
|
||||
//! pruned), and contains transactions.
|
||||
virtual bool haveBlockOnDisk(int height) = 0;
|
||||
|
||||
//! Return height of the first block in the chain with timestamp equal
|
||||
//! or greater than the given time and height equal or greater than the
|
||||
//! given height, or nullopt if there is no block with a high enough
|
||||
//! timestamp and height. Also return the block hash as an optional output parameter
|
||||
//! (to avoid the cost of a second lookup in case this information is needed.)
|
||||
virtual Optional<int> findFirstBlockWithTimeAndHeight(int64_t time, int height, uint256* hash) = 0;
|
||||
|
||||
//! Return height of the specified block if it is on the chain, otherwise
|
||||
//! return the height of the highest block on chain that's an ancestor
|
||||
//! of the specified block, or nullopt if there is no common ancestor.
|
||||
//! Also return the height of the specified block as an optional output
|
||||
//! parameter (to avoid the cost of a second hash lookup in case this
|
||||
//! information is desired).
|
||||
virtual Optional<int> findFork(const uint256& hash, Optional<int>* height) = 0;
|
||||
|
||||
//! Get locator for the current chain tip.
|
||||
virtual CBlockLocator getTipLocator() = 0;
|
||||
|
||||
//! Return height of the highest block on chain in common with the locator,
|
||||
//! which will either be the original block used to create the locator,
|
||||
//! or one of its ancestors.
|
||||
virtual Optional<int> findLocatorFork(const CBlockLocator& locator) = 0;
|
||||
|
||||
//! Check if transaction will be final given chain height current time.
|
||||
virtual bool checkFinalTx(const CTransaction& tx) = 0;
|
||||
};
|
||||
|
||||
//! Return Lock interface. Chain is locked when this is called, and
|
||||
@@ -135,6 +105,28 @@ public:
|
||||
//! Get block hash. Height must be valid or this function will abort.
|
||||
virtual uint256 getBlockHash(int height) = 0;
|
||||
|
||||
//! Check that the block is available on disk (i.e. has not been
|
||||
//! pruned), and contains transactions.
|
||||
virtual bool haveBlockOnDisk(int height) = 0;
|
||||
|
||||
//! Return height of the first block in the chain with timestamp equal
|
||||
//! or greater than the given time and height equal or greater than the
|
||||
//! given height, or nullopt if there is no block with a high enough
|
||||
//! timestamp and height. Also return the block hash as an optional output parameter
|
||||
//! (to avoid the cost of a second lookup in case this information is needed.)
|
||||
virtual Optional<int> findFirstBlockWithTimeAndHeight(int64_t time, int height, uint256* hash) = 0;
|
||||
|
||||
//! Get locator for the current chain tip.
|
||||
virtual CBlockLocator getTipLocator() = 0;
|
||||
|
||||
//! Return height of the highest block on chain in common with the locator,
|
||||
//! which will either be the original block used to create the locator,
|
||||
//! or one of its ancestors.
|
||||
virtual Optional<int> findLocatorFork(const CBlockLocator& locator) = 0;
|
||||
|
||||
//! Check if transaction will be final given chain height current time.
|
||||
virtual bool checkFinalTx(const CTransaction& tx) = 0;
|
||||
|
||||
//! Return whether node has the block and optionally return block metadata
|
||||
//! or contents.
|
||||
virtual bool findBlock(const uint256& hash, const FoundBlock& block={}) = 0;
|
||||
|
||||
@@ -60,7 +60,7 @@ WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
|
||||
}
|
||||
|
||||
//! Construct wallet tx status struct.
|
||||
WalletTxStatus MakeWalletTxStatus(interfaces::Chain::Lock& locked_chain, const CWalletTx& wtx)
|
||||
WalletTxStatus MakeWalletTxStatus(CWallet& wallet, const CWalletTx& wtx)
|
||||
{
|
||||
WalletTxStatus result;
|
||||
result.block_height = wtx.m_confirm.block_height > 0 ? wtx.m_confirm.block_height : std::numeric_limits<int>::max();
|
||||
@@ -68,8 +68,8 @@ WalletTxStatus MakeWalletTxStatus(interfaces::Chain::Lock& locked_chain, const C
|
||||
result.depth_in_main_chain = wtx.GetDepthInMainChain();
|
||||
result.time_received = wtx.nTimeReceived;
|
||||
result.lock_time = wtx.tx->nLockTime;
|
||||
result.is_final = locked_chain.checkFinalTx(*wtx.tx);
|
||||
result.is_trusted = wtx.IsTrusted(locked_chain);
|
||||
result.is_final = wallet.chain().checkFinalTx(*wtx.tx);
|
||||
result.is_trusted = wtx.IsTrusted();
|
||||
result.is_abandoned = wtx.isAbandoned();
|
||||
result.is_coinbase = wtx.IsCoinBase();
|
||||
result.is_in_main_chain = wtx.IsInMainChain();
|
||||
@@ -322,7 +322,7 @@ public:
|
||||
num_blocks = m_wallet->GetLastBlockHeight();
|
||||
block_time = -1;
|
||||
CHECK_NONFATAL(m_wallet->chain().findBlock(m_wallet->GetLastBlockHash(), FoundBlock().time(block_time)));
|
||||
tx_status = MakeWalletTxStatus(*locked_chain, mi->second);
|
||||
tx_status = MakeWalletTxStatus(*m_wallet, mi->second);
|
||||
return true;
|
||||
}
|
||||
WalletTx getWalletTxDetails(const uint256& txid,
|
||||
@@ -338,7 +338,7 @@ public:
|
||||
num_blocks = m_wallet->GetLastBlockHeight();
|
||||
in_mempool = mi->second.InMempool();
|
||||
order_form = mi->second.vOrderForm;
|
||||
tx_status = MakeWalletTxStatus(*locked_chain, mi->second);
|
||||
tx_status = MakeWalletTxStatus(*m_wallet, mi->second);
|
||||
return MakeWalletTx(*m_wallet, mi->second);
|
||||
}
|
||||
return {};
|
||||
@@ -413,7 +413,7 @@ public:
|
||||
auto locked_chain = m_wallet->chain().lock();
|
||||
LOCK(m_wallet->cs_wallet);
|
||||
CoinsList result;
|
||||
for (const auto& entry : m_wallet->ListCoins(*locked_chain)) {
|
||||
for (const auto& entry : m_wallet->ListCoins()) {
|
||||
auto& group = result[entry.first];
|
||||
for (const auto& coin : entry.second) {
|
||||
group.emplace_back(COutPoint(coin.tx->GetHash(), coin.i),
|
||||
|
||||
Reference in New Issue
Block a user