mirror of
https://github.com/ton-blockchain/ton
synced 2025-02-15 04:32:21 +00:00
Check peer version before getOutMsgQueueProof
This commit is contained in:
parent
0d6af3f52d
commit
20c20e236b
3 changed files with 23 additions and 11 deletions
|
@ -1005,7 +1005,7 @@ void FullNodeShardImpl::download_out_msg_queue_proof(ShardIdFull dst_shard, std:
|
||||||
block::ImportedMsgQueueLimits limits, td::Timestamp timeout,
|
block::ImportedMsgQueueLimits limits, td::Timestamp timeout,
|
||||||
td::Promise<std::vector<td::Ref<OutMsgQueueProof>>> promise) {
|
td::Promise<std::vector<td::Ref<OutMsgQueueProof>>> promise) {
|
||||||
// TODO: maybe more complex download (like other requests here)
|
// 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()) {
|
if (b.adnl_id == adnl::AdnlNodeIdShort::zero()) {
|
||||||
promise.set_error(td::Status::Error(ErrorCode::notready, "no nodes"));
|
promise.set_error(td::Status::Error(ErrorCode::notready, "no nodes"));
|
||||||
return;
|
return;
|
||||||
|
@ -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) {
|
if (neighbours_.size() == 0) {
|
||||||
return Neighbour::zero;
|
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;
|
double min_unreliability = 1e9;
|
||||||
for (auto &x : neighbours_) {
|
for (auto &[_, x] : neighbours_) {
|
||||||
min_unreliability = std::min(min_unreliability, x.second.unreliability);
|
if (!is_eligible(x)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
min_unreliability = std::min(min_unreliability, x.unreliability);
|
||||||
}
|
}
|
||||||
const Neighbour *best = nullptr;
|
const Neighbour *best = nullptr;
|
||||||
td::uint32 sum = 0;
|
td::uint32 sum = 0;
|
||||||
|
|
||||||
for (auto &x : neighbours_) {
|
for (auto &[_, x] : neighbours_) {
|
||||||
auto unr = static_cast<td::uint32>(x.second.unreliability - min_unreliability);
|
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;
|
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;
|
unr += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1279,7 +1291,7 @@ const Neighbour &FullNodeShardImpl::choose_neighbour() const {
|
||||||
auto w = 1 << (f - unr);
|
auto w = 1 << (f - unr);
|
||||||
sum += w;
|
sum += w;
|
||||||
if (td::Random::fast(0, sum - 1) <= w - 1) {
|
if (td::Random::fast(0, sum - 1) <= w - 1) {
|
||||||
best = &x.second;
|
best = &x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -209,7 +209,7 @@ class FullNodeShardImpl : public FullNodeShard {
|
||||||
void got_neighbours(std::vector<adnl::AdnlNodeIdShort> res);
|
void got_neighbours(std::vector<adnl::AdnlNodeIdShort> res);
|
||||||
void update_neighbour_stats(adnl::AdnlNodeIdShort adnl_id, double t, bool success);
|
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);
|
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>
|
template <typename T>
|
||||||
td::Promise<T> create_neighbour_promise(const Neighbour &x, td::Promise<T> p, bool require_state = false) {
|
td::Promise<T> create_neighbour_promise(const Neighbour &x, td::Promise<T> p, bool require_state = false) {
|
||||||
|
|
|
@ -1794,7 +1794,7 @@ void ValidatorManagerImpl::send_validator_telemetry(PublicKeyHash key,
|
||||||
void ValidatorManagerImpl::send_get_out_msg_queue_proof_request(
|
void ValidatorManagerImpl::send_get_out_msg_queue_proof_request(
|
||||||
ShardIdFull dst_shard, std::vector<BlockIdExt> blocks, block::ImportedMsgQueueLimits limits,
|
ShardIdFull dst_shard, std::vector<BlockIdExt> blocks, block::ImportedMsgQueueLimits limits,
|
||||||
td::Promise<std::vector<td::Ref<OutMsgQueueProof>>> promise) {
|
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));
|
std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue