Skip to content

Commit 36285ad

Browse files
authored
Merge pull request #1765 from ton-blockchain/version-12
Version 12: new bounce, BTOS, HASHBU opcodes
2 parents 743deba + 228c489 commit 36285ad

24 files changed

+307
-124
lines changed

common/global-version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
namespace ton {
2020

2121
// See doc/GlobalVersions.md
22-
constexpr int SUPPORTED_VERSION = 11;
22+
constexpr int SUPPORTED_VERSION = 12;
2323

2424
}

crypto/block/block-parse.cpp

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ bool CommonMsgInfo::validate_skip(int* ops, vm::CellSlice& cs, bool weak) const
665665
&& t_MsgAddressInt.validate_skip(ops, cs, weak) // src
666666
&& t_MsgAddressInt.validate_skip(ops, cs, weak) // dest
667667
&& t_CurrencyCollection.validate_skip(ops, cs, weak) // value
668-
&& t_Grams.validate_skip(ops, cs, weak) // ihr_fee
668+
&& t_Grams.validate_skip(ops, cs, weak) // extra_flags
669669
&& t_Grams.validate_skip(ops, cs, weak) // fwd_fee
670670
&& cs.advance(64 + 32); // created_lt:uint64 created_at:uint32
671671
case ext_in_msg_info:
@@ -684,7 +684,7 @@ bool CommonMsgInfo::unpack(vm::CellSlice& cs, CommonMsgInfo::Record_int_msg_info
684684
return get_tag(cs) == int_msg_info && cs.advance(1) && cs.fetch_bool_to(data.ihr_disabled) &&
685685
cs.fetch_bool_to(data.bounce) && cs.fetch_bool_to(data.bounced) && t_MsgAddressInt.fetch_to(cs, data.src) &&
686686
t_MsgAddressInt.fetch_to(cs, data.dest) && t_CurrencyCollection.fetch_to(cs, data.value) &&
687-
t_Grams.fetch_to(cs, data.ihr_fee) && t_Grams.fetch_to(cs, data.fwd_fee) &&
687+
t_Grams.fetch_to(cs, data.extra_flags) && t_Grams.fetch_to(cs, data.fwd_fee) &&
688688
cs.fetch_uint_to(64, data.created_lt) && cs.fetch_uint_to(32, data.created_at);
689689
}
690690

