Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Optimize key directory reloads #4583

Merged
merged 5 commits into from
Feb 17, 2017
Merged

Optimize key directory reloads #4583

merged 5 commits into from
Feb 17, 2017

Conversation

NikVolf
Copy link
Contributor

@NikVolf NikVolf commented Feb 16, 2017

Only reloads if something changed in the directory (including from outside of the app)

addresses #4443

@NikVolf NikVolf added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. labels Feb 16, 2017
@NikVolf NikVolf changed the title Optimize disk directory reloads in secret store Optimize key directory reloads Feb 16, 2017
util/src/sha3.rs Outdated
@@ -68,6 +68,24 @@ impl<T> Hashable for T where T: AsRef<[u8]> {
}
}

impl<T> Hashable for [T] where T: Hashable {
fn sha3(&self) -> H256 {
Copy link
Contributor

@rphmeier rphmeier Feb 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation seems strange: intuitively I'm not sure what it would mean to call
vec!["a, "b", "c"].sha3(), but I don't think I would expect it to be

sha3("a") ^ sha3("b") ^ sha3("c") ^ sha3("").

Seems like any invocation of this could be replaced with:

things_to_hash.into_iter().map(|x| x.sha3()).fold(H256::default(), BitXor::bitxor)

To me, it has a much more apparent meaning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. actually, I think i won't use sha3 at all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and btw, just fyi, xoring is the preferred way to combine multiple hashes (that is proven to be as good as the individual hashes are themselves), so that's quite natural to expect this implementation when hashing list of hashes

@@ -62,6 +63,8 @@ pub trait KeyDirectory: Send + Sync {
fn path(&self) -> Option<&PathBuf> { None }
/// Return vault provider, if available
fn as_vault_provider(&self) -> Option<&VaultKeyDirectoryProvider> { None }
/// Returns hash of the directory content, if supported
fn hash(&self) -> Result<H256, Error> { Ok(H256::zero()) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this default implementation would lead to accounts never being reloaded?

Copy link
Contributor Author

@NikVolf NikVolf Feb 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key directory does not operate the concept of "reloading accounts" at all
it just returns hash of all account headers, if it is able to

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even so, there should not be a valid implementation of a key directory which causes reload_if_changed to think the data has never changed.

If we broaden the description of the function to something like "Returns a unique 32-byte representation of the directory's contents.", then I don't imagine any implementation which couldn't do it.

(in that case, a more descriptive name like unique_repr(&self) -> Result<H256, Error> might make sense)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, seems legit

return Ok(())
}
self.reload_accounts()?;
*last_dir_hash = dir_hash;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be set before reloading to prevent parallel reloads.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What? Set and release a lock before actual reloading?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, yeah, disregard that :)

@NikVolf NikVolf added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. and removed A0-pleasereview 🤓 Pull request needs code review. labels Feb 16, 2017
@NikVolf NikVolf added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Feb 16, 2017
@NikVolf
Copy link
Contributor Author

NikVolf commented Feb 16, 2017

@rphmeier updated using simple std hasher & addressed another issue

};
store.reload_accounts()?;
Ok(store)
}

fn reload_if_changed(&self) -> Result<(), Error> {
let mut last_dir_hash = self.dir_hash.lock();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will work for root dir only (not for vaults), but maybe that's a good idea for next PR :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@svyatonik
yeah but i guess users are not supposed to mess with the vault directories themselves

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they can use ethstore cli utility to modify vaults

Copy link
Collaborator

@svyatonik svyatonik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@svyatonik svyatonik added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Feb 17, 2017
@rphmeier rphmeier merged commit 998cb0d into master Feb 17, 2017
@arkpar arkpar deleted the sstore-opt branch March 8, 2017 15:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants