Skip to content

Commit 5b2221a

Browse files
authored
Merge pull request #1709 from DanShaders/state-split
Support splitting persistent states
2 parents 2e0378d + 39d5519 commit 5b2221a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1220
-990
lines changed

create-hardfork/create-hardfork.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ class HardforkCreator : public td::actor::Actor {
258258
td::Promise<td::BufferSlice> promise) override {
259259
}
260260
void download_persistent_state(ton::BlockIdExt block_id, ton::BlockIdExt masterchain_block_id,
261-
td::uint32 priority, td::Timestamp timeout,
262-
td::Promise<td::BufferSlice> promise) override {
261+
ton::validator::PersistentStateType type, td::uint32 priority,
262+
td::Timestamp timeout, td::Promise<td::BufferSlice> promise) override {
263263
}
264264
void download_block_proof(ton::BlockIdExt block_id, td::uint32 priority, td::Timestamp timeout,
265265
td::Promise<td::BufferSlice> promise) override {

crypto/block/block.tlb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ workchain_v2#a7 enabled_since:uint32 monitor_min_split:(## 8)
670670
zerostate_root_hash:bits256 zerostate_file_hash:bits256
671671
version:uint32 format:(WorkchainFormat basic)
672672
split_merge_timings:WcSplitMergeTimings
673+
persistent_state_split_depth:(## 8) { persistent_state_split_depth <= 63 }
673674
= WorkchainDescr;
674675

675676
_ workchains:(HashmapE 32 WorkchainDescr) = ConfigParam 12;

crypto/block/mc-config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,6 +2199,7 @@ bool WorkchainInfo::unpack(ton::WorkchainId wc, vm::CellSlice& cs) {
21992199
split_merge_interval = rec.split_merge_interval;
22002200
min_split_merge_interval = rec.min_split_merge_interval;
22012201
max_split_merge_delay = rec.max_split_merge_delay;
2202+
persistent_state_split_depth = info.persistent_state_split_depth;
22022203
return true;
22032204
};
22042205
block::gen::WorkchainDescr::Record_workchain info_v1;

crypto/block/mc-config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ struct WorkchainInfo : public td::CntObject {
438438
unsigned min_split_merge_interval = 30; // split/merge interval must be at least 30 seconds
439439
unsigned max_split_merge_delay = 1000; // end of split/merge interval must be at most 1000 seconds in the future
440440

441+
td::uint32 persistent_state_split_depth = 0;
442+
441443
bool is_valid() const {
442444
return workchain != ton::workchainInvalid;
443445
}

crypto/vm/cells/MerkleProof.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Copyright 2017-2020 Telegram Systems LLP
1818
*/
1919
#include "vm/cells/MerkleProof.h"
20+
#include "td/utils/Status.h"
2021
#include "vm/cells/CellBuilder.h"
2122
#include "vm/cells/CellSlice.h"
2223
#include "vm/boc.h"
@@ -152,6 +153,11 @@ Ref<Cell> MerkleProof::virtualize(Ref<Cell> cell, int virtualization) {
152153
return virtualize_raw(r_raw.move_as_ok(), {0 /*level*/, static_cast<td::uint8>(virtualization)});
153154
}
154155

156+
td::Result<Ref<Cell>> MerkleProof::try_virtualize(Ref<Cell> cell, int virtualization) {
157+
TRY_RESULT(unpacked_cell, unpack_proof(std::move(cell)));
158+
return unpacked_cell->virtualize({0 /*level*/, static_cast<td::uint8>(virtualization)});
159+
}
160+
155161
class MerkleProofCombineFast {
156162
public:
157163
MerkleProofCombineFast(Ref<Cell> a, Ref<Cell> b) : a_(std::move(a)), b_(std::move(b)) {

crypto/vm/cells/MerkleProof.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class MerkleProof {
3636

3737
// cell must have zero level and must be a MerkleProof
3838
static Ref<Cell> virtualize(Ref<Cell> cell, int virtualization);
39+
static td::Result<Ref<Cell>> try_virtualize(Ref<Cell> cell, int virtualization = 1);
3940

4041
static Ref<Cell> combine(Ref<Cell> a, Ref<Cell> b);
4142
static td::Result<Ref<Cell>> combine_status(Ref<Cell> a, Ref<Cell> b);

crypto/vm/dict.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,6 +2790,12 @@ Ref<CellSlice> AugmentedDictionary::get_root() const {
27902790
return root;
27912791
}
27922792

2793+
Ref<Cell> AugmentedDictionary::get_wrapped_dict_root() const {
2794+
vm::CellBuilder cb;
2795+
cb.append_cellslice(get_root());
2796+
return cb.finalize();
2797+
}
2798+
27932799
Ref<CellSlice> AugmentedDictionary::extract_root() && {
27942800
if (!(flags & f_root_cached) && !compute_root()) {
27952801
return {};

crypto/vm/dict.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ class AugmentedDictionary final : public DictionaryFixed {
572572
AugmentedDictionary(DictNonEmpty, Ref<CellSlice> _root, int _n, const AugmentationData& _aug, bool validate = true);
573573
Ref<CellSlice> get_empty_dictionary() const;
574574
Ref<CellSlice> get_root() const;
575+
Ref<Cell> get_wrapped_dict_root() const;
575576
Ref<CellSlice> extract_root() &&;
576577
bool append_dict_to_bool(CellBuilder& cb) &&;
577578
bool append_dict_to_bool(CellBuilder& cb) const &;

test/test-ton-collator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ class TestNode : public td::actor::Actor {
359359
td::Promise<td::BufferSlice> promise) override {
360360
}
361361
void download_persistent_state(ton::BlockIdExt block_id, ton::BlockIdExt masterchain_block_id,
362-
td::uint32 priority, td::Timestamp timeout,
363-
td::Promise<td::BufferSlice> promise) override {
362+
ton::validator::PersistentStateType type, td::uint32 priority,
363+
td::Timestamp timeout, td::Promise<td::BufferSlice> promise) override {
364364
}
365365
void download_block_proof(ton::BlockIdExt block_id, td::uint32 priority, td::Timestamp timeout,
366366
td::Promise<td::BufferSlice> promise) override {

tl/generate/scheme/ton_api.tl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ tonNode.preparedProof = tonNode.PreparedProof;
409409
tonNode.preparedProofLink = tonNode.PreparedProof;
410410
tonNode.preparedState = tonNode.PreparedState;
411411
tonNode.notFoundState = tonNode.PreparedState;
412+
tonNode.persistentStateIdV2 block:tonNode.blockIdExt masterchain_block:tonNode.blockIdExt effective_shard:long = tonNode.PersistentStateIdV2;
412413
tonNode.persistentStateSize size:long = tonNode.PersistentStateSize;
414+
tonNode.persistentStateSizeNotFound = tonNode.PersistentStateSize;
413415
tonNode.prepared = tonNode.Prepared;
414416
tonNode.notFound = tonNode.Prepared;
415417
tonNode.data data:bytes = tonNode.Data;
@@ -475,15 +477,11 @@ tonNode.prepareBlockProofs blocks:(vector tonNode.blockIdExt) allow_partial:Bool
475477
tonNode.prepareKeyBlockProofs blocks:(vector tonNode.blockIdExt) allow_partial:Bool = tonNode.PreparedProof;
476478
tonNode.prepareBlock block:tonNode.blockIdExt = tonNode.Prepared;
477479
tonNode.prepareBlocks blocks:(vector tonNode.blockIdExt) = tonNode.Prepared;
478-
tonNode.preparePersistentState block:tonNode.blockIdExt masterchain_block:tonNode.blockIdExt = tonNode.PreparedState;
479-
tonNode.getPersistentStateSize block:tonNode.blockIdExt masterchain_block:tonNode.blockIdExt = tonNode.PersistentStateSize;
480480
tonNode.prepareZeroState block:tonNode.blockIdExt = tonNode.PreparedState;
481481
tonNode.getNextKeyBlockIds block:tonNode.blockIdExt max_size:int = tonNode.KeyBlocks;
482482
tonNode.downloadNextBlockFull prev_block:tonNode.blockIdExt = tonNode.DataFull;
483483
tonNode.downloadBlockFull block:tonNode.blockIdExt = tonNode.DataFull;
484484
tonNode.downloadBlock block:tonNode.blockIdExt = tonNode.Data;
485-
tonNode.downloadPersistentState block:tonNode.blockIdExt masterchain_block:tonNode.blockIdExt = tonNode.Data;
486-
tonNode.downloadPersistentStateSlice block:tonNode.blockIdExt masterchain_block:tonNode.blockIdExt offset:long max_size:long = tonNode.Data;
487485
tonNode.downloadZeroState block:tonNode.blockIdExt = tonNode.Data;
488486
tonNode.downloadBlockProof block:tonNode.blockIdExt = tonNode.Data;
489487
tonNode.downloadKeyBlockProof block:tonNode.blockIdExt = tonNode.Data;
@@ -495,6 +493,14 @@ tonNode.getArchiveSlice archive_id:long offset:long max_size:int = tonNode.Data;
495493
tonNode.getOutMsgQueueProof dst_shard:tonNode.shardId blocks:(vector tonNode.blockIdExt)
496494
limits:tonNode.importedMsgQueueLimits = tonNode.OutMsgQueueProof;
497495

496+
tonNode.downloadPersistentState block:tonNode.blockIdExt masterchain_block:tonNode.blockIdExt = tonNode.Data;
497+
tonNode.downloadPersistentStateSlice block:tonNode.blockIdExt masterchain_block:tonNode.blockIdExt offset:long max_size:long = tonNode.Data;
498+
tonNode.getPersistentStateSize block:tonNode.blockIdExt masterchain_block:tonNode.blockIdExt = tonNode.PersistentStateSize;
499+
tonNode.preparePersistentState block:tonNode.blockIdExt masterchain_block:tonNode.blockIdExt = tonNode.PreparedState;
500+
501+
tonNode.downloadPersistentStateSliceV2 state:tonNode.persistentStateIdV2 offset:long max_size:long = tonNode.Data;
502+
tonNode.getPersistentStateSizeV2 state:tonNode.persistentStateIdV2 = tonNode.PersistentStateSize;
503+
498504
tonNode.getCapabilities = tonNode.Capabilities;
499505

500506
tonNode.slave.sendExtMessage message:tonNode.externalMessage = tonNode.Success;
@@ -542,7 +548,9 @@ db.candidate.id source:PublicKey id:tonNode.blockIdExt collated_data_file_hash:i
542548
db.filedb.key.empty = db.filedb.Key;
543549
db.filedb.key.blockFile block_id:tonNode.blockIdExt = db.filedb.Key;
544550
db.filedb.key.zeroStateFile block_id:tonNode.blockIdExt = db.filedb.Key;
545-
db.filedb.key.persistentStateFile block_id:tonNode.blockIdExt masterchain_block_id:tonNode.blockIdExt = db.filedb.Key;
551+
db.filedb.key.persistentStateFile block_id:tonNode.blockIdExt masterchain_block_id:tonNode.blockIdExt = db.filedb.Key;
552+
db.filedb.key.splitAccountStateFile block_id:tonNode.blockIdExt masterchain_block_id:tonNode.blockIdExt effective_shard:long = db.filedb.Key;
553+
db.filedb.key.splitPersistentStateFile block_id:tonNode.blockIdExt masterchain_block_id:tonNode.blockIdExt = db.filedb.Key;
546554
db.filedb.key.proof block_id:tonNode.blockIdExt = db.filedb.Key;
547555
db.filedb.key.proofLink block_id:tonNode.blockIdExt = db.filedb.Key;
548556
db.filedb.key.signatures block_id:tonNode.blockIdExt = db.filedb.Key;
@@ -560,6 +568,8 @@ db.state.asyncSerializer block:tonNode.blockIdExt last:tonNode.blockIdExt last_t
560568
db.state.hardforks blocks:(vector tonNode.blockIdExt) = db.state.Hardforks;
561569
db.state.dbVersion version:int = db.state.DbVersion;
562570
db.state.persistentStateDescriptionShards shard_blocks:(vector tonNode.blockIdExt) = db.state.PersistentStateDescriptionShards;
571+
db.state.persistentStateDescriptionShard block:tonNode.blockIdExt split_depth:int = db.state.PersistentStateDescriptionShard;
572+
db.state.persistentStateDescriptionShardsV2 shard_blocks:(vector db.state.PersistentStateDescriptionShard) = db.state.PersistentStateDescriptionShards;
563573
db.state.persistentStateDescriptionHeader masterchain_id:tonNode.blockIdExt start_time:int end_time:int = db.state.PersistentStateDescriptionHeader;
564574
db.state.persistentStateDescriptionsList list:(vector db.state.persistentStateDescriptionHeader) = db.state.PersistentStateDescriptionsList;
565575

0 commit comments

Comments
 (0)