Merge branch 'rh-grandpa-dynamic2' of github.com:paritytech/substrate

This commit is contained in:
Robert Habermeier
2018-11-15 17:49:36 +01:00
29 changed files with 1833 additions and 478 deletions
+23 -13
View File
@@ -43,6 +43,7 @@ pub(crate) mod columns {
pub const HEADER: Option<u32> = Some(2);
pub const CACHE: Option<u32> = Some(3);
pub const CHT: Option<u32> = Some(4);
pub const AUX: Option<u32> = Some(5);
}
/// Prefix for headers CHT.
@@ -285,6 +286,7 @@ impl<Block> LightBlockchainStorage<Block> for LightStorage<Block>
header: Block::Header,
authorities: Option<Vec<AuthorityId>>,
leaf_state: NewBlockState,
aux_ops: Vec<(Vec<u8>, Option<Vec<u8>>)>,
) -> ClientResult<()> {
let mut transaction = DBTransaction::new();
@@ -300,6 +302,13 @@ impl<Block> LightBlockchainStorage<Block> for LightStorage<Block>
::utils::number_and_hash_to_lookup_key(number, hash)
};
for (key, maybe_val) in aux_ops {
match maybe_val {
Some(val) => transaction.put_vec(columns::AUX, &key, val),
None => transaction.delete(columns::AUX, &key),
}
}
if leaf_state.is_best() {
// handle reorg.
{
@@ -471,16 +480,17 @@ pub(crate) mod tests {
}
}
fn header_with_changes_trie(parent: &Hash, number: u64) -> Header {
let mut header = default_header(parent, number);
header.digest.logs.push(DigestItem::ChangesTrieRoot([(number % 256) as u8; 32].into()));
header
}
fn header_with_extrinsics_root(parent: &Hash, number: u64, extrinsics_root: Hash) -> Header {
let mut header = default_header(parent, number);
header.extrinsics_root = extrinsics_root;
header
pub fn insert_block_with_extrinsics_root(
db: &LightStorage<Block>,
parent: &Hash,
number: u64,
authorities: Option<Vec<AuthorityId>>,
extrinsics_root: Hash,
) -> Hash {
let header = prepare_header(parent, number, extrinsics_root);
let hash = header.hash();
db.import_header(header, authorities, NewBlockState::Best, Vec::new()).unwrap();
hash
}
pub fn insert_block<F: Fn() -> Header>(
@@ -490,7 +500,7 @@ pub(crate) mod tests {
) -> Hash {
let header = header();
let hash = header.hash();
db.import_header(header, authorities, NewBlockState::Best).unwrap();
db.import_header(header, authorities, NewBlockState::Best, Vec::new()).unwrap();
hash
}
@@ -501,7 +511,7 @@ pub(crate) mod tests {
) -> Hash {
let header = header();
let hash = header.hash();
db.import_header(header, authorities, NewBlockState::Final).unwrap();
db.import_header(header, authorities, NewBlockState::Final, Vec::new()).unwrap();
hash
}
@@ -512,7 +522,7 @@ pub(crate) mod tests {
) -> Hash {
let header = header();
let hash = header.hash();
db.import_header(header, authorities, NewBlockState::Normal).unwrap();
db.import_header(header, authorities, NewBlockState::Normal, Vec::new()).unwrap();
hash
}