mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
Fix bugs
This commit is contained in:
@@ -210,13 +210,18 @@ impl DepositCache {
|
|||||||
///
|
///
|
||||||
/// Fetches the `DepositLog` that was emitted at or just before `block_number`
|
/// Fetches the `DepositLog` that was emitted at or just before `block_number`
|
||||||
/// and returns the deposit count as `index + 1`.
|
/// and returns the deposit count as `index + 1`.
|
||||||
|
///
|
||||||
|
/// Returns 0 if no logs are present.
|
||||||
|
/// Note: This function assumes that `block_number` > `deposit_contract_deploy_block`
|
||||||
pub fn get_deposit_count_from_cache(&self, block_number: u64) -> Option<u64> {
|
pub fn get_deposit_count_from_cache(&self, block_number: u64) -> Option<u64> {
|
||||||
|
Some(
|
||||||
self.logs
|
self.logs
|
||||||
.iter()
|
.iter()
|
||||||
.take_while(|log| log.block_number >= block_number)
|
.take_while(|log| block_number >= log.block_number)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.last()
|
.last()
|
||||||
.map(|x| x.index + 1)
|
.map_or(0, |x| x.index + 1),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the deposit root at block height = block_number.
|
/// Gets the deposit root at block height = block_number.
|
||||||
@@ -224,7 +229,7 @@ impl DepositCache {
|
|||||||
/// Fetches the `DepositLog` that was emitted at or just before `block_number`
|
/// Fetches the `DepositLog` that was emitted at or just before `block_number`
|
||||||
/// and returns the deposit root at that state.
|
/// and returns the deposit root at that state.
|
||||||
pub fn get_deposit_root_from_cache(&self, block_number: u64) -> Option<Hash256> {
|
pub fn get_deposit_root_from_cache(&self, block_number: u64) -> Option<Hash256> {
|
||||||
let index = self.get_deposit_count_from_cache(block_number)? - 1;
|
let index = self.get_deposit_count_from_cache(block_number)?;
|
||||||
let roots = self.roots.get(0..index as usize)?;
|
let roots = self.roots.get(0..index as usize)?;
|
||||||
let tree = DepositDataTree::create(roots, index as usize, DEPOSIT_CONTRACT_TREE_DEPTH);
|
let tree = DepositDataTree::create(roots, index as usize, DEPOSIT_CONTRACT_TREE_DEPTH);
|
||||||
Some(tree.root())
|
Some(tree.root())
|
||||||
|
|||||||
Reference in New Issue
Block a user