@@ -2,10 +2,13 @@ use ledger::FpExt;
22use mina_p2p_messages:: bigint:: BigInt ;
33use mina_signer:: Signature ;
44use redux:: Timestamp ;
5- use serde:: Serialize ;
5+ use serde:: { Deserialize , Serialize } ;
66
7- use super :: RpcNodeStatus ;
8- use crate :: p2p:: PeerId ;
7+ use super :: {
8+ RpcNodeStatus , RpcNodeStatusSnarkPool , RpcNodeStatusTransactionPool ,
9+ RpcNodeStatusTransitionFrontier ,
10+ } ;
11+ use crate :: { p2p:: PeerId , stats:: block_producer:: BlockProductionAttempt } ;
912use openmina_node_account:: { AccountPublicKey , AccountSecretKey } ;
1013
1114/// Matches the representation used by o1js where each field is a string
@@ -89,15 +92,38 @@ impl SignedNodeHeartbeat {
8992}
9093
9194/// Node heartbeat
92- #[ derive( Serialize , Debug , Clone ) ]
95+ #[ derive( Serialize , Deserialize , Debug , Clone ) ]
9396pub struct NodeHeartbeat {
94- pub status : RpcNodeStatus ,
97+ pub status : NodeStatus ,
9598 pub node_timestamp : Timestamp ,
9699 pub peer_id : PeerId ,
97100 // binprot+base64 encoded block
98101 pub last_produced_block : Option < String > ,
99102}
100103
104+ #[ derive( Serialize , Deserialize , Debug , Clone ) ]
105+ pub struct NodeStatus {
106+ pub chain_id : Option < String > ,
107+ pub transition_frontier : RpcNodeStatusTransitionFrontier ,
108+ pub peers_count : u32 ,
109+ pub snark_pool : RpcNodeStatusSnarkPool ,
110+ pub transaction_pool : RpcNodeStatusTransactionPool ,
111+ pub current_block_production_attempt : Option < BlockProductionAttempt > ,
112+ }
113+
114+ impl From < RpcNodeStatus > for NodeStatus {
115+ fn from ( status : RpcNodeStatus ) -> Self {
116+ Self {
117+ chain_id : status. chain_id ,
118+ transition_frontier : status. transition_frontier ,
119+ peers_count : status. peers . len ( ) as u32 ,
120+ snark_pool : status. snark_pool ,
121+ transaction_pool : status. transaction_pool ,
122+ current_block_production_attempt : status. current_block_production_attempt ,
123+ }
124+ }
125+ }
126+
101127/// Blake2b hash of the encoded heartbeat payload
102128#[ derive( Clone , Debug ) ]
103129pub struct NodeHeartbeatPayloadDigest ( [ u8 ; 32 ] ) ;
@@ -179,8 +205,8 @@ impl NodeHeartbeat {
179205pub ( crate ) mod tests {
180206
181207 use crate :: rpc:: {
182- RpcNodeStatusResources , RpcNodeStatusSnarkPool , RpcNodeStatusTransactionPool ,
183- RpcNodeStatusTransitionFrontier , RpcNodeStatusTransitionFrontierSync ,
208+ RpcNodeStatusSnarkPool , RpcNodeStatusTransactionPool , RpcNodeStatusTransitionFrontier ,
209+ RpcNodeStatusTransitionFrontierSync ,
184210 } ;
185211
186212 use super :: * ;
@@ -197,14 +223,14 @@ pub(crate) mod tests {
197223 println ! ( "Payload: {}" , signed. payload) ;
198224 println ! ( "Signature: {:?}" , signed. signature) ;
199225
200- assert_eq ! ( & signed. payload, "eyJzdGF0dXMiOnsiY2hhaW5faWQiOm51bGwsInRyYW5zaXRpb25fZnJvbnRpZXIiOnsiYmVzdF90aXAiOm51bGwsInN5bmMiOnsidGltZSI6bnVsbCwic3RhdHVzIjoiU3luY2VkIiwicGhhc2UiOiJSdW5uaW5nIiwidGFyZ2V0IjpudWxsfX0sInBlZXJzIjpbXSwic25hcmtfcG9vbCI6eyJ0b3RhbF9qb2JzIjowLCJzbmFya3MiOjB9LCJ0cmFuc2FjdGlvbl9wb29sIjp7InRyYW5zYWN0aW9ucyI6MCwidHJhbnNhY3Rpb25zX2Zvcl9wcm9wYWdhdGlvbiI6MCwidHJhbnNhY3Rpb25fY2FuZGlkYXRlcyI6MH0sImN1cnJlbnRfYmxvY2tfcHJvZHVjdGlvbl9hdHRlbXB0IjpudWxsfSwibm9kZV90aW1lc3RhbXAiOjAsInBlZXJfaWQiOiIyYkVnQnJQVHpMOHdvdjJENEt6MzRXVkxDeFI0dUNhcnNCbUhZWFdLUUE1d3ZCUXpkOUgiLCJsYXN0X3Byb2R1Y2VkX2Jsb2NrIjpudWxsfQ ==" ) ;
226+ assert_eq ! ( & signed. payload, "eyJzdGF0dXMiOnsiY2hhaW5faWQiOm51bGwsInRyYW5zaXRpb25fZnJvbnRpZXIiOnsiYmVzdF90aXAiOm51bGwsInN5bmMiOnsidGltZSI6bnVsbCwic3RhdHVzIjoiU3luY2VkIiwicGhhc2UiOiJSdW5uaW5nIiwidGFyZ2V0IjpudWxsfX0sInBlZXJzX2NvdW50IjoxMCwic25hcmtfcG9vbCI6eyJ0b3RhbF9qb2JzIjowLCJzbmFya3MiOjB9LCJ0cmFuc2FjdGlvbl9wb29sIjp7InRyYW5zYWN0aW9ucyI6MCwidHJhbnNhY3Rpb25zX2Zvcl9wcm9wYWdhdGlvbiI6MCwidHJhbnNhY3Rpb25fY2FuZGlkYXRlcyI6MH0sImN1cnJlbnRfYmxvY2tfcHJvZHVjdGlvbl9hdHRlbXB0IjpudWxsfSwibm9kZV90aW1lc3RhbXAiOjAsInBlZXJfaWQiOiIyYkVnQnJQVHpMOHdvdjJENEt6MzRXVkxDeFI0dUNhcnNCbUhZWFdLUUE1d3ZCUXpkOUgiLCJsYXN0X3Byb2R1Y2VkX2Jsb2NrIjpudWxsfQ ==" ) ;
201227 assert_eq ! (
202228 & signed. signature. field,
203- "25500978175045040705256298774101531557080530394536110798266178142513301557846 "
229+ "9079786479394174309544438559429014966597223472549276883268325308999016287311 "
204230 ) ;
205231 assert_eq ! (
206232 & signed. signature. scalar,
207- "27991123709623419396663280967637181749724990269901703962618583375785482061803 "
233+ "23390017492020277578751321763314031415515010579676039556553777274088622112706 "
208234 ) ;
209235 assert ! ( signed. verify_signature( ) ) ;
210236 }
@@ -237,7 +263,7 @@ pub(crate) mod tests {
237263
238264 fn create_test_heartbeat ( ) -> NodeHeartbeat {
239265 NodeHeartbeat {
240- status : RpcNodeStatus {
266+ status : NodeStatus {
241267 chain_id : None ,
242268 transition_frontier : RpcNodeStatusTransitionFrontier {
243269 best_tip : None ,
@@ -248,15 +274,10 @@ pub(crate) mod tests {
248274 target : None ,
249275 } ,
250276 } ,
251- peers : vec ! [ ] ,
277+ peers_count : 10 ,
252278 snark_pool : RpcNodeStatusSnarkPool :: default ( ) ,
253279 transaction_pool : RpcNodeStatusTransactionPool :: default ( ) ,
254280 current_block_production_attempt : None ,
255- resources_status : RpcNodeStatusResources {
256- p2p_malloc_size : 0 ,
257- transition_frontier : serde_json:: Value :: Null ,
258- snark_pool : serde_json:: Value :: Null ,
259- } ,
260281 } ,
261282 node_timestamp : Timestamp :: ZERO ,
262283 peer_id : "2bEgBrPTzL8wov2D4Kz34WVLCxR4uCarsBmHYXWKQA5wvBQzd9H"
0 commit comments