@@ -277,16 +277,36 @@ void StateDb::add_persistent_state_description(td::Ref<PersistentStateDescriptio
277277 }
278278 list->list_ .resize (new_size);
279279
280- std::vector<tl_object_ptr<ton_api::tonNode_blockIdExt>> shard_blocks;
281- for (const BlockIdExt& block_id : desc->shard_blocks ) {
282- shard_blocks.push_back (create_tl_block_id (block_id));
280+ bool can_be_stored_as_v1 = true ;
281+ for (auto const & [block_id, split_depth] : desc->shard_blocks ) {
282+ if (split_depth != 0 ) {
283+ can_be_stored_as_v1 = false ;
284+ break ;
285+ }
283286 }
287+
288+ td::BufferSlice serialized_shards;
289+
290+ if (can_be_stored_as_v1) {
291+ std::vector<tl_object_ptr<ton_api::tonNode_blockIdExt>> shard_blocks;
292+ for (auto const & [block_id, _] : desc->shard_blocks ) {
293+ shard_blocks.push_back (create_tl_block_id (block_id));
294+ }
295+ serialized_shards =
296+ create_serialize_tl_object<ton_api::db_state_persistentStateDescriptionShards>(std::move (shard_blocks));
297+ } else {
298+ std::vector<tl_object_ptr<ton_api::db_state_persistentStateDescriptionShard>> shard_blocks;
299+ for (auto const & [block_id, split_depth] : desc->shard_blocks ) {
300+ shard_blocks.push_back (create_tl_object<ton_api::db_state_persistentStateDescriptionShard>(
301+ create_tl_block_id (block_id), static_cast <td::int32>(split_depth)));
302+ }
303+ serialized_shards =
304+ create_serialize_tl_object<ton_api::db_state_persistentStateDescriptionShardsV2>(std::move (shard_blocks));
305+ }
306+
284307 auto key =
285308 create_hash_tl_object<ton_api::db_state_key_persistentStateDescriptionShards>(desc->masterchain_id .seqno ());
286- kv_->set (key.as_slice (),
287- create_serialize_tl_object<ton_api::db_state_persistentStateDescriptionShards>(std::move (shard_blocks))
288- .as_slice ())
289- .ensure ();
309+ kv_->set (key.as_slice (), serialized_shards.as_slice ()).ensure ();
290310
291311 list->list_ .push_back (create_tl_object<ton_api::db_state_persistentStateDescriptionHeader>(
292312 create_tl_block_id (desc->masterchain_id ), desc->start_time , desc->end_time ));
@@ -325,11 +345,26 @@ void StateDb::get_persistent_state_descriptions(td::Promise<std::vector<td::Ref<
325345 if (R2.ok () == td::KeyValue::GetStatus::NotFound) {
326346 continue ;
327347 }
328- auto F2 = fetch_tl_object<ton_api::db_state_persistentStateDescriptionShards >(value, true );
348+ auto F2 = fetch_tl_object<ton_api::db_state_PersistentStateDescriptionShards >(value, true );
329349 F2.ensure ();
330- for (const auto & block_id : F2.ok ()->shard_blocks_ ) {
331- desc.shard_blocks .push_back (create_block_id (block_id));
332- }
350+ ton_api::downcast_call (*F2.ok ().get (),
351+ td::overloaded (
352+ [&](ton_api::db_state_persistentStateDescriptionShards const & shards) {
353+ for (auto const & block : shards.shard_blocks_ ) {
354+ desc.shard_blocks .push_back ({
355+ .block = create_block_id (block),
356+ .split_depth = 0 ,
357+ });
358+ }
359+ },
360+ [&](ton_api::db_state_persistentStateDescriptionShardsV2 const & shards) {
361+ for (auto const & shard_description : shards.shard_blocks_ ) {
362+ desc.shard_blocks .push_back ({
363+ .block = create_block_id (shard_description->block_ ),
364+ .split_depth = static_cast <td::uint32>(shard_description->split_depth_ ),
365+ });
366+ }
367+ }));
333368 result.push_back (td::Ref<PersistentStateDescription>(true , std::move (desc)));
334369 }
335370 promise.set_result (std::move (result));
0 commit comments