@@ -47,20 +47,14 @@ impl<T> FullEthApiServer for T where
4747{
4848}
4949
50- /// Bitfinity lag API
51- pub const LAG_STATUS_BAD : & str = "LAGGING" ;
52-
53- /// Bitfinity lag API
54- pub const LAG_STATUS_OK : & str = "ACCEPTED_LAG" ;
55-
5650/// Eth rpc interface: <https://ethereum.github.io/execution-apis/api-documentation/>
5751#[ cfg_attr( not( feature = "client" ) , rpc( server, namespace = "eth" ) ) ]
5852#[ cfg_attr( feature = "client" , rpc( server, client, namespace = "eth" ) ) ]
5953pub trait EthApi < T : RpcObject , B : RpcObject , R : RpcObject , H : RpcObject > {
60- /// Bitfinity LB api extenstion
61- /// Handler for: `eth_lagging `
62- #[ method( name = "lagging " ) ]
63- async fn lagging ( & self , accepted_lag : Option < U64 > ) -> RpcResult < String > ;
54+ /// Bitfinity LB api extension
55+ /// Handler for: `eth_lbLagCheck `
56+ #[ method( name = "lbLagCheck " ) ]
57+ async fn lb_lag_check ( & self , accepted_lag : Option < U64 > ) -> RpcResult < String > ;
6458
6559 /// Returns the protocol version encoded as a string.
6660 #[ method( name = "protocolVersion" ) ]
@@ -397,22 +391,32 @@ where
397391 T : FullEthApi ,
398392 jsonrpsee_types:: error:: ErrorObject < ' static > : From < T :: Error > ,
399393{
400- /// Handler for: `eth_lagging`
401- async fn lagging ( & self , accepted_lag : Option < U64 > ) -> RpcResult < String > {
394+ /// Handler for: `eth_lbLagCheck`
395+ async fn lb_lag_check ( & self , accepted_lag : Option < U64 > ) -> RpcResult < String > {
396+ const LAG_STATUS_BAD : & str = "LAGGING" ;
397+ const LAG_STATUS_OK : & str = "ACCEPTED_LAG" ;
398+ let network_block = match BitfinityEvmRpc :: network_block_number ( self ) . await {
399+ Ok ( block) => block,
400+ Err ( e) => {
401+ // Must not fail if rpc-url/evmc is not responding
402+ // or it would to break nodes cluster -> LB will stop traffic
403+ tracing:: error!( target: "rpc::eth" , "Failed to get block number from the network. {}" , e) ;
404+ return Ok ( format ! ( "{}: NO_SOURCE" , LAG_STATUS_OK ) ) ;
405+ }
406+ } ;
407+
402408 let accepted_lag = match accepted_lag {
403409 Some ( lag) => U256 :: from ( lag) ,
404410 // Assuming that lag behind for 3 block is ok
405411 None => U256 :: from ( 3 ) ,
406412 } ;
407413
408- let network_block = BitfinityEvmRpc :: network_block_number ( self ) . await ?;
409414 let node_block = self . block_number ( ) ?;
410415 let lag = network_block. saturating_sub ( node_block) ;
411416
412- let status =
413- if lag > accepted_lag { LAG_STATUS_BAD . to_owned ( ) } else { LAG_STATUS_OK . to_owned ( ) } ;
417+ let status = if lag > accepted_lag { LAG_STATUS_BAD } else { LAG_STATUS_OK } ;
414418
415- // Better to repond with string that add structure, import serde and stuff
419+ // Better to respond with string that add structure, import serde and stuff
416420 let response =
417421 format ! ( "{}: lag: {} node: {} network: {}" , status, lag, node_block, network_block) ;
418422
0 commit comments