Skip to content

Commit 378b5e9

Browse files
committed
Automatically issue and import fast sync overlay certificates
1 parent 09c4488 commit 378b5e9

File tree

12 files changed

+659
-181
lines changed

12 files changed

+659
-181
lines changed

adnl/adnl-node-id.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class AdnlNodeIdShort {
3737
}
3838
explicit AdnlNodeIdShort(td::Bits256 value) : hash_(value) {
3939
}
40-
explicit AdnlNodeIdShort(tl_object_ptr<ton_api::adnl_id_short> obj) : hash_(obj->id_) {
40+
explicit AdnlNodeIdShort(tl_object_ptr<ton_api::adnl_id_short> &&obj) : hash_(obj->id_) {
41+
}
42+
explicit AdnlNodeIdShort(const tl_object_ptr<ton_api::adnl_id_short> &obj) : hash_(obj->id_) {
4143
}
4244

4345
const auto &pubkey_hash() const {

dht-server/dht-server.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ ton::tl_object_ptr<ton::ton_api::engine_validator_config> Config::tl() const {
171171
}
172172
return ton::create_tl_object<ton::ton_api::engine_validator_config>(
173173
out_port, std::move(addrs_vec), std::move(adnl_vec), std::move(dht_vec), std::move(val_vec), std::move(col_vec),
174-
ton::PublicKeyHash::zero().tl(), std::move(full_node_slaves_vec), std::move(full_node_masters_vec),
175-
nullptr, nullptr, std::move(liteserver_vec), std::move(control_vec), std::move(shard_vec), std::move(gc_vec));
174+
ton::PublicKeyHash::zero().tl(), std::move(full_node_slaves_vec), std::move(full_node_masters_vec), nullptr,
175+
nullptr, std::move(liteserver_vec), std::move(control_vec), std::move(shard_vec), std::move(gc_vec));
176176
}
177177

