mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 22:21:02 +00:00
Fix light client startup (#1130)
* fix light client startup * fix grumbles
This commit is contained in:
committed by
GitHub
parent
d149f3358a
commit
62c590ef25
@@ -168,7 +168,7 @@ impl<Block: BlockT> BlockchainDb<Block> {
|
||||
is_finalized: bool
|
||||
) {
|
||||
let mut meta = self.meta.write();
|
||||
if number == Zero::zero() {
|
||||
if number.is_zero() {
|
||||
meta.genesis_hash = hash;
|
||||
meta.finalized_hash = hash;
|
||||
}
|
||||
@@ -778,7 +778,7 @@ impl<Block> client::backend::Backend<Block, Blake2Hasher> for Backend<Block> whe
|
||||
|
||||
transaction.put(columns::HASH_LOOKUP, hash.as_ref(), &lookup_key);
|
||||
|
||||
if number == Zero::zero() {
|
||||
if number.is_zero() {
|
||||
transaction.put(columns::META, meta_keys::FINALIZED_BLOCK, &lookup_key);
|
||||
transaction.put(columns::META, meta_keys::GENESIS_HASH, hash.as_ref());
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ impl<Block> LightStorage<Block>
|
||||
) {
|
||||
let mut meta = self.meta.write();
|
||||
|
||||
if number == Zero::zero() {
|
||||
if number.is_zero() {
|
||||
meta.genesis_hash = hash;
|
||||
meta.finalized_hash = hash;
|
||||
}
|
||||
@@ -369,6 +369,11 @@ impl<Block> LightBlockchainStorage<Block> for LightStorage<Block>
|
||||
transaction.put(columns::HEADER, &lookup_key, &header.encode());
|
||||
transaction.put(columns::HASH_LOOKUP, hash.as_ref(), &lookup_key);
|
||||
|
||||
if number.is_zero() {
|
||||
transaction.put(columns::META, meta_keys::FINALIZED_BLOCK, &lookup_key);
|
||||
transaction.put(columns::META, meta_keys::GENESIS_HASH, hash.as_ref());
|
||||
}
|
||||
|
||||
let finalized = match leaf_state {
|
||||
NewBlockState::Final => true,
|
||||
_ => false,
|
||||
@@ -385,7 +390,7 @@ impl<Block> LightBlockchainStorage<Block> for LightStorage<Block>
|
||||
let mut cache = self.cache.0.write();
|
||||
let cache_ops = cache.transaction(&mut transaction)
|
||||
.on_block_insert(
|
||||
ComplexBlockId::new(*header.parent_hash(), if number == Zero::zero() { Zero::zero() } else { number - One::one() }),
|
||||
ComplexBlockId::new(*header.parent_hash(), if number.is_zero() { Zero::zero() } else { number - One::one() }),
|
||||
ComplexBlockId::new(hash, number),
|
||||
authorities,
|
||||
finalized,
|
||||
@@ -429,7 +434,7 @@ impl<Block> LightBlockchainStorage<Block> for LightStorage<Block>
|
||||
let mut cache = self.cache.0.write();
|
||||
let cache_ops = cache.transaction(&mut transaction)
|
||||
.on_block_finalize(
|
||||
ComplexBlockId::new(*header.parent_hash(), if number == Zero::zero() { Zero::zero() } else { number - One::one() }),
|
||||
ComplexBlockId::new(*header.parent_hash(), if number.is_zero() { Zero::zero() } else { number - One::one() }),
|
||||
ComplexBlockId::new(hash, number)
|
||||
)?
|
||||
.into_ops();
|
||||
@@ -860,4 +865,17 @@ pub(crate) mod tests {
|
||||
assert_eq!(db.cache().authorities_at(BlockId::Hash(hash6_2)), Some(vec![[4u8; 32].into()]));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn database_is_reopened() {
|
||||
let db = LightStorage::new_test();
|
||||
let hash0 = insert_final_block(&db, None, || default_header(&Default::default(), 0));
|
||||
assert_eq!(db.info().unwrap().best_hash, hash0);
|
||||
assert_eq!(db.header(BlockId::Hash(hash0)).unwrap().unwrap().hash(), hash0);
|
||||
|
||||
let db = db.db;
|
||||
let db = LightStorage::from_kvdb(db).unwrap();
|
||||
assert_eq!(db.info().unwrap().best_hash, hash0);
|
||||
assert_eq!(db.header(BlockId::Hash::<Block>(hash0)).unwrap().unwrap().hash(), hash0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user