mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
Merge #15842: refactor: replace isPotentialtip/waitForNotifications by higher method
422677963arefactor: replace isPotentialtip/waitForNotifications by higher method (Antoine Riard)edfe9438caAdd WITH_LOCK macro: run code while locking a mutex (Antoine Riard) Pull request description: In Chain interface, instead of a isPotentialTip and a WaitForNotifications method, both used only once in CWallet::BlockUntilSyncedToCurrentChain, combine them in a higher WaitForNotificationsUpToTip method. Semantic should be unchanged, wallet wait for pending notifications to be processed unless block hash points to the current chain tip or a descendant. ACKs for commit 422677: jnewbery: ACK422677963aryanofsky: utACK422677963a. Only change is adding the cs_wallet lock annotation. Tree-SHA512: 2834ff0218795ef607543fae822e5cce25d759c1a9cfcb1f896a4af03071faed5276fbe0966e0c6ed65dc0e88af161899c5b2ca358a2d24fe70969a550000bf2
This commit is contained in:
@@ -122,12 +122,6 @@ class LockImpl : public Chain::Lock
|
||||
}
|
||||
return nullopt;
|
||||
}
|
||||
bool isPotentialTip(const uint256& hash) override
|
||||
{
|
||||
if (::chainActive.Tip()->GetBlockHash() == hash) return true;
|
||||
CBlockIndex* block = LookupBlockIndex(hash);
|
||||
return block && block->GetAncestor(::chainActive.Height()) == ::chainActive.Tip();
|
||||
}
|
||||
CBlockLocator getTipLocator() override { return ::chainActive.GetLocator(); }
|
||||
Optional<int> findLocatorFork(const CBlockLocator& locator) override
|
||||
{
|
||||
@@ -343,7 +337,16 @@ public:
|
||||
{
|
||||
return MakeUnique<NotificationsHandlerImpl>(*this, notifications);
|
||||
}
|
||||
void waitForNotifications() override { SyncWithValidationInterfaceQueue(); }
|
||||
void waitForNotificationsIfNewBlocksConnected(const uint256& old_tip) override
|
||||
{
|
||||
if (!old_tip.IsNull()) {
|
||||
LOCK(::cs_main);
|
||||
if (old_tip == ::chainActive.Tip()->GetBlockHash()) return;
|
||||
CBlockIndex* block = LookupBlockIndex(old_tip);
|
||||
if (block && block->GetAncestor(::chainActive.Height()) == ::chainActive.Tip()) return;
|
||||
}
|
||||
SyncWithValidationInterfaceQueue();
|
||||
}
|
||||
std::unique_ptr<Handler> handleRpc(const CRPCCommand& command) override
|
||||
{
|
||||
return MakeUnique<RpcHandlerImpl>(command);
|
||||
|
||||
@@ -43,12 +43,6 @@ class Wallet;
|
||||
//! asynchronously
|
||||
//! (https://github.com/bitcoin/bitcoin/pull/10973#issuecomment-380101269).
|
||||
//!
|
||||
//! * The isPotentialTip() and waitForNotifications() methods are too low-level
|
||||
//! and should be replaced with a higher level
|
||||
//! waitForNotificationsUpTo(block_hash) method that the wallet can call
|
||||
//! instead
|
||||
//! (https://github.com/bitcoin/bitcoin/pull/10973#discussion_r266995234).
|
||||
//!
|
||||
//! * The relayTransactions() and submitToMemoryPool() methods could be replaced
|
||||
//! with a higher-level broadcastTransaction method
|
||||
//! (https://github.com/bitcoin/bitcoin/pull/14978#issuecomment-459373984).
|
||||
@@ -123,11 +117,6 @@ public:
|
||||
//! information is desired).
|
||||
virtual Optional<int> findFork(const uint256& hash, Optional<int>* height) = 0;
|
||||
|
||||
//! Return true if block hash points to the current chain tip, or to a
|
||||
//! possible descendant of the current chain tip that isn't currently
|
||||
//! connected.
|
||||
virtual bool isPotentialTip(const uint256& hash) = 0;
|
||||
|
||||
//! Get locator for the current chain tip.
|
||||
virtual CBlockLocator getTipLocator() = 0;
|
||||
|
||||
@@ -256,8 +245,10 @@ public:
|
||||
//! Register handler for notifications.
|
||||
virtual std::unique_ptr<Handler> handleNotifications(Notifications& notifications) = 0;
|
||||
|
||||
//! Wait for pending notifications to be handled.
|
||||
virtual void waitForNotifications() = 0;
|
||||
//! Wait for pending notifications to be processed unless block hash points to the current
|
||||
//! chain tip, or to a possible descendant of the current chain tip that isn't currently
|
||||
//! connected.
|
||||
virtual void waitForNotificationsIfNewBlocksConnected(const uint256& old_tip) = 0;
|
||||
|
||||
//! Register handler for RPC. Command is not copied, so reference
|
||||
//! needs to remain valid until Handler is disconnected.
|
||||
|
||||
Reference in New Issue
Block a user