b9f9d11929
* Only use kvdb "column families" This PR contains the changes necessary to use the `kvdb-*` crates from https://github.com/paritytech/parity-common/pull/278 (so a synchronized merge is required) which drops support for the old-style rocksdb "default" column to get a smaller and less complex API. As it stands this PR is working correctly except for secret-store; we need to migrate it to use a new column family. * Fix secretstore build * Fix secretstore build: include ethkey when building with the "accounts" feature * typos * Restore state test commit * Override all of parity-common from git * Be precise about version requirement to migrate secretstore code * Update ethcore/db/src/db.rs Co-Authored-By: Niklas Adolfsson <niklasadolfsson1@gmail.com> * Address review grumbles * Review grumbles * Cleanup Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
89 lines
2.6 KiB
Rust
89 lines
2.6 KiB
Rust
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
|
// This file is part of Parity Ethereum.
|
|
|
|
// Parity Ethereum is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Parity Ethereum is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Blooms migration from rocksdb to blooms-db
|
|
|
|
use std::path::Path;
|
|
use ethereum_types::Bloom;
|
|
use types::errors::EthcoreError as Error;
|
|
use rlp;
|
|
use super::kvdb_rocksdb::DatabaseConfig;
|
|
use super::open_database;
|
|
|
|
const LOG_BLOOMS_ELEMENTS_PER_INDEX: u64 = 16;
|
|
|
|
pub fn migrate_blooms<P: AsRef<Path>>(path: P, config: &DatabaseConfig) -> Result<(), Error> {
|
|
// init
|
|
let db = open_database(&path.as_ref().to_string_lossy(), config)?;
|
|
|
|
// possible optimization:
|
|
// pre-allocate space on disk for faster migration
|
|
|
|
// iterate over header blooms and insert them in blooms-db
|
|
// Some(3) -> COL_EXTRA
|
|
// 3u8 -> ExtrasIndex::BlocksBlooms
|
|
// 0u8 -> level 0
|
|
let blooms_iterator = db.key_value()
|
|
.iter_from_prefix(3, &[3u8, 0u8])
|
|
.filter(|(key, _)| key.len() == 6)
|
|
.take_while(|(key, _)| {
|
|
key[0] == 3u8 && key[1] == 0u8
|
|
})
|
|
.map(|(key, group)| {
|
|
let index =
|
|
(key[2] as u64) << 24 |
|
|
(key[3] as u64) << 16 |
|
|
(key[4] as u64) << 8 |
|
|
(key[5] as u64);
|
|
let number = index * LOG_BLOOMS_ELEMENTS_PER_INDEX;
|
|
|
|
let blooms = rlp::decode_list::<Bloom>(&group);
|
|
(number, blooms)
|
|
});
|
|
|
|
for (number, blooms) in blooms_iterator {
|
|
db.blooms().insert_blooms(number, blooms.iter())?;
|
|
}
|
|
|
|
// iterate over trace blooms and insert them in blooms-db
|
|
// Some(4) -> COL_TRACE
|
|
// 1u8 -> TraceDBIndex::BloomGroups
|
|
// 0u8 -> level 0
|
|
let trace_blooms_iterator = db.key_value()
|
|
.iter_from_prefix(4, &[1u8, 0u8])
|
|
.filter(|(key, _)| key.len() == 6)
|
|
.take_while(|(key, _)| {
|
|
key[0] == 1u8 && key[1] == 0u8
|
|
})
|
|
.map(|(key, group)| {
|
|
let index =
|
|
(key[2] as u64) |
|
|
(key[3] as u64) << 8 |
|
|
(key[4] as u64) << 16 |
|
|
(key[5] as u64) << 24;
|
|
let number = index * LOG_BLOOMS_ELEMENTS_PER_INDEX;
|
|
|
|
let blooms = rlp::decode_list::<Bloom>(&group);
|
|
(number, blooms)
|
|
});
|
|
|
|
for (number, blooms) in trace_blooms_iterator {
|
|
db.trace_blooms().insert_blooms(number, blooms.iter())?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|