Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9062f94
value ranges in consensus cache
svyatonik Aug 2, 2019
ce451c3
skip values in cache
svyatonik Aug 2, 2019
2efc6a4
read epoch0 + epoch1 data from genesis in babe
svyatonik Aug 2, 2019
d9d75bc
sync authorities + session validators at genesis
svyatonik Aug 4, 2019
aa491d0
removed some debug printlns
svyatonik Aug 4, 2019
de097ee
fixed cache encoding
svyatonik Aug 5, 2019
4bbebde
Revert "skip values in cache"
svyatonik Aug 5, 2019
2897a83
Revert "value ranges in consensus cache"
svyatonik Aug 5, 2019
2c72a87
get rid of cache::AUTHORITIES in Babe
svyatonik Aug 5, 2019
1c7b2cd
cleaning up
svyatonik Aug 5, 2019
cb2851f
cleaning up
svyatonik Aug 5, 2019
e5c7bd8
update spec version
svyatonik Aug 5, 2019
a838e9b
lost changes
svyatonik Aug 5, 2019
200a638
fixed tests
svyatonik Aug 5, 2019
3c420ff
Merge branch 'master' into fix_flaming_fir_light_sync
svyatonik Aug 5, 2019
c4c6788
Update node/runtime/src/lib.rs
svyatonik Aug 6, 2019
04f73d5
Merge branch 'master' into fix_flaming_fir_light_sync
svyatonik Aug 6, 2019
f30f0fb
fix once-per-block condition
svyatonik Aug 6, 2019
773982b
fix standalone babe + temp_storage in BuildGenesis
svyatonik Aug 6, 2019
c922fad
fix benhes compilation
svyatonik Aug 6, 2019
69fe38a
fixed comment
svyatonik Aug 6, 2019
b5e223e
Merge branch 'master' into fix_flaming_fir_light_sync
svyatonik Aug 8, 2019
54fd261
Merge branch 'master' into fix_flaming_fir_light_sync
svyatonik Aug 12, 2019
5991212
re-added light nodes to integration tests
svyatonik Aug 12, 2019
d24bb0b
Merge branch 'master' into fix_flaming_fir_light_sync
Demi-Marie Aug 14, 2019
51b79fc
finalize_with_ancestors from extra_requests
svyatonik Aug 14, 2019
651d8ad
Merge branch 'fix_flaming_fir_light_sync' of https://github.com/parit…
svyatonik Aug 14, 2019
8f106ae
post-merge fix
svyatonik Aug 14, 2019
b4dd1bd
aaand removed debug code
svyatonik Aug 14, 2019
d593290
(another one)
svyatonik Aug 14, 2019
a7adc1c
fix warn in logs (do not call ForkTree::finalize twice for the same b…
svyatonik Aug 14, 2019
707b288
sync digest.next_authorities with actual next authorities
svyatonik Aug 14, 2019
f1d0e41
more docs
svyatonik Aug 15, 2019
515587c
Merge branch 'master' into fix_flaming_fir_light_sync
svyatonik Aug 15, 2019
b328acb
reverting all commits affecting storage
svyatonik Aug 16, 2019
4786ea7
Merge branch 'master' into fix_flaming_fir_light_sync
svyatonik Aug 16, 2019
e33fd0f
also remove keys from babe trait
svyatonik Aug 16, 2019
e7644e4
fixed warnings
svyatonik Aug 16, 2019
f70bbcc
Merge branch 'master' into fix_flaming_fir_light_sync
svyatonik Aug 16, 2019
89447ee
post-merge fixes
svyatonik Aug 16, 2019
320534d
reverted some redundant changes
svyatonik Aug 16, 2019
5bf8db9
reverted more changes
svyatonik Aug 16, 2019
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
Prev Previous commit
Next Next commit
Revert "value ranges in consensus cache"
This reverts commit 9062f94.
  • Loading branch information
svyatonik committed Aug 5, 2019
commit 2897a830de69665f81dbfc2a01663f0cf3a0902b
19 changes: 8 additions & 11 deletions core/client/db/src/cache/list_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ impl<Block: BlockT, T: CacheItemT, S: Storage<Block, T>> ListCache<Block, T, S>
}

