Skip to content

Commit 994fc31

Browse files
authored
Merge pull request #18 from tonlabs/0.26.1-rc
Version 0.26.1
2 parents ff89403 + fc41973 commit 994fc31

File tree

4 files changed

+35
-70
lines changed

4 files changed

+35
-70
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Release Notes
22
All notable changes to this project will be documented in this file.
33

4+
## 0.26.1 Apr 14, 2021
5+
### Fixed
6+
- Transaction could be lost if it was created near the end of block producing interval.
7+
48
## 0.26.0 Apr 08, 2021
59
### Fixed
610
- External inbound messages now have `created_at` field filled.

ton-node-se/ton_node/src/node_engine/block_builder.rs

Lines changed: 27 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use parking_lot::{Mutex, Condvar};
22
use std::mem;
33
use std::sync::{Arc};
4-
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
54
use std::sync::mpsc::{ channel, Sender, Receiver };
65
use std::thread;
76
use std::time::{Duration, Instant};
@@ -36,7 +35,6 @@ enum BuilderIn {
3635
AppendSerialized {
3736
value: AppendSerializedContext,
3837
},
39-
Close,
4038
}
4139

4240
///
@@ -46,13 +44,11 @@ struct BlockData {
4644
block_info: BlockInfo,
4745
block_extra: BlockExtra,
4846
value_flow: ValueFlow,
49-
stopped: bool,
5047
//log_time_gen: LogicalTimeGenerator,
5148
end_lt: u64, // biggest logical time of all messages
5249
p1: Duration,
5350
p2: Duration,
5451
p3: Duration,
55-
counter: AtomicUsize
5652
}
5753

5854
impl BlockData {
@@ -73,10 +69,9 @@ impl BlockData {
7369
/// BlockBuilder structure
7470
///
7571
pub struct BlockBuilder {
76-
sender: Option<Arc<Mutex<Sender<BuilderIn>>>>,
72+
sender: Mutex<Option<Sender<BuilderIn>>>,
7773
current_block_data: Arc<Mutex<BlockData>>,
7874
stop_event: Arc<Condvar>,
79-
stopped: AtomicBool,
8075
block_gen_utime: UnixTime32,
8176
start_lt: u64,
8277
}
@@ -139,20 +134,15 @@ impl BlockBuilder {
139134
block_info: block_info,
140135
block_extra: BlockExtra::default(),
141136
value_flow: ValueFlow::default(),
142-
stopped: false,
143137
end_lt: 0,
144138
p1: Duration::new(0, 0),
145139
p2: Duration::new(0, 0),
146140
p3: Duration::new(0, 0),
147-
counter: AtomicUsize::new(0)
148141
}));
149142

