Skip to content

Commit 3d49e8b

Browse files
authored
Fix selecting shard overlays after decreasing monitor_min_split (#1756)
When node is out of sync (e.g., during initial sync), it may try to use shard overlays that do not exist anymore because monitor min split was decreased. "Download state", "download archive" and "download proof link" are the types of requests that are necessary to sync.
1 parent 7d1995e commit 3d49e8b

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

validator/full-node.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ void FullNodeImpl::download_zero_state(BlockIdExt id, td::uint32 priority, td::T
444444
void FullNodeImpl::download_persistent_state(BlockIdExt id, BlockIdExt masterchain_block_id, PersistentStateType type,
445445
td::uint32 priority, td::Timestamp timeout,
446446
td::Promise<td::BufferSlice> promise) {
447-
auto shard = get_shard(id.shard_full());
447+
auto shard = get_shard(id.shard_full(), /* historical = */ true);
448448
if (shard.empty()) {
449449
VLOG(FULL_NODE_WARNING) << "dropping download state diff query to unknown shard";
450450
promise.set_error(td::Status::Error(ErrorCode::notready, "shard not ready"));
@@ -467,7 +467,7 @@ void FullNodeImpl::download_block_proof(BlockIdExt block_id, td::uint32 priority
467467

468468
void FullNodeImpl::download_block_proof_link(BlockIdExt block_id, td::uint32 priority, td::Timestamp timeout,
469469
td::Promise<td::BufferSlice> promise) {
470-
auto shard = get_shard(block_id.shard_full());
470+
auto shard = get_shard(block_id.shard_full(), /* historical = */ true);
471471
if (shard.empty()) {
472472
VLOG(FULL_NODE_WARNING) << "dropping download proof link query to unknown shard";
473473
promise.set_error(td::Status::Error(ErrorCode::notready, "shard not ready"));
@@ -490,7 +490,7 @@ void FullNodeImpl::get_next_key_blocks(BlockIdExt block_id, td::Timestamp timeou
490490

491491
void FullNodeImpl::download_archive(BlockSeqno masterchain_seqno, ShardIdFull shard_prefix, std::string tmp_dir,
492492
td::Timestamp timeout, td::Promise<std::string> promise) {
493-
auto shard = get_shard(shard_prefix);
493+
auto shard = get_shard(shard_prefix, /* historical = */ true);
494494
if (shard.empty()) {
495495
VLOG(FULL_NODE_WARNING) << "dropping download archive query to unknown shard";
496496
promise.set_error(td::Status::Error(ErrorCode::notready, "shard not ready"));
@@ -519,16 +519,20 @@ void FullNodeImpl::download_out_msg_queue_proof(ShardIdFull dst_shard, std::vect
519519
timeout, std::move(promise));
520520
}
521521

522-
td::actor::ActorId<FullNodeShard> FullNodeImpl::get_shard(ShardIdFull shard) {
522+
td::actor::ActorId<FullNodeShard> FullNodeImpl::get_shard(ShardIdFull shard, bool historical) {
523523
if (shard.is_masterchain()) {
524524
return shards_[ShardIdFull{masterchainId}].actor.get();
525525
}
526526
if (shard.workchain != basechainId) {
527527
return {};
528528
}
529529
int pfx_len = shard.pfx_len();
530-
if (pfx_len > wc_monitor_min_split_) {
531-
shard = shard_prefix(shard, wc_monitor_min_split_);
530+
int min_split = wc_monitor_min_split_;
531+
if (historical) {
532+
min_split = td::Random::fast(0, min_split);
533+
}
534+
if (pfx_len > min_split) {
535+
shard = shard_prefix(shard, min_split);
532536
}
533537
while (true) {
534538
auto it = shards_.find(shard);

validator/full-node.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class FullNodeImpl : public FullNode {
131131
FileHash zero_state_file_hash_;
132132

133133
td::actor::ActorId<FullNodeShard> get_shard(AccountIdPrefixFull dst);
134-
td::actor::ActorId<FullNodeShard> get_shard(ShardIdFull shard);
134+
td::actor::ActorId<FullNodeShard> get_shard(ShardIdFull shard, bool historical = false);
135135
std::map<ShardIdFull, ShardInfo> shards_;
136136
int wc_monitor_min_split_ = 0;
137137

0 commit comments

Comments
 (0)