Skip to content

Commit

Permalink
Add serialize/deserialize time, serialized size to validator session …
Browse files Browse the repository at this point in the history
…stats, fix setting is_accepted
  • Loading branch information
SpyCheese committed Apr 24, 2024
1 parent 3bd53d8 commit d8911cf
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
3 changes: 2 additions & 1 deletion tl/generate/scheme/ton_api.tl
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,8 @@ validatorSession.statsProducer id:int256 candidate_id:int256 block_status:int co
validation_time:double validated_at:double validation_cached:Bool
gen_utime:double
approved_weight:long approved_33pct_at:double approved_66pct_at:double
signed_weight:long signed_33pct_at:double signed_66pct_at:double = validatorSession.StatsProducer;
signed_weight:long signed_33pct_at:double signed_66pct_at:double
serialize_time:double deserialize_time:double serialized_size:int = validatorSession.StatsProducer;

validatorSession.statsRound timestamp:long producers:(vector validatorSession.statsProducer) = validatorSession.StatsRound;

Expand Down
Binary file modified tl/generate/scheme/ton_api.tlo
Binary file not shown.
4 changes: 4 additions & 0 deletions validator-session/validator-session-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ struct ValidatorSessionStats {
double signed_33pct_at = -1.0;
double signed_66pct_at = -1.0;

double serialize_time = -1.0;
double deserialize_time = -1.0;
td::int32 serialized_size = -1;

void set_approved_by(td::uint32 id, ValidatorWeight weight, ValidatorWeight total_weight) {
if (!approvers.at(id)) {
approvers.at(id) = true;
Expand Down
27 changes: 18 additions & 9 deletions validator-session/validator-session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,11 @@ void ValidatorSessionImpl::process_broadcast(PublicKeyHash src, td::BufferSlice
// Note: src is not necessarily equal to the sender of this message:
// If requested using get_broadcast_p2p, src is the creator of the block, sender possibly is some other node.
auto src_idx = description().get_source_idx(src);
td::Timer deserialize_timer;
auto R =
deserialize_candidate(data, compress_block_candidates_,
description().opts().max_block_size + description().opts().max_collated_data_size + 1024);
double deserialize_time = deserialize_timer.elapsed();
if (R.is_error()) {
VLOG(VALIDATOR_SESSION_WARNING) << this << "[node " << src << "][broadcast " << sha256_bits256(data.as_slice())
<< "]: failed to parse: " << R.move_as_error();
Expand Down Expand Up @@ -266,6 +268,8 @@ void ValidatorSessionImpl::process_broadcast(PublicKeyHash src, td::BufferSlice
if (stat->block_timestamp <= 0.0) {
stat->block_timestamp = td::Clocks::system();
}
stat->deserialize_time = deserialize_time;
stat->serialized_size = data.size();
}

if ((td::int32)block_round < (td::int32)cur_round_ - MAX_PAST_ROUND_BLOCK ||
Expand Down Expand Up @@ -468,9 +472,14 @@ void ValidatorSessionImpl::generated_block(td::uint32 round, ValidatorSessionCan
if (round != cur_round_) {
return;
}
td::Timer serialize_timer;
auto b = create_tl_object<ton_api::validatorSession_candidate>(local_id().tl(), round, root_hash, std::move(data),
std::move(collated_data));
auto B = serialize_candidate(b, compress_block_candidates_).move_as_ok();
if (stat) {
stat->serialize_time = serialize_timer.elapsed();
stat->serialized_size = B.size();
}

td::actor::send_closure(catchain_, &catchain::CatChain::send_broadcast, std::move(B));

Expand Down Expand Up @@ -861,18 +870,18 @@ void ValidatorSessionImpl::on_new_round(td::uint32 round) {
if (!have_block) {
callback_->on_block_skipped(cur_round_);
} else {
auto stats = cur_stats_;
stats.success = true;
stats.timestamp = (td::uint64)td::Clocks::system();
stats.signatures = (td::uint32)export_sigs.size();
stats.signatures_weight = signatures_weight;
stats.approve_signatures = (td::uint32)export_approve_sigs.size();
stats.approve_signatures_weight = approve_signatures_weight;
stats.creator = description().get_source_id(block->get_src_idx());
auto stat = stats_get_candidate_stat(cur_round_, stats.creator);
cur_stats_.success = true;
cur_stats_.timestamp = (td::uint64)td::Clocks::system();
cur_stats_.signatures = (td::uint32)export_sigs.size();
cur_stats_.signatures_weight = signatures_weight;
cur_stats_.approve_signatures = (td::uint32)export_approve_sigs.size();
cur_stats_.approve_signatures_weight = approve_signatures_weight;
cur_stats_.creator = description().get_source_id(block->get_src_idx());
auto stat = stats_get_candidate_stat(cur_round_, cur_stats_.creator);
if (stat) {
stat->is_accepted = true;
}
auto stats = cur_stats_;
while (!stats.rounds.empty() && stats.rounds.size() + stats.first_round - 1 > cur_round_) {
stats.rounds.pop_back();
}
Expand Down
2 changes: 1 addition & 1 deletion validator/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2719,7 +2719,7 @@ void ValidatorManagerImpl::log_validator_session_stats(BlockIdExt block_id,
producer.collation_time, producer.collated_at, producer.collation_cached, producer.validation_time,
producer.validated_at, producer.validation_cached, producer.gen_utime, producer.approved_weight,
producer.approved_33pct_at, producer.approved_66pct_at, producer.signed_weight, producer.signed_33pct_at,
producer.signed_66pct_at));
producer.signed_66pct_at, producer.serialize_time, producer.deserialize_time, producer.serialized_size));
}
rounds.push_back(create_tl_object<ton_api::validatorSession_statsRound>(round.timestamp, std::move(producers)));
}
Expand Down

0 comments on commit d8911cf

Please sign in to comment.