150-
let sender = Arc::new(Sender::clone(&sender));
151-
152143
let block = BlockBuilder {
153-
sender: Some(Arc::new(Mutex::new(Sender::clone(&sender)))),
144+
sender: Mutex::new(Some(sender)),
154145
stop_event: stop_event.clone(),
155-
stopped: AtomicBool::new(false),
156146
current_block_data: current_block_data.clone(),
157147
block_gen_utime,
158148
start_lt,
@@ -176,17 +166,8 @@ impl BlockBuilder {
176166
for msg in receiver {
177167
let now = Instant::now();
178168
match msg {
179-
BuilderIn::Close => {
180-
let mut block_data = current_block_data.lock();
181-
// set end logical time - logical time of last message of last transaction
182-
let end_lt = block_data.end_lt;
183-
block_data.block_info.set_end_lt(end_lt);
184-
block_data.stopped = true;
185-
break;
186-
},
187169
BuilderIn::Append{ in_msg, out_msgs } => {
188170
let mut block_data = current_block_data.lock();
189-
block_data.counter.fetch_sub(1, Ordering::SeqCst);
190171
if let Err(err) = Self::append_messages(&mut block_data, &in_msg, out_msgs) {
191172
log::error!("error append messages {}", err);
192173
}
@@ -203,6 +184,11 @@ impl BlockBuilder {
203184
let d = n.elapsed();
204185
current_block_data.lock().p3 = d;
205186

187+
let mut block_data = current_block_data.lock();
188+
// set end logical time - logical time of last message of last transaction
189+
let end_lt = block_data.end_lt;
190+
block_data.block_info.set_end_lt(end_lt);
191+
206192
stop_event.notify_one();
207193
}
208194

@@ -290,8 +276,6 @@ impl BlockBuilder {
290276
account_blocks.add_serialized_transaction(&value.transaction, &value.transaction_cell)?;
291277
block_data.block_extra.write_account_blocks(&account_blocks)?;
292278

293-
block_data.counter.fetch_sub(1, Ordering::SeqCst);
294-
295279
// calculate ValueFlow
296280
// imported increase to in-value
297281
if let Some(in_value) = value.imported_value {
@@ -331,43 +315,30 @@ impl BlockBuilder {
331315
/// Add transaction to block
332316
///
333317
pub fn add_transaction(&self, in_msg: Arc<InMsg>, out_msgs: Vec<OutMsg>) -> bool {
334-
if !self.stopped.load(Ordering::SeqCst) {
335-
if let Some(sender) = &self.sender {
336-
self.current_block_data.lock().counter.fetch_add(1, Ordering::SeqCst);
337-
if sender.lock().send(BuilderIn::Append{ in_msg, out_msgs }).is_err() {
338-
return false
339-
}
340-
}
341-
return true
318+
if let Some(sender) = self.sender.lock().as_ref() {
319+
sender.send(BuilderIn::Append{ in_msg, out_msgs }).is_ok()
320+
} else {
321+
false
342322
}
343-
false
344323
}
345324

346325
///
347326
/// Add serialized transaction to block
348327
///
349328
pub fn add_serialized_transaction(&self, value: AppendSerializedContext ) -> bool {
350-
if !self.stopped.load(Ordering::SeqCst) {
351-
if let Some(sender) = &self.sender {
352-
self.current_block_data.lock().counter.fetch_add(1, Ordering::SeqCst);
353-
if sender.lock().send(BuilderIn::AppendSerialized{ value }).is_err() {
354-
return false
355-
}
356-
}
357-
return true
329+
if let Some(sender) = self.sender.lock().as_ref() {
330+
sender.send(BuilderIn::AppendSerialized{ value }).is_ok()
331+
} else {
332+
false
358333
}
359-
false
360334
}
361335

362336
///
363337
/// Stop processing messages thread.
364338
///
365339
fn brake_block_builder_thread(&self) {
366-
if let Some(sender) = &self.sender {
367-
if sender.lock().send(BuilderIn::Close).is_err() {
368-
error!(target: "node", "try to break builder, but it is already broken");
369-
}
370-
}
340+
let mut sender = self.sender.lock();
341+
*sender = None;
371342
}
372343

373344
///
@@ -400,24 +371,16 @@ impl BlockBuilder {
400371
new_shard_state: &ShardStateUnsplit
401372
) -> Result<(Block, usize)> {
402373

403-
let mut time = [0u128; 6];
404-
let now = Instant::now();
374+
let mut time = [0u128; 3];
375+
let now = Instant::now();
376+
377+
let mut block_data = self.current_block_data.lock();
405378

406-
self.stopped.store(true, Ordering::SeqCst);
407379
self.brake_block_builder_thread();
408-
self.stopped.store(true, Ordering::Relaxed);
380+
self.stop_event.wait(&mut block_data);
409381

410382
time[0] = now.elapsed().as_micros();
411-
let now = Instant::now();
412-
413-
let mut block_data = self.current_block_data.lock();
414-
time[5] = block_data.counter.load(Ordering::SeqCst) as u128;
415-
while !block_data.stopped {
416-
self.stop_event.wait(&mut block_data);
417-
}
418-
419-
time[1] = now.elapsed().as_micros();
420-
let now = Instant::now();
383+
let now = Instant::now();
421384

422385
// merkle updates for account_blocks calculating
423386
let mut account_blocks = vec![];
@@ -460,7 +423,7 @@ info!(target: "ton_block", "want to remove shard state {}", str2);
460423
&old_ss_root,
461424
&new_ss_root)?;
462425

463-
time[2] = now.elapsed().as_micros();
426+
time[1] = now.elapsed().as_micros();
464427
let now = Instant::now();
465428

466429
let block = Block::with_params(
@@ -471,15 +434,11 @@ let now = Instant::now();
471434
mem::take(&mut block_data.block_extra),
472435
)?;
473436

474-
time[3] = now.elapsed().as_micros();
475-
let now = Instant::now();
476-
477-
// Let's calc blocks's id and save it in struct while block is accesed as mutable
437+
time[2] = now.elapsed().as_micros();
478438

479-
time[4] = now.elapsed().as_micros();
480439
info!(target: "profiler",
481-
"Block builder time: {} / {} / {} / {} / {} / {}",
482-
time[0], time[1], time[2], time[3], time[4], time[5]
440+
"Block builder time: {} / {} / {}",
441+
time[0], time[1], time[2]
483442
);
484443
info!(target: "profiler",
485444
"Block builder thread time: {} / {} / {}",

ton-node-se/ton_node/src/node_engine/blocks_finality.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,9 @@ pub(crate) fn generate_block_with_seq_no(shard_ident: ShardIdent, seq_no: u32, p
900900

901901
let inmsg = Arc::new(if rng.gen() { inmsg_int} else { inmsg_ex });
902902
// builder can stop earler than writing threads it is not a problem here
903-
builder_clone.add_transaction(inmsg, vec![out_msg1, out_msg2]);
903+
if !builder_clone.add_transaction(inmsg, vec![out_msg1, out_msg2]) {
904+
break;
905+
}
904906

905907
thread::sleep(Duration::from_millis(1)); // emulate timeout working TVM
906908
}

ton-node-se/ton_node_startup/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
build = "../build/build.rs"
33
name = "ton_node_startup"
4-
version = "0.26.0"
4+
version = "0.26.1"
55

66
[dependencies]
77
clap = "2.32.0"

0 commit comments

Comments
 (0)