Skip to content

Commit 298db54

Browse files
committed
New account size limit for masterchain
1 parent 07f2565 commit 298db54

File tree

7 files changed

+21
-13
lines changed

7 files changed

+21
-13
lines changed

crypto/block/block.tlb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ _ MisbehaviourPunishmentConfig = ConfigParam 40;
796796
size_limits_config#01 max_msg_bits:uint32 max_msg_cells:uint32 max_library_cells:uint32 max_vm_data_depth:uint16
797797
max_ext_msg_size:uint32 max_ext_msg_depth:uint16 = SizeLimitsConfig;
798798
size_limits_config_v2#02 max_msg_bits:uint32 max_msg_cells:uint32 max_library_cells:uint32 max_vm_data_depth:uint16
799-
max_ext_msg_size:uint32 max_ext_msg_depth:uint16 max_acc_state_cells:uint32 max_acc_state_bits:uint32
799+
max_ext_msg_size:uint32 max_ext_msg_depth:uint16 max_acc_state_cells:uint32 max_mc_acc_state_cells:uint32
800800
max_acc_public_libraries:uint32 defer_out_queue_size_limit:uint32 max_msg_extra_currencies:uint32
801801
max_acc_fixed_prefix_length:uint8 acc_state_cells_for_storage_dict:uint32 = SizeLimitsConfig;
802802
_ SizeLimitsConfig = ConfigParam 43;

