Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean the unused build_index #3026

Merged
merged 1 commit into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,6 @@ impl Chain {
},
)?;

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

Expand Down Expand Up @@ -1128,7 +1127,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 @@ -1235,9 +1234,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