Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc-types-engine): add forkchoice state zero helpers #1231

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Changes from all commits
Commits
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
35 changes: 35 additions & 0 deletions crates/rpc-types-engine/src/forkchoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,41 @@ pub struct ForkchoiceState {
pub finalized_block_hash: B256,
}

impl ForkchoiceState {
/// Returns the `head_block_hash`, only if it is not [`B256::ZERO`], otherwise this returns
/// [`None`].
#[inline]
pub fn state_head_hash(&self) -> Option<B256> {
if self.head_block_hash.is_zero() {
None
} else {
Some(self.head_block_hash)
}
}

/// Returns the `safe_block_hash`, only if it is not [`B256::ZERO`], otherwise this returns
/// [`None`].
#[inline]
pub fn state_safe_hash(&self) -> Option<B256> {
if self.safe_block_hash.is_zero() {
None
} else {
Some(self.safe_block_hash)
}
}

/// Returns the `finalized_block_hash`, only if it is not [`B256::ZERO`], otherwise this
/// returns [`None`].
#[inline]
pub fn state_finalized_hash(&self) -> Option<B256> {
if self.finalized_block_hash.is_zero() {
None
} else {
Some(self.finalized_block_hash)
}
}
}

/// A standalone forkchoice update errors for RPC.
///
/// These are considered hard RPC errors and are _not_ returned as [PayloadStatus] or
Expand Down