Skip to content

Commit a31e4de

Browse files
committed
feat(collator): use prev data accounts extra total count for finalize wu calculation
1 parent 643cd25 commit a31e4de

File tree

5 files changed

+30
-19
lines changed

5 files changed

+30
-19
lines changed

Cargo.lock

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ dirs = "5.0.1"
4646
ed25519 = "2.0"
4747
ed25519-dalek = "2.1"
4848
everscale-crypto = { version = "0.2", features = ["tl-proto", "serde"] }
49-
everscale-types = { version = "0.1.2", features = ["tycho"] }
49+
everscale-types = { git = "https://github.com/broxus/everscale-types.git", features = ["tycho"], branch = "feature/depth-balance-update" }
5050
exponential-backoff = "1"
5151
fdlimit = "0.3.0"
5252
futures-util = "0.3"
@@ -239,3 +239,6 @@ opt-level = 3
239239
opt-level = 3
240240
[profile.dev.package."*"]
241241
opt-level = 1
242+
243+
[patch.crates-io]
244+
everscale-types = { git = "https://github.com/broxus/everscale-types.git", features = ["tycho"], branch = "feature/depth-balance-update" }

block-util/src/dict.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ where
5555
Ok(Self {
5656
dict_root: build_aug_dict_from_sorted_iter(
5757
iter.into_iter().map(|(k, a, v)| {
58-
// SAFETY: We know that this cell is not a library cell.
59-
let value = unsafe { v.inner().as_slice_unchecked() };
58+
let value = v.inner().as_slice_allow_pruned();
6059
(k, a, value)
6160
}),
6261
K::BITS,

cli/src/cmd/tools/gen_zerostate.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,7 @@ impl ZerostateConfig {
324324

325325
accounts.set(
326326
account,
327-
DepthBalanceInfo {
328-
balance,
329-
split_depth: 0,
330-
},
327+
DepthBalanceInfo { balance, count: 1 },
331328
ShardAccount {
332329
account: account_state_cell,
333330
last_trans_hash: HashBytes::ZERO,

collator/src/collator/do_collate/finalize.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,19 +344,27 @@ impl Phase<FinalizeState> {
344344
);
345345

346346
let accounts_count = self.state.collation_data.accounts_count;
347+
let old_accounts_count = self
348+
.state
349+
.prev_shard_data
350+
.observable_accounts()
351+
.root_extra()
352+
.count as u64;
347353
let in_msgs_len = self.state.collation_data.in_msgs.len() as u64;
348354
let out_msgs_len = self.state.collation_data.out_msgs.len() as u64;
349355

350356
finalize_wu_total = Self::calc_finalize_wu_total(
357+
old_accounts_count,
351358
accounts_count,
352359
in_msgs_len,
353360
out_msgs_len,
354361
wu_params_finalize,
355362
);
356363

357364
tracing::debug!(target: tracing_targets::COLLATOR,
358-
"finalize_wu_total: {}, accounts_count: {}, in_msgs: {}, out_msgs: {} ",
365+
"finalize_wu_total: {}, old_state_accounts_count: {}, updated_accounts_count: {}, in_msgs: {}, out_msgs: {} ",
359366
finalize_wu_total,
367+
old_accounts_count,
360368
accounts_count,
361369
in_msgs_len,
362370
out_msgs_len,
@@ -640,6 +648,7 @@ impl Phase<FinalizeState> {
640648
}
641649

642650
fn calc_finalize_wu_total(
651+
old_accounts_count: u64,
643652
accounts_count: u64,
644653
in_msgs_len: u64,
645654
out_msgs_len: u64,
@@ -655,13 +664,18 @@ impl Phase<FinalizeState> {
655664
serialize_msg,
656665
state_update_min,
657666
state_update_accounts,
658-
state_update_msg,
667+
..
659668
} = wu_params_finalize;
660669

661-
let accounts_count_logarithm = accounts_count.checked_ilog2().unwrap_or_default() as u64;
670+
let delimiter = 1000;
671+
672+
let old_accounts_count_logarithm =
673+
((old_accounts_count as f64).log2() * delimiter as f64) as u64;
674+
662675
let build = accounts_count
663-
.saturating_mul(accounts_count_logarithm)
664-
.saturating_mul(build_accounts as u64);
676+
.saturating_mul(old_accounts_count_logarithm)
677+
.saturating_mul(build_accounts as u64)
678+
.saturating_div(delimiter);
665679
let build_in_msg = in_msgs_len
666680
.saturating_mul(in_msgs_len.checked_ilog2().unwrap_or_default() as u64)
667681
.saturating_mul(build_in_msg as u64);
@@ -677,9 +691,9 @@ impl Phase<FinalizeState> {
677691
let merkle_calc = std::cmp::max(
678692
state_update_min as u64,
679693
accounts_count
680-
.saturating_mul(accounts_count_logarithm)
681694
.saturating_mul(state_update_accounts as u64)
682-
.saturating_add(out_msgs_len.saturating_mul(state_update_msg as u64)),
695+
.saturating_mul(old_accounts_count_logarithm)
696+
.saturating_div(delimiter),
683697
);
684698

685699
let serialize = std::cmp::max(
@@ -948,7 +962,7 @@ impl Phase<FinalizeState> {
948962
shard_accounts.set_any(
949963
&updated_account.account_addr,
950964
&DepthBalanceInfo {
951-
split_depth: 0, // NOTE: will need to set when we implement accounts split/merge logic
965+
count: 1,
952966
balance: account.balance.clone(),
953967
},
954968
&updated_account.shard_account,

0 commit comments

Comments
 (0)