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

tonlib updated

- updated tonlib
- added documentation
- speed up full node synchronization
This commit is contained in:
ton 2019-09-25 17:50:58 +04:00
parent 07b26e2259
commit ac3eb1a7b8
30 changed files with 1351 additions and 160 deletions

View file

@ -26,6 +26,25 @@ namespace validator {
namespace fullnode {
struct Neighbour {
adnl::AdnlNodeIdShort adnl_id;
td::uint32 proto_version = 0;
td::uint64 capabilities = 0;
td::Clocks::Duration roundtrip = 0;
td::Clocks::Duration roundtrip_relax_at = 0;
double roundtrip_weight = 0;
double unreliability = 0;
Neighbour(adnl::AdnlNodeIdShort adnl_id) : adnl_id(std::move(adnl_id)) {
}
void update_proto_version(const ton_api::tonNode_capabilities &q);
void query_success(td::Clocks::Duration t);
void query_failed();
void update_roundtrip(td::Clocks::Duration t);
static Neighbour zero;
};
class FullNodeShardImpl : public FullNodeShard {
public:
WorkchainId get_workchain() const override {
@ -47,6 +66,15 @@ class FullNodeShardImpl : public FullNodeShard {
static constexpr td::uint64 proto_capabilities() {
return 0;
}
static constexpr td::uint32 max_neighbours() {
return 16;
}
static constexpr double stop_unreliability() {
return 5.0;
}
static constexpr double fail_unreliability() {
return 10.0;
}
void create_overlay();
void update_adnl_id(adnl::AdnlNodeIdShort adnl_id, td::Promise<td::Unit> promise) override;
@ -130,6 +158,26 @@ class FullNodeShardImpl : public FullNodeShard {
void sign_new_certificate(PublicKeyHash sign_by);
void signed_new_certificate(ton::overlay::Certificate cert);
void ping_neighbours();
void reload_neighbours();
void got_neighbours(std::vector<adnl::AdnlNodeIdShort> res);
void update_neighbour_stats(adnl::AdnlNodeIdShort adnl_id, td::Clocks::Duration t, bool success);
void got_neighbour_capabilities(adnl::AdnlNodeIdShort adnl_id, td::Clocks::Duration t, td::BufferSlice data);
const Neighbour &choose_neighbour() const;
template <typename T>
td::Promise<T> create_neighbour_promise(const Neighbour &x, td::Promise<T> p) {
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) {
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);
}
p.set_result(std::move(R));
});
}
FullNodeShardImpl(ShardIdFull shard, PublicKeyHash local_id, adnl::AdnlNodeIdShort adnl_id,
FileHash zero_state_file_hash, td::actor::ActorId<keyring::Keyring> keyring,
td::actor::ActorId<adnl::Adnl> adnl, td::actor::ActorId<rldp::Rldp> rldp,
@ -167,6 +215,11 @@ class FullNodeShardImpl : public FullNodeShard {
std::shared_ptr<ton::overlay::Certificate> cert_;
overlay::OverlayPrivacyRules rules_;
std::map<adnl::AdnlNodeIdShort, Neighbour> neighbours_;
td::Timestamp reload_neighbours_at_;
td::Timestamp ping_neighbours_at_;
adnl::AdnlNodeIdShort last_pinged_neighbour_ = adnl::AdnlNodeIdShort::zero();
};
} // namespace fullnode