Skip to content

Commit 7907e96

Browse files
committed
Automatic project update
1 parent 7fdbf69 commit 7907e96

File tree

8 files changed

+71
-33
lines changed

8 files changed

+71
-33
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
edition = '2018'
33
name = 'ton_node'
4-
version = '0.48.9'
4+
version = '0.48.11'
55

66
[workspace]
77
members = [ 'storage' ]

commit_hash.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
eae0344e13e3a11918b3c830db28c68b24ccc77f
1+
9eb5cd04b1b913d5c07c7b01f863d66fdb835391

common

deps_map.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"adnl":"2587e9f5b9622940de20c51ef49e8d316e168b26","overlay":"864ea30a7fee351e6225d971a4d8836e3fec74c9","rldp":"14c7858004c3c941b97523cc49c1d83f47665eee","ton-labs-abi":"a74609a928d17cd02985ced2fcaf93f50321c21e","ton-tl":"8a4777b6bc1065019a9b5c52ac2a740a48fd926c","ton-block":"447a265d0013336b3c506cad45558922aa67f9f6","ton-block-json":"0fba14f552e67b9144404503612dc159b49d7e6b","ton-executor":"979410555a2961ffb080a112f8ebb4db90e466de","ton-types":"164867fa842b1efd0eeb378e727a17677ae8a322","ton-vm":"95512b5a06fb90695bfefda4ba99f7b0bd2d35d0"}
1+
{"adnl":"2587e9f5b9622940de20c51ef49e8d316e168b26","dht":"6529fcd71524c434407aa7240a1c89b2203e7b73","overlay":"864ea30a7fee351e6225d971a4d8836e3fec74c9","rldp":"14c7858004c3c941b97523cc49c1d83f47665eee","ton-labs-abi":"a74609a928d17cd02985ced2fcaf93f50321c21e","ton-tl":"8a4777b6bc1065019a9b5c52ac2a740a48fd926c","ton-block":"447a265d0013336b3c506cad45558922aa67f9f6","ton-block-json":"0fba14f552e67b9144404503612dc159b49d7e6b","ton-executor":"979410555a2961ffb080a112f8ebb4db90e466de","ton-types":"164867fa842b1efd0eeb378e727a17677ae8a322","ton-vm":"95512b5a06fb90695bfefda4ba99f7b0bd2d35d0"}

src/internal_db/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ use ton_block::{Block, BlockIdExt, AccountIdPrefixFull, UnixTime32};
3737
use ton_types::{error, fail, Result, UInt256};
3838

3939
/// Full node state keys
40-
pub(crate) const INITIAL_MC_BLOCK: &str = "InitMcBlockId";
41-
pub(crate) const LAST_APPLIED_MC_BLOCK: &str = "LastMcBlockId";
42-
pub(crate) const PSS_KEEPER_MC_BLOCK: &str = "PssKeeperBlockId";
43-
pub(crate) const SHARD_CLIENT_MC_BLOCK: &str = "ShardsClientMcBlockId";
40+
pub const INITIAL_MC_BLOCK: &str = "InitMcBlockId";
41+
pub const LAST_APPLIED_MC_BLOCK: &str = "LastMcBlockId";
42+
pub const PSS_KEEPER_MC_BLOCK: &str = "PssKeeperBlockId";
43+
pub const SHARD_CLIENT_MC_BLOCK: &str = "ShardsClientMcBlockId";
4444

4545
/// Validator state keys
4646
pub(crate) const LAST_ROTATION_MC_BLOCK: &str = "LastRotationBlockId";

src/validator/collator_sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ impl Collator {
837837
mc_data.mc_state_extra().shards(),
838838
mc_data.config(),
839839
now,
840-
false,
840+
self.collator_settings.is_fake
841841
)?;
842842

843843
self.check_utime(&mc_data, &prev_data, &mut collator_data)?;

