mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Improve validator session stats (#861)
This commit is contained in:
parent
be94982348
commit
a68b5cbe62
8 changed files with 58 additions and 18 deletions
|
@ -742,11 +742,12 @@ http.server.config dhs:(vector http.server.dnsEntry) local_hosts:(vector http.se
|
||||||
|
|
||||||
---types---
|
---types---
|
||||||
|
|
||||||
validatorSession.statsProducer id:int256 block_status:int block_timestamp:long = validatorSession.StatsProducer;
|
validatorSession.statsProducer id:int256 candidate_id:int256 block_status:int block_timestamp:long comment:string = validatorSession.StatsProducer;
|
||||||
|
|
||||||
validatorSession.statsRound timestamp:long producers:(vector validatorSession.statsProducer) = validatorSession.StatsRound;
|
validatorSession.statsRound timestamp:long producers:(vector validatorSession.statsProducer) = validatorSession.StatsRound;
|
||||||
|
|
||||||
validatorSession.stats id:tonNode.blockId timestamp:long self:int256 creator:int256 total_validators:int total_weight:long
|
validatorSession.stats success:Bool id:tonNode.blockIdExt timestamp:long 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
|
signatures:int signatures_weight:long approve_signatures:int approve_signatures_weight:long
|
||||||
first_round:int rounds:(vector validatorSession.statsRound) = validatorSession.Stats;
|
first_round:int rounds:(vector validatorSession.statsRound) = validatorSession.Stats;
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -74,8 +74,10 @@ struct ValidatorSessionStats {
|
||||||
|
|
||||||
struct Producer {
|
struct Producer {
|
||||||
PublicKeyHash id = PublicKeyHash::zero();
|
PublicKeyHash id = PublicKeyHash::zero();
|
||||||
|
ValidatorSessionCandidateId candidate_id = ValidatorSessionCandidateId::zero();
|
||||||
int block_status = status_none;
|
int block_status = status_none;
|
||||||
td::uint64 block_timestamp = 0;
|
td::uint64 block_timestamp = 0;
|
||||||
|
std::string comment;
|
||||||
};
|
};
|
||||||
struct Round {
|
struct Round {
|
||||||
td::uint64 timestamp = 0;
|
td::uint64 timestamp = 0;
|
||||||
|
@ -85,6 +87,9 @@ struct ValidatorSessionStats {
|
||||||
td::uint32 first_round;
|
td::uint32 first_round;
|
||||||
std::vector<Round> rounds;
|
std::vector<Round> rounds;
|
||||||
|
|
||||||
|
bool success = false;
|
||||||
|
ValidatorSessionId session_id = ValidatorSessionId::zero();
|
||||||
|
CatchainSeqno cc_seqno = 0;
|
||||||
td::uint64 timestamp = 0;
|
td::uint64 timestamp = 0;
|
||||||
PublicKeyHash self = PublicKeyHash::zero();
|
PublicKeyHash self = PublicKeyHash::zero();
|
||||||
PublicKeyHash creator = PublicKeyHash::zero();
|
PublicKeyHash creator = PublicKeyHash::zero();
|
||||||
|
|
|
@ -288,7 +288,7 @@ void ValidatorSessionImpl::process_broadcast(PublicKeyHash src, td::BufferSlice
|
||||||
CHECK(!pending_reject_.count(block_id));
|
CHECK(!pending_reject_.count(block_id));
|
||||||
CHECK(!rejected_.count(block_id));
|
CHECK(!rejected_.count(block_id));
|
||||||
|
|
||||||
stats_set_candidate_status(cur_round_, src, ValidatorSessionStats::status_received);
|
stats_set_candidate_status(cur_round_, src, block_id, ValidatorSessionStats::status_received);
|
||||||
auto v = virtual_state_->choose_blocks_to_approve(description(), local_idx());
|
auto v = virtual_state_->choose_blocks_to_approve(description(), local_idx());
|
||||||
for (auto &b : v) {
|
for (auto &b : v) {
|
||||||
if (b && SentBlock::get_block_id(b) == block_id) {
|
if (b && SentBlock::get_block_id(b) == block_id) {
|
||||||
|
@ -361,7 +361,8 @@ void ValidatorSessionImpl::process_query(PublicKeyHash src, td::BufferSlice data
|
||||||
|
|
||||||
void ValidatorSessionImpl::candidate_decision_fail(td::uint32 round, ValidatorSessionCandidateId hash,
|
void ValidatorSessionImpl::candidate_decision_fail(td::uint32 round, ValidatorSessionCandidateId hash,
|
||||||
std::string result, td::uint32 src, td::BufferSlice proof) {
|
std::string result, td::uint32 src, td::BufferSlice proof) {
|
||||||
stats_set_candidate_status(round, description().get_source_id(src), ValidatorSessionStats::status_rejected);
|
stats_set_candidate_status(round, description().get_source_id(src), hash, ValidatorSessionStats::status_rejected,
|
||||||
|
result);
|
||||||
if (round != cur_round_) {
|
if (round != cur_round_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -376,7 +377,8 @@ void ValidatorSessionImpl::candidate_decision_fail(td::uint32 round, ValidatorSe
|
||||||
|
|
||||||
void ValidatorSessionImpl::candidate_decision_ok(td::uint32 round, ValidatorSessionCandidateId hash, RootHash root_hash,
|
void ValidatorSessionImpl::candidate_decision_ok(td::uint32 round, ValidatorSessionCandidateId hash, RootHash root_hash,
|
||||||
FileHash file_hash, td::uint32 src, td::uint32 ok_from) {
|
FileHash file_hash, td::uint32 src, td::uint32 ok_from) {
|
||||||
stats_set_candidate_status(round, description().get_source_id(src), ValidatorSessionStats::status_approved);
|
stats_set_candidate_status(round, description().get_source_id(src), hash, ValidatorSessionStats::status_approved,
|
||||||
|
PSTRING() << "ts=" << ok_from);
|
||||||
if (round != cur_round_) {
|
if (round != cur_round_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -812,15 +814,13 @@ void ValidatorSessionImpl::on_new_round(td::uint32 round) {
|
||||||
if (!have_block) {
|
if (!have_block) {
|
||||||
callback_->on_block_skipped(cur_round_);
|
callback_->on_block_skipped(cur_round_);
|
||||||
} else {
|
} else {
|
||||||
|
cur_stats_.success = true;
|
||||||
cur_stats_.timestamp = (td::uint64)td::Clocks::system();
|
cur_stats_.timestamp = (td::uint64)td::Clocks::system();
|
||||||
cur_stats_.total_validators = description().get_total_nodes();
|
|
||||||
cur_stats_.total_weight = description().get_total_weight();
|
|
||||||
cur_stats_.signatures = (td::uint32)export_sigs.size();
|
cur_stats_.signatures = (td::uint32)export_sigs.size();
|
||||||
cur_stats_.signatures_weight = signatures_weight;
|
cur_stats_.signatures_weight = signatures_weight;
|
||||||
cur_stats_.approve_signatures = (td::uint32)export_approve_sigs.size();
|
cur_stats_.approve_signatures = (td::uint32)export_approve_sigs.size();
|
||||||
cur_stats_.approve_signatures_weight = approve_signatures_weight;
|
cur_stats_.approve_signatures_weight = approve_signatures_weight;
|
||||||
cur_stats_.creator = description().get_source_id(block->get_src_idx());
|
cur_stats_.creator = description().get_source_id(block->get_src_idx());
|
||||||
cur_stats_.self = description().get_source_id(local_idx());
|
|
||||||
|
|
||||||
if (it == blocks_.end()) {
|
if (it == blocks_.end()) {
|
||||||
callback_->on_block_committed(cur_round_, description().get_source_public_key(block->get_src_idx()),
|
callback_->on_block_committed(cur_round_, description().get_source_public_key(block->get_src_idx()),
|
||||||
|
@ -923,6 +923,12 @@ void ValidatorSessionImpl::destroy() {
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ValidatorSessionImpl::get_current_stats(td::Promise<ValidatorSessionStats> promise) {
|
||||||
|
ValidatorSessionStats stats = cur_stats_;
|
||||||
|
stats.timestamp = (td::uint64)td::Clocks::system();
|
||||||
|
promise.set_result(std::move(stats));
|
||||||
|
}
|
||||||
|
|
||||||
void ValidatorSessionImpl::start_up() {
|
void ValidatorSessionImpl::start_up() {
|
||||||
CHECK(!rldp_.empty());
|
CHECK(!rldp_.empty());
|
||||||
cur_round_ = 0;
|
cur_round_ = 0;
|
||||||
|
@ -941,6 +947,10 @@ void ValidatorSessionImpl::start_up() {
|
||||||
void ValidatorSessionImpl::stats_init() {
|
void ValidatorSessionImpl::stats_init() {
|
||||||
cur_stats_ = ValidatorSessionStats();
|
cur_stats_ = ValidatorSessionStats();
|
||||||
cur_stats_.first_round = cur_round_;
|
cur_stats_.first_round = cur_round_;
|
||||||
|
cur_stats_.session_id = unique_hash_;
|
||||||
|
cur_stats_.total_validators = description().get_total_nodes();
|
||||||
|
cur_stats_.total_weight = description().get_total_weight();
|
||||||
|
cur_stats_.self = description().get_source_id(local_idx());
|
||||||
stats_add_round();
|
stats_add_round();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -961,20 +971,26 @@ void ValidatorSessionImpl::stats_add_round() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValidatorSessionImpl::stats_set_candidate_status(td::uint32 round, PublicKeyHash src, int status) {
|
void ValidatorSessionImpl::stats_set_candidate_status(td::uint32 round, PublicKeyHash src,
|
||||||
|
ValidatorSessionCandidateId candidate_id, int status,
|
||||||
|
std::string comment) {
|
||||||
if (round < cur_stats_.first_round || round - cur_stats_.first_round >= cur_stats_.rounds.size()) {
|
if (round < cur_stats_.first_round || round - cur_stats_.first_round >= cur_stats_.rounds.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto& stats_round = cur_stats_.rounds[round - cur_stats_.first_round];
|
auto &stats_round = cur_stats_.rounds[round - cur_stats_.first_round];
|
||||||
auto it = std::find_if(stats_round.producers.begin(), stats_round.producers.end(),
|
auto it = std::find_if(stats_round.producers.begin(), stats_round.producers.end(),
|
||||||
[&](const ValidatorSessionStats::Producer& p) { return p.id == src; });
|
[&](const ValidatorSessionStats::Producer &p) { return p.id == src; });
|
||||||
if (it == stats_round.producers.end()) {
|
if (it == stats_round.producers.end()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
it->candidate_id = candidate_id;
|
||||||
if (it->block_status == ValidatorSessionStats::status_none) {
|
if (it->block_status == ValidatorSessionStats::status_none) {
|
||||||
it->block_timestamp = (td::uint64)td::Clocks::system();
|
it->block_timestamp = (td::uint64)td::Clocks::system();
|
||||||
}
|
}
|
||||||
it->block_status = status;
|
it->block_status = status;
|
||||||
|
if (!comment.empty()) {
|
||||||
|
it->comment = std::move(comment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
td::actor::ActorOwn<ValidatorSession> ValidatorSession::create(
|
td::actor::ActorOwn<ValidatorSession> ValidatorSession::create(
|
||||||
|
|
|
@ -91,6 +91,7 @@ class ValidatorSession : public td::actor::Actor {
|
||||||
|
|
||||||
virtual void start() = 0;
|
virtual void start() = 0;
|
||||||
virtual void destroy() = 0;
|
virtual void destroy() = 0;
|
||||||
|
virtual void get_current_stats(td::Promise<ValidatorSessionStats> promise) = 0;
|
||||||
|
|
||||||
static td::actor::ActorOwn<ValidatorSession> create(
|
static td::actor::ActorOwn<ValidatorSession> create(
|
||||||
catchain::CatChainSessionId session_id, ValidatorSessionOptions opts, PublicKeyHash local_id,
|
catchain::CatChainSessionId session_id, ValidatorSessionOptions opts, PublicKeyHash local_id,
|
||||||
|
|
|
@ -160,7 +160,8 @@ class ValidatorSessionImpl : public ValidatorSession {
|
||||||
ValidatorSessionStats cur_stats_;
|
ValidatorSessionStats cur_stats_;
|
||||||
void stats_init();
|
void stats_init();
|
||||||
void stats_add_round();
|
void stats_add_round();
|
||||||
void stats_set_candidate_status(td::uint32 round, PublicKeyHash src, int status);
|
void stats_set_candidate_status(td::uint32 round, PublicKeyHash src, ValidatorSessionCandidateId candidate_id,
|
||||||
|
int status, std::string comment = "");
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ValidatorSessionImpl(catchain::CatChainSessionId session_id, ValidatorSessionOptions opts, PublicKeyHash local_id,
|
ValidatorSessionImpl(catchain::CatChainSessionId session_id, ValidatorSessionOptions opts, PublicKeyHash local_id,
|
||||||
|
@ -173,6 +174,7 @@ class ValidatorSessionImpl : public ValidatorSession {
|
||||||
|
|
||||||
void start() override;
|
void start() override;
|
||||||
void destroy() override;
|
void destroy() override;
|
||||||
|
void get_current_stats(td::Promise<ValidatorSessionStats> promise) override;
|
||||||
|
|
||||||
void process_blocks(std::vector<catchain::CatChainBlock *> blocks);
|
void process_blocks(std::vector<catchain::CatChainBlock *> blocks);
|
||||||
void finished_processing();
|
void finished_processing();
|
||||||
|
|
|
@ -2640,18 +2640,19 @@ void ValidatorManagerImpl::log_validator_session_stats(BlockIdExt block_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<tl_object_ptr<ton_api::validatorSession_statsRound>> rounds;
|
std::vector<tl_object_ptr<ton_api::validatorSession_statsRound>> rounds;
|
||||||
for (const auto& round : stats.rounds) {
|
for (const auto &round : stats.rounds) {
|
||||||
std::vector<tl_object_ptr<ton_api::validatorSession_statsProducer>> producers;
|
std::vector<tl_object_ptr<ton_api::validatorSession_statsProducer>> producers;
|
||||||
for (const auto& producer : round.producers) {
|
for (const auto &producer : round.producers) {
|
||||||
producers.push_back(create_tl_object<ton_api::validatorSession_statsProducer>(
|
producers.push_back(create_tl_object<ton_api::validatorSession_statsProducer>(
|
||||||
producer.id.bits256_value(), producer.block_status, producer.block_timestamp));
|
producer.id.bits256_value(), producer.candidate_id, producer.block_status, producer.block_timestamp,
|
||||||
|
producer.comment));
|
||||||
}
|
}
|
||||||
rounds.push_back(create_tl_object<ton_api::validatorSession_statsRound>(round.timestamp, std::move(producers)));
|
rounds.push_back(create_tl_object<ton_api::validatorSession_statsRound>(round.timestamp, std::move(producers)));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto obj = create_tl_object<ton_api::validatorSession_stats>(
|
auto obj = create_tl_object<ton_api::validatorSession_stats>(
|
||||||
create_tl_block_id_simple(block_id.id), stats.timestamp, stats.self.bits256_value(),
|
stats.success, create_tl_block_id(block_id), stats.timestamp, stats.self.bits256_value(), stats.session_id,
|
||||||
stats.creator.bits256_value(), stats.total_validators, stats.total_weight, stats.signatures,
|
stats.cc_seqno, stats.creator.bits256_value(), stats.total_validators, stats.total_weight, stats.signatures,
|
||||||
stats.signatures_weight, stats.approve_signatures, stats.approve_signatures_weight, stats.first_round,
|
stats.signatures_weight, stats.approve_signatures, stats.approve_signatures_weight, stats.first_round,
|
||||||
std::move(rounds));
|
std::move(rounds));
|
||||||
std::string s = td::json_encode<std::string>(td::ToJson(*obj.get()), false);
|
std::string s = td::json_encode<std::string>(td::ToJson(*obj.get()), false);
|
||||||
|
|
|
@ -136,7 +136,8 @@ void ValidatorGroup::accept_block_candidate(td::uint32 round_id, PublicKeyHash s
|
||||||
std::vector<BlockSignature> approve_signatures,
|
std::vector<BlockSignature> approve_signatures,
|
||||||
validatorsession::ValidatorSessionStats stats,
|
validatorsession::ValidatorSessionStats stats,
|
||||||
td::Promise<td::Unit> promise) {
|
td::Promise<td::Unit> promise) {
|
||||||
if (round_id >= last_known_round_id_) {
|
stats.cc_seqno = validator_set_->get_catchain_seqno();
|
||||||
|
if (round_id >= last_known_round_id_) {
|
||||||
last_known_round_id_ = round_id + 1;
|
last_known_round_id_ = round_id + 1;
|
||||||
}
|
}
|
||||||
auto sig_set = create_signature_set(std::move(signatures));
|
auto sig_set = create_signature_set(std::move(signatures));
|
||||||
|
@ -354,6 +355,19 @@ void ValidatorGroup::start(std::vector<BlockIdExt> prev, BlockIdExt min_masterch
|
||||||
|
|
||||||
void ValidatorGroup::destroy() {
|
void ValidatorGroup::destroy() {
|
||||||
if (!session_.empty()) {
|
if (!session_.empty()) {
|
||||||
|
td::actor::send_closure(session_, &validatorsession::ValidatorSession::get_current_stats,
|
||||||
|
[manager = manager_, cc_seqno = validator_set_->get_catchain_seqno(),
|
||||||
|
block_id = create_next_block_id(RootHash::zero(), FileHash::zero())](
|
||||||
|
td::Result<validatorsession::ValidatorSessionStats> R) {
|
||||||
|
if (R.is_error()) {
|
||||||
|
LOG(WARNING) << "Failed to get validator session stats: " << R.move_as_error();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto stats = R.move_as_ok();
|
||||||
|
stats.cc_seqno = cc_seqno;
|
||||||
|
td::actor::send_closure(manager, &ValidatorManager::log_validator_session_stats, block_id,
|
||||||
|
std::move(stats));
|
||||||
|
});
|
||||||
auto ses = session_.release();
|
auto ses = session_.release();
|
||||||
delay_action([ses]() mutable { td::actor::send_closure(ses, &validatorsession::ValidatorSession::destroy); },
|
delay_action([ses]() mutable { td::actor::send_closure(ses, &validatorsession::ValidatorSession::destroy); },
|
||||||
td::Timestamp::in(10.0));
|
td::Timestamp::in(10.0));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue