mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
update tonlib
tonlib: update collator: increased collation speed for masterchain fift: bugfixes
This commit is contained in:
parent
7ea00ebfcf
commit
dd745485e2
27 changed files with 313 additions and 172 deletions
|
@ -3099,7 +3099,8 @@ bool Collator::create_mc_state_extra() {
|
|||
CHECK(cb.store_long_bool(0x17, 8) && cb.append_cellslice_bool(block_create_stats_->get_root()));
|
||||
auto cs = vm::load_cell_slice_ref(cb.finalize());
|
||||
state_extra.r1.block_create_stats = cs;
|
||||
if (verify >= 1) {
|
||||
if (verify >= 2) {
|
||||
LOG(INFO) << "verifying new BlockCreateStats";
|
||||
if (!block::gen::t_BlockCreateStats.validate_csr(cs)) {
|
||||
cs->print_rec(std::cerr);
|
||||
block::gen::t_BlockCreateStats.print(std::cerr, *cs);
|
||||
|
@ -3154,10 +3155,12 @@ bool Collator::update_block_creator_count(td::ConstBitPtr key, unsigned shard_in
|
|||
int Collator::creator_count_outdated(td::ConstBitPtr key, vm::CellSlice& cs) {
|
||||
block::DiscountedCounter mc_cnt, shard_cnt;
|
||||
if (!(block::fetch_CreatorStats(cs, mc_cnt, shard_cnt) && cs.empty_ext())) {
|
||||
return fatal_error("cannot unpack CreatorStats for "s + key.to_hex(256) + " from previous masterchain state");
|
||||
fatal_error("cannot unpack CreatorStats for "s + key.to_hex(256) + " from previous masterchain state");
|
||||
return -1;
|
||||
}
|
||||
if (!(mc_cnt.increase_by(0, now_) && shard_cnt.increase_by(0, now_))) {
|
||||
return fatal_error("cannot amortize counters in CreatorStats for "s + key.to_hex(256));
|
||||
fatal_error("cannot amortize counters in CreatorStats for "s + key.to_hex(256));
|
||||
return -1;
|
||||
}
|
||||
if (!(mc_cnt.cnt65536 | shard_cnt.cnt65536)) {
|
||||
LOG(DEBUG) << "removing stale CreatorStats for " << key.to_hex(256);
|
||||
|
@ -3178,17 +3181,42 @@ bool Collator::update_block_creator_stats() {
|
|||
return fatal_error("cannot update CreatorStats for "s + p.first.to_hex());
|
||||
}
|
||||
}
|
||||
if (!created_by_.is_zero() && !update_block_creator_count(created_by_.as_bits256().bits(), 0, 1)) {
|
||||
auto has_creator = !created_by_.is_zero();
|
||||
if (has_creator && !update_block_creator_count(created_by_.as_bits256().bits(), 0, 1)) {
|
||||
return fatal_error("cannot update CreatorStats for "s + created_by_.as_bits256().to_hex());
|
||||
}
|
||||
if (!update_block_creator_count(td::Bits256::zero().bits(), block_create_total_, !created_by_.is_zero())) {
|
||||
if ((has_creator || block_create_total_) &&
|
||||
!update_block_creator_count(td::Bits256::zero().bits(), block_create_total_, has_creator)) {
|
||||
return fatal_error("cannot update CreatorStats with zero index (representing the sum of other CreatorStats)");
|
||||
}
|
||||
// -> DEBUG
|
||||
LOG(INFO) << "scanning for outdated CreatorStats entries";
|
||||
/*
|
||||
int cnt = block_create_stats_->filter([this](vm::CellSlice& cs, td::ConstBitPtr key, int key_len) {
|
||||
CHECK(key_len == 256);
|
||||
return creator_count_outdated(key, cs);
|
||||
});
|
||||
LOG(DEBUG) << "removed " << cnt << " stale CreatorStats entries";
|
||||
*/
|
||||
// alternative version with partial scan
|
||||
td::Bits256 key;
|
||||
prng::rand_gen().rand_bytes(key.data(), 32);
|
||||
int scanned, cnt = 0;
|
||||
for (scanned = 0; scanned < 100; scanned++) {
|
||||
auto cs = block_create_stats_->lookup_nearest_key(key.bits(), 256, true);
|
||||
if (cs.is_null()) {
|
||||
break;
|
||||
}
|
||||
auto res = creator_count_outdated(key.bits(), cs.write());
|
||||
if (!res) {
|
||||
LOG(DEBUG) << "prunning CreatorStats for " << key.to_hex();
|
||||
block_create_stats_->lookup_delete(key);
|
||||
++cnt;
|
||||
} else if (res < 0) {
|
||||
return fatal_error("error scanning stale CreatorStats entries");
|
||||
}
|
||||
}
|
||||
// -> DEBUG
|
||||
LOG(INFO) << "removed " << cnt << " stale CreatorStats entries out of " << scanned << " scanned";
|
||||
return cnt >= 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue