Skip to content

Commit

Permalink
fix: sort by node id
Browse files Browse the repository at this point in the history
fix #3282
  • Loading branch information
aoudiamoncef committed Dec 2, 2022
1 parent 006ad38 commit 57da2cd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
22 changes: 12 additions & 10 deletions massa-api/src/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use massa_pool_exports::PoolController;
use massa_signature::KeyPair;
use massa_storage::Storage;
use massa_time::MassaTime;
use std::collections::BTreeMap;
use std::net::{IpAddr, SocketAddr};

impl API<Public> {
Expand Down Expand Up @@ -359,21 +360,22 @@ impl MassaRpcServer for API<Public> {
Err(e) => return Err(ApiError::from(e).into()),
};

let connected_nodes = peers
.peers
.iter()
.flat_map(|(ip, peer)| {
peer.active_nodes
.iter()
.map(move |(id, is_outgoing)| (*id, (*ip, *is_outgoing)))
})
.collect::<BTreeMap<_, _>>();

Ok(NodeStatus {
node_id,
node_ip: network_config.routable_ip,
version,
current_time: now,
connected_nodes: peers
.peers
.iter()
.sorted()
.flat_map(|(ip, peer)| {
peer.active_nodes
.iter()
.map(move |(id, is_outgoing)| (*id, (*ip, *is_outgoing)))
})
.collect(),
connected_nodes,
last_slot,
next_slot,
execution_stats,
Expand Down
4 changes: 2 additions & 2 deletions massa-models/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
use massa_signature::{PublicKey, Signature};
use massa_time::MassaTime;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::collections::BTreeMap;
use std::net::IpAddr;

/// operation input
Expand Down Expand Up @@ -41,7 +41,7 @@ pub struct NodeStatus {
/// current cycle
pub current_cycle: u64,
/// connected nodes (node id, ip address, true if the connection is outgoing, false if incoming)
pub connected_nodes: HashMap<NodeId, (IpAddr, bool)>,
pub connected_nodes: BTreeMap<NodeId, (IpAddr, bool)>,
/// latest slot, none if now is before genesis timestamp
pub last_slot: Option<Slot>,
/// next slot
Expand Down
4 changes: 2 additions & 2 deletions massa-network-exports/src/peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize};
use std::ops::Bound::Included;
use std::{collections::HashMap, net::IpAddr};
/// Associate a peer info with nodes
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Peer {
/// peer info
pub peer_info: PeerInfo,
Expand Down Expand Up @@ -176,7 +176,7 @@ impl Default for PeerType {
}

/// All information concerning a peer is here
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Debug)]
#[derive(Clone, Copy, Serialize, Deserialize, Debug)]
pub struct PeerInfo {
/// Peer ip address.
pub ip: IpAddr,
Expand Down

0 comments on commit 57da2cd

Please sign in to comment.