aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2019-01-07 23:38:53 -0800
committerRussell Yanofsky <russ@yanofsky.org>2019-01-15 08:42:00 -0800
commitdb21f0264855406c9b6ec4c084a15988c5c71b32 (patch)
tree453f8541449673867736c10f9fd1edd8b53b5476 /src/interfaces
parent2ffb07929ef480bd114defdc10b6a84463f222be (diff)
downloadbitcoin-db21f0264855406c9b6ec4c084a15988c5c71b32.tar.xz
Convert CWallet::ScanForWalletTransactions and SyncTransaction to the new Chain apis
Only change in behavior is "Rescan started from block <height>" message replaced by "Rescan started from block <hash>" message in ScanForWalletTransactions. Co-authored-by: Ben Woosley <ben.woosley@gmail.com>
Diffstat (limited to 'src/interfaces')
-rw-r--r--src/interfaces/chain.cpp41
-rw-r--r--src/interfaces/chain.h24
2 files changed, 65 insertions, 0 deletions
diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp
index 6e2224bc3e..1f39e650dc 100644
--- a/src/interfaces/chain.cpp
+++ b/src/interfaces/chain.cpp
@@ -60,6 +60,42 @@ class LockImpl : public Chain::Lock
assert(block != nullptr);
return block->GetMedianTimePast();
}
+ Optional<int> findFirstBlockWithTime(int64_t time, uint256* hash) override
+ {
+ CBlockIndex* block = ::chainActive.FindEarliestAtLeast(time);
+ if (block) {
+ if (hash) *hash = block->GetBlockHash();
+ return block->nHeight;
+ }
+ return nullopt;
+ }
+ Optional<int> findFirstBlockWithTimeAndHeight(int64_t time, int height) override
+ {
+ // TODO: Could update CChain::FindEarliestAtLeast() to take a height
+ // parameter and use it with std::lower_bound() to make this
+ // implementation more efficient and allow combining
+ // findFirstBlockWithTime and findFirstBlockWithTimeAndHeight into one
+ // method.
+ for (CBlockIndex* block = ::chainActive[height]; block; block = ::chainActive.Next(block)) {
+ if (block->GetBlockTime() >= time) {
+ return block->nHeight;
+ }
+ }
+ return nullopt;
+ }
+ Optional<int> findPruned(int start_height, Optional<int> stop_height) override
+ {
+ if (::fPruneMode) {
+ CBlockIndex* block = stop_height ? ::chainActive[*stop_height] : ::chainActive.Tip();
+ while (block && block->nHeight >= start_height) {
+ if ((block->nStatus & BLOCK_HAVE_DATA) == 0) {
+ return block->nHeight;
+ }
+ block = block->pprev;
+ }
+ }
+ return nullopt;
+ }
Optional<int> findFork(const uint256& hash, Optional<int>* height) override
{
const CBlockIndex* block = LookupBlockIndex(hash);
@@ -116,6 +152,11 @@ public:
}
return true;
}
+ double guessVerificationProgress(const uint256& block_hash) override
+ {
+ LOCK(cs_main);
+ return GuessVerificationProgress(Params().TxData(), LookupBlockIndex(block_hash));
+ }
};
} // namespace
diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h
index 8c7bd8c6ea..aef81675e0 100644
--- a/src/interfaces/chain.h
+++ b/src/interfaces/chain.h
@@ -58,6 +58,26 @@ public:
//! will abort.
virtual int64_t getBlockMedianTimePast(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
+ //! output parameter (to avoid the cost of a second lookup in case this
+ //! information is needed.)
+ virtual Optional<int> findFirstBlockWithTime(int64_t time, uint256* hash) = 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 such block.
+ //!
+ //! Calling this with height 0 is equivalent to calling
+ //! findFirstBlockWithTime, but less efficient because it requires a
+ //! linear instead of a binary search.
+ virtual Optional<int> findFirstBlockWithTimeAndHeight(int64_t time, int height) = 0;
+
+ //! Return height of last block in the specified range which is pruned, or
+ //! nullopt if no block in the range is pruned. Range is inclusive.
+ virtual Optional<int> findPruned(int start_height = 0, Optional<int> stop_height = nullopt) = 0;
+
//! Return height of the highest block on the chain that is an ancestor
//! of the specified block, or nullopt if no common ancestor is found.
//! Also return the height of the specified block as an optional output
@@ -85,6 +105,10 @@ public:
CBlock* block = nullptr,
int64_t* time = nullptr,
int64_t* max_time = nullptr) = 0;
+
+ //! Estimate fraction of total transactions verified if blocks up to
+ //! the specified block hash are verified.
+ virtual double guessVerificationProgress(const uint256& block_hash) = 0;
};
//! Interface to let node manage chain clients (wallets, or maybe tools for