Skip to content

Commit c07bffa

Browse files
committed
Remove cells of current block data from current collated data
1 parent c26855a commit c07bffa

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

crypto/vm/boc.cpp

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,12 +1310,38 @@ ProofStorageStat::CellStatus ProofStorageStat::get_cell_status(const Cell::Hash&
13101310
return it == cells_.end() ? c_none : it->second.status;
13111311
}
13121312

1313-
std::vector<Ref<Cell>> ProofStorageStat::build_collated_data() const {
1313+
std::vector<Ref<Cell>> ProofStorageStat::build_collated_data(std::vector<Ref<Cell>> skip_roots) const {
13141314
struct Cache {
13151315
Ref<Cell> result;
13161316
bool is_root = true;
1317+
bool skip = false;
1318+
bool skip_visited = false;
13171319
};
13181320
std::map<Cell::Hash, Cache> cache;
1321+
1322+
std::function<void(const Ref<Cell>&)> dfs_skip = [&](const Ref<Cell>& cell) {
1323+
Cell::Hash hash = cell->get_hash();
1324+
Cache& entry = cache[hash];
1325+
if (entry.skip_visited) {
1326+
return;
1327+
}
1328+
entry.skip_visited = entry.skip = true;
1329+
CellSlice cs{NoVm{}, cell};
1330+
if (cs.special_type() != CellTraits::SpecialType::PrunnedBranch) {
1331+
for (unsigned i = 0; i < cell->get_level(); ++i) {
1332+
cache[cell->get_hash(i)].skip = true;
1333+
}
1334+
}
1335+
for (unsigned i = 0; i < cs.size_refs(); ++i) {
1336+
dfs_skip(cs.prefetch_ref(i));
1337+
}
1338+
};
1339+
for (const auto& cell : skip_roots) {
1340+
if (cell.not_null()) {
1341+
dfs_skip(cell);
1342+
}
1343+
}
1344+
13191345
std::function<Cache&(const CellInfo&)> dfs = [&](const CellInfo& info) -> Cache& {
13201346
Cell::Hash hash = info.cell->get_hash(info.cell_max_level);
13211347
Cache& entry = cache[hash];
@@ -1333,7 +1359,7 @@ std::vector<Ref<Cell>> ProofStorageStat::build_collated_data() const {
13331359
Ref<Cell> child = info.cell->get_ref(i);
13341360
Cell::Hash child_hash = child->get_hash(child_max_level);
13351361
auto it = cells_.find(child_hash);
1336-
if (it == cells_.end() || it->second.status != c_loaded) {
1362+
if (it == cells_.end() || it->second.status != c_loaded || cache[child_hash].skip) {
13371363
cb.store_ref(CellBuilder::create_pruned_branch(child, Cell::max_level, child_max_level));
13381364
} else {
13391365
Cache& child_result = dfs(it->second);
@@ -1345,14 +1371,14 @@ std::vector<Ref<Cell>> ProofStorageStat::build_collated_data() const {
13451371
entry2.result = cb.finalize(info.cell->is_special());
13461372
return entry2;
13471373
};
1348-
for (auto& [_, info] : cells_) {
1349-
if (info.status == c_loaded) {
1374+
for (auto& [hash, info] : cells_) {
1375+
if (info.status == c_loaded && !cache[hash].skip) {
13501376
dfs(info);
13511377
}
13521378
}
13531379
std::vector<Ref<Cell>> result;
13541380
for (auto& [_, entry] : cache) {
1355-
if (entry.is_root) {
1381+
if (entry.result.not_null() && entry.is_root) {
13561382
result.push_back(std::move(entry.result));
13571383
}
13581384
}

crypto/vm/boc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class ProofStorageStat {
177177
return get_cell_status(hash) == c_loaded;
178178
}
179179

180-
std::vector<Ref<Cell>> build_collated_data() const;
180+
std::vector<Ref<Cell>> build_collated_data(std::vector<Ref<Cell>> skip_roots = {}) const;
181181

182182
static td::uint64 estimate_prunned_size();
183183
static td::uint64 estimate_serialized_size(const Ref<DataCell>& cell);

validator/impl/collator.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6353,7 +6353,14 @@ bool Collator::create_collated_data() {
63536353
// 7. Collated data proofs
63546354
collated_roots_.push_back(
63556355
vm::CellBuilder().store_long(block::gen::CollatedDataSeparator::cons_tag[0], 32).finalize_novm());
6356-
std::vector<Ref<vm::Cell>> proofs = collated_data_stat.build_collated_data();
6356+
std::vector<Ref<vm::Cell>> block_data_parts = {
6357+
shard_account_blocks_,
6358+
in_msg_dict->get_root_cell(),
6359+
out_msg_dict->get_root_cell(),
6360+
state_update
6361+
};
6362+
std::vector<Ref<vm::Cell>> proofs =
6363+
collated_data_stat.build_collated_data(/* skip_roots = */ std::move(block_data_parts));
63576364
collated_roots_.insert(collated_roots_.end(), proofs.begin(), proofs.end());
63586365
} else {
63596366
std::map<td::Bits256, Ref<vm::Cell>> proofs;

0 commit comments

Comments
 (0)