/// Get value valid at block.
pub fn value_at_block(
&self,
at: &ComplexBlockId<Block>,
) -> ClientResult<Option<(ComplexBlockId<Block>, Option<ComplexBlockId<Block>>, T)>> {
pub fn value_at_block(&self, at: &ComplexBlockId<Block>) -> ClientResult<Option<T>> {
let head = if at.number <= self.best_finalized_block.number {
// if the block is older than the best known finalized block
// => we're should search for the finalized value
Expand Down Expand Up @@ -167,7 +164,7 @@ impl<Block: BlockT, T: CacheItemT, S: Storage<Block, T>> ListCache<Block, T, S>

match head {
Some(head) => head.search_best_before(&self.storage, at.number)
.map(|e| e.map(|e| (e.0.valid_from, e.1, e.0.value))),
.map(|e| e.map(|e| e.0.value)),
None => Ok(None),
}
}
Expand Down Expand Up @@ -680,7 +677,7 @@ pub mod tests {
.with_entry(test_id(100), StorageEntry { prev_valid_from: Some(test_id(30)), value: 100 })
.with_entry(test_id(30), StorageEntry { prev_valid_from: None, value: 30 }),
1024, test_id(100)
).value_at_block(&test_id(50)).unwrap(), Some((test_id(30), Some(test_id(100)), 30)));
).value_at_block(&test_id(50)).unwrap(), Some(30));
// when block is the best finalized block AND value is some
// ---> [100]
assert_eq!(ListCache::new(
Expand All @@ -690,7 +687,7 @@ pub mod tests {
.with_entry(test_id(100), StorageEntry { prev_valid_from: Some(test_id(30)), value: 100 })
.with_entry(test_id(30), StorageEntry { prev_valid_from: None, value: 30 }),
1024, test_id(100)
).value_at_block(&test_id(100)).unwrap(), Some((test_id(100), None, 100)));
).value_at_block(&test_id(100)).unwrap(), Some(100));
// when block is parallel to the best finalized block
// ---- 100
// ---> [100]
Expand All @@ -711,7 +708,7 @@ pub mod tests {
.with_id(50, H256::from_low_u64_be(50))
.with_entry(test_id(100), StorageEntry { prev_valid_from: Some(test_id(30)), value: 100 }),
1024, test_id(100)
).value_at_block(&test_id(200)).unwrap(), Some((test_id(100), None, 100)));
).value_at_block(&test_id(200)).unwrap(), Some(100));

// when block is later than last finalized block AND there are no matching forks
// AND block is connected to finalized block AND finalized value is Some
Expand All @@ -727,7 +724,7 @@ pub mod tests {
.with_header(test_header(4))
.with_header(fork_header(0, 2, 3)),
1024, test_id(2)
).value_at_block(&fork_id(0, 2, 3)).unwrap(), Some((correct_id(2), None, 2)));
).value_at_block(&fork_id(0, 2, 3)).unwrap(), Some(2));
// when block is later than last finalized block AND there are no matching forks
// AND block is not connected to finalized block
// --- 2 --- 3
Expand Down Expand Up @@ -757,7 +754,7 @@ pub mod tests {
.with_header(test_header(4))
.with_header(test_header(5)),
1024, test_id(2)
).value_at_block(&correct_id(5)).unwrap(), Some((correct_id(4), None, 4)));
).value_at_block(&correct_id(5)).unwrap(), Some(4));
// when block is later than last finalized block AND it does not fits unfinalized fork
// AND it is connected to the finalized block AND finalized value is Some
// ---> [2] ----------> [4]
Expand All @@ -772,7 +769,7 @@ pub mod tests {
.with_header(test_header(4))
.with_header(fork_header(0, 2, 3)),
1024, test_id(2)
).value_at_block(&fork_id(0, 2, 3)).unwrap(), Some((correct_id(2), None, 2)));
).value_at_block(&fork_id(0, 2, 3)).unwrap(), Some(2));
}