crypto/block/mc-config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2040,8 +2040,8 @@ td::Result<SizeLimitsConfig> Config::do_get_size_limits_config(td::Ref<vm::CellS
20402040

20412041
auto unpack_v2 = [&](auto& rec) {
20422042
unpack_v1(rec);
2043-
limits.max_acc_state_bits = rec.max_acc_state_bits;
20442043
limits.max_acc_state_cells = rec.max_acc_state_cells;
2044+
limits.max_mc_acc_state_cells = rec.max_mc_acc_state_cells;
20452045
limits.max_acc_public_libraries = rec.max_acc_public_libraries;
20462046
limits.defer_out_queue_size_limit = rec.defer_out_queue_size_limit;
20472047
limits.max_msg_extra_currencies = rec.max_msg_extra_currencies;

crypto/block/mc-config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ struct SizeLimitsConfig {
398398
td::uint16 max_vm_data_depth = 512;
399399
ExtMsgLimits ext_msg_limits;
400400
td::uint32 max_acc_state_cells = 1 << 16;
401-
td::uint32 max_acc_state_bits = (1 << 16) * 1023;
401+
td::uint32 max_mc_acc_state_cells = 1 << 11; // enabled in global version 12
402402
td::uint32 max_acc_public_libraries = 256;
403403
td::uint32 defer_out_queue_size_limit = 256;
404404
td::uint32 max_msg_extra_currencies = 2;

crypto/block/transaction.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@ bool Transaction::unpack_msg_state(const ComputePhaseConfig& cfg, bool lib_only,
16401640
if (forbid_public_libs) {
16411641
size_limits.max_acc_public_libraries = 0;
16421642
}
1643-
auto S = check_state_limits(size_limits, false);
1643+
auto S = check_state_limits(size_limits, cfg.global_version, false);
16441644
if (S.is_error()) {
16451645
LOG(DEBUG) << "Cannot unpack msg state: " << S.move_as_error();
16461646
new_code = old_code;
@@ -2046,7 +2046,7 @@ bool Transaction::prepare_action_phase(const ActionPhaseConfig& cfg) {
20462046
if (account.is_special) {
20472047
return 1;
20482048
}
2049-
auto S = check_state_limits(cfg.size_limits);
2049+
auto S = check_state_limits(cfg.size_limits, cfg.global_version);
20502050
if (S.is_error()) {
20512051
if (S.code() != AccountStorageStat::errorcode_limits_exceeded) {
20522052
LOG(ERROR) << "Account storage stat error: " << S.move_as_error();
@@ -3175,14 +3175,16 @@ static td::uint32 get_public_libraries_diff_count(const td::Ref<vm::Cell>& old_l
31753175
* This function is not called for special accounts.
31763176
*
31773177
* @param size_limits The size limits configuration.
3178+
* @param global_version Global version (ConfigParam 8).
31783179
* @param is_account_stat Store storage stat in the Transaction's AccountStorageStat.
31793180
*
31803181
* @returns A `td::Status` indicating the result of the check.
31813182
* - If the state limits are within the allowed range, returns OK.
31823183
* - If the state limits exceed the maximum allowed range, returns an error with AccountStorageStat::errorcode_limits_exceeded code.
31833184
* - If an error occurred during storage stat calculation, returns other error.
31843185
*/
3185-
td::Status Transaction::check_state_limits(const SizeLimitsConfig& size_limits, bool is_account_stat) {
3186+
td::Status Transaction::check_state_limits(const SizeLimitsConfig& size_limits, int global_version,
3187+
bool is_account_stat) {
31863188
auto cell_equal = [](const td::Ref<vm::Cell>& a, const td::Ref<vm::Cell>& b) -> bool {
31873189
return a.is_null() || b.is_null() ? a.is_null() == b.is_null() : a->get_hash() == b->get_hash();
31883190
};
@@ -3213,13 +3215,12 @@ td::Status Transaction::check_state_limits(const SizeLimitsConfig& size_limits,
32133215
}
32143216
}
32153217

3216-
if (storage_stat.get_total_cells() > size_limits.max_acc_state_cells ||
3217-
storage_stat.get_total_bits() > size_limits.max_acc_state_bits) {
3218+
td::uint32 max_cells = account.is_masterchain() && global_version >= 12 ? size_limits.max_mc_acc_state_cells
3219+
: size_limits.max_acc_state_cells;
3220+
if (storage_stat.get_total_cells() > max_cells) {
32183221
return td::Status::Error(AccountStorageStat::errorcode_limits_exceeded,
32193222
PSTRING() << "account state is too big: cells=" << storage_stat.get_total_cells()
3220-
<< ", bits=" << storage_stat.get_total_bits()
3221-
<< " (max cells=" << size_limits.max_acc_state_cells
3222-
<< ", max bits=" << size_limits.max_acc_state_bits << ")");
3223+
<< " (max cells=" << max_cells << ")");
32233224
}
32243225
if (account.is_masterchain() && !cell_equal(account.library, new_library)) {
32253226
auto libraries_count = get_public_libraries_count(new_library);
@@ -4178,6 +4179,7 @@ td::Status FetchConfigParams::fetch_config_params(
41784179
action_phase_cfg->extra_currency_v2 = config.get_global_version() >= 10;
41794180
action_phase_cfg->disable_anycast = config.get_global_version() >= 10;
41804181
action_phase_cfg->disable_ihr_flag = config.get_global_version() >= 11;
4182+
action_phase_cfg->global_version = config.get_global_version();
41814183
}
41824184
{
41834185
serialize_cfg->extra_currency_v2 = config.get_global_version() >= 10;

crypto/block/transaction.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ struct ActionPhaseConfig {
177177
bool disable_ihr_flag{false};
178178
td::optional<td::Bits256> mc_blackhole_addr;
179179
bool disable_anycast{false};
180+
int global_version = 0;
180181
const MsgPrices& fetch_msg_prices(bool is_masterchain) const {
181182
return is_masterchain ? fwd_mc : fwd_std;
182183
}
@@ -413,7 +414,7 @@ struct Transaction {
413414
bool run_precompiled_contract(const ComputePhaseConfig& cfg, precompiled::PrecompiledSmartContract& precompiled);
414415
bool prepare_compute_phase(const ComputePhaseConfig& cfg);
415416
bool prepare_action_phase(const ActionPhaseConfig& cfg);
416-
td::Status check_state_limits(const SizeLimitsConfig& size_limits, bool is_account_stat = true);
417+
td::Status check_state_limits(const SizeLimitsConfig& size_limits, int global_version, bool is_account_stat = true);
417418
bool prepare_bounce_phase(const ActionPhaseConfig& cfg);
418419
bool compute_state(const SerializeConfig& cfg);
419420
bool serialize(const SerializeConfig& cfg);

doc/GlobalVersions.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,8 @@ This is required to help computing storage stats in the future, after collator-v
236236
- `HASHBU` (`b - hash`) - same as `ENDC HASHCU`, but without gas cost for cell creation. Gas cost: `26`.
237237

238238
### Other TVM changes
239-
- `HASHSU` (`s - hash`) now does not spend gas for cell creation. Gas cost: `26`.
239+
- `HASHSU` (`s - hash`) now does not spend gas for cell creation. Gas cost: `26`.
240+
241+
### Other changes
242+
- Account size in masterchain is now limited to `2048` cells. This can be configured in size limits config (`ConfigParam 43`).
243+
- The previous limit was the same as in basechain (`65536`).

validator/impl/validate-query.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,7 @@ bool ValidateQuery::fetch_config_params() {
10741074
action_phase_cfg_.extra_currency_v2 = config_->get_global_version() >= 10;
10751075
action_phase_cfg_.disable_anycast = config_->get_global_version() >= 10;
10761076
action_phase_cfg_.disable_ihr_flag = config_->get_global_version() >= 11;
1077+
action_phase_cfg_.global_version = config_->get_global_version();
10771078
}
10781079
{
10791080
serialize_cfg_.extra_currency_v2 = config_->get_global_version() >= 10;

0 commit comments

Comments
 (0)