Changeset View
Changeset View
Standalone View
Standalone View
src/txdb.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | |||||
std::vector<uint256> CCoinsViewDB::GetHeadBlocks() const { | std::vector<uint256> CCoinsViewDB::GetHeadBlocks() const { | ||||
std::vector<uint256> vhashHeadBlocks; | std::vector<uint256> vhashHeadBlocks; | ||||
if (!db.Read(DB_HEAD_BLOCKS, vhashHeadBlocks)) { | if (!db.Read(DB_HEAD_BLOCKS, vhashHeadBlocks)) { | ||||
return std::vector<uint256>(); | return std::vector<uint256>(); | ||||
} | } | ||||
return vhashHeadBlocks; | return vhashHeadBlocks; | ||||
} | } | ||||
CUtxoCommit CCoinsViewDB::GetCommitment() { | |||||
// TODO fetch from storage | |||||
// TODO perform initial upgrade using CUtxoCommit::AddCoinView | |||||
return CUtxoCommit(); | |||||
} | |||||
void CCoinsViewDB::UpdateCommitment(CCoinsMap &mapCoins) { | |||||
size_t updated = 0; | |||||
LogPrintf("Starting update commitment delta\n"); | |||||
// TODO parallelize | |||||
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end(); | |||||
it++) { | |||||
// Ignore non-dirty entries (optimization). | |||||
if (it->second.flags & CCoinsCacheEntry::UNCOMMITED) { | |||||
if (it->second.coin.IsSpent()) { | |||||
// TODO: This doesn't work; we'll need to change | |||||
// Coin::IsSpent to keep the TxOut in memory if spent | |||||
// and add a bool is spent | |||||
utxoCommitDelta.Remove(it->first, it->second.coin); | |||||
} else { | |||||
utxoCommitDelta.Add(it->first, it->second.coin); | |||||
} | |||||
updated++; | |||||
it->second.flags &= | |||||
~(CCoinsCacheEntry::UNCOMMITED | CCoinsCacheEntry::FRESH); | |||||
} | |||||
} | |||||
LogPrintf("Done update commitment delta; %d entries\n", updated); | |||||
} | |||||
bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { | bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { | ||||
CDBBatch batch(db); | CDBBatch batch(db); | ||||
size_t count = 0; | size_t count = 0; | ||||
size_t changed = 0; | size_t changed = 0; | ||||
size_t batch_size = | size_t batch_size = | ||||
(size_t)gArgs.GetArg("-dbbatchsize", nDefaultDbBatchSize); | (size_t)gArgs.GetArg("-dbbatchsize", nDefaultDbBatchSize); | ||||
int crash_simulate = gArgs.GetArg("-dbcrashratio", 0); | int crash_simulate = gArgs.GetArg("-dbcrashratio", 0); | ||||
assert(!hashBlock.IsNull()); | assert(!hashBlock.IsNull()); | ||||
Show All 9 Lines | bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { | ||||
// In the first batch, mark the database as being in the middle of a | // In the first batch, mark the database as being in the middle of a | ||||
// transition from old_tip to hashBlock. | // transition from old_tip to hashBlock. | ||||
// A vector is used for future extensibility, as we may want to support | // A vector is used for future extensibility, as we may want to support | ||||
// interrupting after partial writes from multiple independent reorgs. | // interrupting after partial writes from multiple independent reorgs. | ||||
batch.Erase(DB_BEST_BLOCK); | batch.Erase(DB_BEST_BLOCK); | ||||
batch.Write(DB_HEAD_BLOCKS, std::vector<uint256>{hashBlock, old_tip}); | batch.Write(DB_HEAD_BLOCKS, std::vector<uint256>{hashBlock, old_tip}); | ||||
UpdateCommitment(mapCoins); | |||||
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) { | for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) { | ||||
if (it->second.flags & CCoinsCacheEntry::DIRTY) { | if (it->second.flags & CCoinsCacheEntry::DIRTY) { | ||||
CoinEntry entry(&it->first); | CoinEntry entry(&it->first); | ||||
if (it->second.coin.IsSpent()) { | if (it->second.coin.IsSpent()) { | ||||
batch.Erase(entry); | batch.Erase(entry); | ||||
} else { | } else { | ||||
batch.Write(entry, it->second.coin); | batch.Write(entry, it->second.coin); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 341 Lines • Show Last 20 Lines |