#[test]
Expand Down
16 changes: 2 additions & 14 deletions core/client/db/src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,7 @@ impl<Block: BlockT> BlockchainCache<Block> for DbCacheSync<Block> {
Ok(())
}

fn get_at(
&self,
key: &CacheKeyId,
at: &BlockId<Block>,
) -> Option<((NumberFor<Block>, Block::Hash), Option<(NumberFor<Block>, Block::Hash)>, Vec<u8>)> {
fn get_at(&self, key: &CacheKeyId, at: &BlockId<Block>) -> Option<Vec<u8>> {
let cache = self.0.read();
let storage = cache.cache_at.get(key)?.storage();
let db = storage.db();
Expand All @@ -322,15 +318,7 @@ impl<Block: BlockT> BlockchainCache<Block> for DbCacheSync<Block> {
},
};

cache.cache_at.get(key)?
.value_at_block(&at)
.map(|block_and_value| block_and_value.map(|(begin_block, end_block, value)|
(
(begin_block.number, begin_block.hash),
end_block.map(|end_block| (end_block.number, end_block.hash)),
value,
)))
.ok()?
cache.cache_at.get(key)?.value_at_block(&at).ok()?
}
}

16 changes: 5 additions & 11 deletions core/client/db/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,10 @@ pub(crate) mod tests {
header
}

