Skip to content

Commit 8c06c0c

Browse files
authored
Merge pull request #1037 from openmina/tweaks/heartbeat-format
Tweak heartbeat format
2 parents 7ca6ecd + 69931a8 commit 8c06c0c

File tree

4 files changed

+45
-23
lines changed

4 files changed

+45
-23
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/src/rpc/heartbeat.rs

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ use ledger::FpExt;
22
use mina_p2p_messages::bigint::BigInt;
33
use mina_signer::Signature;
44
use 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};
912
use 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)]
9396
pub 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)]
103129
pub struct NodeHeartbeatPayloadDigest([u8; 32]);
@@ -179,8 +205,8 @@ impl NodeHeartbeat {
179205
pub(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"

node/src/rpc/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -471,35 +471,35 @@ pub struct RpcNodeStatusResources {
471471
pub snark_pool: serde_json::Value,
472472
}
473473

474-
#[derive(Serialize, Debug, Clone)]
474+
#[derive(Serialize, Deserialize, Debug, Clone)]
475475
pub struct RpcNodeStatusTransitionFrontier {
476476
pub best_tip: Option<RpcNodeStatusTransitionFrontierBlockSummary>,
477477
pub sync: RpcNodeStatusTransitionFrontierSync,
478478
}
479479

480-
#[derive(Serialize, Debug, Clone)]
480+
#[derive(Serialize, Deserialize, Debug, Clone)]
481481
pub struct RpcNodeStatusTransitionFrontierSync {
482482
pub time: Option<redux::Timestamp>,
483483
pub status: String,
484484
pub phase: String,
485485
pub target: Option<RpcNodeStatusTransitionFrontierBlockSummary>,
486486
}
487487

488-
#[derive(Serialize, Debug, Clone)]
488+
#[derive(Serialize, Deserialize, Debug, Clone)]
489489
pub struct RpcNodeStatusTransitionFrontierBlockSummary {
490490
pub hash: StateHash,
491491
pub height: u32,
492492
pub global_slot: u32,
493493
}
494494

495-
#[derive(Serialize, Debug, Default, Clone)]
495+
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
496496
pub struct RpcNodeStatusTransactionPool {
497497
pub transactions: usize,
498498
pub transactions_for_propagation: usize,
499499
pub transaction_candidates: usize,
500500
}
501501

502-
#[derive(Serialize, Debug, Default, Clone)]
502+
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
503503
pub struct RpcNodeStatusSnarkPool {
504504
pub total_jobs: usize,
505505
pub snarks: usize,

node/src/rpc_effectful/rpc_effectful_effects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn rpc_effects<S: Service>(store: &mut Store<S>, action: ActionWithMeta<RpcE
7878
};
7979

8080
let heartbeat = NodeHeartbeat {
81-
status,
81+
status: status.into(),
8282
node_timestamp: meta.time(),
8383
peer_id: store.state().p2p.my_id(),
8484
last_produced_block,

0 commit comments

Comments
 (0)