-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Conversation
It looks like @andresilva signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
e75b14d
to
4c02710
Compare
4c02710
to
9346d29
Compare
ethstore/src/accounts_dir/disk.rs
Outdated
pub fn insert_with_filename(&self, account: SafeAccount, filename: String) -> Result<SafeAccount, Error> { | ||
/// insert account with given file name. if the filename is a duplicate of any stored account, a number is appended | ||
/// to the filename. | ||
pub fn insert_with_filename(&self, account: SafeAccount, mut filename: String) -> Result<SafeAccount, Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please check that this comment in update
(https://github.com/paritytech/parity/blob/006b2f35640d2b729b77b4c5f93b2e9b6a10c5d4/ethstore/src/accounts_dir/disk.rs#L202) is still valid? I mean - if existing account is updated (the file with the same name already exists), file won't be duplicated (with suffix append).
ethstore/src/accounts_dir/disk.rs
Outdated
/// to the filename. | ||
pub fn insert_with_filename(&self, account: SafeAccount, mut filename: String) -> Result<SafeAccount, Error> { | ||
// check for duplicate filenames and append/increment counter | ||
let dups: Vec<_> = self.files()?.into_iter().filter_map(|f| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also - maybe just check if file exists (fs::metadata(_)is_ok()
) and then just add a random suffix, instead of reading all the files list (self.files()
) and trying to maintain an order (do not know if an order is important here)? This should increase performance of insert/update - iirc there are cases when there are a lot (>>10000) key files in single dir.
Do not have a strong opinion on this, though
Codecov Report
@@ Coverage Diff @@
## master #7873 +/- ##
=========================================
+ Coverage 81.91% 82.12% +0.2%
=========================================
Files 660 660
Lines 83539 83539
=========================================
+ Hits 68435 68608 +173
+ Misses 15104 14931 -173
Continue to review full report at Codecov.
|
@svyatonik I simplified the deduplication according to your suggestion and fixed the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks good. But maybe worth another check by someone familiar with all account id caveats.
|
||
/// insert account with given filename. if the filename is a duplicate of any stored account and dedup is set to | ||
/// true, a random suffix is appended to the filename. | ||
pub fn insert_with_filename(&self, account: SafeAccount, mut filename: String, dedup: bool) -> Result<SafeAccount, Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is dedup
optional and not a default behaviour?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Afair this function is also used to update the key file (for instance after a name change or meta change).
|
||
/// insert account with given filename. if the filename is a duplicate of any stored account and dedup is set to | ||
/// true, a random suffix is appended to the filename. | ||
pub fn insert_with_filename(&self, account: SafeAccount, mut filename: String, dedup: bool) -> Result<SafeAccount, Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Afair this function is also used to update the key file (for instance after a name change or meta change).
ethstore/src/accounts_dir/disk.rs
Outdated
@@ -286,6 +291,14 @@ impl KeyFileManager for DiskKeyFileManager { | |||
} | |||
} | |||
|
|||
fn account_filename(account: &SafeAccount) -> String { | |||
// build file path | |||
account.filename.as_ref().cloned().unwrap_or_else(|| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.as_ref().cloned() -> .clone()
ethstore/src/accounts_dir/disk.rs
Outdated
/// true, a random suffix is appended to the filename. | ||
pub fn insert_with_filename(&self, account: SafeAccount, mut filename: String, dedup: bool) -> Result<SafeAccount, Error> { | ||
// path to keyfile | ||
let mut keyfile_path = self.path.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let keyfile_path = self.path.join(&filename)
Fixed grumbles. |
* rpc: generate new account id for imported wallets * ethstore: handle duplicate wallet filenames * ethstore: simplify deduplication of wallet file names * ethstore: do not dedup wallet filenames on update * ethstore: fix minor grumbles
* rpc: generate new account id for imported wallets * ethstore: handle duplicate wallet filenames * ethstore: simplify deduplication of wallet file names * ethstore: do not dedup wallet filenames on update * ethstore: fix minor grumbles
* update back-references more aggressively after answering from cache (#7578) * Add new EF ropstens nodes. (#7824) * Add new EF ropstens nodes. * Fix tests * Add a timeout for light client sync requests (#7848) * Add a timeout for light client sync requests * Adjusting timeout to number of headers * Flush keyfiles. Resolves #7632 (#7868) * Fix wallet import (#7873) * rpc: generate new account id for imported wallets * ethstore: handle duplicate wallet filenames * ethstore: simplify deduplication of wallet file names * ethstore: do not dedup wallet filenames on update * ethstore: fix minor grumbles * [WASM] mem_cmp added to the Wasm runtime (#7539) * mem_cmp added to the Wasm runtime * schedule.wasm.mem_copy to schedule.wasm.mem_cmp for mem_cmp * [Wasm] memcmp fix and test added (#7590) * [Wasm] memcmp fix and test added * [Wasm] use reqrep_test! macro for memcmp test * wasmi interpreter (#7796) * adjust storage update evm-style (#7812) * disable internal memory (#7842)
* update back-references more aggressively after answering from cache (#7578) * Flush keyfiles. Resolves #7632 (#7868) * Fix wallet import (#7873) * rpc: generate new account id for imported wallets * ethstore: handle duplicate wallet filenames * ethstore: simplify deduplication of wallet file names * ethstore: do not dedup wallet filenames on update * ethstore: fix minor grumbles * parity-version pr reopen (#7136) * parity-version module split from util removed unused util deps and features trigger buildbot again only kvdb links rocksdb snappy linker issues * rm snappy * fixed old version imports * Move updater metadata to Cargo.toml of parity-version. (#7832) * Update version. * Bump parity version. * Fix version. * Fix compilation.
This PR updates the wallet import to always generate a new account id and handle duplicate key filenames.