mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-13 12:33:42 +02:00
Merge ee9befe8b4 into merged_master (Bitcoin PR bitcoin/bitcoin#21584)
This commit is contained in:
commit
1fd44e5dfc
10 changed files with 130 additions and 123 deletions
|
|
@ -1236,7 +1236,7 @@ void CoinsViews::InitCache()
|
|||
m_cacheview = std::make_unique<CCoinsViewCache>(&m_catcherview);
|
||||
}
|
||||
|
||||
CChainState::CChainState(CTxMemPool& mempool, BlockManager& blockman, uint256 from_snapshot_blockhash)
|
||||
CChainState::CChainState(CTxMemPool& mempool, BlockManager& blockman, std::optional<uint256> from_snapshot_blockhash)
|
||||
: m_mempool(mempool),
|
||||
m_blockman(blockman),
|
||||
m_from_snapshot_blockhash(from_snapshot_blockhash) {}
|
||||
|
|
@ -1247,8 +1247,8 @@ void CChainState::InitCoinsDB(
|
|||
bool should_wipe,
|
||||
std::string leveldb_name)
|
||||
{
|
||||
if (!m_from_snapshot_blockhash.IsNull()) {
|
||||
leveldb_name += "_" + m_from_snapshot_blockhash.ToString();
|
||||
if (m_from_snapshot_blockhash) {
|
||||
leveldb_name += "_" + m_from_snapshot_blockhash->ToString();
|
||||
}
|
||||
|
||||
m_coins_views = std::make_unique<CoinsViews>(
|
||||
|
|
@ -4234,7 +4234,7 @@ bool CVerifyDB::VerifyDB(
|
|||
int reportDone = 0;
|
||||
LogPrintf("[0%%]..."); /* Continued */
|
||||
|
||||
bool is_snapshot_cs = !chainstate.m_from_snapshot_blockhash.IsNull();
|
||||
const bool is_snapshot_cs{!chainstate.m_from_snapshot_blockhash};
|
||||
|
||||
for (pindex = chainstate.m_chain.Tip(); pindex && pindex->pprev; pindex = pindex->pprev) {
|
||||
const int percentageDone = std::max(1, std::min(99, (int)(((double)(chainstate.m_chain.Height() - pindex->nHeight)) / (double)nCheckDepth * (nCheckLevel >= 4 ? 50 : 100))));
|
||||
|
|
@ -4815,8 +4815,8 @@ std::string CChainState::ToString()
|
|||
{
|
||||
CBlockIndex* tip = m_chain.Tip();
|
||||
return strprintf("Chainstate [%s] @ height %d (%s)",
|
||||
m_from_snapshot_blockhash.IsNull() ? "ibd" : "snapshot",
|
||||
tip ? tip->nHeight : -1, tip ? tip->GetBlockHash().ToString() : "null");
|
||||
m_from_snapshot_blockhash ? "snapshot" : "ibd",
|
||||
tip ? tip->nHeight : -1, tip ? tip->GetBlockHash().ToString() : "null");
|
||||
}
|
||||
|
||||
bool CChainState::ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
|
||||
|
|
@ -5018,10 +5018,10 @@ double GuessVerificationProgress(const CBlockIndex* pindex, int64_t blockInterva
|
|||
return std::min(1.0, progress);
|
||||
}
|
||||
|
||||
std::optional<uint256> ChainstateManager::SnapshotBlockhash() const {
|
||||
std::optional<uint256> ChainstateManager::SnapshotBlockhash() const
|
||||
{
|
||||
LOCK(::cs_main);
|
||||
if (m_active_chainstate != nullptr &&
|
||||
!m_active_chainstate->m_from_snapshot_blockhash.IsNull()) {
|
||||
if (m_active_chainstate && m_active_chainstate->m_from_snapshot_blockhash) {
|
||||
// If a snapshot chainstate exists, it will always be our active.
|
||||
return m_active_chainstate->m_from_snapshot_blockhash;
|
||||
}
|
||||
|
|
@ -5044,9 +5044,9 @@ std::vector<CChainState*> ChainstateManager::GetAll()
|
|||
return out;
|
||||
}
|
||||
|
||||
CChainState& ChainstateManager::InitializeChainstate(CTxMemPool& mempool, const uint256& snapshot_blockhash)
|
||||
CChainState& ChainstateManager::InitializeChainstate(CTxMemPool& mempool, const std::optional<uint256>& snapshot_blockhash)
|
||||
{
|
||||
bool is_snapshot = !snapshot_blockhash.IsNull();
|
||||
bool is_snapshot = snapshot_blockhash.has_value();
|
||||
std::unique_ptr<CChainState>& to_modify =
|
||||
is_snapshot ? m_snapshot_chainstate : m_ibd_chainstate;
|
||||
|
||||
|
|
@ -5171,6 +5171,26 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
|
|||
|
||||
uint256 base_blockhash = metadata.m_base_blockhash;
|
||||
|
||||
CBlockIndex* snapshot_start_block = WITH_LOCK(::cs_main, return m_blockman.LookupBlockIndex(base_blockhash));
|
||||
|
||||
if (!snapshot_start_block) {
|
||||
// Needed for GetUTXOStats and ExpectedAssumeutxo to determine the height and to avoid a crash when base_blockhash.IsNull()
|
||||
LogPrintf("[snapshot] Did not find snapshot start blockheader %s\n",
|
||||
base_blockhash.ToString());
|
||||
return false;
|
||||
}
|
||||
|
||||
int base_height = snapshot_start_block->nHeight;
|
||||
auto maybe_au_data = ExpectedAssumeutxo(base_height, ::Params());
|
||||
|
||||
if (!maybe_au_data) {
|
||||
LogPrintf("[snapshot] assumeutxo height in snapshot metadata not recognized " /* Continued */
|
||||
"(%d) - refusing to load snapshot\n", base_height);
|
||||
return false;
|
||||
}
|
||||
|
||||
const AssumeutxoData& au_data = *maybe_au_data;
|
||||
|
||||
COutPoint outpoint;
|
||||
Coin coin;
|
||||
const uint64_t coins_count = metadata.m_coins_count;
|
||||
|
|
@ -5261,15 +5281,6 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
|
|||
|
||||
assert(coins_cache.GetBestBlock() == base_blockhash);
|
||||
|
||||
CBlockIndex* snapshot_start_block = WITH_LOCK(::cs_main, return m_blockman.LookupBlockIndex(base_blockhash));
|
||||
|
||||
if (!snapshot_start_block) {
|
||||
// Needed for GetUTXOStats to determine the height
|
||||
LogPrintf("[snapshot] Did not find snapshot start blockheader %s\n",
|
||||
base_blockhash.ToString());
|
||||
return false;
|
||||
}
|
||||
|
||||
CCoinsStats stats{CoinStatsHashType::HASH_SERIALIZED};
|
||||
auto breakpoint_fnc = [] { /* TODO insert breakpoint here? */ };
|
||||
|
||||
|
|
@ -5283,19 +5294,7 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
|
|||
}
|
||||
|
||||
// Assert that the deserialized chainstate contents match the expected assumeutxo value.
|
||||
|
||||
int base_height = snapshot_start_block->nHeight;
|
||||
auto maybe_au_data = ExpectedAssumeutxo(base_height, ::Params());
|
||||
|
||||
if (!maybe_au_data) {
|
||||
LogPrintf("[snapshot] assumeutxo height in snapshot metadata not recognized " /* Continued */
|
||||
"(%d) - refusing to load snapshot\n", base_height);
|
||||
return false;
|
||||
}
|
||||
|
||||
const AssumeutxoData& au_data = *maybe_au_data;
|
||||
|
||||
if (stats.hashSerialized != au_data.hash_serialized) {
|
||||
if (AssumeutxoHash{stats.hashSerialized} != au_data.hash_serialized) {
|
||||
LogPrintf("[snapshot] bad snapshot content hash: expected %s, got %s\n",
|
||||
au_data.hash_serialized.ToString(), stats.hashSerialized.ToString());
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue