Skip to content

Commit 5482e85

Browse files
bowenwang1996Bowen Wang
authored andcommitted
fix: address issues related to log summary (#3259)
1 parent 44146c7 commit 5482e85

2 files changed

Lines changed: 48 additions & 47 deletions

File tree

chain/client/src/client_actor.rs

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use near_store::ColBlock;
4343
use near_telemetry::TelemetryActor;
4444

4545
use crate::client::Client;
46-
use crate::info::InfoHelper;
46+
use crate::info::{InfoHelper, ValidatorInfoHelper};
4747
use crate::sync::{highest_height_peer, StateSync, StateSyncResult};
4848
use crate::types::{
4949
Error, GetNetworkInfo, NetworkInfoResponse, ShardSyncDownload, ShardSyncStatus, Status,
@@ -858,11 +858,10 @@ impl ClientActor {
858858
);
859859
let block = self.client.chain.get_block(&accepted_block.hash).unwrap();
860860
let gas_used = Block::compute_gas_used(&block.chunks(), block.header().height());
861-
let gas_limit = Block::compute_gas_limit(&block.chunks(), block.header().height());
862861

863862
let last_final_hash = *block.header().last_final_block();
864863

865-
self.info_helper.block_processed(gas_used, gas_limit);
864+
self.info_helper.block_processed(gas_used);
866865
self.check_send_announce_account(last_final_hash);
867866
}
868867
}
@@ -1280,39 +1279,35 @@ impl ClientActor {
12801279

12811280
/// Periodically log summary.
12821281
fn log_summary(&self, ctx: &mut Context<Self>) {
1283-
#[cfg(feature = "delay_detector")]
1284-
let _d = DelayDetector::new("client log summary".into());
12851282
ctx.run_later(self.client.config.log_summary_period, move |act, ctx| {
1286-
let head = unwrap_or_return!(act.client.chain.head());
1287-
let validators = unwrap_or_return!(act
1288-
.client
1289-
.runtime_adapter
1290-
.get_epoch_block_producers_ordered(&head.epoch_id, &head.last_block_hash));
1291-
let num_validators = validators.len();
1292-
let account_id = act.client.validator_signer.as_ref().map(|x| x.validator_id());
1293-
let is_validator = if let Some(ref account_id) = account_id {
1294-
match act.client.runtime_adapter.get_validator_by_account_id(
1295-
&head.epoch_id,
1296-
&head.last_block_hash,
1297-
account_id,
1298-
) {
1299-
Ok((_, is_slashed)) => !is_slashed,
1300-
Err(_) => false,
1301-
}
1302-
} else {
1303-
false
1304-
};
1305-
let is_fishermen = if let Some(ref account_id) = account_id {
1306-
match act.client.runtime_adapter.get_fisherman_by_account_id(
1307-
&head.epoch_id,
1308-
&head.last_block_hash,
1309-
account_id,
1310-
) {
1311-
Ok((_, is_slashed)) => !is_slashed,
1312-
Err(_) => false,
1313-
}
1283+
#[cfg(feature = "delay_detector")]
1284+
let _d = DelayDetector::new("client log summary".into());
1285+
let is_syncing = act.client.sync_status.is_syncing();
1286+
let head = unwrap_or_return!(act.client.chain.head(), act.log_summary(ctx));
1287+
let validator_info = if !is_syncing {
1288+
let validators = unwrap_or_return!(
1289+
act.client
1290+
.runtime_adapter
1291+
.get_epoch_block_producers_ordered(&head.epoch_id, &head.last_block_hash),
1292+
act.log_summary(ctx)
1293+
);
1294+
let num_validators = validators.len();
1295+
let account_id = act.client.validator_signer.as_ref().map(|x| x.validator_id());
1296+
let is_validator = if let Some(ref account_id) = account_id {
1297+
match act.client.runtime_adapter.get_validator_by_account_id(
1298+
&head.epoch_id,
1299+
&head.last_block_hash,
1300+
account_id,
1301+
) {
1302+
Ok((_, is_slashed)) => !is_slashed,
1303+
Err(_) => false,
1304+
}
1305+
} else {
1306+
false
1307+
};
1308+
Some(ValidatorInfoHelper { is_validator, num_validators })
13141309
} else {
1315-
false
1310+
None
13161311
};
13171312

13181313
act.info_helper.info(
@@ -1321,9 +1316,7 @@ impl ClientActor {
13211316
&act.client.sync_status,
13221317
&act.node_id,
13231318
&act.network_info,
1324-
is_validator,
1325-
is_fishermen,
1326-
num_validators,
1319+
validator_info,
13271320
);
13281321

13291322
act.log_summary(ctx);

chain/client/src/info.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ use crate::metrics;
2525
use crate::types::ShardSyncStatus;
2626
use crate::SyncStatus;
2727

28+
pub struct ValidatorInfoHelper {
29+
pub is_validator: bool,
30+
pub num_validators: usize,
31+
}
32+
2833
/// A helper that prints information about current chain and reports to telemetry.
2934
pub struct InfoHelper {
3035
/// Nearcore agent (executable) version
@@ -39,8 +44,6 @@ pub struct InfoHelper {
3944
num_blocks_processed: u64,
4045
/// Total gas used during period.
4146
gas_used: u64,
42-
/// Total gas limit during period.
43-
gas_limit: u64,
4447
/// Sign telemetry with block producer key if available.
4548
validator_signer: Option<Arc<dyn ValidatorSigner>>,
4649
/// Telemetry actor.
@@ -61,16 +64,14 @@ impl InfoHelper {
6164
started: Instant::now(),
6265
num_blocks_processed: 0,
6366
gas_used: 0,
64-
gas_limit: 0,
6567
telemetry_actor,
6668
validator_signer,
6769
}
6870
}
6971

70-
pub fn block_processed(&mut self, gas_used: Gas, gas_limit: Gas) {
72+
pub fn block_processed(&mut self, gas_used: Gas) {
7173
self.num_blocks_processed += 1;
7274
self.gas_used += gas_used;
73-
self.gas_limit += gas_limit;
7475
}
7576

7677
pub fn info(
@@ -80,9 +81,7 @@ impl InfoHelper {
8081
sync_status: &SyncStatus,
8182
node_id: &PeerId,
8283
network_info: &NetworkInfo,
83-
is_validator: bool,
84-
is_fisherman: bool,
85-
num_validators: usize,
84+
validator_info: Option<ValidatorInfoHelper>,
8685
) {
8786
let (cpu_usage, memory_usage) = if let Some(pid) = self.pid {
8887
if self.sys.refresh_process(pid) {
@@ -104,15 +103,25 @@ impl InfoHelper {
104103
* 1000.0;
105104
let avg_gas_used =
106105
((self.gas_used as f64) / (self.started.elapsed().as_millis() as f64) * 1000.0) as u64;
106+
let validator_info_log = if let Some(ref validator_info) = validator_info {
107+
White.bold().paint(format!(
108+
"{}/{}",
109+
if validator_info.is_validator { "V" } else { "-" },
110+
validator_info.num_validators
111+
))
112+
} else {
113+
White.bold().paint("")
114+
};
107115
info!(target: "stats", "{} {} {} {} {} {}",
108116
Yellow.bold().paint(display_sync_status(&sync_status, &head, genesis_height)),
109-
White.bold().paint(format!("{}/{}", if is_validator { "V" } else if is_fisherman { "F" } else { "-" }, num_validators)),
117+
validator_info_log,
110118
Cyan.bold().paint(format!("{:2}/{:?}/{:2} peers", network_info.num_active_peers, network_info.highest_height_peers.len(), network_info.peer_max_count)),
111119
Cyan.bold().paint(format!("⬇ {} ⬆ {}", pretty_bytes_per_sec(network_info.received_bytes_per_sec), pretty_bytes_per_sec(network_info.sent_bytes_per_sec))),
112120
Green.bold().paint(format!("{:.2} bps {}", avg_bls, gas_used_per_sec(avg_gas_used))),
113121
Blue.bold().paint(format!("CPU: {:.0}%, Mem: {}", cpu_usage, pretty_bytes(memory_usage * 1024)))
114122
);
115123

124+
let is_validator = validator_info.map(|v| v.is_validator).unwrap_or_default();
116125
set_gauge(&metrics::IS_VALIDATOR, is_validator as i64);
117126
set_gauge(&metrics::RECEIVED_BYTES_PER_SECOND, network_info.received_bytes_per_sec as i64);
118127
set_gauge(&metrics::SENT_BYTES_PER_SECOND, network_info.sent_bytes_per_sec as i64);
@@ -123,7 +132,6 @@ impl InfoHelper {
123132
self.started = Instant::now();
124133
self.num_blocks_processed = 0;
125134
self.gas_used = 0;
126-
self.gas_limit = 0;
127135

128136
let info = TelemetryInfo {
129137
agent: TelemetryAgentInfo {

0 commit comments

Comments
 (0)