Skip to content

Commit

Permalink
Clean the unused build_index (#3026)
Browse files Browse the repository at this point in the history
  • Loading branch information
garyyu authored Sep 9, 2019
1 parent fa0fed9 commit 7a07541
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 41 deletions.
7 changes: 2 additions & 5 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,6 @@ impl Chain {
},
)?;

extension.rebuild_index()?;
Ok(())
})?;

Expand Down Expand Up @@ -1140,7 +1139,7 @@ impl Chain {
self.txhashset.read().last_n_kernel(distance)
}

/// as above, for kernels
/// Return Commit's MMR position
pub fn get_output_pos(&self, commit: &Commitment) -> Result<u64, Error> {
Ok(self.txhashset.read().get_output_pos(commit)?)
}
Expand Down Expand Up @@ -1247,9 +1246,7 @@ impl Chain {
}

/// Migrate the index 'commitment -> output_pos' to index 'commitment -> (output_pos, block_height)'
/// Note: should only be called in two cases:
/// - Node start-up. For database migration from the old version.
/// - After the txhashset 'rebuild_index' when state syncing.
/// Note: should only be called when Node start-up, for database migration from the old version.
pub fn rebuild_height_for_pos(&self) -> Result<(), Error> {
let header_pmmr = self.header_pmmr.read();
let txhashset = self.txhashset.read();
Expand Down
10 changes: 1 addition & 9 deletions chain/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,6 @@ impl<'a> Batch<'a> {
Ok(())
}

/// Save output_pos to index.
pub fn save_output_pos(&self, commit: &Commitment, pos: u64) -> Result<(), Error> {
self.db.put_ser(
&to_key(COMMIT_POS_PREFIX, &mut commit.as_ref().to_vec())[..],
&pos,
)
}

/// Save output_pos and block height to index.
pub fn save_output_pos_height(
&self,
Expand Down Expand Up @@ -328,7 +320,7 @@ impl<'a> Batch<'a> {
)
}

/// Clear all entries from the output_pos index.
/// Clear all entries from the output_pos index. (only for migration purpose)
pub fn clear_output_pos(&self) -> Result<(), Error> {
let key = to_key(COMMIT_POS_PREFIX, &mut "".to_string().into_bytes());
for (k, _) in self.db.iter::<u64>(&key)? {
Expand Down
27 changes: 0 additions & 27 deletions chain/src/txhashset/txhashset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,33 +1142,6 @@ impl<'a> Extension<'a> {
Ok((output_sum, kernel_sum))
}

/// Rebuild the index of MMR positions to the corresponding UTXOs.
/// This is a costly operation performed only when we receive a full new chain state.
///
/// Note: only called by txhashset_write, and should be replaced by 'rebuild_height_pos_index'
/// in the future, after a refactoring of 'txhashset_write'.
pub fn rebuild_index(&self) -> Result<(), Error> {
let now = Instant::now();

self.batch.clear_output_pos()?;

let mut count = 0;
for pos in self.output_pmmr.leaf_pos_iter() {
if let Some(out) = self.output_pmmr.get_data(pos) {
self.batch.save_output_pos(&out.commit, pos)?;
count += 1;
}
}

debug!(
"txhashset: rebuild_index: {} UTXOs, took {}s",
count,
now.elapsed().as_secs(),
);

Ok(())
}

/// Force the rollback of this extension, no matter the result
pub fn force_rollback(&mut self) {
self.rollback = true;
Expand Down

0 comments on commit 7a07541

Please sign in to comment.