178178
td::Result<bool> Config::config_add_network_addr(td::IPAddress in_ip, td::IPAddress out_ip,
@@ -1195,7 +1195,8 @@ int main(int argc, char *argv[]) {
11951195
SET_VERBOSITY_LEVEL(v);
11961196
});
11971197
p.add_option('V', "version", "shows dht-server build information", [&]() {
1198-
std::cout << "dht-server build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n";
1198+
std::cout << "dht-server build information: [ Commit: " << GitMetadata::CommitSHA1()
1199+
<< ", Date: " << GitMetadata::CommitDate() << "]\n";
11991200
std::exit(0);
12001201
});
12011202
p.add_option('h', "help", "prints_help", [&]() {

tl/generate/scheme/ton_api.tl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,8 @@ tonNode.outMsgQueueProof queue_proofs:bytes block_state_proofs:bytes msg_counts:
464464
tonNode.outMsgQueueProofEmpty = tonNode.OutMsgQueueProof;
465465

466466
tonNode.forgetPeer = tonNode.ForgetPeer;
467+
tonNode.newFastSyncMemberCertificate adnl_id:int256 certificate:overlay.MemberCertificate = tonNode.NewFastSyncMemberCertificate;
468+
467469

468470
---functions---
469471

@@ -501,6 +503,8 @@ tonNode.slave.sendExtMessage message:tonNode.externalMessage = tonNode.Success;
501503

502504
tonNode.query = Object;
503505

506+
tonNode.requestFastSyncOverlayMemberCertificate sign_by:int256 adnl_id:int256 slot:int = overlay.MemberCertificate;
507+
504508
---types---
505509

506510
// bit 0 - started
@@ -654,9 +658,11 @@ engine.validator.fullNodeMaster port:int adnl:int256 = engine.validator.FullNode
654658
engine.validator.fullNodeSlave ip:int port:int adnl:PublicKey = engine.validator.FullNodeSlave;
655659
engine.validator.fullNodeConfig ext_messages_broadcast_disabled:Bool = engine.validator.FullNodeConfig;
656660
engine.validator.fastSyncMemberCertificate adnl_id:int256 certificate:overlay.MemberCertificate = engine.validator.FastSyncMemberCertificate;
661+
engine.validator.fastSyncOverlayClient adnl_id:int256 slot:int = engine.validator.FastSyncOverlayClient;
657662
engine.validator.collatorNodeWhitelist enabled:Bool adnl_ids:(vector int256) = engine.validator.CollatorNodeWhitelist;
658663
engine.validator.extraConfig state_serializer_enabled:Bool fast_sync_member_certificates:(vector engine.validator.fastSyncMemberCertificate)
659-
collator_node_whitelist:engine.validator.collatorNodeWhitelist = engine.validator.ExtraConfig;
664+
collator_node_whitelist:engine.validator.collatorNodeWhitelist
665+
fast_sync_overlay_clients:(vector engine.validator.fastSyncOverlayClient) = engine.validator.ExtraConfig;
660666
engine.validator.config out_port:int addrs:(vector engine.Addr) adnl:(vector engine.adnl)
661667
dht:(vector engine.dht)
662668
validators:(vector engine.validator) collators:(vector engine.collator)
@@ -840,6 +846,8 @@ engine.validator.getCollationManagerStats = engine.validator.CollationManagerSta
840846

841847
engine.validator.signOverlayMemberCertificate sign_by:int256 adnl_id:int256 slot:int expire_at:int = overlay.MemberCertificate;
842848
engine.validator.importFastSyncMemberCertificate adnl_id:int256 certificate:overlay.MemberCertificate = engine.validator.Success;
849+
engine.validator.addFastSyncClient adnl_id:int256 slot:int = engine.validator.Success;
850+
engine.validator.delFastSyncClient adnl_id:int256 = engine.validator.Success;
843851

844852
---types---
845853

tl/generate/scheme/ton_api.tlo

932 Bytes
Binary file not shown.

validator-engine-console/validator-engine-console-query.cpp

Lines changed: 68 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -807,21 +807,21 @@ td::Status SignCertificateQuery::send() {
807807
auto sign = ton::create_serialize_tl_object<ton::ton_api::engine_validator_sign>(signer_.tl(), std::move(cid));
808808
auto pub = ton::create_serialize_tl_object<ton::ton_api::engine_validator_exportPublicKey>(signer_.tl());
809809
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(pub),
810-
td::PromiseCreator::lambda([SelfId = actor_id(this)](td::Result<td::BufferSlice> R) {
811-
if (R.is_error()) {
812-
td::actor::send_closure(SelfId, &SignCertificateQuery::handle_error, R.move_as_error());
813-
} else {
814-
td::actor::send_closure(SelfId, &SignCertificateQuery::receive_pubkey, R.move_as_ok());
815-
}
816-
}));
810+
td::PromiseCreator::lambda([SelfId = actor_id(this)](td::Result<td::BufferSlice> R) {
811+
if (R.is_error()) {
812+
td::actor::send_closure(SelfId, &SignCertificateQuery::handle_error, R.move_as_error());
813+
} else {
814+
td::actor::send_closure(SelfId, &SignCertificateQuery::receive_pubkey, R.move_as_ok());
815+
}
816+
}));
817817
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(sign),
818-
td::PromiseCreator::lambda([SelfId = actor_id(this)](td::Result<td::BufferSlice> R) {
819-
if (R.is_error()) {
820-
td::actor::send_closure(SelfId, &SignCertificateQuery::handle_error, R.move_as_error());
821-
} else {
822-
td::actor::send_closure(SelfId, &SignCertificateQuery::receive_signature, R.move_as_ok());
823-
}
824-
}));
818+
td::PromiseCreator::lambda([SelfId = actor_id(this)](td::Result<td::BufferSlice> R) {
819+
if (R.is_error()) {
820+
td::actor::send_closure(SelfId, &SignCertificateQuery::handle_error, R.move_as_error());
821+
} else {
822+
td::actor::send_closure(SelfId, &SignCertificateQuery::receive_signature, R.move_as_ok());
823+
}
824+
}));
825825
return td::Status::OK();
826826
}
827827

@@ -833,33 +833,32 @@ void SignCertificateQuery::receive_pubkey(td::BufferSlice R) {
833833
}
834834
pubkey_ = f.move_as_ok();
835835
has_pubkey_ = true;
836-
if(has_signature_) {
836+
if (has_signature_) {
837837
save_certificate();
838838
}
839839
}
840840

841-
842841
td::Status SignCertificateQuery::receive(td::BufferSlice data) {
843842
UNREACHABLE();
844843
}
845844

846845
void SignCertificateQuery::receive_signature(td::BufferSlice R) {
847846
auto f = ton::fetch_tl_object<ton::ton_api::engine_validator_signature>(R.as_slice(), true);
848-
if(f.is_error()){
847+
if (f.is_error()) {
849848
handle_error(f.move_as_error_prefix("Failed to get signature: "));
850849
return;
851850
}
852851
signature_ = std::move(f.move_as_ok()->signature_);
853-
if(has_pubkey_) {
852+
if (has_pubkey_) {
854853
save_certificate();
855854
}
856855
}
857856

858857
void SignCertificateQuery::save_certificate() {
859-
auto c = ton::create_serialize_tl_object<ton::ton_api::overlay_certificate>(
860-
std::move(pubkey_), expire_at_, max_size_, std::move(signature_));
858+
auto c = ton::create_serialize_tl_object<ton::ton_api::overlay_certificate>(std::move(pubkey_), expire_at_, max_size_,
859+
std::move(signature_));
861860
auto w = td::write_file(out_file_, c.as_slice());
862-
if(w.is_error()) {
861+
if (w.is_error()) {
863862
handle_error(w.move_as_error_prefix("Failed to write certificate to file: "));
864863
return;
865864
}
@@ -880,11 +879,8 @@ td::Status ImportCertificateQuery::send() {
880879
TRY_RESULT_PREFIX(cert, ton::fetch_tl_object<ton::ton_api::overlay_Certificate>(data.as_slice(), true),
881880
"incorrect certificate");
882881
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_importCertificate>(
883-
overlay_,
884-
ton::create_tl_object<ton::ton_api::adnl_id_short>(id_),
885-
ton::create_tl_object<ton::ton_api::engine_validator_keyHash>(kh_.tl()),
886-
std::move(cert)
887-
);
882+
overlay_, ton::create_tl_object<ton::ton_api::adnl_id_short>(id_),
883+
ton::create_tl_object<ton::ton_api::engine_validator_keyHash>(kh_.tl()), std::move(cert));
888884
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
889885
return td::Status::OK();
890886
}
@@ -1031,18 +1027,16 @@ td::Status GetOverlaysStatsJsonQuery::receive(td::BufferSlice data) {
10311027
return td::Status::OK();
10321028
}
10331029

1034-
10351030
td::Status ImportCertificateQuery::receive(td::BufferSlice data) {
10361031
TRY_RESULT_PREFIX(f, ton::fetch_tl_object<ton::ton_api::engine_validator_success>(data.as_slice(), true),
10371032
"received incorrect answer: ");
10381033
td::TerminalIO::out() << "successfully sent certificate to overlay manager\n";
10391034
return td::Status::OK();
10401035
}
10411036

1042-
10431037
td::Status SignShardOverlayCertificateQuery::run() {
10441038
TRY_RESULT_ASSIGN(wc_, tokenizer_.get_token<td::int32>());
1045-
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<td::int64>() );
1039+
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<td::int64>());
10461040
TRY_RESULT_ASSIGN(key_, tokenizer_.get_token<ton::PublicKeyHash>());
10471041
TRY_RESULT_ASSIGN(expire_at_, tokenizer_.get_token<td::int32>());
10481042
TRY_RESULT_ASSIGN(max_size_, tokenizer_.get_token<td::uint32>());
@@ -1052,8 +1046,8 @@ td::Status SignShardOverlayCertificateQuery::run() {
10521046
}
10531047

10541048
td::Status SignShardOverlayCertificateQuery::send() {
1055-
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_signShardOverlayCertificate>
1056-
(wc_, shard_, ton::create_tl_object<ton::ton_api::engine_validator_keyHash>(key_.tl()), expire_at_, max_size_);
1049+
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_signShardOverlayCertificate>(
1050+
wc_, shard_, ton::create_tl_object<ton::ton_api::engine_validator_keyHash>(key_.tl()), expire_at_, max_size_);
10571051
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
10581052
return td::Status::OK();
10591053
}
@@ -1062,7 +1056,7 @@ td::Status SignShardOverlayCertificateQuery::receive(td::BufferSlice data) {
10621056
TRY_RESULT_PREFIX(c, ton::fetch_tl_object<ton::ton_api::overlay_certificate>(data.as_slice(), true),
10631057
"received incorrect cert: ");
10641058
auto w = td::write_file(out_file_, data.as_slice());
1065-
if(w.is_error()) {
1059+
if (w.is_error()) {
10661060
return w.move_as_error_prefix("Failed to write certificate to file: ");
10671061
}
10681062
td::TerminalIO::out() << "saved certificate\n";
@@ -1072,7 +1066,7 @@ td::Status SignShardOverlayCertificateQuery::receive(td::BufferSlice data) {
10721066

10731067
td::Status ImportShardOverlayCertificateQuery::run() {
10741068
TRY_RESULT_ASSIGN(wc_, tokenizer_.get_token<td::int32>());
1075-
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<td::int64>() );
1069+
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<td::int64>());
10761070
TRY_RESULT_ASSIGN(key_, tokenizer_.get_token<ton::PublicKeyHash>());
10771071
TRY_RESULT_ASSIGN(in_file_, tokenizer_.get_token<std::string>());
10781072

@@ -1083,8 +1077,8 @@ td::Status ImportShardOverlayCertificateQuery::send() {
10831077
TRY_RESULT(data, td::read_file(in_file_));
10841078
TRY_RESULT_PREFIX(cert, ton::fetch_tl_object<ton::ton_api::overlay_Certificate>(data.as_slice(), true),
10851079
"incorrect certificate");
1086-
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_importShardOverlayCertificate>
1087-
(wc_, shard_, ton::create_tl_object<ton::ton_api::engine_validator_keyHash>(key_.tl()), std::move(cert));
1080+
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_importShardOverlayCertificate>(
1081+
wc_, shard_, ton::create_tl_object<ton::ton_api::engine_validator_keyHash>(key_.tl()), std::move(cert));
10881082
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
10891083
return td::Status::OK();
10901084
}
@@ -1908,3 +1902,42 @@ td::Status ImportFastSyncMemberCertificateQuery::receive(td::BufferSlice data) {
19081902
td::TerminalIO::out() << "success\n";
19091903
return td::Status::OK();
19101904
}
1905+
1906+
td::Status AddFastSyncOverlayClientQuery::run() {
1907+
TRY_RESULT_ASSIGN(adnl_id_, tokenizer_.get_token<td::Bits256>());
1908+
TRY_RESULT_ASSIGN(slot_, tokenizer_.get_token<td::int32>());
1909+
TRY_STATUS(tokenizer_.check_endl());
1910+
return td::Status::OK();
1911+
}
1912+
1913+
td::Status AddFastSyncOverlayClientQuery::send() {
1914+
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_addFastSyncClient>(adnl_id_, slot_);
1915+
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
1916+
return td::Status::OK();
1917+
}
1918+
1919+
td::Status AddFastSyncOverlayClientQuery::receive(td::BufferSlice data) {
1920+
TRY_RESULT_PREFIX(f, ton::fetch_tl_object<ton::ton_api::engine_validator_success>(data.as_slice(), true),
1921+
"received incorrect answer: ");
1922+
td::TerminalIO::out() << "success\n";
1923+
return td::Status::OK();
1924+
}
1925+
1926+
td::Status DelFastSyncOverlayClientQuery::run() {
1927+
TRY_RESULT_ASSIGN(adnl_id_, tokenizer_.get_token<td::Bits256>());
1928+
TRY_STATUS(tokenizer_.check_endl());
1929+
return td::Status::OK();
1930+
}
1931+
1932+
td::Status DelFastSyncOverlayClientQuery::send() {
1933+
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_delFastSyncClient>(adnl_id_);
1934+
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
1935+
return td::Status::OK();
1936+
}
1937+
1938+
td::Status DelFastSyncOverlayClientQuery::receive(td::BufferSlice data) {
1939+
TRY_RESULT_PREFIX(f, ton::fetch_tl_object<ton::ton_api::engine_validator_success>(data.as_slice(), true),
1940+
"received incorrect answer: ");
1941+
td::TerminalIO::out() << "success\n";
1942+
return td::Status::OK();
1943+
}

0 commit comments

Comments
 (0)