Skip to content

Commit f50aacf

Browse files
EmelyanenkoKice-charon
authored andcommitted
Fix bug of broadcast stop on receiving the last FEC piece (ton-blockchain#1040)
1 parent 1ac83a9 commit f50aacf

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

overlay/overlay-fec-broadcast.cpp

+15-9
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ td::Status OverlayFecBroadcastPart::check_signature() {
7878
}
7979

8080
td::Status OverlayFecBroadcastPart::run_checks() {
81-
8281
TRY_STATUS(check_time());
8382
TRY_STATUS(check_duplicate());
8483
TRY_STATUS(check_source());
@@ -94,14 +93,17 @@ void BroadcastFec::broadcast_checked(td::Result<td::Unit> R) {
9493
overlay_->deliver_broadcast(get_source().compute_short_id(), data_.clone());
9594
auto manager = overlay_->overlay_manager();
9695
while (!parts_.empty()) {
97-
distribute_part(parts_.begin()->first);
96+
distribute_part(parts_.begin()->first);
9897
}
98+
99+
is_checked_ = true;
99100
}
100101

101102
// Do we need status here??
102-
td::Status BroadcastFec::distribute_part(td::uint32 seqno) {
103+
td::Status BroadcastFec::distribute_part(td::uint32 seqno) {
103104
auto i = parts_.find(seqno);
104105
if (i == parts_.end()) {
106+
VLOG(OVERLAY_WARNING) << "not distibuting empty part " << seqno;
105107
// should not get here
106108
return td::Status::OK();
107109
}
@@ -132,7 +134,6 @@ td::Status BroadcastFec::distribute_part(td::uint32 seqno) {
132134
}
133135

134136
td::Status OverlayFecBroadcastPart::apply() {
135-
136137
if (!bcast_) {
137138
bcast_ = overlay_->get_fec_broadcast(broadcast_hash_);
138139
}
@@ -165,16 +166,20 @@ td::Status OverlayFecBroadcastPart::apply() {
165166
return S;
166167
}
167168
} else {
168-
if(untrusted_) {
169+
if (untrusted_) {
169170
auto P = td::PromiseCreator::lambda(
170-
[id = broadcast_hash_, overlay_id = actor_id(overlay_)](td::Result<td::Unit> RR) mutable {
171-
td::actor::send_closure(std::move(overlay_id), &OverlayImpl::broadcast_checked, id, std::move(RR));
172-
});
171+
[id = broadcast_hash_, overlay_id = actor_id(overlay_)](td::Result<td::Unit> RR) mutable {
172+
td::actor::send_closure(std::move(overlay_id), &OverlayImpl::broadcast_checked, id, std::move(RR));
173+
});
173174
overlay_->check_broadcast(bcast_->get_source().compute_short_id(), R.move_as_ok(), std::move(P));
174175
} else {
175176
overlay_->deliver_broadcast(bcast_->get_source().compute_short_id(), R.move_as_ok());
176177
}
177178
}
179+
} else {
180+
bcast_->set_overlay(overlay_);
181+
bcast_->set_src_peer_id(src_peer_id_);
182+
TRY_STATUS(bcast_->add_part(seqno_, data_.clone(), export_serialized_short(), export_serialized()));
178183
}
179184
return td::Status::OK();
180185
}
@@ -304,7 +309,8 @@ td::Status OverlayFecBroadcastPart::create_new(OverlayImpl *overlay, td::actor::
304309

305310
auto B = std::make_unique<OverlayFecBroadcastPart>(
306311
broadcast_hash, part_hash, PublicKey{}, overlay->get_certificate(local_id), data_hash, size, flags,
307-
part_data_hash, std::move(part), seqno, std::move(fec_type), date, td::BufferSlice{}, false, nullptr, overlay, adnl::AdnlNodeIdShort::zero());
312+
part_data_hash, std::move(part), seqno, std::move(fec_type), date, td::BufferSlice{}, false, nullptr, overlay,
313+
adnl::AdnlNodeIdShort::zero());
308314
auto to_sign = B->to_sign();
309315

310316
auto P = td::PromiseCreator::lambda(

overlay/overlay-fec-broadcast.hpp

+19-12
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ class BroadcastFec : public td::ListNode {
8282
}
8383
}
8484

85-
td::Status add_part(td::uint32 seqno, td::BufferSlice data,
86-
td::BufferSlice serialized_fec_part_short,
85+
td::Status add_part(td::uint32 seqno, td::BufferSlice data, td::BufferSlice serialized_fec_part_short,
8786
td::BufferSlice serialized_fec_part) {
88-
CHECK(decoder_);
89-
td::fec::Symbol s;
90-
s.id = seqno;
91-
s.data = std::move(data);
87+
if (decoder_) {
88+
td::fec::Symbol s;
89+
s.id = seqno;
90+
s.data = std::move(data);
9291

93-
decoder_->add_symbol(std::move(s));
92+
decoder_->add_symbol(std::move(s));
93+
}
9494
parts_[seqno] = std::pair<td::BufferSlice, td::BufferSlice>(std::move(serialized_fec_part_short),
9595
std::move(serialized_fec_part));
9696

@@ -200,8 +200,13 @@ class BroadcastFec : public td::ListNode {
200200

201201
td::Status distribute_part(td::uint32 seqno);
202202

203+
bool is_checked() const {
204+
return is_checked_;
205+
}
206+
203207
private:
204208
bool ready_ = false;
209+
bool is_checked_ = false;
205210

206211
Overlay::BroadcastHash hash_;
207212
Overlay::BroadcastDataHash data_hash_;
@@ -281,7 +286,7 @@ class OverlayFecBroadcastPart : public td::ListNode {
281286
, signature_(std::move(signature))
282287
, is_short_(is_short)
283288
, bcast_(bcast)
284-
, overlay_(overlay)
289+
, overlay_(overlay)
285290
, src_peer_id_(src_peer_id) {
286291
}
287292

@@ -300,7 +305,7 @@ class OverlayFecBroadcastPart : public td::ListNode {
300305
signature_ = std::move(signature);
301306
}
302307
void update_overlay(OverlayImpl *overlay);
303-
308+
304309
tl_object_ptr<ton_api::overlay_broadcastFec> export_tl();
305310
tl_object_ptr<ton_api::overlay_broadcastFecShort> export_tl_short();
306311
td::BufferSlice export_serialized();
@@ -310,14 +315,16 @@ class OverlayFecBroadcastPart : public td::ListNode {
310315
td::Status run() {
311316
TRY_STATUS(run_checks());
312317
TRY_STATUS(apply());
313-
if(!untrusted_) {
318+
if (!untrusted_ || bcast_->is_checked()) {
314319
TRY_STATUS(distribute());
315320
}
316321
return td::Status::OK();
317322
}
318323

319-
static td::Status create(OverlayImpl *overlay, adnl::AdnlNodeIdShort src_peer_id, tl_object_ptr<ton_api::overlay_broadcastFec> broadcast);
320-
static td::Status create(OverlayImpl *overlay, adnl::AdnlNodeIdShort src_peer_id, tl_object_ptr<ton_api::overlay_broadcastFecShort> broadcast);
324+
static td::Status create(OverlayImpl *overlay, adnl::AdnlNodeIdShort src_peer_id,
325+
tl_object_ptr<ton_api::overlay_broadcastFec> broadcast);
326+
static td::Status create(OverlayImpl *overlay, adnl::AdnlNodeIdShort src_peer_id,
327+
tl_object_ptr<ton_api::overlay_broadcastFecShort> broadcast);
321328
static td::Status create_new(OverlayImpl *overlay, td::actor::ActorId<OverlayImpl> overlay_actor_id,
322329
PublicKeyHash local_id, Overlay::BroadcastDataHash data_hash, td::uint32 size,
323330
td::uint32 flags, td::BufferSlice part, td::uint32 seqno, fec::FecType fec_type,

0 commit comments

Comments
 (0)