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

client: fix justifications migration #8489

Merged
3 commits merged into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 5 additions & 2 deletions client/db/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ 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
let justifications = sp_runtime::Justifications::from((*b"FRNK", justification));
// 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 justifications = sp_runtime::Justifications::from((*b"FRNK", justification.decode()));
tomaka marked this conversation as resolved.
Show resolved Hide resolved
transaction.put_vec(columns::JUSTIFICATIONS, &key, justifications.encode());
}
}
Expand Down