Merge branch 'lmdb_update' into grim
This commit is contained in:
+5
-3
@@ -1299,9 +1299,11 @@ impl Chain {
|
||||
|
||||
// Remove old blocks (including short lived fork blocks) which height < tail.height
|
||||
for block in batch.blocks_iter()? {
|
||||
if block.header.height < tail.height {
|
||||
let _ = batch.delete_block(&block.hash());
|
||||
count += 1;
|
||||
if let Ok(block) = block {
|
||||
if block.header.height < tail.height {
|
||||
let _ = batch.delete_block(&block.hash());
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -409,13 +409,17 @@ impl<T: PosEntry> PruneableListIndex for MultiIndex<T> {
|
||||
let mut entry_count = 0;
|
||||
let list_db_key = Some(self.list_prefix);
|
||||
for key in batch.db.iter(list_db_key, |k, _| Ok(k.to_vec()))? {
|
||||
let _ = batch.delete(list_db_key, &key);
|
||||
list_count += 1;
|
||||
if let Ok(key) = key {
|
||||
let _ = batch.delete(list_db_key, &key);
|
||||
list_count += 1;
|
||||
}
|
||||
}
|
||||
let entry_db_key = Some(self.entry_prefix);
|
||||
for key in batch.db.iter(entry_db_key, |k, _| Ok(k.to_vec()))? {
|
||||
let _ = batch.delete(entry_db_key, &key);
|
||||
entry_count += 1;
|
||||
if let Ok(key) = key {
|
||||
let _ = batch.delete(entry_db_key, &key);
|
||||
entry_count += 1;
|
||||
}
|
||||
}
|
||||
debug!(
|
||||
"clear: lists deleted: {}, entries deleted: {}",
|
||||
|
||||
+7
-3
@@ -339,7 +339,9 @@ impl<'a> Batch<'a> {
|
||||
}
|
||||
|
||||
/// Iterator over the output_pos index.
|
||||
pub fn output_pos_iter(&self) -> Result<impl Iterator<Item = (Vec<u8>, CommitPos)>, Error> {
|
||||
pub fn output_pos_iter(
|
||||
&self,
|
||||
) -> Result<impl Iterator<Item = Result<(Vec<u8>, CommitPos), Error>>, Error> {
|
||||
let protocol_version = self.db.protocol_version();
|
||||
self.db.iter(Some(OUTPUT_POS_PREFIX), move |k, mut v| {
|
||||
ser::deserialize(&mut v, protocol_version, DeserializationMode::default())
|
||||
@@ -459,7 +461,7 @@ impl<'a> Batch<'a> {
|
||||
|
||||
/// Iterator over all full blocks in the db.
|
||||
/// Uses default db serialization strategy via db protocol version.
|
||||
pub fn blocks_iter(&self) -> Result<impl Iterator<Item = Block> + 'a, Error> {
|
||||
pub fn blocks_iter(&self) -> Result<impl Iterator<Item = Result<Block, Error>> + 'a, Error> {
|
||||
let protocol_version = self.db.protocol_version();
|
||||
self.db.iter(Some(BLOCK_PREFIX), move |_, mut v| {
|
||||
ser::deserialize(&mut v, protocol_version, DeserializationMode::default())
|
||||
@@ -469,7 +471,9 @@ impl<'a> Batch<'a> {
|
||||
|
||||
/// Iterator over raw data for full blocks in the db.
|
||||
/// Used during block migration (we need flexibility around deserialization).
|
||||
pub fn blocks_raw_iter(&self) -> Result<impl Iterator<Item = (Vec<u8>, Vec<u8>)>, Error> {
|
||||
pub fn blocks_raw_iter(
|
||||
&self,
|
||||
) -> Result<impl Iterator<Item = Result<(Vec<u8>, Vec<u8>), Error>>, Error> {
|
||||
self.db
|
||||
.iter(Some(BLOCK_PREFIX), |k, v| Ok((k.to_vec(), v.to_vec())))
|
||||
}
|
||||
|
||||
@@ -644,21 +644,23 @@ impl TxHashSet {
|
||||
// Iterate over the current output_pos index, removing any entries that
|
||||
// do not point to to the expected output.
|
||||
let mut removed_count = 0;
|
||||
for (key, pos1) in batch.output_pos_iter()? {
|
||||
let pos0 = pos1.pos - 1;
|
||||
if let Some(out) = output_pmmr.get_data(pos0) {
|
||||
if let Ok(pos0_via_mmr) = batch.get_output_pos(&out.commitment()) {
|
||||
// If the pos matches and the index key matches the commitment
|
||||
// then keep the entry, other we want to clean it up.
|
||||
if pos0 == pos0_via_mmr
|
||||
&& batch.is_match_output_pos_key(&key, &out.commitment())
|
||||
{
|
||||
continue;
|
||||
for kp in batch.output_pos_iter()? {
|
||||
if let Ok((key, pos1)) = kp {
|
||||
let pos0 = pos1.pos - 1;
|
||||
if let Some(out) = output_pmmr.get_data(pos0) {
|
||||
if let Ok(pos0_via_mmr) = batch.get_output_pos(&out.commitment()) {
|
||||
// If the pos matches and the index key matches the commitment
|
||||
// then keep the entry, other we want to clean it up.
|
||||
if pos0 == pos0_via_mmr
|
||||
&& batch.is_match_output_pos_key(&key, &out.commitment())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
batch.delete(Some(store::OUTPUT_POS_PREFIX), &key)?;
|
||||
removed_count += 1;
|
||||
}
|
||||
batch.delete(Some(store::OUTPUT_POS_PREFIX), &key)?;
|
||||
removed_count += 1;
|
||||
}
|
||||
debug!(
|
||||
"init_output_pos_index: removed {} stale index entries",
|
||||
|
||||
Reference in New Issue
Block a user