pub fn insert_block<F: FnMut() -> Header>(
pub fn insert_block<F: Fn() -> Header>(
db: &LightStorage<Block>,
cache: HashMap<well_known_cache_keys::Id, Vec<u8>>,
mut header: F,
header: F,
) -> Hash {
let header = header();
let hash = header.hash();
Expand Down Expand Up @@ -887,8 +887,7 @@ pub(crate) mod tests {
}

fn get_authorities(cache: &dyn BlockchainCache<Block>, at: BlockId<Block>) -> Option<Vec<AuthorityId>> {
cache.get_at(&well_known_cache_keys::AUTHORITIES, &at)
.and_then(|(_, _, val)| Decode::decode(&mut &val[..]))
cache.get_at(&well_known_cache_keys::AUTHORITIES, &at).and_then(|val| Decode::decode(&mut &val[..]))
}

let auth1 = || AuthorityId::from_raw([1u8; 32]);
Expand Down Expand Up @@ -1098,12 +1097,7 @@ pub(crate) mod tests {
assert_eq!(db.cache().get_at(b"test", &BlockId::Number(0)), None);

// insert genesis block (no value for cache is provided)
let mut genesis_hash = None;
insert_block(&db, HashMap::new(), || {
let header = default_header(&Default::default(), 0);
genesis_hash = Some(header.hash());
header
});
insert_block(&db, HashMap::new(), || default_header(&Default::default(), 0));

// after genesis is inserted => None
assert_eq!(db.cache().get_at(b"test", &BlockId::Number(0)), None);
Expand All @@ -1112,6 +1106,6 @@ pub(crate) mod tests {
db.cache().initialize(b"test", vec![42]).unwrap();

// after genesis is inserted + cache is initialized => Some
assert_eq!(db.cache().get_at(b"test", &BlockId::Number(0)), Some(((0, genesis_hash.unwrap()), None, vec![42])));
assert_eq!(db.cache().get_at(b"test", &BlockId::Number(0)), Some(vec![42]));
}
}
10 changes: 2 additions & 8 deletions core/client/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,8 @@ pub trait Cache<Block: BlockT>: Send + Sync {
/// The operation should be performed once before anything else is inserted in the cache.
/// Otherwise cache may end up in inconsistent state.
fn initialize(&self, key: &well_known_cache_keys::Id, value_at_genesis: Vec<u8>) -> Result<()>;
/// Returns cached value valid at given block.
///
/// Returned tuple is the range where value has been active and the value itself.
fn get_at(
&self,
key: &well_known_cache_keys::Id,
block: &BlockId<Block>,
) -> Option<((NumberFor<Block>, Block::Hash), Option<(NumberFor<Block>, Block::Hash)>, Vec<u8>)>;
/// Returns cached value by the given key.
fn get_at(&self, key: &well_known_cache_keys::Id, block: &BlockId<Block>) -> Option<Vec<u8>>;
}

/// Blockchain info
Expand Down
4 changes: 2 additions & 2 deletions core/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ fn initialize_authorities_cache<A, B, C>(client: &C) -> Result<(), ConsensusErro
let genesis_id = BlockId::Number(Zero::zero());
let genesis_authorities: Option<Vec<A>> = cache
.get_at(&well_known_cache_keys::AUTHORITIES, &genesis_id)
.and_then(|(_, _, v)| Decode::decode(&mut &v[..]));
.and_then(|v| Decode::decode(&mut &v[..]));
if genesis_authorities.is_some() {
return Ok(());
}
Expand Down Expand Up @@ -651,7 +651,7 @@ fn authorities<A, B, C>(client: &C, at: &BlockId<B>) -> Result<Vec<A>, Consensus
.cache()
.and_then(|cache| cache
.get_at(&well_known_cache_keys::AUTHORITIES, at)
.and_then(|(_, _, v)| Decode::decode(&mut &v[..]))
.and_then(|v| Decode::decode(&mut &v[..]))
)
.or_else(|| AuraApi::authorities(&*client.runtime_api(), at).ok())
.ok_or_else(|| consensus_common::Error::InvalidAuthoritiesSet.into())
Expand Down
9 changes: 5 additions & 4 deletions core/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ impl MaybeSpanEpoch {
}
}

#[cfg(test)]
pub fn into_regular(self) -> Option<Epoch> {
match self {
MaybeSpanEpoch::Regular(epoch) => Some(epoch),
Expand Down Expand Up @@ -799,8 +800,8 @@ fn epoch_from_cache<B, C>(client: &C, at: &BlockId<B>) -> Option<MaybeSpanEpoch>
// we need to go back for maximum two steps
client.cache()
.and_then(|cache| cache
.get_at_and_skip(0, &well_known_cache_keys::EPOCH, at)
.and_then(|(_, _, _, v)| Decode::decode(&mut &v[..])))
.get_at(&well_known_cache_keys::EPOCH, at)
.and_then(|v| Decode::decode(&mut &v[..])))
}

/// Extract current epoch from runtime.
Expand Down Expand Up @@ -929,7 +930,7 @@ fn initialize_authorities_cache<B, C>(client: &C) -> Result<(), ConsensusError>
let genesis_id = BlockId::Number(Zero::zero());
let genesis_epoch: Option<MaybeSpanEpoch> = cache
.get_at(&well_known_cache_keys::EPOCH, &genesis_id)
.and_then(|(_, _, v)| Decode::decode(&mut &v[..]));
.and_then(|v| Decode::decode(&mut &v[..]));
if genesis_epoch.is_some() {
return Ok(());
}
Expand Down Expand Up @@ -1076,7 +1077,7 @@ impl<B, E, Block, I, RA, PRA> BlockImport<Block> for BabeBlockImport<B, E, Block
&is_descendent_of,
&|epoch| epoch.start_slot <= slot_number,
).map_err(|e| ConsensusError::from(ConsensusError::ClientImport(e.to_string())))?;
println!("=== ENACTED_EPOCH: {:?}", enacted_epoch);

let check_roots = || -> Result<bool, ConsensusError> {
// this can only happen when the chain starts, since there's no
// epoch change at genesis. afterwards every time we expect an epoch
Expand Down