1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

Improve block broadcasts

This commit is contained in:
SpyCheese 2024-07-25 16:33:19 +03:00
parent 4c8d25ac1b
commit 0e7374610d
20 changed files with 125 additions and 278 deletions

View file

@ -40,22 +40,14 @@ struct Neighbour {
double roundtrip_weight = 0;
double unreliability = 0;
Neighbour(adnl::AdnlNodeIdShort adnl_id) : adnl_id(std::move(adnl_id)) {
explicit Neighbour(adnl::AdnlNodeIdShort adnl_id) : adnl_id(std::move(adnl_id)) {
}
void update_proto_version(ton_api::tonNode_capabilities &q);
void query_success(double t);
void query_failed();
void update_roundtrip(double t);
bool has_state() const {
return !(flags & FLAG_NO_STATE);
}
bool has_state_known() const {
return version_major != 0;
}
static Neighbour zero;
static constexpr td::uint32 FLAG_NO_STATE = 1;
};
class FullNodeShardImpl : public FullNodeShard {
@ -82,9 +74,6 @@ class FullNodeShardImpl : public FullNodeShard {
static constexpr td::uint32 max_neighbours() {
return 16;
}
static constexpr td::uint32 min_neighbours_with_state() {
return 10;
}
static constexpr double stop_unreliability() {
return 5.0;
}
@ -94,15 +83,12 @@ class FullNodeShardImpl : public FullNodeShard {
void create_overlay();
void update_adnl_id(adnl::AdnlNodeIdShort adnl_id, td::Promise<td::Unit> promise) override;
void set_mode(FullNodeShardMode mode) override;
void set_active(bool active) override;
void set_config(FullNodeConfig config) override {
config_ = config;
}
//td::Result<Block> fetch_block(td::BufferSlice data);
void prevalidate_block(BlockIdExt block_id, td::BufferSlice data, td::BufferSlice proof,
td::Promise<ReceivedBlock> promise);
void try_get_next_block(td::Timestamp timestamp, td::Promise<ReceivedBlock> promise);
void got_next_block(td::Result<BlockHandle> block);
void get_next_block();
@ -155,8 +141,6 @@ class FullNodeShardImpl : public FullNodeShard {
td::Promise<td::BufferSlice> promise);
void process_query(adnl::AdnlNodeIdShort src, ton_api::tonNode_getOutMsgQueueProof &query,
td::Promise<td::BufferSlice> promise);
// void process_query(adnl::AdnlNodeIdShort src, ton_api::tonNode_prepareNextKeyBlockProof &query,
// td::Promise<td::BufferSlice> promise);
void receive_query(adnl::AdnlNodeIdShort src, td::BufferSlice query, td::Promise<td::BufferSlice> promise);
void receive_message(adnl::AdnlNodeIdShort src, td::BufferSlice data);
@ -222,16 +206,14 @@ 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(bool require_state = false) const;
const Neighbour &choose_neighbour() const;
template <typename T>
td::Promise<T> create_neighbour_promise(const Neighbour &x, td::Promise<T> p, bool require_state = false) {
return td::PromiseCreator::lambda([id = x.adnl_id, SelfId = actor_id(this), p = std::move(p), ts = td::Time::now(),
ignore_error = require_state && !x.has_state_known()](td::Result<T> R) mutable {
return td::PromiseCreator::lambda([id = x.adnl_id, SelfId = actor_id(this), p = std::move(p),
ts = td::Time::now()](td::Result<T> R) mutable {
if (R.is_error() && R.error().code() != ErrorCode::notready && R.error().code() != ErrorCode::cancelled) {
if (!ignore_error) {
td::actor::send_closure(SelfId, &FullNodeShardImpl::update_neighbour_stats, id, td::Time::now() - ts, false);
}
td::actor::send_closure(SelfId, &FullNodeShardImpl::update_neighbour_stats, id, td::Time::now() - ts, false);
} else {
td::actor::send_closure(SelfId, &FullNodeShardImpl::update_neighbour_stats, id, td::Time::now() - ts, true);
}
@ -245,17 +227,13 @@ class FullNodeShardImpl : public FullNodeShard {
td::actor::ActorId<rldp2::Rldp> rldp2, td::actor::ActorId<overlay::Overlays> overlays,
td::actor::ActorId<ValidatorManagerInterface> validator_manager,
td::actor::ActorId<adnl::AdnlExtClient> client, td::actor::ActorId<FullNode> full_node,
FullNodeShardMode mode = FullNodeShardMode::active);
bool active);
private:
bool use_new_download() const {
return false;
}
bool is_active() const {
return mode_ != FullNodeShardMode::inactive;
}
ShardIdFull shard_;
BlockHandle handle_;
td::Promise<td::Unit> promise_;
@ -289,7 +267,7 @@ class FullNodeShardImpl : public FullNodeShard {
td::Timestamp ping_neighbours_at_;
adnl::AdnlNodeIdShort last_pinged_neighbour_ = adnl::AdnlNodeIdShort::zero();
FullNodeShardMode mode_;
bool active_;
FullNodeConfig config_;