Skip to content

Commit

Permalink
client: fix justifications migration (paritytech#8489)
Browse files Browse the repository at this point in the history
* client: rename variables

* client: fix justifications migration

* client: fix compilation
  • Loading branch information
andresilva authored and hirschenberger committed Apr 14, 2021
1 parent fd518d5 commit 2d42831
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,10 @@ impl<Block: BlockT> sc_client_api::blockchain::Backend<Block> for BlockchainDb<B

fn justifications(&self, id: BlockId<Block>) -> ClientResult<Option<Justifications>> {
match read_db(&*self.db, columns::KEY_LOOKUP, columns::JUSTIFICATIONS, id)? {
Some(justification) => match Decode::decode(&mut &justification[..]) {
Ok(justification) => Ok(Some(justification)),
Some(justifications) => match Decode::decode(&mut &justifications[..]) {
Ok(justifications) => Ok(Some(justifications)),
Err(err) => return Err(sp_blockchain::Error::Backend(
format!("Error decoding justification: {}", err)
format!("Error decoding justifications: {}", err)
)),
}
None => Ok(None),
Expand Down
9 changes: 7 additions & 2 deletions client/db/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::path::{Path, PathBuf};
use sp_runtime::traits::Block as BlockT;
use crate::{columns, utils::DatabaseType};
use kvdb_rocksdb::{Database, DatabaseConfig};
use codec::Encode;
use codec::{Decode, Encode};

/// Version file name.
const VERSION_FILE_NAME: &'static str = "db_version";
Expand Down Expand Up @@ -83,7 +83,12 @@ fn migrate_2_to_3<Block: BlockT>(db_path: &Path, _db_type: DatabaseType) -> sp_b
let mut transaction = db.transaction();
for key in keys {
if let Some(justification) = db.get(columns::JUSTIFICATIONS, &key).map_err(db_err)? {
// Tag each Justification with the hardcoded ID for GRANDPA. Avoid the dependency on the GRANDPA crate
// Tag each justification with the hardcoded ID for GRANDPA to avoid the dependency on
// the GRANDPA crate.
// NOTE: when storing justifications the previous API would get a `Vec<u8>` and still
// call encode on it.
let justification = Vec::<u8>::decode(&mut &justification[..])
.map_err(|_| sp_blockchain::Error::Backend("Invalid justification blob".into()))?;
let justifications = sp_runtime::Justifications::from((*b"FRNK", justification));
transaction.put_vec(columns::JUSTIFICATIONS, &key, justifications.encode());
}
Expand Down

0 comments on commit 2d42831

Please sign in to comment.