Page MenuHomePhabricator

D7875.diff
No OneTemporary

D7875.diff

diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h
--- a/src/interfaces/chain.h
+++ b/src/interfaces/chain.h
@@ -121,9 +121,6 @@
//! Get block hash. Height must be valid or this function will abort.
virtual BlockHash getBlockHash(int height) = 0;
- //! Get block time. Height must be valid or this function will abort.
- virtual int64_t getBlockTime(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;
diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp
--- a/src/interfaces/chain.cpp
+++ b/src/interfaces/chain.cpp
@@ -88,12 +88,6 @@
assert(block != nullptr);
return block->GetBlockHash();
}
- int64_t getBlockTime(int height) override {
- LockAssertion lock(::cs_main);
- CBlockIndex *block = ::ChainActive()[height];
- assert(block != nullptr);
- return block->GetBlockTime();
- }
bool haveBlockOnDisk(int height) override {
LockAssertion lock(::cs_main);
CBlockIndex *block = ::ChainActive()[height];
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -3838,15 +3838,18 @@
}
}
- // Map in which we'll infer heights of other keys
- const Optional<int> tip_height = locked_chain.getHeight();
+ // map in which we'll infer heights of other keys
+ std::map<CKeyID, const CWalletTx::Confirmation *> mapKeyFirstBlock;
+ CWalletTx::Confirmation max_confirm;
// the tip can be reorganized; use a 144-block safety margin
- const int max_height =
- tip_height && *tip_height > 144 ? *tip_height - 144 : 0;
- std::map<CKeyID, int> mapKeyFirstBlock;
+ max_confirm.block_height =
+ GetLastBlockHeight() > 144 ? GetLastBlockHeight() - 144 : 0;
+ CHECK_NONFATAL(chain().findAncestorByHeight(
+ GetLastBlockHash(), max_confirm.block_height,
+ FoundBlock().hash(max_confirm.hashBlock)));
for (const CKeyID &keyid : spk_man->GetKeys()) {
if (mapKeyBirth.count(keyid) == 0) {
- mapKeyFirstBlock[keyid] = max_height;
+ mapKeyFirstBlock[keyid] = &max_confirm;
}
}
@@ -3859,19 +3862,18 @@
for (const auto &entry : mapWallet) {
// iterate over all wallet transactions...
const CWalletTx &wtx = entry.second;
- if (Optional<int> height =
- locked_chain.getBlockHeight(wtx.m_confirm.hashBlock)) {
+ if (wtx.m_confirm.status == CWalletTx::CONFIRMED) {
// ... which are already in a block
for (const CTxOut &txout : wtx.tx->vout) {
// Iterate over all their outputs...
for (const auto &keyid :
GetAffectedKeys(txout.scriptPubKey, *spk_man)) {
// ... and all their affected keys.
- std::map<CKeyID, int>::iterator rit =
- mapKeyFirstBlock.find(keyid);
+ auto rit = mapKeyFirstBlock.find(keyid);
if (rit != mapKeyFirstBlock.end() &&
- *height < rit->second) {
- rit->second = *height;
+ wtx.m_confirm.block_height <
+ rit->second->block_height) {
+ rit->second = &wtx.m_confirm;
}
}
}
@@ -3880,9 +3882,11 @@
// Extract block timestamps for those keys.
for (const auto &entry : mapKeyFirstBlock) {
+ int64_t block_time;
+ CHECK_NONFATAL(chain().findBlock(entry.second->hashBlock,
+ FoundBlock().time(block_time)));
// block times can be 2h off
- mapKeyBirth[entry.first] =
- locked_chain.getBlockTime(entry.second) - TIMESTAMP_WINDOW;
+ mapKeyBirth[entry.first] = block_time - TIMESTAMP_WINDOW;
}
}

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 1, 11:02 (16 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5187460
Default Alt Text
D7875.diff (4 KB)

Event Timeline