Skip to content

Commit

Permalink
Check peer version before getOutMsgQueueProof
Browse files Browse the repository at this point in the history
  • Loading branch information
SpyCheese committed Dec 10, 2024
1 parent 0d6af3f commit 20c20e2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
30 changes: 21 additions & 9 deletions validator/full-node-shard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ void FullNodeShardImpl::download_out_msg_queue_proof(ShardIdFull dst_shard, std:
block::ImportedMsgQueueLimits limits, td::Timestamp timeout,
td::Promise<std::vector<td::Ref<OutMsgQueueProof>>> promise) {
// TODO: maybe more complex download (like other requests here)
auto &b = choose_neighbour();
auto &b = choose_neighbour(3, 0); // Required version: 3.0
if (b.adnl_id == adnl::AdnlNodeIdShort::zero()) {
promise.set_error(td::Status::Error(ErrorCode::notready, "no nodes"));
return;
Expand Down Expand Up @@ -1252,24 +1252,36 @@ void FullNodeShardImpl::got_neighbours(std::vector<adnl::AdnlNodeIdShort> vec) {
}
}

const Neighbour &FullNodeShardImpl::choose_neighbour() const {
const Neighbour &FullNodeShardImpl::choose_neighbour(td::uint32 required_version_major,
td::uint32 required_version_minor) const {
if (neighbours_.size() == 0) {
return Neighbour::zero;
}
auto is_eligible =
[&](const Neighbour &n) {
return n.version_major > required_version_major ||
(n.version_major == required_version_major && n.version_minor >= required_version_minor);
};

double min_unreliability = 1e9;
for (auto &x : neighbours_) {
min_unreliability = std::min(min_unreliability, x.second.unreliability);
for (auto &[_, x] : neighbours_) {
if (!is_eligible(x)) {
continue;
}
min_unreliability = std::min(min_unreliability, x.unreliability);
}
const Neighbour *best = nullptr;
td::uint32 sum = 0;

for (auto &x : neighbours_) {
auto unr = static_cast<td::uint32>(x.second.unreliability - min_unreliability);
for (auto &[_, x] : neighbours_) {
if (!is_eligible(x)) {
continue;
}
auto unr = static_cast<td::uint32>(x.unreliability - min_unreliability);

if (x.second.version_major < proto_version_major()) {
if (x.version_major < proto_version_major()) {
unr += 4;
} else if (x.second.version_major == proto_version_major() && x.second.version_minor < proto_version_minor()) {
} else if (x.version_major == proto_version_major() && x.version_minor < proto_version_minor()) {
unr += 2;
}

Expand All @@ -1279,7 +1291,7 @@ const Neighbour &FullNodeShardImpl::choose_neighbour() const {
auto w = 1 << (f - unr);
sum += w;
if (td::Random::fast(0, sum - 1) <= w - 1) {
best = &x.second;
best = &x;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion validator/full-node-shard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class FullNodeShardImpl : public FullNodeShard {
void got_neighbours(std::vector<adnl::AdnlNodeIdShort> res);
void update_neighbour_stats(adnl::AdnlNodeIdShort adnl_id, double t, bool success);
void got_neighbour_capabilities(adnl::AdnlNodeIdShort adnl_id, double t, td::BufferSlice data);
const Neighbour &choose_neighbour() const;
const Neighbour &choose_neighbour(td::uint32 required_version_major = 0, td::uint32 required_version_minor = 0) const;

template <typename T>
td::Promise<T> create_neighbour_promise(const Neighbour &x, td::Promise<T> p, bool require_state = false) {
Expand Down
2 changes: 1 addition & 1 deletion validator/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,7 @@ void ValidatorManagerImpl::send_validator_telemetry(PublicKeyHash key,
void ValidatorManagerImpl::send_get_out_msg_queue_proof_request(
ShardIdFull dst_shard, std::vector<BlockIdExt> blocks, block::ImportedMsgQueueLimits limits,
td::Promise<std::vector<td::Ref<OutMsgQueueProof>>> promise) {
callback_->download_out_msg_queue_proof(dst_shard, std::move(blocks), limits, td::Timestamp::in(10.0),
callback_->download_out_msg_queue_proof(dst_shard, std::move(blocks), limits, td::Timestamp::in(5.0),
std::move(promise));
}

Expand Down

0 comments on commit 20c20e2

Please sign in to comment.