Skip to content

Commit

Permalink
Rework session stats
Browse files Browse the repository at this point in the history
  • Loading branch information
SpyCheese committed Dec 26, 2024
1 parent 392cf64 commit 71342bd
Show file tree
Hide file tree
Showing 24 changed files with 438 additions and 336 deletions.
90 changes: 54 additions & 36 deletions tl/generate/scheme/ton_api.tl
Original file line number Diff line number Diff line change
Expand Up @@ -895,48 +895,66 @@ http.server.config dhs:(vector http.server.dnsEntry) local_hosts:(vector http.se

---types---

validatorSession.collationStats actual_bytes:int actual_collated_data_bytes:int
bytes:int gas:int lt_delta:int collated_data_bytes:int
cat_bytes:int cat_gas:int cat_lt_delta:int cat_collated_data_bytes:int
limits_log:string ext_msgs_total:int ext_msgs_filtered:int ext_msgs_accepted:int ext_msgs_rejected:int
work_time:double cpu_work_time:double
serialized_size:int serialized_size_no_collated_data:int = validadorSession.CollationStats;

validatorSession.statsProducer id:int256 candidate_id:int256 block_status:int root_hash:int256 file_hash:int256
comment:string block_timestamp:double is_accepted:Bool is_ours:Bool got_submit_at:double
collation_time:double collated_at:double collation_cached:Bool
collation_work_time:double collation_cpu_work_time:double
collation_stats:validatorSession.collationStats
validation_time:double validated_at:double validation_cached:Bool
validation_work_time:double validation_cpu_work_time:double
gen_utime:double
approved_weight:long approved_33pct_at:double approved_66pct_at:double approvers:string
signed_weight:long signed_33pct_at:double signed_66pct_at:double signers:string
serialize_time:double deserialize_time:double serialized_size:int = validatorSession.StatsProducer;

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

validatorSession.stats success:Bool id:tonNode.blockIdExt timestamp:double self:int256 session_id:int256 cc_seqno:int
creator:int256 total_validators:int total_weight:long
signatures:int signatures_weight:long approve_signatures:int approve_signatures_weight:long
first_round:int rounds:(vector validatorSession.statsRound) = validatorSession.Stats;

validatorSession.statsCollatedBlock timestamp:double id:tonNode.blockIdExt stats:validatorSession.collationStats = validatorSession.StatsCollatedBlock;
validatorStats.stats.producer flags:#
validator_id:int256 block_status:int
candidate_id:flags.0?int256 block_id:flags.0?tonNode.blockIdExt collated_data_hash:flags.0?int256
is_accepted:flags.0?Bool is_ours:flags.0?Bool
got_block_at:flags.0?double got_submit_at:flags.0?double gen_utime:flags.0?int comment:flags.0?string
collation_time:flags.1?double collated_at:flags.1?double collation_cached:flags.1?Bool self_collated:flags.1?Bool collator_node_id:flags.2?int256
validation_time:flags.3?double validated_at:flags.3?double validation_cached:flags.3?Bool
approved_weight:flags.0?long approved_33pct_at:flags.0?double approved_66pct_at:flags.0?double approvers:flags.0?string
signed_weight:flags.0?long signed_33pct_at:flags.0?double signed_66pct_at:flags.0?double signers:flags.0?string
serialize_time:flags.4?double deserialize_time:flags.4?double serialized_size:flags.4?int = validatorStats.stats.Producer;

validatorStats.stats.round started_at:double producers:(vector validatorStats.stats.producer) = validatorStats.stats.Round;

validatorStats.stats flags:#
session_id:int256 self:int256 block_id:tonNode.blockIdExt cc_seqno:int success:Bool timestamp:double
creator:flags.0?int256
total_validators:int total_weight:long
signatures:flags.0?int signatures_weight:flags.0?long
approve_signatures:flags.0?int approve_signatures_weight:flags.0?long
first_round:int rounds:(vector validatorStats.stats.round) = validatorStats.Stats;

validatorStats.blockLimitsStatus
bytes:int gas:int lt_delta:int collated_data_bytes:int
cat_bytes:int cat_gas:int cat_lt_delta:int cat_collated_data_bytes:int
limits_log:string = validatorStats.BlockLimitsStatus;
validatorStats.extMsgsStats
ext_msgs_total:int ext_msgs_filtered:int ext_msgs_accepted:int ext_msgs_rejected:int = validatorStats.ExtMsgsStats;

validatorStats.collatedBlock flags:#
block_id:tonNode.blockIdExt collated_data_hash:int256 cc_seqno:int collated_at:double
bytes:int collated_data_bytes:int attempt:int
collator_node_id:flags.0?int256 validator_id:flags.1?int256
total_time:double work_time:double cpu_work_time:double time_stats:string
block_limits:validatorStats.blockLimitsStatus
ext_msgs_stats:validatorStats.extMsgsStats = validatorSession.stats.CollatedBlock;

validatorStats.validatedBlock
block_id:tonNode.blockIdExt collated_data_hash:int256 validated_at:double
valid:Bool comment:string
bytes:int collated_data_bytes:int
total_time:double work_time:double cpu_work_time:double = validatorStats.ValidatedBlock;

validatorStats.newValidatorGroup.node id:int256 weight:long = validatorStats.newValidatorGroup.Node;
validatorStats.newValidatorGroup session_id:int256 shard:tonNode.shardId cc_seqno:int
last_key_block_seqno:int started_at:double
self_idx:int nodes:(vector validatorStats.newValidatorGroup.node) = validatorStats.NewValidatorGroup;

validatorStats.endValidatorGroup.node id:int256 catchain_blocks:int = validatorStats.endValidatorGroup.Node;
validatorStats.endValidatorGroup session_id:int256 timestamp:double
nodes:(vector validatorStats.endValidatorGroup.node) = validatorStats.EndValidatorGroup;

validatorStats.collatorNodeResponse collator_node_id:int256 validator_id:int256 timestamp:double
block_id:tonNode.blockIdExt original_block_id:tonNode.blockIdExt collated_data_hash:int256
= validatorStats.CollatorNodeResponse;

collatorNode.candidate source:PublicKey id:tonNode.blockIdExt data:bytes collated_data:bytes = collatorNode.Candidate;
collatorNode.compressedCandidate flags:# source:PublicKey id:tonNode.blockIdExt decompressed_size:int data:bytes = collatorNode.Candidate;
collatorNode.pong flags:# = collatorNode.Pong;
collatorNode.error code:int message:string = collatorNode.Error;

validatorSession.newValidatorGroupStats.node id:int256 weight:long = validatorSession.newValidatorGroupStats.Node;
validatorSession.newValidatorGroupStats session_id:int256 workchain:int shard:long cc_seqno:int
last_key_block_seqno:int timestamp:double
self_idx:int nodes:(vector validatorSession.newValidatorGroupStats.node) = validatorSession.NewValidatorGroupStats;

validatorSession.endValidatorGroupStats.node id:int256 catchain_blocks:int = validatorSession.endValidatorGroupStats.Node;
validatorSession.endValidatorGroupStats session_id:int256 timestamp:double
nodes:(vector validatorSession.endValidatorGroupStats.node) = validatorSession.EndValidatorGroupStats;

---functions---
collatorNode.generateBlock shard:tonNode.shardId cc_seqno:int prev_blocks:(vector tonNode.blockIdExt)
creator:int256 round:int first_block_round:int priority:int = collatorNode.Candidate;
Expand Down
Binary file modified tl/generate/scheme/ton_api.tlo
Binary file not shown.
11 changes: 11 additions & 0 deletions ton/ton-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,17 @@ struct BlockCandidate {
}
};

struct GeneratedCandidate {
BlockCandidate candidate;
bool is_cached = false;
bool self_collated = false;
td::Bits256 collator_node_id = td::Bits256::zero();

GeneratedCandidate clone() const {
return {candidate.clone(), is_cached, self_collated, collator_node_id};
}
};

struct BlockCandidatePriority {
td::uint32 round{};
td::uint32 first_block_round{};
Expand Down
116 changes: 97 additions & 19 deletions validator-session/validator-session-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "adnl/adnl-node-id.hpp"
#include "ton/ton-types.h"

#include <ton/ton-tl.hpp>

namespace ton {

namespace validatorsession {
Expand Down Expand Up @@ -73,24 +75,25 @@ struct ValidatorSessionStats {
enum { status_none = 0, status_received = 1, status_rejected = 2, status_approved = 3 };

struct Producer {
PublicKeyHash id = PublicKeyHash::zero();
ValidatorSessionCandidateId candidate_id = ValidatorSessionCandidateId::zero();
int block_status = status_none;
double block_timestamp = -1.0;
td::Bits256 root_hash = td::Bits256::zero();
td::Bits256 file_hash = td::Bits256::zero();
std::string comment;

PublicKeyHash validator_id = PublicKeyHash::zero();
ValidatorSessionCandidateId candidate_id = ValidatorSessionCandidateId::zero();
BlockIdExt block_id{workchainIdNotYet, 0, 0, td::Bits256::zero(), td::Bits256::zero()};
td::Bits256 collated_data_hash = td::Bits256::zero();
bool is_accepted = false;
bool is_ours = false;
double got_block_at = -1.0;
double got_submit_at = -1.0;
double collation_time = -1.0;
double validation_time = -1.0;
double collated_at = -1.0;
double validated_at = -1.0;
td::int32 gen_utime = -1;
std::string comment;

double collation_time = -1.0, collated_at = -1.0;
bool collation_cached = false;
bool self_collated = false;
td::Bits256 collator_node_id = td::Bits256::zero();

double validation_time = -1.0, validated_at = -1.0;
bool validation_cached = false;
double gen_utime = -1.0;

std::vector<bool> approvers, signers;
ValidatorWeight approved_weight = 0;
Expand Down Expand Up @@ -129,27 +132,82 @@ struct ValidatorSessionStats {
}
}
}

tl_object_ptr<ton_api::validatorStats_stats_producer> tl() const {
std::string approvers_str(approvers.size(), '0');
for (size_t i = 0; i < approvers.size(); ++i) {
approvers_str[i] = '0' + approvers[i];
}
std::string signers_str(signers.size(), '0');
for (size_t i = 0; i < signers.size(); ++i) {
signers_str[i] = '0' + signers[i];
}
int flags =
(block_status != status_none ? ton_api::validatorStats_stats_producer::Flags::BLOCK_ID_MASK : 0) |
(collated_at >= 0.0 ? ton_api::validatorStats_stats_producer::Flags::COLLATED_AT_MASK : 0) |
(!collator_node_id.is_zero() ? ton_api::validatorStats_stats_producer::Flags::COLLATOR_NODE_ID_MASK : 0) |
(validated_at >= 0.0 ? ton_api::validatorStats_stats_producer::Flags::VALIDATED_AT_MASK : 0) |
(serialize_time >= 0.0 || deserialize_time >= 0.0 || serialized_size >= 0
? ton_api::validatorStats_stats_producer::Flags::SERIALIZE_TIME_MASK
: 0);
return create_tl_object<ton_api::validatorStats_stats_producer>(
flags, validator_id.bits256_value(), block_status, candidate_id, create_tl_block_id(block_id),
collated_data_hash, is_accepted, is_ours, got_block_at, got_submit_at, gen_utime, comment, collation_time,
collated_at, collation_cached, self_collated, collator_node_id, validation_time, validated_at,
validation_cached, approved_weight, approved_33pct_at, approved_66pct_at, std::move(approvers_str),
signed_weight, signed_33pct_at, signed_66pct_at, std::move(signers_str), serialize_time, deserialize_time,
serialized_size);
}
};
struct Round {
double timestamp = -1.0;
double started_at = -1.0;
std::vector<Producer> producers;
};

td::uint32 first_round;
std::vector<Round> rounds;
tl_object_ptr<ton_api::validatorStats_stats_round> tl() const {
std::vector<tl_object_ptr<ton_api::validatorStats_stats_producer>> producers_tl;
for (const auto &producer : producers) {
producers_tl.push_back(producer.tl());
}
return create_tl_object<ton_api::validatorStats_stats_round>(started_at, std::move(producers_tl));
}
};

bool success = false;
ValidatorSessionId session_id = ValidatorSessionId::zero();
PublicKeyHash self = PublicKeyHash::zero();
BlockIdExt block_id{workchainIdNotYet, 0, 0, td::Bits256::zero(), td::Bits256::zero()};
CatchainSeqno cc_seqno = 0;
bool success = false;
double timestamp = -1.0;
PublicKeyHash self = PublicKeyHash::zero();
PublicKeyHash creator = PublicKeyHash::zero();
td::uint32 total_validators = 0;
ValidatorWeight total_weight = 0;
td::uint32 signatures = 0;
ValidatorWeight signatures_weight = 0;
td::uint32 approve_signatures = 0;
ValidatorWeight approve_signatures_weight = 0;

td::uint32 first_round = 0;
std::vector<Round> rounds;

void fix_block_ids() {
for (auto &round : rounds) {
for (auto &producer : round.producers) {
producer.block_id.id = block_id.id;
}
}
}

tl_object_ptr<ton_api::validatorStats_stats> tl() const {
std::vector<tl_object_ptr<ton_api::validatorStats_stats_round>> rounds_tl;
for (const auto &round : rounds) {
rounds_tl.push_back(round.tl());
}
int flags = success ? ton_api::validatorStats_stats::Flags::CREATOR_MASK : 0;
return create_tl_object<ton_api::validatorStats_stats>(
flags, session_id, self.bits256_value(), create_tl_block_id(block_id), cc_seqno, success, timestamp,
creator.bits256_value(), total_validators, total_weight, signatures, signatures_weight, approve_signatures,
approve_signatures_weight, first_round, std::move(rounds_tl));
}
};

struct NewValidatorGroupStats {
Expand All @@ -162,9 +220,20 @@ struct NewValidatorGroupStats {
ShardIdFull shard{masterchainId};
CatchainSeqno cc_seqno = 0;
BlockSeqno last_key_block_seqno = 0;
double timestamp = -1.0;
double started_at = -1.0;
td::uint32 self_idx = 0;
std::vector<Node> nodes;

tl_object_ptr<ton_api::validatorStats_newValidatorGroup> tl() const {
std::vector<tl_object_ptr<ton_api::validatorStats_newValidatorGroup_node>> nodes_arr;
for (const auto &node : nodes) {
nodes_arr.push_back(
create_tl_object<ton_api::validatorStats_newValidatorGroup_node>(node.id.bits256_value(), node.weight));
}
return create_tl_object<ton_api::validatorStats_newValidatorGroup>(session_id, create_tl_shard_id(shard), cc_seqno,
last_key_block_seqno, started_at, self_idx,
std::move(nodes_arr));
}
};

struct EndValidatorGroupStats {
Expand All @@ -176,6 +245,15 @@ struct EndValidatorGroupStats {
ValidatorSessionId session_id = ValidatorSessionId::zero();
double timestamp = -1.0;
std::vector<Node> nodes;

tl_object_ptr<ton_api::validatorStats_endValidatorGroup> tl() const {
std::vector<tl_object_ptr<ton_api::validatorStats_endValidatorGroup_node>> nodes_arr;
for (const auto &node : nodes) {
nodes_arr.push_back(create_tl_object<ton_api::validatorStats_endValidatorGroup_node>(node.id.bits256_value(),
node.catchain_blocks));
}
return create_tl_object<ton_api::validatorStats_endValidatorGroup>(session_id, timestamp, std::move(nodes_arr));
}
};

struct BlockSourceInfo {
Expand Down
Loading

0 comments on commit 71342bd

Please sign in to comment.