From 3d4a6d2db8f9e0ca1e68bf1944d12ee558aa06de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Tue, 30 Mar 2021 09:48:17 +0100 Subject: [PATCH 1/3] client: rename variables --- client/db/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/db/src/lib.rs b/client/db/src/lib.rs index 0fc8e299f2a6c..03a6ce2200957 100644 --- a/client/db/src/lib.rs +++ b/client/db/src/lib.rs @@ -561,10 +561,10 @@ impl sc_client_api::blockchain::Backend for BlockchainDb) -> ClientResult> { 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), From e8236ace500036f2c750ff64a32ed48d15478da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Tue, 30 Mar 2021 09:49:31 +0100 Subject: [PATCH 2/3] client: fix justifications migration --- client/db/src/upgrade.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/db/src/upgrade.rs b/client/db/src/upgrade.rs index 6c7cbbb4a1af6..b45e86d9cebf0 100644 --- a/client/db/src/upgrade.rs +++ b/client/db/src/upgrade.rs @@ -83,8 +83,11 @@ fn migrate_2_to_3(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` and still + // call encode on it. + let justifications = sp_runtime::Justifications::from((*b"FRNK", justification.decode())); transaction.put_vec(columns::JUSTIFICATIONS, &key, justifications.encode()); } } From 88562716beeb713c75cc3405bb7ed0b6229d9590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Tue, 30 Mar 2021 10:04:48 +0100 Subject: [PATCH 3/3] client: fix compilation --- client/db/src/upgrade.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/db/src/upgrade.rs b/client/db/src/upgrade.rs index b45e86d9cebf0..ea91b8253e1d8 100644 --- a/client/db/src/upgrade.rs +++ b/client/db/src/upgrade.rs @@ -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"; @@ -87,7 +87,9 @@ fn migrate_2_to_3(db_path: &Path, _db_type: DatabaseType) -> sp_b // the GRANDPA crate. // NOTE: when storing justifications the previous API would get a `Vec` and still // call encode on it. - let justifications = sp_runtime::Justifications::from((*b"FRNK", justification.decode())); + let justification = Vec::::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()); } }