mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Accelerator, part 1 (#1119)
This commit contains some parts of https://github.com/ton-blockchain/ton/tree/accelerator This is auxiliary code that mostly does not change node behavior. 1) Semiprivate overlays and other improvements in overlays code 2) Rename actual_min_split -> monitor_min_split, fix building shard overlays 3) Loading block candidates by block id from DB, fix accept_block after validator restart 4) Cells: ProofStorageStat and changes in CellUsageTree 5) Remove some unused code, other minor changes
This commit is contained in:
parent
9a10f79fba
commit
908415d00b
66 changed files with 2221 additions and 638 deletions
|
@ -21,8 +21,14 @@
|
|||
#include "auto/tl/ton_api.h"
|
||||
#include "adnl/adnl-node-id.hpp"
|
||||
#include "overlay/overlays.h"
|
||||
#include "td/utils/SharedSlice.h"
|
||||
#include "td/utils/buffer.h"
|
||||
#include "td/utils/overloaded.h"
|
||||
#include "keys/encryptor.h"
|
||||
#include "td/utils/port/StdStreams.h"
|
||||
#include "td/utils/unique_ptr.h"
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
namespace ton {
|
||||
|
||||
|
@ -30,18 +36,30 @@ namespace overlay {
|
|||
|
||||
class OverlayNode {
|
||||
public:
|
||||
explicit OverlayNode(adnl::AdnlNodeIdShort self_id, OverlayIdShort overlay) {
|
||||
explicit OverlayNode(adnl::AdnlNodeIdShort self_id, OverlayIdShort overlay, td::uint32 flags) {
|
||||
source_ = self_id;
|
||||
overlay_ = overlay;
|
||||
flags_ = flags;
|
||||
version_ = static_cast<td::int32>(td::Clocks::system());
|
||||
}
|
||||
static td::Result<OverlayNode> create(const tl_object_ptr<ton_api::overlay_node> &node) {
|
||||
TRY_RESULT(source, adnl::AdnlNodeIdFull::create(node->id_));
|
||||
return OverlayNode{source, OverlayIdShort{node->overlay_}, node->version_, node->signature_.as_slice()};
|
||||
return OverlayNode{source, OverlayIdShort{node->overlay_}, 0, node->version_, node->signature_.as_slice()};
|
||||
}
|
||||
OverlayNode(td::Variant<adnl::AdnlNodeIdFull, adnl::AdnlNodeIdShort> source, OverlayIdShort overlay,
|
||||
static td::Result<OverlayNode> create(const tl_object_ptr<ton_api::overlay_nodeV2> &node) {
|
||||
TRY_RESULT(source, adnl::AdnlNodeIdFull::create(node->id_));
|
||||
auto res = OverlayNode{source, OverlayIdShort{node->overlay_}, (td::uint32)node->flags_, node->version_,
|
||||
node->signature_.as_slice()};
|
||||
res.update_certificate(OverlayMemberCertificate(node->certificate_.get()));
|
||||
return res;
|
||||
}
|
||||
OverlayNode(td::Variant<adnl::AdnlNodeIdFull, adnl::AdnlNodeIdShort> source, OverlayIdShort overlay, td::uint32 flags,
|
||||
td::int32 version, td::Slice signature)
|
||||
: source_(std::move(source)), overlay_(overlay), version_(version), signature_(td::SharedSlice(signature)) {
|
||||
: source_(std::move(source))
|
||||
, overlay_(overlay)
|
||||
, flags_(flags)
|
||||
, version_(version)
|
||||
, signature_(td::SharedSlice(signature)) {
|
||||
}
|
||||
OverlayNode(td::Variant<adnl::AdnlNodeIdFull, adnl::AdnlNodeIdShort> source, OverlayIdShort overlay,
|
||||
td::int32 version, td::SharedSlice signature)
|
||||
|
@ -64,10 +82,17 @@ class OverlayNode {
|
|||
}
|
||||
|
||||
td::BufferSlice to_sign() const {
|
||||
auto obj = create_tl_object<ton_api::overlay_node_toSign>(nullptr, overlay_.tl(), version_);
|
||||
source_.visit(td::overloaded([&](const adnl::AdnlNodeIdShort &id) { obj->id_ = id.tl(); },
|
||||
[&](const adnl::AdnlNodeIdFull &id) { obj->id_ = id.compute_short_id().tl(); }));
|
||||
return serialize_tl_object(obj, true);
|
||||
if (flags_ == 0) {
|
||||
auto obj = create_tl_object<ton_api::overlay_node_toSign>(nullptr, overlay_.tl(), version_);
|
||||
source_.visit(td::overloaded([&](const adnl::AdnlNodeIdShort &id) { obj->id_ = id.tl(); },
|
||||
[&](const adnl::AdnlNodeIdFull &id) { obj->id_ = id.compute_short_id().tl(); }));
|
||||
return serialize_tl_object(obj, true);
|
||||
} else {
|
||||
auto obj = create_tl_object<ton_api::overlay_node_toSignEx>(nullptr, overlay_.tl(), flags_, version_);
|
||||
source_.visit(td::overloaded([&](const adnl::AdnlNodeIdShort &id) { obj->id_ = id.tl(); },
|
||||
[&](const adnl::AdnlNodeIdFull &id) { obj->id_ = id.compute_short_id().tl(); }));
|
||||
return serialize_tl_object(obj, true);
|
||||
}
|
||||
}
|
||||
void update_adnl_id(adnl::AdnlNodeIdFull node_id) {
|
||||
source_ = node_id;
|
||||
|
@ -81,6 +106,9 @@ class OverlayNode {
|
|||
td::int32 version() const {
|
||||
return version_;
|
||||
}
|
||||
td::uint32 flags() const {
|
||||
return flags_;
|
||||
}
|
||||
td::BufferSlice signature() const {
|
||||
return signature_.clone_as_buffer_slice();
|
||||
}
|
||||
|
@ -103,15 +131,69 @@ class OverlayNode {
|
|||
[&](const adnl::AdnlNodeIdFull &id) { obj->id_ = id.tl(); }));
|
||||
return obj;
|
||||
}
|
||||
tl_object_ptr<ton_api::overlay_nodeV2> tl_v2() const {
|
||||
tl_object_ptr<ton_api::overlay_MemberCertificate> cert;
|
||||
if (cert_ && !cert_->empty()) {
|
||||
cert = cert_->tl();
|
||||
} else {
|
||||
cert = create_tl_object<ton_api::overlay_emptyMemberCertificate>();
|
||||
}
|
||||
auto obj = create_tl_object<ton_api::overlay_nodeV2>(nullptr, overlay_.tl(), flags_, version_,
|
||||
signature_.clone_as_buffer_slice(), std::move(cert));
|
||||
source_.visit(td::overloaded([&](const adnl::AdnlNodeIdShort &id) { UNREACHABLE(); },
|
||||
[&](const adnl::AdnlNodeIdFull &id) { obj->id_ = id.tl(); }));
|
||||
return obj;
|
||||
}
|
||||
OverlayNode clone() const {
|
||||
return OverlayNode{source_, overlay_, version_, signature_.clone()};
|
||||
auto res = OverlayNode{source_, overlay_, version_, signature_.clone()};
|
||||
if (cert_) {
|
||||
res.cert_ = td::make_unique<OverlayMemberCertificate>(*cert_);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
const OverlayMemberCertificate *certificate() const {
|
||||
if (cert_) {
|
||||
return cert_.get();
|
||||
}
|
||||
return &empty_certificate_;
|
||||
}
|
||||
|
||||
void update_certificate(OverlayMemberCertificate cert) {
|
||||
if (!cert_ || cert_->empty() || cert_->is_expired() || cert.is_newer(*cert_)) {
|
||||
cert_ = td::make_unique<OverlayMemberCertificate>(std::move(cert));
|
||||
}
|
||||
}
|
||||
|
||||
void update(OverlayNode from) {
|
||||
if (version_ < from.version_) {
|
||||
source_ = from.source_;
|
||||
overlay_ = from.overlay_;
|
||||
flags_ = from.flags_;
|
||||
version_ = from.version_;
|
||||
signature_ = from.signature_.clone();
|
||||
}
|
||||
if (from.cert_ && !from.cert_->empty()) {
|
||||
update_certificate(std::move(*from.cert_));
|
||||
}
|
||||
}
|
||||
|
||||
void clear_certificate() {
|
||||
cert_ = nullptr;
|
||||
}
|
||||
|
||||
bool has_full_id() const {
|
||||
return source_.get_offset() == source_.offset<adnl::AdnlNodeIdFull>();
|
||||
}
|
||||
|
||||
private:
|
||||
td::Variant<adnl::AdnlNodeIdFull, adnl::AdnlNodeIdShort> source_;
|
||||
OverlayIdShort overlay_;
|
||||
td::uint32 flags_;
|
||||
td::int32 version_;
|
||||
td::unique_ptr<OverlayMemberCertificate> cert_;
|
||||
td::SharedSlice signature_;
|
||||
static const OverlayMemberCertificate empty_certificate_;
|
||||
};
|
||||
|
||||
} // namespace overlay
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue