Skip to content

Commit 8a08bf6

Browse files
committed
Experimental flags for speeding up broadcasts
1 parent 04f2bc1 commit 8a08bf6

19 files changed

+131
-46
lines changed

catchain/catchain-receiver.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,12 @@ void CatChainReceiverImpl::start_up() {
526526
for (td::uint32 i = 0; i < get_sources_cnt(); i++) {
527527
root_keys.emplace(get_source(i)->get_hash(), OVERLAY_MAX_ALLOWED_PACKET_SIZE);
528528
}
529-
td::actor::send_closure(overlay_manager_, &overlay::Overlays::create_private_overlay,
529+
overlay::OverlayOptions overlay_options;
530+
overlay_options.broadcast_speed_multiplier_ = opts_.broadcast_speed_multiplier;
531+
td::actor::send_closure(overlay_manager_, &overlay::Overlays::create_private_overlay_ex,
530532
get_source(local_idx_)->get_adnl_id(), overlay_full_id_.clone(), std::move(ids),
531533
make_callback(), overlay::OverlayPrivacyRules{0, 0, std::move(root_keys)},
532-
R"({ "type": "catchain" })");
534+
R"({ "type": "catchain" })", std::move(overlay_options));
533535

534536
CHECK(root_block_);
535537

overlay/overlay-fec.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void OverlayOutboundFecBroadcast::alarm() {
3232
fec_type_.size(), flags_, std::move(X.data), X.id, fec_type_, date_);
3333
}
3434

35-
alarm_timestamp() = td::Timestamp::in(0.010);
35+
alarm_timestamp() = td::Timestamp::in(delay_);
3636

3737
if (seqno_ >= to_send_) {
3838
stop();
@@ -46,8 +46,9 @@ void OverlayOutboundFecBroadcast::start_up() {
4646

4747
OverlayOutboundFecBroadcast::OverlayOutboundFecBroadcast(td::BufferSlice data, td::uint32 flags,
4848
td::actor::ActorId<OverlayImpl> overlay,
49-
PublicKeyHash local_id)
49+
PublicKeyHash local_id, double speed_multiplier)
5050
: flags_(flags) {
51+
delay_ /= speed_multiplier;
5152
CHECK(data.size() <= (1 << 27));
5253
local_id_ = local_id;
5354
overlay_ = std::move(overlay);
@@ -63,9 +64,10 @@ OverlayOutboundFecBroadcast::OverlayOutboundFecBroadcast(td::BufferSlice data, t
6364
}
6465

6566
td::actor::ActorId<OverlayOutboundFecBroadcast> OverlayOutboundFecBroadcast::create(
66-
td::BufferSlice data, td::uint32 flags, td::actor::ActorId<OverlayImpl> overlay, PublicKeyHash local_id) {
67-
return td::actor::create_actor<OverlayOutboundFecBroadcast>(td::actor::ActorOptions().with_name("bcast"),
68-
std::move(data), flags, overlay, local_id)
67+
td::BufferSlice data, td::uint32 flags, td::actor::ActorId<OverlayImpl> overlay, PublicKeyHash local_id,
68+
double speed_multiplier) {
69+
return td::actor::create_actor<OverlayOutboundFecBroadcast>(
70+
td::actor::ActorOptions().with_name("bcast"), std::move(data), flags, overlay, local_id, speed_multiplier)
6971
.release();
7072
}
7173

overlay/overlay-fec.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class OverlayOutboundFecBroadcast : public td::actor::Actor {
3737
PublicKeyHash local_id_;
3838
Overlay::BroadcastDataHash data_hash_;
3939
td::uint32 flags_ = 0;
40+
double delay_ = 0.010;
4041
td::int32 date_;
4142
std::unique_ptr<td::fec::Encoder> encoder_;
4243
td::actor::ActorId<OverlayImpl> overlay_;
@@ -45,9 +46,9 @@ class OverlayOutboundFecBroadcast : public td::actor::Actor {
4546
public:
4647
static td::actor::ActorId<OverlayOutboundFecBroadcast> create(td::BufferSlice data, td::uint32 flags,
4748
td::actor::ActorId<OverlayImpl> overlay,
48-
PublicKeyHash local_id);
49+
PublicKeyHash local_id, double speed_multiplier = 1.0);
4950
OverlayOutboundFecBroadcast(td::BufferSlice data, td::uint32 flags, td::actor::ActorId<OverlayImpl> overlay,
50-
PublicKeyHash local_id);
51+
PublicKeyHash local_id, double speed_multiplier = 1.0);
5152

5253
void alarm() override;
5354
void start_up() override;

overlay/overlay.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ td::actor::ActorOwn<Overlay> Overlay::create_private(
6363
return td::actor::create_actor<OverlayImpl>(
6464
overlay_actor_name(overlay_id), keyring, adnl, manager, dht_node, local_id, std::move(overlay_id),
6565
OverlayType::FixedMemberList, std::move(nodes), std::vector<PublicKeyHash>(), OverlayMemberCertificate{},
66-
std::move(callback), std::move(rules), std::move(scope));
66+
std::move(callback), std::move(rules), std::move(scope), std::move(opts));
6767
}
6868

6969
td::actor::ActorOwn<Overlay> Overlay::create_semiprivate(
@@ -99,6 +99,7 @@ OverlayImpl::OverlayImpl(td::actor::ActorId<keyring::Keyring> keyring, td::actor
9999
overlay_id_ = id_full_.compute_short_id();
100100
frequent_dht_lookup_ = opts_.frequent_dht_lookup_;
101101
peer_list_.local_member_flags_ = opts_.local_overlay_member_flags_;
102+
opts_.broadcast_speed_multiplier_ = std::max(opts_.broadcast_speed_multiplier_, 1e-9);
102103

103104
VLOG(OVERLAY_INFO) << this << ": creating";
104105

@@ -490,7 +491,8 @@ void OverlayImpl::send_broadcast_fec(PublicKeyHash send_as, td::uint32 flags, td
490491
VLOG(OVERLAY_WARNING) << "broadcast source certificate is invalid";
491492
return;
492493
}
493-
OverlayOutboundFecBroadcast::create(std::move(data), flags, actor_id(this), send_as);
494+
OverlayOutboundFecBroadcast::create(std::move(data), flags, actor_id(this), send_as,
495+
opts_.broadcast_speed_multiplier_);
494496
}
495497

496498
void OverlayImpl::print(td::StringBuilder &sb) {

overlay/overlays.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ struct OverlayOptions {
269269
td::uint32 nodes_to_send_ = 4;
270270
td::uint32 propagate_broadcast_to_ = 5;
271271
td::uint32 default_permanent_members_flags_ = 0;
272+
double broadcast_speed_multiplier_ = 1.0;
272273
};
273274

274275
class Overlays : public td::actor::Actor {

ton/ton-types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ struct CatChainOptions {
493493
td::uint64 max_block_height_coeff = 0;
494494

495495
bool debug_disable_db = false;
496+
double broadcast_speed_multiplier = 1.0;
496497
};
497498

498499
struct ValidatorSessionConfig {

validator-engine/validator-engine.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,7 @@ td::Status ValidatorEngine::load_global_config() {
15041504
}
15051505
validator_options_.write().set_hardforks(std::move(h));
15061506
validator_options_.write().set_fast_state_serializer_enabled(fast_state_serializer_enabled_);
1507+
validator_options_.write().set_catchain_broadcast_speed_multiplier(broadcast_speed_multiplier_catchain_);
15071508

15081509
return td::Status::OK();
15091510
}
@@ -2004,9 +2005,13 @@ void ValidatorEngine::start_full_node() {
20042005
R.ensure();
20052006
td::actor::send_closure(SelfId, &ValidatorEngine::started_full_node);
20062007
});
2008+
ton::validator::fullnode::FullNodeOptions full_node_options{
2009+
.config_ = config_.full_node_config,
2010+
.public_broadcast_speed_multiplier_ = broadcast_speed_multiplier_public_,
2011+
.private_broadcast_speed_multiplier_ = broadcast_speed_multiplier_private_};
20072012
full_node_ = ton::validator::fullnode::FullNode::create(
20082013
short_id, ton::adnl::AdnlNodeIdShort{config_.full_node}, validator_options_->zero_block_id().file_hash,
2009-
config_.full_node_config, keyring_.get(), adnl_.get(), rldp_.get(), rldp2_.get(),
2014+
full_node_options, keyring_.get(), adnl_.get(), rldp_.get(), rldp2_.get(),
20102015
default_dht_node_.is_zero() ? td::actor::ActorId<ton::dht::Dht>{} : dht_nodes_[default_dht_node_].get(),
20112016
overlay_manager_.get(), validator_manager_.get(), full_node_client_.get(), db_root_, std::move(P));
20122017
for (auto &v : config_.validators) {
@@ -4562,6 +4567,42 @@ int main(int argc, char *argv[]) {
45624567
"disable persistent state serializer (similar to set-state-serializer-enabled 0 in validator console)", [&]() {
45634568
acts.push_back([&x]() { td::actor::send_closure(x, &ValidatorEngine::set_state_serializer_disabled_flag); });
45644569
});
4570+
p.add_checked_option(
4571+
'\0', "broadcast-speed-catchain",
4572+
"multiplier for broadcast speed in catchain overlays (experimental, default is 1.0, which is ~300 KB/s)",
4573+
[&](td::Slice s) -> td::Status {
4574+
auto v = td::to_double(s);
4575+
if (v <= 0.0) {
4576+
return td::Status::Error("broadcast-speed-catchain should be positive");
4577+
}
4578+
acts.push_back(
4579+
[&x, v]() { td::actor::send_closure(x, &ValidatorEngine::set_broadcast_speed_multiplier_catchain, v); });
4580+
return td::Status::OK();
4581+
});
4582+
p.add_checked_option(
4583+
'\0', "broadcast-speed-public",
4584+
"multiplier for broadcast speed in public shard overlays (experimental, default is 1.0, which is ~300 KB/s)",
4585+
[&](td::Slice s) -> td::Status {
4586+
auto v = td::to_double(s);
4587+
if (v <= 0.0) {
4588+
return td::Status::Error("broadcast-speed-public should be positive");
4589+
}
4590+
acts.push_back(
4591+
[&x, v]() { td::actor::send_closure(x, &ValidatorEngine::set_broadcast_speed_multiplier_public, v); });
4592+
return td::Status::OK();
4593+
});
4594+
p.add_checked_option(
4595+
'\0', "broadcast-speed-private",
4596+
"multiplier for broadcast speed in private block overlays (experimental, default is 1.0, which is ~300 KB/s)",
4597+
[&](td::Slice s) -> td::Status {
4598+
auto v = td::to_double(s);
4599+
if (v <= 0.0) {
4600+
return td::Status::Error("broadcast-speed-private should be positive");
4601+
}
4602+
acts.push_back(
4603+
[&x, v]() { td::actor::send_closure(x, &ValidatorEngine::set_broadcast_speed_multiplier_private, v); });
4604+
return td::Status::OK();
4605+
});
45654606
auto S = p.run(argc, argv);
45664607
if (S.is_error()) {
45674608
LOG(ERROR) << "failed to parse options: " << S.move_as_error();

validator-engine/validator-engine.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ class ValidatorEngine : public td::actor::Actor {
229229
bool not_all_shards_ = false;
230230
std::vector<ton::ShardIdFull> add_shard_cmds_;
231231
bool state_serializer_disabled_flag_ = false;
232+
double broadcast_speed_multiplier_catchain_ = 1.0;
233+
double broadcast_speed_multiplier_public_ = 1.0;
234+
double broadcast_speed_multiplier_private_ = 1.0;
232235

233236
std::set<ton::CatchainSeqno> unsafe_catchains_;
234237
std::map<ton::BlockSeqno, std::pair<ton::CatchainSeqno, td::uint32>> unsafe_catchain_rotations_;
@@ -329,6 +332,15 @@ class ValidatorEngine : public td::actor::Actor {
329332
void set_state_serializer_disabled_flag() {
330333
state_serializer_disabled_flag_ = true;
331334
}
335+
void set_broadcast_speed_multiplier_catchain(double value) {
336+
broadcast_speed_multiplier_catchain_ = value;
337+
}
338+
void set_broadcast_speed_multiplier_public(double value) {
339+
broadcast_speed_multiplier_public_ = value;
340+
}
341+
void set_broadcast_speed_multiplier_private(double value) {
342+
broadcast_speed_multiplier_private_ = value;
343+
}
332344

333345
void start_up() override;
334346
ValidatorEngine() {

validator/full-node-private-overlay.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,11 @@ void FullNodePrivateBlockOverlay::init() {
264264
overlay::OverlayPrivacyRules rules{overlay::Overlays::max_fec_broadcast_size(),
265265
overlay::CertificateFlags::AllowFec | overlay::CertificateFlags::Trusted,
266266
{}};
267-
td::actor::send_closure(overlays_, &overlay::Overlays::create_private_overlay, local_id_, overlay_id_full_.clone(),
268-
nodes_, std::make_unique<Callback>(actor_id(this)), rules, R"({ "type": "private-blocks" })");
267+
overlay::OverlayOptions overlay_options;
268+
overlay_options.broadcast_speed_multiplier_ = opts_.private_broadcast_speed_multiplier_;
269+
td::actor::send_closure(overlays_, &overlay::Overlays::create_private_overlay_ex, local_id_, overlay_id_full_.clone(),
270+
nodes_, std::make_unique<Callback>(actor_id(this)), rules, R"({ "type": "private-blocks" })",
271+
overlay_options);
269272

270273
td::actor::send_closure(rldp_, &rldp::Rldp::add_id, local_id_);
271274
td::actor::send_closure(rldp2_, &rldp2::Rldp::add_id, local_id_);
@@ -366,7 +369,7 @@ void FullNodeCustomOverlay::receive_broadcast(PublicKeyHash src, td::BufferSlice
366369
}
367370

368371
void FullNodeCustomOverlay::send_external_message(td::BufferSlice data) {
369-
if (!inited_ || config_.ext_messages_broadcast_disabled_) {
372+
if (!inited_ || opts_.config_.ext_messages_broadcast_disabled_) {
370373
return;
371374
}
372375
VLOG(FULL_NODE_DEBUG) << "Sending external message to custom overlay \"" << name_ << "\"";
@@ -472,10 +475,13 @@ void FullNodeCustomOverlay::init() {
472475
authorized_keys[sender.pubkey_hash()] = overlay::Overlays::max_fec_broadcast_size();
473476
}
474477
overlay::OverlayPrivacyRules rules{overlay::Overlays::max_fec_broadcast_size(), 0, std::move(authorized_keys)};
478+
overlay::OverlayOptions overlay_options;
479+
overlay_options.broadcast_speed_multiplier_ = opts_.private_broadcast_speed_multiplier_;
475480
td::actor::send_closure(
476-
overlays_, &overlay::Overlays::create_private_overlay, local_id_, overlay_id_full_.clone(), nodes_,
481+
overlays_, &overlay::Overlays::create_private_overlay_ex, local_id_, overlay_id_full_.clone(), nodes_,
477482
std::make_unique<Callback>(actor_id(this)), rules,
478-
PSTRING() << R"({ "type": "custom-overlay", "name": ")" << td::format::Escaped{name_} << R"(" })");
483+
PSTRING() << R"({ "type": "custom-overlay", "name": ")" << td::format::Escaped{name_} << R"(" })",
484+
overlay_options);
479485

480486
td::actor::send_closure(rldp_, &rldp::Rldp::add_id, local_id_);
481487
td::actor::send_closure(rldp2_, &rldp2::Rldp::add_id, local_id_);

validator/full-node-private-overlay.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ class FullNodePrivateBlockOverlay : public td::actor::Actor {
5050
void collect_validator_telemetry(std::string filename);
5151

5252
void set_config(FullNodeConfig config) {
53-
config_ = std::move(config);
53+
opts_.config_ = std::move(config);
5454
}
5555

5656
void start_up() override;
5757
void tear_down() override;
5858

5959
FullNodePrivateBlockOverlay(adnl::AdnlNodeIdShort local_id, std::vector<adnl::AdnlNodeIdShort> nodes,
60-
FileHash zero_state_file_hash, FullNodeConfig config,
60+
FileHash zero_state_file_hash, FullNodeOptions opts,
6161
td::actor::ActorId<keyring::Keyring> keyring, td::actor::ActorId<adnl::Adnl> adnl,
6262
td::actor::ActorId<rldp::Rldp> rldp, td::actor::ActorId<rldp2::Rldp> rldp2,
6363
td::actor::ActorId<overlay::Overlays> overlays,
@@ -66,7 +66,7 @@ class FullNodePrivateBlockOverlay : public td::actor::Actor {
6666
: local_id_(local_id)
6767
, nodes_(std::move(nodes))
6868
, zero_state_file_hash_(zero_state_file_hash)
69-
, config_(config)
69+
, opts_(opts)
7070
, keyring_(keyring)
7171
, adnl_(adnl)
7272
, rldp_(rldp)
@@ -80,7 +80,7 @@ class FullNodePrivateBlockOverlay : public td::actor::Actor {
8080
adnl::AdnlNodeIdShort local_id_;
8181
std::vector<adnl::AdnlNodeIdShort> nodes_;
8282
FileHash zero_state_file_hash_;
83-
FullNodeConfig config_;
83+
FullNodeOptions opts_;
8484
bool enable_compression_ = true;
8585

8686
td::actor::ActorId<keyring::Keyring> keyring_;
@@ -126,14 +126,14 @@ class FullNodeCustomOverlay : public td::actor::Actor {
126126
td::BufferSlice data);
127127

128128
void set_config(FullNodeConfig config) {
129-
config_ = std::move(config);
129+
opts_.config_ = std::move(config);
130130
}
131131

132132
void start_up() override;
133133
void tear_down() override;
134134

135135
FullNodeCustomOverlay(adnl::AdnlNodeIdShort local_id, CustomOverlayParams params, FileHash zero_state_file_hash,
136-
FullNodeConfig config, td::actor::ActorId<keyring::Keyring> keyring,
136+
FullNodeOptions opts, td::actor::ActorId<keyring::Keyring> keyring,
137137
td::actor::ActorId<adnl::Adnl> adnl, td::actor::ActorId<rldp::Rldp> rldp,
138138
td::actor::ActorId<rldp2::Rldp> rldp2, td::actor::ActorId<overlay::Overlays> overlays,
139139
td::actor::ActorId<ValidatorManagerInterface> validator_manager,
@@ -144,7 +144,7 @@ class FullNodeCustomOverlay : public td::actor::Actor {
144144
, msg_senders_(std::move(params.msg_senders_))
145145
, block_senders_(std::move(params.block_senders_))
146146
, zero_state_file_hash_(zero_state_file_hash)
147-
, config_(config)
147+
, opts_(opts)
148148
, keyring_(keyring)
149149
, adnl_(adnl)
150150
, rldp_(rldp)
@@ -161,7 +161,7 @@ class FullNodeCustomOverlay : public td::actor::Actor {
161161
std::map<adnl::AdnlNodeIdShort, int> msg_senders_;
162162
std::set<adnl::AdnlNodeIdShort> block_senders_;
163163
FileHash zero_state_file_hash_;
164-
FullNodeConfig config_;
164+
FullNodeOptions opts_;
165165

166166
td::actor::ActorId<keyring::Keyring> keyring_;
167167
td::actor::ActorId<adnl::Adnl> adnl_;

0 commit comments

Comments
 (0)