diff options
author | Russell Yanofsky <russ@yanofsky.org> | 2019-01-08 00:06:24 -0800 |
---|---|---|
committer | Russell Yanofsky <russ@yanofsky.org> | 2019-01-15 08:42:00 -0800 |
commit | 44de1561aaf7556bb8ae8b582c233742ff76767d (patch) | |
tree | 9b4497111bdfb87a5b37516283ee21a37f852440 /src/interfaces | |
parent | db21f0264855406c9b6ec4c084a15988c5c71b32 (diff) |
Remove remaining chainActive references from CWallet
This commit does not change behavior.
Co-authored-by: Ben Woosley <ben.woosley@gmail.com>
Diffstat (limited to 'src/interfaces')
-rw-r--r-- | src/interfaces/chain.cpp | 20 | ||||
-rw-r--r-- | src/interfaces/chain.h | 18 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp index 1f39e650dc..38888be8a3 100644 --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -60,6 +60,11 @@ class LockImpl : public Chain::Lock assert(block != nullptr); return block->GetMedianTimePast(); } + bool haveBlockOnDisk(int height) override + { + CBlockIndex* block = ::chainActive[height]; + return block && ((block->nStatus & BLOCK_HAVE_DATA) != 0) && block->nTx > 0; + } Optional<int> findFirstBlockWithTime(int64_t time, uint256* hash) override { CBlockIndex* block = ::chainActive.FindEarliestAtLeast(time); @@ -112,6 +117,21 @@ 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 getLocator() override { return ::chainActive.GetLocator(); } + Optional<int> findLocatorFork(const CBlockLocator& locator) override + { + LockAnnotation lock(::cs_main); + if (CBlockIndex* fork = FindForkInGlobalIndex(::chainActive, locator)) { + return fork->nHeight; + } + return nullopt; + } }; class LockingStateImpl : public LockImpl, public UniqueLock<CCriticalSection> diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index aef81675e0..735d5b60df 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -15,6 +15,7 @@ class CBlock; class CScheduler; class uint256; +struct CBlockLocator; namespace interfaces { @@ -58,6 +59,10 @@ public: //! will abort. virtual int64_t getBlockMedianTimePast(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, or nullopt if there is no block with //! a high enough timestamp. Also return the block hash as an optional @@ -84,6 +89,19 @@ public: //! 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; + + //! 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 getLocator() = 0; + + //! Return height of the latest block common to locator and chain, which + //! is guaranteed to be an ancestor of the block used to create the + //! locator. + virtual Optional<int> findLocatorFork(const CBlockLocator& locator) = 0; }; //! Return Lock interface. Chain is locked when this is called, and |