mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Cache recent block states and adjust timeouts (#823)
* Add parameter --celldb-compress-depth to speed up celldb * Fix collator timeout * Add block_state_cache * Adjust state cache ttl * Don't merge shards when queue is too big * Decrease lt limit if previous block is too old --------- Co-authored-by: SpyCheese <mikle98@yandex.ru>
This commit is contained in:
parent
7fcf267717
commit
9b6d699c21
20 changed files with 230 additions and 37 deletions
|
@ -585,6 +585,12 @@ void ValidatorManagerImpl::run_ext_query(td::BufferSlice data, td::Promise<td::B
|
|||
|
||||
void ValidatorManagerImpl::wait_block_state(BlockHandle handle, td::uint32 priority, td::Timestamp timeout,
|
||||
td::Promise<td::Ref<ShardState>> promise) {
|
||||
auto it0 = block_state_cache_.find(handle->id());
|
||||
if (it0 != block_state_cache_.end()) {
|
||||
it0->second.ttl_ = td::Timestamp::in(30.0);
|
||||
promise.set_result(it0->second.state_);
|
||||
return;
|
||||
}
|
||||
auto it = wait_state_.find(handle->id());
|
||||
if (it == wait_state_.end()) {
|
||||
auto P = td::PromiseCreator::lambda([SelfId = actor_id(this), handle](td::Result<td::Ref<ShardState>> R) {
|
||||
|
@ -988,6 +994,9 @@ void ValidatorManagerImpl::get_block_by_seqno_from_db(AccountIdPrefixFull accoun
|
|||
}
|
||||
|
||||
void ValidatorManagerImpl::finished_wait_state(BlockHandle handle, td::Result<td::Ref<ShardState>> R) {
|
||||
if (R.is_ok()) {
|
||||
block_state_cache_[handle->id()] = {R.ok(), td::Timestamp::in(30.0)};
|
||||
}
|
||||
auto it = wait_state_.find(handle->id());
|
||||
if (it != wait_state_.end()) {
|
||||
if (R.is_error()) {
|
||||
|
@ -1441,7 +1450,7 @@ void ValidatorManagerImpl::send_block_broadcast(BlockBroadcast broadcast) {
|
|||
}
|
||||
|
||||
void ValidatorManagerImpl::start_up() {
|
||||
db_ = create_db_actor(actor_id(this), db_root_);
|
||||
db_ = create_db_actor(actor_id(this), db_root_, opts_);
|
||||
lite_server_cache_ = create_liteserver_cache_actor(actor_id(this), db_root_);
|
||||
token_manager_ = td::actor::create_actor<TokenManager>("tokenmanager");
|
||||
td::mkdir(db_root_ + "/tmp/").ensure();
|
||||
|
@ -2373,6 +2382,31 @@ void ValidatorManagerImpl::alarm() {
|
|||
for (auto &w : shard_client_waiters_) {
|
||||
w.second.check_timers();
|
||||
}
|
||||
for (auto it = block_state_cache_.begin(); it != block_state_cache_.end();) {
|
||||
bool del = it->second.ttl_.is_in_past();
|
||||
if (del) {
|
||||
auto block_id = it->first;
|
||||
if (block_id.is_masterchain()) {
|
||||
if (block_id.seqno() == last_masterchain_seqno_) {
|
||||
it->second.ttl_ = td::Timestamp::in(30.0);
|
||||
del = false;
|
||||
}
|
||||
} else if (last_masterchain_state_.not_null()) {
|
||||
auto shard = last_masterchain_state_->get_shard_from_config(block_id.shard_full());
|
||||
if (shard.not_null()) {
|
||||
if (block_id.seqno() == shard->top_block_id().seqno()) {
|
||||
it->second.ttl_ = td::Timestamp::in(30.0);
|
||||
del = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (del) {
|
||||
it = block_state_cache_.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
alarm_timestamp().relax(check_waiters_at_);
|
||||
if (check_shard_clients_.is_in_past()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue