add a database migration for new accountdb
This commit is contained in:
@@ -2,4 +2,4 @@
|
||||
|
||||
mod v6;
|
||||
|
||||
pub use self::v6::ToV6;
|
||||
pub use self::v6::ToV6;
|
||||
@@ -1,3 +1,4 @@
|
||||
//! Database migrations.
|
||||
|
||||
pub mod extras;
|
||||
pub mod state;
|
||||
|
||||
5
ethcore/src/migrations/state/mod.rs
Normal file
5
ethcore/src/migrations/state/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
//! State database migrations.
|
||||
|
||||
mod v7;
|
||||
|
||||
pub use self::v7::ToV7;
|
||||
31
ethcore/src/migrations/state/v7.rs
Normal file
31
ethcore/src/migrations/state/v7.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use util::hash::{FixedHash, H256};
|
||||
use util::migration::SimpleMigration;
|
||||
use util::sha3::Hashable;
|
||||
|
||||
/// This migration migrates the state db to use an accountdb which ensures uniqueness
|
||||
/// using an address' hash as opposed to the address itself.
|
||||
pub struct ToV7;
|
||||
|
||||
impl SimpleMigration for ToV7 {
|
||||
fn version(&self) -> u32 {
|
||||
7
|
||||
}
|
||||
|
||||
fn simple_migrate(&self, mut key: Vec<u8>, value: Vec<u8>) -> Option<(Vec<u8>, Vec<u8>)> {
|
||||
let val_hash = value.sha3();
|
||||
assert!(key.len() == 32); // all keys in the state db are hashes.
|
||||
let key_h = H256::from_slice(&key[..]);
|
||||
if key_h != val_hash {
|
||||
// this is a key which has been xor'd with an address.
|
||||
// recover the address
|
||||
let address = key_h ^ val_hash;
|
||||
let address_hash = address.sha3();
|
||||
|
||||
let new_key = address_hash ^ val_hash;
|
||||
key.copy_from_slice(&new_key[..]);
|
||||
}
|
||||
// nothing to do here
|
||||
Some((key, value))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user