mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-05-25 09:29:33 +00:00
Merge 48e5b10bf7fe0d23e9fc054a0c4d9cf5f0361014 into 694e48422847771b9d3d1948dc796830986003f2
This commit is contained in:
commit
7e2f2f180f
@ -8,6 +8,7 @@ license = { workspace = true }
|
|||||||
workspace = true
|
workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
sequencer_service_protocol.workspace = true
|
sequencer_service_protocol.workspace = true
|
||||||
|
|
||||||
jsonrpsee = { workspace = true, features = ["macros"] }
|
jsonrpsee = { workspace = true, features = ["macros"] }
|
||||||
|
|||||||
@ -5,11 +5,22 @@ use jsonrpsee::proc_macros::rpc;
|
|||||||
use jsonrpsee::types::ErrorObjectOwned;
|
use jsonrpsee::types::ErrorObjectOwned;
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
pub use jsonrpsee::{core::ClientError, http_client::HttpClientBuilder as SequencerClientBuilder};
|
pub use jsonrpsee::{core::ClientError, http_client::HttpClientBuilder as SequencerClientBuilder};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use sequencer_service_protocol::{
|
use sequencer_service_protocol::{
|
||||||
Account, AccountId, Block, BlockId, Commitment, HashType, MembershipProof, NSSATransaction,
|
Account, AccountId, Block, BlockId, Commitment, HashType, MembershipProof, NSSATransaction,
|
||||||
Nonce, ProgramId,
|
Nonce, ProgramId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Health status returned by the sequencer healthcheck endpoint.
|
||||||
|
/// The chain_height field can be polled twice to verify the sequencer is progressing.
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct HealthStatus {
|
||||||
|
/// Current chain height (block count). Should increase over time if sequencer is healthy.
|
||||||
|
pub chain_height: BlockId,
|
||||||
|
/// Whether the sequencer considers itself healthy.
|
||||||
|
pub is_healthy: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(all(not(feature = "server"), not(feature = "client")))]
|
#[cfg(all(not(feature = "server"), not(feature = "client")))]
|
||||||
compile_error!("At least one of `server` or `client` features must be enabled.");
|
compile_error!("At least one of `server` or `client` features must be enabled.");
|
||||||
|
|
||||||
@ -39,9 +50,10 @@ pub trait Rpc {
|
|||||||
#[method(name = "sendTransaction")]
|
#[method(name = "sendTransaction")]
|
||||||
async fn send_transaction(&self, tx: NSSATransaction) -> Result<HashType, ErrorObjectOwned>;
|
async fn send_transaction(&self, tx: NSSATransaction) -> Result<HashType, ErrorObjectOwned>;
|
||||||
|
|
||||||
// TODO: expand healthcheck response into some kind of report
|
/// Returns the current chain height (block count).
|
||||||
|
/// A sequencer is healthy if this value increases over time.
|
||||||
#[method(name = "checkHealth")]
|
#[method(name = "checkHealth")]
|
||||||
async fn check_health(&self) -> Result<(), ErrorObjectOwned>;
|
async fn check_health(&self) -> Result<HealthStatus, ErrorObjectOwned>;
|
||||||
|
|
||||||
// TODO: These functions should be removed after wallet starts using indexer
|
// TODO: These functions should be removed after wallet starts using indexer
|
||||||
// for this type of queries.
|
// for this type of queries.
|
||||||
|
|||||||
@ -12,6 +12,7 @@ use sequencer_core::{DbError, SequencerCore, block_publisher::BlockPublisherTrai
|
|||||||
use sequencer_service_protocol::{
|
use sequencer_service_protocol::{
|
||||||
Account, AccountId, Block, BlockId, Commitment, HashType, MembershipProof, Nonce, ProgramId,
|
Account, AccountId, Block, BlockId, Commitment, HashType, MembershipProof, Nonce, ProgramId,
|
||||||
};
|
};
|
||||||
|
use sequencer_service_rpc::HealthStatus;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
const NOT_FOUND_ERROR_CODE: i32 = -31999;
|
const NOT_FOUND_ERROR_CODE: i32 = -31999;
|
||||||
@ -79,8 +80,18 @@ impl<BC: BlockPublisherTrait + Send + 'static> sequencer_service_rpc::RpcServer
|
|||||||
Ok(tx_hash)
|
Ok(tx_hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn check_health(&self) -> Result<(), ErrorObjectOwned> {
|
async fn check_health(&self) -> Result<HealthStatus, ErrorObjectOwned> {
|
||||||
Ok(())
|
let sequencer = self.sequencer.lock().await;
|
||||||
|
let chain_height = sequencer.chain_height();
|
||||||
|
|
||||||
|
// Sequencer is considered healthy if it has produced at least the genesis block.
|
||||||
|
// Clients should poll this endpoint twice with a delay to verify chain_height increases.
|
||||||
|
let is_healthy = sequencer.block_store().latest_block_meta().is_ok();
|
||||||
|
|
||||||
|
Ok(HealthStatus {
|
||||||
|
chain_height,
|
||||||
|
is_healthy,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_block(&self, block_id: BlockId) -> Result<Option<Block>, ErrorObjectOwned> {
|
async fn get_block(&self, block_id: BlockId) -> Result<Option<Block>, ErrorObjectOwned> {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user