@@ -676,10 +676,25 @@ bool ParamLimits::deserialize(vm::CellSlice& cs) {
676676}
677677
678678bool BlockLimits::deserialize (vm::CellSlice& cs) {
679- return cs.fetch_ulong (8 ) == 0x5d // block_limits#5d
680- && bytes.deserialize (cs) // bytes:ParamLimits
681- && gas.deserialize (cs) // gas:ParamLimits
682- && lt_delta.deserialize (cs); // lt_delta:ParamLimits
679+ auto tag = cs.fetch_ulong (8 );
680+ if (tag != 0x5d && tag != 0x5e ) {
681+ return false ;
682+ }
683+ // block_limits#5d
684+ // block_limits_v2#5e
685+ bool ok = bytes.deserialize (cs) // bytes:ParamLimits
686+ && gas.deserialize (cs) // gas:ParamLimits
687+ && lt_delta.deserialize (cs); // lt_delta:ParamLimits
688+ if (!ok) {
689+ return false ;
690+ }
691+ if (tag == 0x5e ) {
692+ return collated_data.deserialize (cs) && // collated_data:ParamLimits
693+ imported_msg_queue.deserialize (cs); // imported_msg_queue:ImportedMsgQueueLimits
694+ } else {
695+ collated_data = bytes;
696+ return true ;
697+ }
683698}
684699
685700int ParamLimits::classify (td::uint64 value) const {
@@ -711,12 +726,19 @@ int BlockLimits::classify_lt(ton::LogicalTime lt) const {
711726 return lt_delta.classify (lt - start_lt);
712727}
713728
714- int BlockLimits::classify (td::uint64 size, td::uint64 gas, ton::LogicalTime lt) const {
715- return std::max (std::max (classify_size (size), classify_gas (gas)), classify_lt (lt));
729+ int BlockLimits::classify_collated_data_size (td::uint64 size) const {
730+ return collated_data.classify (size);
731+ }
732+
733+ int BlockLimits::classify (td::uint64 size, td::uint64 gas, ton::LogicalTime lt, td::uint64 collated_size) const {
734+ return std::max (
735+ {classify_size (size), classify_gas (gas), classify_lt (lt), classify_collated_data_size (collated_size)});
716736}
717737
718- bool BlockLimits::fits (unsigned cls, td::uint64 size, td::uint64 gas_value, ton::LogicalTime lt) const {
719- return bytes.fits (cls, size) && gas.fits (cls, gas_value) && lt_delta.fits (cls, lt - start_lt);
738+ bool BlockLimits::fits (unsigned cls, td::uint64 size, td::uint64 gas_value, ton::LogicalTime lt,
739+ td::uint64 collated_size) const {
740+ return bytes.fits (cls, size) && gas.fits (cls, gas_value) && lt_delta.fits (cls, lt - start_lt) &&
741+ collated_data.fits (cls, collated_size);
720742}
721743
722744td::uint64 BlockLimitStatus::estimate_block_size (const vm::NewCellStorageStat::Stat* extra) const {
@@ -729,20 +751,30 @@ td::uint64 BlockLimitStatus::estimate_block_size(const vm::NewCellStorageStat::S
729751}
730752
731753int BlockLimitStatus::classify () const {
732- return limits.classify (estimate_block_size (), gas_used, cur_lt);
754+ return limits.classify (estimate_block_size (), gas_used, cur_lt, collated_data_size_estimate );
733755}
734756
735757bool BlockLimitStatus::fits (unsigned cls) const {
736758 return cls >= ParamLimits::limits_cnt ||
737759 (limits.gas .fits (cls, gas_used) && limits.lt_delta .fits (cls, cur_lt - limits.start_lt ) &&
738- limits.bytes .fits (cls, estimate_block_size ()));
760+ limits.bytes .fits (cls, estimate_block_size ()) && limits. collated_data . fits (cls, collated_data_size_estimate) );
739761}
740762
741763bool BlockLimitStatus::would_fit (unsigned cls, ton::LogicalTime end_lt, td::uint64 more_gas,
742764 const vm::NewCellStorageStat::Stat* extra) const {
743765 return cls >= ParamLimits::limits_cnt || (limits.gas .fits (cls, gas_used + more_gas) &&
744766 limits.lt_delta .fits (cls, std::max (cur_lt, end_lt) - limits.start_lt ) &&
745- limits.bytes .fits (cls, estimate_block_size (extra)));
767+ limits.bytes .fits (cls, estimate_block_size (extra)) &&
768+ limits.collated_data .fits (cls, collated_data_size_estimate));
769+ }
770+
771+ double BlockLimitStatus::load_fraction (unsigned cls) const {
772+ if (cls >= ParamLimits::limits_cnt) {
773+ return 0.0 ;
774+ }
775+ return std::max ({(double )estimate_block_size () / (double )limits.bytes .limit (cls),
776+ (double )gas_used / (double )limits.gas .limit (cls),
777+ (double )collated_data_size_estimate / (double )limits.collated_data .limit (cls)});
746778}
747779
748780// SETS: account_dict, shard_libraries_, mc_state_extra
0 commit comments