diff --git a/node/libs/roles/src/validator/messages/consensus.rs b/node/libs/roles/src/validator/messages/consensus.rs index 00ec37cb..51502bf6 100644 --- a/node/libs/roles/src/validator/messages/consensus.rs +++ b/node/libs/roles/src/validator/messages/consensus.rs @@ -358,7 +358,7 @@ impl std::ops::BitAnd for &Signers { } /// A struct that represents a view number. -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct ViewNumber(pub u64); impl ViewNumber { diff --git a/node/tools/src/rpc/methods/last_view.rs b/node/tools/src/rpc/methods/last_view.rs index 832e017c..162ca902 100644 --- a/node/tools/src/rpc/methods/last_view.rs +++ b/node/tools/src/rpc/methods/last_view.rs @@ -1,19 +1,29 @@ //! Peers method for RPC server. -use jsonrpsee::core::RpcResult; +use anyhow::Context; +use jsonrpsee::{ + core::RpcResult, + types::{error::ErrorCode, ErrorObjectOwned}, +}; use std::sync::Arc; use zksync_consensus_storage::BlockStore; -/// Config response for /config endpoint. +/// Last view response for /last_view endpoint. pub fn callback(node_storage: Arc) -> RpcResult { let sub = &mut node_storage.subscribe(); let state = sub.borrow().clone(); - let a = state.last.unwrap().view().number; + let last_view = state + .last + .context("Failed to get last state") + .map_err(|_| ErrorObjectOwned::from(ErrorCode::InternalError))? + .view() + .number + .0; Ok(serde_json::json!({ - "last_view": a + "last_view": last_view })) } -/// Config method name. +/// Last view method name. pub fn method() -> &'static str { "last_view" }