src/validator/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ pub struct CollatorSettings {
5050
pub want_split: Option<bool>,
5151
pub want_merge: Option<bool>,
5252
pub max_collate_threads: Option<usize>,
53+
pub is_fake: bool,
54+
}
55+
56+
impl CollatorSettings {
57+
#[allow(dead_code)]
58+
pub fn fake() -> Self {
59+
Self {
60+
is_fake: true,
61+
..Self::default()
62+
}
63+
}
5364
}
5465

5566
pub struct McData {

storage/src/shardstate_db.rs

+51-24
Original file line numberDiff line numberDiff line change
@@ -27,42 +27,42 @@ use crate::db::rocksdb::RocksDb;
2727
use std::{
2828
io::{Cursor, Read, Write}, ops::Deref,
2929
sync::{Arc, atomic::{AtomicU8, AtomicU32, Ordering}},
30-
time::{Duration, Instant, SystemTime, UNIX_EPOCH}
30+
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
3131
};
3232
use ton_block::BlockIdExt;
3333
use ton_types::{ByteOrderRead, Cell, Result, fail};
3434

3535
pub(crate) struct DbEntry {
3636
pub cell_id: CellId, // TODO: remove this id
37-
pub block_id_ext: BlockIdExt,
37+
pub block_id: BlockIdExt,
3838
pub db_index: u32,
39-
pub saved_at: u64,
39+
pub save_utime: u64,
4040
}
4141

4242
impl DbEntry {
43-
pub fn with_params(cell_id: CellId, block_id_ext: BlockIdExt, db_index: u32, saved_at: u64) -> Self {
44-
Self { cell_id, block_id_ext, db_index, saved_at }
43+
pub fn with_params(cell_id: CellId, block_id: BlockIdExt, db_index: u32, save_utime: u64) -> Self {
44+
Self { cell_id, block_id, db_index, save_utime }
4545
}
4646
}
4747

4848
impl Serializable for DbEntry {
4949
fn serialize<T: Write>(&self, writer: &mut T) -> Result<()> {
5050
writer.write_all(self.cell_id.key())?;
51-
self.block_id_ext.serialize(writer)?;
51+
self.block_id.serialize(writer)?;
5252
writer.write_all(&self.db_index.to_le_bytes())?;
53-
writer.write_all(&self.saved_at.to_le_bytes())?;
53+
writer.write_all(&self.save_utime.to_le_bytes())?;
5454
Ok(())
5555
}
5656

5757
fn deserialize<T: Read>(reader: &mut T) -> Result<Self> {
5858
let mut buf = [0; 32];
5959
reader.read_exact(&mut buf)?;
6060
let cell_id = CellId::new(buf.into());
61-
let block_id_ext = BlockIdExt::deserialize(reader)?;
61+
let block_id = BlockIdExt::deserialize(reader)?;
6262
let db_index = reader.read_le_u32().unwrap_or(0); // use 0 db by default
63-
let saved_at = reader.read_le_u64().unwrap_or(0);
63+
let save_utime = reader.read_le_u64().unwrap_or(0);
6464

65-
Ok(Self { cell_id, block_id_ext, db_index, saved_at })
65+
Ok(Self { cell_id, block_id, db_index, save_utime })
6666
}
6767
}
6868

@@ -76,6 +76,8 @@ pub struct ShardStateDb {
7676
stop: AtomicU8
7777
}
7878

79+
const SHARDSTATES_GC_LAG_SEC: u64 = 300;
80+
7981
impl ShardStateDb {
8082

8183
const MASK_GC_STARTED: u8 = 0x01;
@@ -305,8 +307,8 @@ impl ShardStateDb {
305307

306308
let c = boc_db.save_as_dynamic_boc(state_root.deref())?;
307309

308-
let saved_at = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
309-
let db_entry = DbEntry::with_params(cell_id.clone(), id.clone(), boc_db.db_index(), saved_at);
310+
let save_utime = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
311+
let db_entry = DbEntry::with_params(cell_id.clone(), id.clone(), boc_db.db_index(), save_utime);
310312
let mut buf = Vec::new();
311313
db_entry.serialize(&mut Cursor::new(&mut buf))?;
312314

@@ -341,7 +343,7 @@ impl ShardStateDb {
341343
}
342344

343345
pub trait AllowStateGcResolver: Send + Sync {
344-
fn allow_state_gc(&self, block_id: &BlockIdExt, saved_at: u64, gc_utime: u64) -> Result<bool>;
346+
fn allow_state_gc(&self, block_id: &BlockIdExt, save_utime: u64, gc_utime: u64) -> Result<bool>;
345347
}
346348

347349
#[derive(Default)]
@@ -416,26 +418,51 @@ fn mark(
416418
gc_resolver: &dyn AllowStateGcResolver,
417419
gc_time: u64
418420
) -> MarkResult {
419-
let mut to_mark = Vec::new();
420-
let mut to_sweep = Vec::new();
421+
// We should leave last states in DB to avoid full state saving when DB will active.
422+
// 1) enumerate all roots with their save-time
423+
// 2) remember max time and max masterchain root
424+
// 3) do not sweep last masterchain root and shardchains roots
425+
// for last SHARDSTATES_GC_LAG_SEC seconds
426+
427+
let mut last_mc_seqno = 0;
428+
let mut roots = Vec::new();
429+
let mut max_shard_utime = 0;
430+
421431
shardstate_db.for_each(&mut |_key, value| {
422432
let db_entry = DbEntry::from_slice(value)?;
423-
let cell_id = db_entry.cell_id;
424-
let block_id_ext = db_entry.block_id_ext;
425433
if db_entry.db_index == dynamic_boc_db.db_index() {
426-
if gc_resolver.allow_state_gc(&block_id_ext, db_entry.saved_at, gc_time)? {
427-
log::trace!(target: TARGET, "mark to_sweep block_id {} cell_id {} db_index {} ",
428-
block_id_ext, cell_id, dynamic_boc_db.db_index());
429-
to_sweep.push((block_id_ext, cell_id));
434+
if db_entry.block_id.shard().is_masterchain() {
435+
if db_entry.block_id.seq_no() > last_mc_seqno {
436+
last_mc_seqno = db_entry.block_id.seq_no();
437+
}
430438
} else {
431-
log::trace!(target: TARGET, "mark to_mark block_id {} cell_id {} db_index {} ",
432-
block_id_ext, cell_id, dynamic_boc_db.db_index());
433-
to_mark.push(cell_id);
439+
if db_entry.save_utime > max_shard_utime{
440+
max_shard_utime = db_entry.save_utime;
441+
}
434442
}
443+
roots.push(db_entry);
435444
}
436445
Ok(true)
437446
})?;
438447

448+
let mut to_mark = Vec::new();
449+
let mut to_sweep = Vec::new();
450+
for root in roots {
451+
let is_mc = root.block_id.shard().is_masterchain();
452+
if gc_resolver.allow_state_gc(&root.block_id, root.save_utime, gc_time)?
453+
&& (!is_mc || root.block_id.seq_no() < last_mc_seqno)
454+
&& (is_mc || root.save_utime + SHARDSTATES_GC_LAG_SEC < max_shard_utime)
455+
{
456+
log::trace!(target: TARGET, "mark to_sweep block_id {} cell_id {} db_index {} utime {}",
457+
root.block_id, root.cell_id, dynamic_boc_db.db_index(), root.save_utime);
458+
to_sweep.push((root.block_id, root.cell_id));
459+
} else {
460+
log::trace!(target: TARGET, "mark to_mark block_id {} cell_id {} db_index {} utime {}",
461+
root.block_id, root.cell_id, dynamic_boc_db.db_index(), root.save_utime);
462+
to_mark.push(root.cell_id);
463+
}
464+
}
465+
439466
let marked_roots = to_mark.len();
440467
let mut marked = FnvHashSet::default();
441468
if !to_sweep.is_empty() {

0 commit comments

Comments
 (0)