Skip to content

Commit 13e4b62

Browse files
committed
(feat/malloc_size_of): fix clippy warns and rebase mistakes
1 parent bc4cd57 commit 13e4b62

File tree

6 files changed

+15
-22
lines changed

6 files changed

+15
-22
lines changed

node/src/rpc/heartbeat.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ impl NodeHeartbeat {
179179
pub(crate) mod tests {
180180

181181
use crate::rpc::{
182-
RpcNodeStatusSnarkPool, RpcNodeStatusTransactionPool, RpcNodeStatusTransitionFrontier,
183-
RpcNodeStatusTransitionFrontierSync,
182+
RpcNodeStatusResources, RpcNodeStatusSnarkPool, RpcNodeStatusTransactionPool,
183+
RpcNodeStatusTransitionFrontier, RpcNodeStatusTransitionFrontierSync,
184184
};
185185

186186
use super::*;
@@ -252,6 +252,11 @@ pub(crate) mod tests {
252252
snark_pool: RpcNodeStatusSnarkPool::default(),
253253
transaction_pool: RpcNodeStatusTransactionPool::default(),
254254
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+
},
255260
},
256261
node_timestamp: Timestamp::ZERO,
257262
peer_id: "2bEgBrPTzL8wov2D4Kz34WVLCxR4uCarsBmHYXWKQA5wvBQzd9H"

node/src/rpc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mod rpc_state;
2-
use std::collections::{BTreeMap, BTreeSet};
2+
use std::collections::BTreeMap;
33
use std::str::FromStr;
44

55
use ark_ff::fields::arithmetic::InvalidBigInt;

node/src/rpc_effectful/rpc_effectful_effects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ fn compute_node_status<S: Service>(store: &mut Store<S>) -> RpcNodeStatus {
815815
let mut set = BTreeSet::new();
816816
let fun = move |ptr: *const c_void| !set.insert(ptr.addr());
817817
let mut ops = MallocSizeOfOps::new(None, Some(Box::new(fun)));
818-
size_of_val(&state.p2p) + state.p2p.size_of(&mut ops)
818+
size_of_val(&state.p2p).saturating_add(state.p2p.size_of(&mut ops))
819819
},
820820
transition_frontier: state.transition_frontier.resources_usage(),
821821
snark_pool: state.snark_pool.resources_usage(),

node/src/snark_pool/candidate/snark_pool_candidate_state.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,16 @@ impl SnarkPoolCandidatesState {
5252
}
5353

5454
pub fn check(&self) -> (usize, Vec<(PeerId, SnarkJobId)>) {
55-
let len = self.by_peer.iter().map(|(_, v)| v.len()).sum::<usize>();
55+
let len = self.by_peer.values().map(BTreeMap::len).sum::<usize>();
5656
let lhs = self
5757
.by_job_id
5858
.iter()
59-
.map(|(job_id, v)| v.iter().map(|peer_id| (*peer_id, job_id.clone())))
60-
.flatten()
59+
.flat_map(|(job_id, v)| v.iter().map(|peer_id| (*peer_id, job_id.clone())))
6160
.collect::<BTreeSet<_>>();
6261
let rhs = self
6362
.by_peer
6463
.iter()
65-
.map(|(peer_id, v)| v.keys().map(|job_id| (*peer_id, job_id.clone())))
66-
.flatten()
64+
.flat_map(|(peer_id, v)| v.keys().map(|job_id| (*peer_id, job_id.clone())))
6765
.collect::<BTreeSet<_>>();
6866
let inconsistency = lhs.symmetric_difference(&rhs).cloned().collect();
6967
(len, inconsistency)

node/src/transition_frontier/transition_frontier_state.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ impl TransitionFrontierState {
207207
"diff_tx_size": self
208208
.chain_diff
209209
.as_ref()
210-
.map(|d| d.new_commands.len() + d.removed_commands.len())
210+
// `saturating_add` is not needed here as collection size cannot overflow usize
211+
// but it makes clippy satisfied
212+
.map(|d| d.new_commands.len().saturating_add(d.removed_commands.len()))
211213
.unwrap_or_default()
212214
})
213215
}

p2p/src/network/pubsub/p2p_network_pubsub_state.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -440,18 +440,6 @@ mod measurement {
440440

441441
use super::*;
442442

443-
pub fn snark(val: &Vec<(Snark, u32)>, ops: &mut MallocSizeOfOps) -> usize {
444-
// TODO(vlad):
445-
let _ = (val, ops);
446-
0
447-
}
448-
449-
pub fn transaction(val: &Vec<(Transaction, u32)>, ops: &mut MallocSizeOfOps) -> usize {
450-
// TODO(vlad):
451-
let _ = (val, ops);
452-
0
453-
}
454-
455443
pub fn clients(
456444
val: &BTreeMap<PeerId, P2pNetworkPubsubClientState>,
457445
ops: &mut MallocSizeOfOps,

0 commit comments

Comments
 (0)