mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
Add just/fin block getters to fork choice
This commit is contained in:
@@ -43,6 +43,12 @@ pub enum Error<T> {
|
|||||||
block_root: Hash256,
|
block_root: Hash256,
|
||||||
payload_verification_status: PayloadVerificationStatus,
|
payload_verification_status: PayloadVerificationStatus,
|
||||||
},
|
},
|
||||||
|
MissingJustifiedBlock {
|
||||||
|
justified_checkpoint: Checkpoint,
|
||||||
|
},
|
||||||
|
MissingFinalizedBlock {
|
||||||
|
finalized_checkpoint: Checkpoint,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> From<InvalidAttestation> for Error<T> {
|
impl<T> From<InvalidAttestation> for Error<T> {
|
||||||
@@ -875,6 +881,29 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the `ProtoBlock` for the justified checkpoint.
|
||||||
|
///
|
||||||
|
/// ## Notes
|
||||||
|
///
|
||||||
|
/// This does *not* return the "best justified checkpoint". It returns the justified checkpoint
|
||||||
|
/// that is used for computing balances.
|
||||||
|
pub fn get_justified_block(&self) -> Result<ProtoBlock, Error<T::Error>> {
|
||||||
|
let justified_checkpoint = self.justified_checkpoint();
|
||||||
|
self.get_block(&justified_checkpoint.root)
|
||||||
|
.ok_or(Error::MissingJustifiedBlock {
|
||||||
|
justified_checkpoint,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the `ProtoBlock` for the finalized checkpoint.
|
||||||
|
pub fn get_finalized_block(&self) -> Result<ProtoBlock, Error<T::Error>> {
|
||||||
|
let finalized_checkpoint = self.finalized_checkpoint();
|
||||||
|
self.get_block(&finalized_checkpoint.root)
|
||||||
|
.ok_or(Error::MissingFinalizedBlock {
|
||||||
|
finalized_checkpoint,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Return `true` if `block_root` is equal to the finalized root, or a known descendant of it.
|
/// Return `true` if `block_root` is equal to the finalized root, or a known descendant of it.
|
||||||
pub fn is_descendant_of_finalized(&self, block_root: Hash256) -> bool {
|
pub fn is_descendant_of_finalized(&self, block_root: Hash256) -> bool {
|
||||||
self.proto_array
|
self.proto_array
|
||||||
|
|||||||
Reference in New Issue
Block a user