@@ -696,7 +696,7 @@ bool CommonMsgInfo::skip(vm::CellSlice& cs) const {
696696
&& t_MsgAddressInt.skip(cs) // src
697697
&& t_MsgAddressInt.skip(cs) // dest
698698
&& t_CurrencyCollection.skip(cs) // value
699-
&& t_Grams.skip(cs) // ihr_fee
699+
&& t_Grams.skip(cs) // extra_flags
700700
&& t_Grams.skip(cs) // fwd_fee
701701
&& cs.advance(64 + 32); // created_lt:uint64 created_at:uint32
702702
case ext_in_msg_info:
@@ -718,7 +718,7 @@ bool CommonMsgInfo::get_created_lt(vm::CellSlice& cs, unsigned long long& create
718718
&& t_MsgAddressInt.skip(cs) // src
719719
&& t_MsgAddressInt.skip(cs) // dest
720720
&& t_CurrencyCollection.skip(cs) // value
721-
&& t_Grams.skip(cs) // ihr_fee
721+
&& t_Grams.skip(cs) // extra_flags
722722
&& t_Grams.skip(cs) // fwd_fee
723723
&& cs.fetch_ulong_bool(64, created_lt) // created_lt:uint64
724724
&& cs.advance(32); // created_at:uint32
@@ -1843,26 +1843,18 @@ bool InMsg::validate_skip(int* ops, vm::CellSlice& cs, bool weak) const {
18431843
return false;
18441844
}
18451845

1846-
bool InMsg::get_import_fees(vm::CellBuilder& cb, vm::CellSlice& cs) const {
1846+
static td::RefInt256 get_ihr_fee(const CommonMsgInfo::Record_int_msg_info &info, int global_version) {
1847+
// Legacy: extra_flags was previously ihr_fee
1848+
return global_version >= 12 ? td::zero_refint() : t_Grams.as_integer(std::move(info.extra_flags));
1849+
}
1850+
1851+
bool InMsg::get_import_fees(vm::CellBuilder& cb, vm::CellSlice& cs, int global_version) const {
18471852
int tag = get_tag(cs);
18481853
switch (tag) {
18491854
case msg_import_ext: // inbound external message
18501855
return t_ImportFees.null_value(cb); // external messages have no value and no import fees
18511856
case msg_import_ihr: // IHR-forwarded internal message to its final destination
1852-
if (cs.advance(3) && cs.size_refs() >= 3) {
1853-
auto msg_cs = load_cell_slice(cs.fetch_ref());
1854-
CommonMsgInfo::Record_int_msg_info msg_info;
1855-
td::RefInt256 ihr_fee;
1856-
vm::CellBuilder aux;
1857-
// sort of Prolog-style in C++
1858-
return t_Message.extract_info(msg_cs) && t_CommonMsgInfo.unpack(msg_cs, msg_info) &&
1859-
cs.fetch_ref().not_null() && (ihr_fee = t_Grams.as_integer_skip(cs)).not_null() &&
1860-
cs.fetch_ref().not_null() && !cmp(ihr_fee, t_Grams.as_integer(*msg_info.ihr_fee)) &&
1861-
cb.append_cellslice_bool(msg_info.ihr_fee) // fees_collected := ihr_fee
1862-
&& aux.append_cellslice_bool(msg_info.ihr_fee) && t_ExtraCurrencyCollection.null_value(aux) &&
1863-
t_CurrencyCollection.add_values(cb, aux.as_cellslice_ref().write(),
1864-
msg_info.value.write()); // value_imported := ihr_fee + value
1865-
}
1857+
// IHR is not implemented
18661858
return false;
18671859
case msg_import_imm: // internal message re-imported from this very block
18681860
if (cs.advance(3) && cs.size_refs() >= 2) {
@@ -1888,7 +1880,7 @@ bool InMsg::get_import_fees(vm::CellBuilder& cb, vm::CellSlice& cs) const {
18881880
return t_Message.extract_info(msg_cs) && t_CommonMsgInfo.unpack(msg_cs, msg_info) &&
18891881
cb.append_cellslice_bool(in_msg.fwd_fee_remaining) // fees_collected := fwd_fee_remaining
18901882
&& t_Grams.as_integer_skip_to(msg_info.value.write(), value_grams) &&
1891-
(ihr_fee = t_Grams.as_integer(std::move(msg_info.ihr_fee))).not_null() &&
1883+
(ihr_fee = get_ihr_fee(msg_info, global_version)).not_null() &&
18921884
t_Grams.store_integer_ref(cb, value_grams + ihr_fee + fwd_fee_remaining) &&
18931885
cb.append_cellslice_bool(
18941886
msg_info.value.write()); // value_imported = msg.value + msg.ihr_fee + fwd_fee_remaining
@@ -1911,7 +1903,7 @@ bool InMsg::get_import_fees(vm::CellBuilder& cb, vm::CellSlice& cs) const {
19111903
return t_Message.extract_info(msg_cs) && t_CommonMsgInfo.unpack(msg_cs, msg_info) &&
19121904
t_Grams.store_integer_ref(cb, std::move(transit_fee)) // fees_collected := transit_fees
19131905
&& t_Grams.as_integer_skip_to(msg_info.value.write(), value_grams) &&
1914-
(ihr_fee = t_Grams.as_integer(std::move(msg_info.ihr_fee))).not_null() &&
1906+
(ihr_fee = get_ihr_fee(msg_info, global_version)).not_null() &&
19151907
t_Grams.store_integer_ref(cb, value_grams + ihr_fee + fwd_fee_remaining) &&
19161908
cb.append_cellslice_bool(
19171909
msg_info.value.write()); // value_imported = msg.value + msg.ihr_fee + fwd_fee_remaining
@@ -1941,8 +1933,8 @@ bool InMsg::get_import_fees(vm::CellBuilder& cb, vm::CellSlice& cs) const {
19411933

19421934
const InMsg t_InMsg;
19431935

1944-
const Aug_InMsgDescr aug_InMsgDescr;
1945-
const InMsgDescr t_InMsgDescr;
1936+
const Aug_InMsgDescr aug_InMsgDescrDefault(ton::SUPPORTED_VERSION);
1937+
const InMsgDescr t_InMsgDescrDefault(ton::SUPPORTED_VERSION);
19461938

19471939
bool OutMsg::skip(vm::CellSlice& cs) const {
19481940
switch (get_tag(cs)) {
@@ -2038,7 +2030,7 @@ bool OutMsg::validate_skip(int* ops, vm::CellSlice& cs, bool weak) const {
20382030
return false;
20392031
}
20402032

2041-
bool OutMsg::get_export_value(vm::CellBuilder& cb, vm::CellSlice& cs) const {
2033+
bool OutMsg::get_export_value(vm::CellBuilder& cb, vm::CellSlice& cs, int global_version) const {
20422034
auto tag = get_tag(cs);
20432035
switch (tag) {
20442036
case msg_export_ext: // external outbound message carries no value
@@ -2071,7 +2063,7 @@ bool OutMsg::get_export_value(vm::CellBuilder& cb, vm::CellSlice& cs) const {
20712063
td::RefInt256 value_grams, ihr_fee, fwd_fee_remaining;
20722064
return t_Message.extract_info(msg_cs) && t_CommonMsgInfo.unpack(msg_cs, msg_info) &&
20732065
(value_grams = t_Grams.as_integer_skip(msg_info.value.write())).not_null() &&
2074-
(ihr_fee = t_Grams.as_integer(std::move(msg_info.ihr_fee))).not_null() &&
2066+
(ihr_fee = get_ihr_fee(msg_info, global_version)).not_null() &&
20752067
(fwd_fee_remaining = t_Grams.as_integer(out_msg.fwd_fee_remaining)).not_null() &&
20762068
t_Grams.store_integer_ref(cb, value_grams + ihr_fee + fwd_fee_remaining) &&
20772069
cb.append_cellslice_bool(std::move(msg_info.value));
@@ -2112,8 +2104,8 @@ bool OutMsg::get_emitted_lt(vm::CellSlice& cs, unsigned long long& emitted_lt) c
21122104

21132105
const OutMsg t_OutMsg;
21142106

2115-
const Aug_OutMsgDescr aug_OutMsgDescr;
2116-
const OutMsgDescr t_OutMsgDescr;
2107+
const Aug_OutMsgDescr aug_OutMsgDescrDefault(ton::SUPPORTED_VERSION);
2108+
const OutMsgDescr t_OutMsgDescrDefault(ton::SUPPORTED_VERSION);
21172109

21182110
bool EnqueuedMsg::validate_skip(int* ops, vm::CellSlice& cs, bool weak) const {
21192111
return cs.advance(64) && t_Ref_MsgEnvelope.validate_skip(ops, cs, weak);

crypto/block/block-parse.h

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ struct CommonMsgInfo final : TLB_Complex {
405405

406406
struct CommonMsgInfo::Record_int_msg_info {
407407
bool ihr_disabled, bounce, bounced;
408-
Ref<vm::CellSlice> src, dest, value, ihr_fee, fwd_fee;
408+
Ref<vm::CellSlice> src, dest, value, extra_flags, fwd_fee;
409409
unsigned long long created_lt;
410410
unsigned created_at;
411411
};
@@ -604,7 +604,7 @@ extern const Aug_ShardAccounts aug_ShardAccounts;
604604

605605
struct ShardAccounts final : TLB_Complex {
606606
HashmapAugE dict_type;
607-
ShardAccounts() : dict_type(256, aug_ShardAccounts){};
607+
ShardAccounts() : dict_type(256, aug_ShardAccounts) {};
608608
bool skip(vm::CellSlice& cs) const override {
609609
return dict_type.skip(cs);
610610
}
@@ -814,7 +814,7 @@ struct InMsg final : TLB_Complex {
814814
}
815815
return (int)cs.prefetch_ulong(5) - 0b00100 + 8;
816816
}
817-
bool get_import_fees(vm::CellBuilder& cb, vm::CellSlice& cs) const;
817+
bool get_import_fees(vm::CellBuilder& cb, vm::CellSlice& cs, int global_version) const;
818818
};
819819

820820
extern const InMsg t_InMsg;
@@ -844,7 +844,7 @@ struct OutMsg final : TLB_Complex {
844844
}
845845
return t;
846846
}
847-
bool get_export_value(vm::CellBuilder& cb, vm::CellSlice& cs) const;
847+
bool get_export_value(vm::CellBuilder& cb, vm::CellSlice& cs, int global_version) const;
848848
bool get_emitted_lt(vm::CellSlice& cs, unsigned long long& emitted_lt) const;
849849
};
850850

@@ -853,18 +853,22 @@ extern const OutMsg t_OutMsg;
853853
// next: InMsgDescr, OutMsgDescr, OutMsgQueue, and their augmentations
854854

855855
struct Aug_InMsgDescr final : AugmentationCheckData {
856-
Aug_InMsgDescr() : AugmentationCheckData(t_InMsg, t_ImportFees) {
856+
explicit Aug_InMsgDescr(int global_version)
857+
: AugmentationCheckData(t_InMsg, t_ImportFees), global_version(global_version) {
857858
}
858859
bool eval_leaf(vm::CellBuilder& cb, vm::CellSlice& cs) const override {
859-
return t_InMsg.get_import_fees(cb, cs);
860+
return t_InMsg.get_import_fees(cb, cs, global_version);
860861
}
862+
int global_version;
861863
};
862864

863-
extern const Aug_InMsgDescr aug_InMsgDescr;
865+
extern const Aug_InMsgDescr aug_InMsgDescrDefault;
864866

865867
struct InMsgDescr final : TLB_Complex {
868+
Aug_InMsgDescr aug;
866869
HashmapAugE dict_type;
867-
InMsgDescr() : dict_type(256, aug_InMsgDescr){};
870+
explicit InMsgDescr(int global_version) : aug(global_version), dict_type(256, aug) {
871+
}
868872
bool skip(vm::CellSlice& cs) const override {
869873
return dict_type.skip(cs);
870874
}
@@ -873,21 +877,25 @@ struct InMsgDescr final : TLB_Complex {
873877
}
874878
};
875879

876-
extern const InMsgDescr t_InMsgDescr;
880+
extern const InMsgDescr t_InMsgDescrDefault;
877881

878882
struct Aug_OutMsgDescr final : AugmentationCheckData {
879-
Aug_OutMsgDescr() : AugmentationCheckData(t_OutMsg, t_CurrencyCollection) {
883+
explicit Aug_OutMsgDescr(int global_version)
884+
: AugmentationCheckData(t_OutMsg, t_CurrencyCollection), global_version(global_version) {
880885
}
881886
bool eval_leaf(vm::CellBuilder& cb, vm::CellSlice& cs) const override {
882-
return t_OutMsg.get_export_value(cb, cs);
887+
return t_OutMsg.get_export_value(cb, cs, global_version);
883888
}
889+
int global_version;
884890
};
885891

886-
extern const Aug_OutMsgDescr aug_OutMsgDescr;
892+
extern const Aug_OutMsgDescr aug_OutMsgDescrDefault;
887893

888894
struct OutMsgDescr final : TLB_Complex {
895+
Aug_OutMsgDescr aug;
889896
HashmapAugE dict_type;
890-
OutMsgDescr() : dict_type(256, aug_OutMsgDescr){};
897+
explicit OutMsgDescr(int global_version) : aug(global_version), dict_type(256, aug) {
898+
}
891899
bool skip(vm::CellSlice& cs) const override {
892900
return dict_type.skip(cs);
893901
}
@@ -896,7 +904,7 @@ struct OutMsgDescr final : TLB_Complex {
896904
}
897905
};
898906

899-
extern const OutMsgDescr t_OutMsgDescr;
907+
extern const OutMsgDescr t_OutMsgDescrDefault;
900908

901909
struct EnqueuedMsg final : TLB_Complex {
902910
int get_size(const vm::CellSlice& cs) const override {
@@ -935,7 +943,7 @@ extern const Aug_DispatchQueue aug_DispatchQueue;
935943

936944
struct OutMsgQueue final : TLB_Complex {
937945
HashmapAugE dict_type;
938-
OutMsgQueue() : dict_type(32 + 64 + 256, aug_OutMsgQueue){};
946+
OutMsgQueue() : dict_type(32 + 64 + 256, aug_OutMsgQueue) {};
939947
bool skip(vm::CellSlice& cs) const override {
940948
return dict_type.skip(cs);
941949
}
@@ -1138,8 +1146,8 @@ struct Aug_ShardFees final : AugmentationCheckData {
11381146
extern const Aug_ShardFees aug_ShardFees;
11391147

11401148
// Validate dict of libraries in message: used when sending and receiving message
1141-
bool validate_message_libs(const td::Ref<vm::Cell> &cell);
1142-
bool validate_message_relaxed_libs(const td::Ref<vm::Cell> &cell);
1149+
bool validate_message_libs(const td::Ref<vm::Cell>& cell);
1150+
bool validate_message_relaxed_libs(const td::Ref<vm::Cell>& cell);
11431151

11441152
} // namespace tlb
11451153
} // namespace block

crypto/block/block.tlb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ currencies$_ grams:Grams other:ExtraCurrencyCollection
125125
//
126126
int_msg_info$0 ihr_disabled:Bool bounce:Bool bounced:Bool
127127
src:MsgAddressInt dest:MsgAddressInt
128-
value:CurrencyCollection ihr_fee:Grams fwd_fee:Grams
128+
value:CurrencyCollection extra_flags:(VarUInteger 16) fwd_fee:Grams
129129
created_lt:uint64 created_at:uint32 = CommonMsgInfo;
130130
ext_in_msg_info$10 src:MsgAddressExt dest:MsgAddressInt
131131
import_fee:Grams = CommonMsgInfo;
@@ -134,7 +134,7 @@ ext_out_msg_info$11 src:MsgAddressInt dest:MsgAddressExt
134134

135135
int_msg_info$0 ihr_disabled:Bool bounce:Bool bounced:Bool
136136
src:MsgAddress dest:MsgAddressInt
137-
value:CurrencyCollection ihr_fee:Grams fwd_fee:Grams
137+
value:CurrencyCollection extra_flags:(VarUInteger 16) fwd_fee:Grams
138138
created_lt:uint64 created_at:uint32 = CommonMsgInfoRelaxed;
139139
ext_out_msg_info$11 src:MsgAddress dest:MsgAddressExt
140140
created_lt:uint64 created_at:uint32 = CommonMsgInfoRelaxed;
@@ -162,6 +162,16 @@ message$_ {X:Type} info:CommonMsgInfoRelaxed
162162

163163
_ (Message Any) = MessageAny;
164164

165+
166+
_ value:CurrencyCollection created_lt:uint64 created_at:uint32 = NewBounceOriginalInfo;
167+
_ gas_used:uint32 vm_steps:uint32 = NewBounceComputePhaseInfo;
168+
new_bounce_body#fffffffe
169+
original_body:^Cell
170+
original_info:^NewBounceOriginalInfo
171+
bounced_by_phase:uint8 exit_code:int32
172+
compute_phase:(Maybe NewBounceComputePhaseInfo)
173+
= NewBounceBody;
174+
165175
//
166176
interm_addr_regular$0 use_dest_bits:(#<= 96)
167177
= IntermediateAddress;
@@ -796,9 +806,9 @@ _ MisbehaviourPunishmentConfig = ConfigParam 40;
796806
size_limits_config#01 max_msg_bits:uint32 max_msg_cells:uint32 max_library_cells:uint32 max_vm_data_depth:uint16
797807
max_ext_msg_size:uint32 max_ext_msg_depth:uint16 = SizeLimitsConfig;
798808
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
809+
max_ext_msg_size:uint32 max_ext_msg_depth:uint16 max_acc_state_cells:uint32 max_mc_acc_state_cells:uint32
800810
max_acc_public_libraries:uint32 defer_out_queue_size_limit:uint32 max_msg_extra_currencies:uint32
801-
max_acc_fixed_prefix_length:uint8 = SizeLimitsConfig;
811+
max_acc_fixed_prefix_length:uint8 acc_state_cells_for_storage_dict:uint32 = SizeLimitsConfig;
802812
_ SizeLimitsConfig = ConfigParam 43;
803813

804814
// key is [ wc:int32 addr:uint256 ]

crypto/block/mc-config.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2034,12 +2034,13 @@ td::Result<SizeLimitsConfig> Config::do_get_size_limits_config(td::Ref<vm::CellS
20342034

20352035
auto unpack_v2 = [&](auto& rec) {
20362036
unpack_v1(rec);
2037-
limits.max_acc_state_bits = rec.max_acc_state_bits;
20382037
limits.max_acc_state_cells = rec.max_acc_state_cells;
2038+
limits.max_mc_acc_state_cells = rec.max_mc_acc_state_cells;
20392039
limits.max_acc_public_libraries = rec.max_acc_public_libraries;
20402040
limits.defer_out_queue_size_limit = rec.defer_out_queue_size_limit;
20412041
limits.max_msg_extra_currencies = rec.max_msg_extra_currencies;
20422042
limits.max_acc_fixed_prefix_length = rec.max_acc_fixed_prefix_length;
2043+
limits.acc_state_cells_for_storage_dict = rec.acc_state_cells_for_storage_dict;
20432044
};
20442045
gen::SizeLimitsConfig::Record_size_limits_config rec_v1;
20452046
gen::SizeLimitsConfig::Record_size_limits_config_v2 rec_v2;

crypto/block/mc-config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,12 @@ 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;
405405
td::uint32 max_acc_fixed_prefix_length = 8;
406+
td::uint32 acc_state_cells_for_storage_dict = 26;
406407
};
407408

408409
struct CatchainValidatorsConfig {

0 commit comments

Comments
 (0)