mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Merge branch 'testnet' into block-generation
# Conflicts: # adnl/adnl-query.cpp # crypto/block/block.tlb # crypto/block/mc-config.h # lite-client/lite-client.cpp # overlay/overlay-manager.h # overlay/overlay-peers.cpp # overlay/overlay.cpp # overlay/overlay.h # overlay/overlay.hpp # overlay/overlays.h # rldp-http-proxy/DNSResolver.cpp # rldp-http-proxy/rldp-http-proxy.cpp # tl/generate/scheme/ton_api.tl # tl/generate/scheme/ton_api.tlo # tl/generate/scheme/tonlib_api.tlo # ton/ton-types.h # tonlib/tonlib/ExtClient.cpp # tonlib/tonlib/ExtClient.h # tonlib/tonlib/ExtClientLazy.cpp # tonlib/tonlib/ExtClientOutbound.h # tonlib/tonlib/ExtClientRaw.h # tonlib/tonlib/TonlibClient.cpp # tonlib/tonlib/TonlibClient.h # tonlib/tonlib/tonlib-cli.cpp # validator/impl/collator.cpp # validator/impl/validate-query.cpp # validator/impl/validate-query.hpp # validator/manager.cpp # validator/state-serializer.cpp # validator/state-serializer.hpp # validator/validator-group.cpp # validator/validator-group.hpp # validator/validator.h
This commit is contained in:
commit
d652f7d706
200 changed files with 13492 additions and 2997 deletions
|
@ -113,7 +113,10 @@ var_uint$_ {n:#} len:(#< n) value:(uint (len * 8))
|
|||
= VarUInteger n;
|
||||
var_int$_ {n:#} len:(#< n) value:(int (len * 8))
|
||||
= VarInteger n;
|
||||
nanograms$_ amount:(VarUInteger 16) = Grams;
|
||||
nanograms$_ amount:(VarUInteger 16) = Grams;
|
||||
|
||||
_ grams:Grams = Coins;
|
||||
|
||||
//
|
||||
extra_currencies$_ dict:(HashmapE 32 (VarUInteger 32))
|
||||
= ExtraCurrencyCollection;
|
||||
|
@ -611,15 +614,29 @@ wfmt_ext#0 min_addr_len:(## 12) max_addr_len:(## 12) addr_len_step:(## 12)
|
|||
workchain_type_id:(## 32) { workchain_type_id >= 1 }
|
||||
= WorkchainFormat 0;
|
||||
|
||||
workchain#a6 enabled_since:uint32 actual_min_split:(## 8)
|
||||
min_split:(## 8) max_split:(## 8) { actual_min_split <= min_split }
|
||||
wc_split_merge_timings#0
|
||||
split_merge_delay:uint32 split_merge_interval:uint32
|
||||
min_split_merge_interval:uint32 max_split_merge_delay:uint32
|
||||
= WcSplitMergeTimings;
|
||||
|
||||
//workchain#a5 enabled_since:uint32 min_split:(## 8) max_split:(## 8)
|
||||
// { min_split <= max_split } { max_split <= 60 }
|
||||
|
||||
workchain#a6 enabled_since:uint32 actual_min_split:(## 8)
|
||||
min_split:(## 8) max_split:(## 8) { actual_min_split <= min_split }
|
||||
basic:(## 1) active:Bool accept_msgs:Bool flags:(## 13) { flags = 0 }
|
||||
zerostate_root_hash:bits256 zerostate_file_hash:bits256
|
||||
version:uint32 format:(WorkchainFormat basic)
|
||||
= WorkchainDescr;
|
||||
|
||||
workchain_v2#a7 enabled_since:uint32 actual_min_split:(## 8)
|
||||
min_split:(## 8) max_split:(## 8) { actual_min_split <= min_split }
|
||||
basic:(## 1) active:Bool accept_msgs:Bool flags:(## 13) { flags = 0 }
|
||||
zerostate_root_hash:bits256 zerostate_file_hash:bits256
|
||||
version:uint32 format:(WorkchainFormat basic)
|
||||
split_merge_timings:WcSplitMergeTimings
|
||||
= WorkchainDescr;
|
||||
|
||||
_ workchains:(HashmapE 32 WorkchainDescr) = ConfigParam 12;
|
||||
|
||||
complaint_prices#1a deposit:Grams bit_price:Grams cell_price:Grams = ComplaintPricing;
|
||||
|
@ -739,11 +756,32 @@ collator_info#0 full_node_id:(Maybe uint256) = CollatorInfo;
|
|||
colator_config#a0 full_collated_data:Bool collator_nodes:(HashmapE 352 CollatorInfo) = CollatorConfig;
|
||||
_ CollatorConfig = ConfigParam 41;
|
||||
|
||||
size_limits_config#01 max_msg_bits:uint32 max_msg_cells:uint32 max_library_cells:uint32 max_vm_data_depth:uint16
|
||||
max_ext_msg_size:uint32 max_ext_msg_depth:uint16 = SizeLimitsConfig;
|
||||
size_limits_config_v2#02 max_msg_bits:uint32 max_msg_cells:uint32 max_library_cells:uint32 max_vm_data_depth:uint16
|
||||
max_ext_msg_size:uint32 max_ext_msg_depth:uint16 max_acc_state_cells:uint32 max_acc_state_bits:uint32 = SizeLimitsConfig;
|
||||
_ SizeLimitsConfig = ConfigParam 43;
|
||||
|
||||
oracle_bridge_params#_ bridge_address:bits256 oracle_mutlisig_address:bits256 oracles:(HashmapE 256 uint256) external_chain_address:bits256 = OracleBridgeParams;
|
||||
_ OracleBridgeParams = ConfigParam 71; // Ethereum bridge
|
||||
_ OracleBridgeParams = ConfigParam 72; // Binance Smart Chain bridge
|
||||
_ OracleBridgeParams = ConfigParam 73; // Polygon bridge
|
||||
|
||||
// Note that chains in which bridge, minter and jetton-wallet operate are fixated
|
||||
jetton_bridge_prices#_ bridge_burn_fee:Coins bridge_mint_fee:Coins
|
||||
wallet_min_tons_for_storage:Coins
|
||||
wallet_gas_consumption:Coins
|
||||
minter_min_tons_for_storage:Coins
|
||||
discover_gas_consumption:Coins = JettonBridgePrices;
|
||||
|
||||
jetton_bridge_params_v0#00 bridge_address:bits256 oracles_address:bits256 oracles:(HashmapE 256 uint256) state_flags:uint8 burn_bridge_fee:Coins = JettonBridgeParams;
|
||||
jetton_bridge_params_v1#01 bridge_address:bits256 oracles_address:bits256 oracles:(HashmapE 256 uint256) state_flags:uint8 prices:^JettonBridgePrices external_chain_address:bits256 = JettonBridgeParams;
|
||||
|
||||
_ JettonBridgeParams = ConfigParam 79; // ETH->TON token bridge
|
||||
_ JettonBridgeParams = ConfigParam 80; // BNB->TON token bridge
|
||||
_ JettonBridgeParams = ConfigParam 81; // Polygon->TON token bridge
|
||||
|
||||
|
||||
//
|
||||
// PROOFS
|
||||
//
|
||||
|
@ -870,4 +908,3 @@ chan_op_cmd#912838d1 msg:ChanSignedMsg = ChanOp;
|
|||
|
||||
|
||||
chan_data$_ config:^ChanConfig state:^ChanState = ChanData;
|
||||
|
||||
|
|
|
@ -1913,6 +1913,38 @@ std::vector<ton::ValidatorDescr> Config::compute_total_validator_set(int next) c
|
|||
return res.move_as_ok()->export_validator_set();
|
||||
}
|
||||
|
||||
td::Result<SizeLimitsConfig> Config::get_size_limits_config() const {
|
||||
SizeLimitsConfig limits;
|
||||
td::Ref<vm::Cell> param = get_config_param(43);
|
||||
if (param.is_null()) {
|
||||
return limits;
|
||||
}
|
||||
auto unpack_v1 = [&](auto& rec) {
|
||||
limits.max_msg_bits = rec.max_msg_bits;
|
||||
limits.max_msg_cells = rec.max_msg_cells;
|
||||
limits.max_library_cells = rec.max_library_cells;
|
||||
limits.max_vm_data_depth = static_cast<td::uint16>(rec.max_vm_data_depth);
|
||||
limits.ext_msg_limits.max_size = rec.max_ext_msg_size;
|
||||
limits.ext_msg_limits.max_depth = static_cast<td::uint16>(rec.max_ext_msg_depth);
|
||||
};
|
||||
|
||||
auto unpack_v2 = [&](auto& rec) {
|
||||
unpack_v1(rec);
|
||||
limits.max_acc_state_bits = rec.max_acc_state_bits;
|
||||
limits.max_acc_state_cells = rec.max_acc_state_cells;
|
||||
};
|
||||
gen::SizeLimitsConfig::Record_size_limits_config rec_v1;
|
||||
gen::SizeLimitsConfig::Record_size_limits_config_v2 rec_v2;
|
||||
if (tlb::unpack_cell(param, rec_v1)) {
|
||||
unpack_v1(rec_v1);
|
||||
} else if (tlb::unpack_cell(param, rec_v2)) {
|
||||
unpack_v2(rec_v2);
|
||||
} else {
|
||||
return td::Status::Error("configuration parameter 43 is invalid");
|
||||
}
|
||||
return limits;
|
||||
}
|
||||
|
||||
td::Result<std::pair<ton::UnixTime, ton::UnixTime>> Config::unpack_validator_set_start_stop(Ref<vm::Cell> vset_root) {
|
||||
if (vset_root.is_null()) {
|
||||
return td::Status::Error("validator set absent");
|
||||
|
@ -1942,31 +1974,58 @@ bool WorkchainInfo::unpack(ton::WorkchainId wc, vm::CellSlice& cs) {
|
|||
if (wc == ton::workchainInvalid) {
|
||||
return false;
|
||||
}
|
||||
block::gen::WorkchainDescr::Record info;
|
||||
if (!tlb::unpack(cs, info)) {
|
||||
return false;
|
||||
}
|
||||
enabled_since = info.enabled_since;
|
||||
actual_min_split = info.actual_min_split;
|
||||
min_split = info.min_split;
|
||||
max_split = info.max_split;
|
||||
basic = info.basic;
|
||||
active = info.active;
|
||||
accept_msgs = info.accept_msgs;
|
||||
flags = info.flags;
|
||||
zerostate_root_hash = info.zerostate_root_hash;
|
||||
zerostate_file_hash = info.zerostate_file_hash;
|
||||
version = info.version;
|
||||
if (basic) {
|
||||
min_addr_len = max_addr_len = addr_len_step = 256;
|
||||
} else {
|
||||
block::gen::WorkchainFormat::Record_wfmt_ext ext;
|
||||
if (!tlb::type_unpack(cs, block::gen::WorkchainFormat{basic}, ext)) {
|
||||
auto unpack_v1 = [this](auto& info) {
|
||||
enabled_since = info.enabled_since;
|
||||
actual_min_split = info.actual_min_split;
|
||||
min_split = info.min_split;
|
||||
max_split = info.max_split;
|
||||
basic = info.basic;
|
||||
active = info.active;
|
||||
accept_msgs = info.accept_msgs;
|
||||
flags = info.flags;
|
||||
zerostate_root_hash = info.zerostate_root_hash;
|
||||
zerostate_file_hash = info.zerostate_file_hash;
|
||||
version = info.version;
|
||||
if (basic) {
|
||||
min_addr_len = max_addr_len = addr_len_step = 256;
|
||||
} else {
|
||||
block::gen::WorkchainFormat::Record_wfmt_ext ext;
|
||||
if (!tlb::csr_type_unpack(info.format, block::gen::WorkchainFormat{basic}, ext)) {
|
||||
return false;
|
||||
}
|
||||
min_addr_len = ext.min_addr_len;
|
||||
max_addr_len = ext.max_addr_len;
|
||||
addr_len_step = ext.addr_len_step;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
auto unpack_v2 = [&, this](auto& info) {
|
||||
if (!unpack_v1(info)) {
|
||||
return false;
|
||||
}
|
||||
min_addr_len = ext.min_addr_len;
|
||||
max_addr_len = ext.max_addr_len;
|
||||
addr_len_step = ext.addr_len_step;
|
||||
block::gen::WcSplitMergeTimings::Record rec;
|
||||
if (!tlb::csr_unpack(info.split_merge_timings, rec)) {
|
||||
return false;
|
||||
}
|
||||
split_merge_delay = rec.split_merge_delay;
|
||||
split_merge_interval = rec.split_merge_interval;
|
||||
min_split_merge_interval = rec.min_split_merge_interval;
|
||||
max_split_merge_delay = rec.max_split_merge_delay;
|
||||
return true;
|
||||
};
|
||||
block::gen::WorkchainDescr::Record_workchain info_v1;
|
||||
block::gen::WorkchainDescr::Record_workchain_v2 info_v2;
|
||||
vm::CellSlice cs0 = cs;
|
||||
if (tlb::unpack(cs, info_v1)) {
|
||||
if (!unpack_v1(info_v1)) {
|
||||
return false;
|
||||
}
|
||||
} else if (tlb::unpack(cs = cs0, info_v2)) {
|
||||
if (!unpack_v2(info_v2)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
workchain = wc;
|
||||
LOG(DEBUG) << "unpacked info for workchain " << wc << ": basic=" << basic << ", active=" << active
|
||||
|
|
|
@ -376,6 +376,21 @@ struct MsgPrices {
|
|||
td::RefInt256 get_next_part(td::RefInt256 total) const;
|
||||
};
|
||||
|
||||
struct SizeLimitsConfig {
|
||||
// Default values are used when not present in global config
|
||||
struct ExtMsgLimits {
|
||||
td::uint32 max_size = 65535;
|
||||
td::uint16 max_depth = 512;
|
||||
};
|
||||
td::uint32 max_msg_bits = 1 << 21;
|
||||
td::uint32 max_msg_cells = 1 << 13;
|
||||
td::uint32 max_library_cells = 1000;
|
||||
td::uint16 max_vm_data_depth = 512;
|
||||
ExtMsgLimits ext_msg_limits;
|
||||
td::uint32 max_acc_state_cells = 1 << 16;
|
||||
td::uint32 max_acc_state_bits = (1 << 16) * 1023;
|
||||
};
|
||||
|
||||
struct CatchainValidatorsConfig {
|
||||
td::uint32 mc_cc_lifetime, shard_cc_lifetime, shard_val_lifetime, shard_val_num;
|
||||
bool shuffle_mc_val;
|
||||
|
@ -402,6 +417,13 @@ struct WorkchainInfo : public td::CntObject {
|
|||
ton::RootHash zerostate_root_hash;
|
||||
ton::FileHash zerostate_file_hash;
|
||||
int min_addr_len, max_addr_len, addr_len_step;
|
||||
|
||||
// Default values are used when split_merge_timings is not set in config
|
||||
unsigned split_merge_delay = 100; // prepare (delay) split/merge for 100 seconds
|
||||
unsigned split_merge_interval = 100; // split/merge is enabled during 60 second interval
|
||||
unsigned min_split_merge_interval = 30; // split/merge interval must be at least 30 seconds
|
||||
unsigned max_split_merge_delay = 1000; // end of split/merge interval must be at most 1000 seconds in the future
|
||||
|
||||
bool is_valid() const {
|
||||
return workchain != ton::workchainInvalid;
|
||||
}
|
||||
|
@ -605,6 +627,7 @@ class Config {
|
|||
ton::CatchainSeqno cc_seqno) const;
|
||||
std::vector<ton::ValidatorDescr> compute_total_validator_set(int next) const;
|
||||
CollatorConfig get_collator_config(bool need_collator_nodes) const;
|
||||
td::Result<SizeLimitsConfig> get_size_limits_config() const;
|
||||
static std::vector<ton::ValidatorDescr> do_compute_validator_set(const block::CatchainValidatorsConfig& ccv_conf,
|
||||
ton::ShardIdFull shard,
|
||||
const block::ValidatorSet& vset, ton::UnixTime time,
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "td/utils/uint128.h"
|
||||
#include "ton/ton-shard.h"
|
||||
#include "vm/vm.h"
|
||||
#include "td/utils/Timer.h"
|
||||
|
||||
namespace {
|
||||
class StringLoggerTail : public td::LogInterface {
|
||||
|
@ -345,7 +346,7 @@ bool Account::unpack(Ref<vm::CellSlice> shard_account, Ref<vm::CellSlice> extra,
|
|||
block::gen::AccountStorage::Record storage;
|
||||
if (!(tlb::unpack_exact(acc_cs, acc) && (my_addr = acc.addr).not_null() && unpack_address(acc.addr.write()) &&
|
||||
compute_my_addr() && unpack_storage_info(acc.storage_stat.write()) &&
|
||||
tlb::csr_unpack(std::move(acc.storage), storage) &&
|
||||
tlb::csr_unpack(this->storage = std::move(acc.storage), storage) &&
|
||||
std::max(storage.last_trans_lt, 1ULL) > acc_info.last_trans_lt && balance.unpack(std::move(storage.balance)))) {
|
||||
return false;
|
||||
}
|
||||
|
@ -459,7 +460,6 @@ bool Account::deactivate() {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Account::belongs_to_shard(ton::ShardIdFull shard) const {
|
||||
return workchain == shard.workchain && ton::shard_is_ancestor(shard.shard, addr);
|
||||
}
|
||||
|
@ -593,7 +593,7 @@ bool Transaction::unpack_input_msg(bool ihr_delivered, const ActionPhaseConfig*
|
|||
sstat.bits -= cs.size(); // bits in the root cells are free
|
||||
sstat.cells--; // the root cell itself is not counted as a cell
|
||||
LOG(DEBUG) << "storage paid for a message: " << sstat.cells << " cells, " << sstat.bits << " bits";
|
||||
if (sstat.bits > max_msg_bits || sstat.cells > max_msg_cells) {
|
||||
if (sstat.bits > cfg->size_limits.max_msg_bits || sstat.cells > cfg->size_limits.max_msg_cells) {
|
||||
LOG(DEBUG) << "inbound external message too large, invalid";
|
||||
return false;
|
||||
}
|
||||
|
@ -1043,12 +1043,15 @@ bool Transaction::prepare_compute_phase(const ComputePhaseConfig& cfg) {
|
|||
vm_log.log_options = td::LogOptions(VERBOSITY_NAME(DEBUG), true, false);
|
||||
}
|
||||
vm::VmState vm{new_code, std::move(stack), gas, 1, new_data, vm_log, compute_vm_libraries(cfg)};
|
||||
vm.set_max_data_depth(cfg.max_vm_data_depth);
|
||||
vm.set_c7(prepare_vm_c7(cfg)); // tuple with SmartContractInfo
|
||||
// vm.incr_stack_trace(1); // enable stack dump after each step
|
||||
|
||||
LOG(DEBUG) << "starting VM";
|
||||
cp.vm_init_state_hash = vm.get_state_hash();
|
||||
td::Timer timer;
|
||||
cp.exit_code = ~vm.run();
|
||||
double elapsed = timer.elapsed();
|
||||
LOG(DEBUG) << "VM terminated with exit code " << cp.exit_code;
|
||||
cp.out_of_gas = (cp.exit_code == ~(int)vm::Excno::out_of_gas);
|
||||
cp.vm_final_state_hash = vm.get_final_state_hash(cp.exit_code);
|
||||
|
@ -1064,7 +1067,8 @@ bool Transaction::prepare_compute_phase(const ComputePhaseConfig& cfg) {
|
|||
}
|
||||
LOG(INFO) << "steps: " << vm.get_steps_count() << " gas: used=" << gas.gas_consumed() << ", max=" << gas.gas_max
|
||||
<< ", limit=" << gas.gas_limit << ", credit=" << gas.gas_credit;
|
||||
LOG(INFO) << "out_of_gas=" << cp.out_of_gas << ", accepted=" << cp.accepted << ", success=" << cp.success;
|
||||
LOG(INFO) << "out_of_gas=" << cp.out_of_gas << ", accepted=" << cp.accepted << ", success=" << cp.success
|
||||
<< ", time=" << elapsed << "s";
|
||||
if (logger != nullptr) {
|
||||
cp.vm_log = logger->get_log();
|
||||
}
|
||||
|
@ -1121,6 +1125,25 @@ bool Transaction::prepare_action_phase(const ActionPhaseConfig& cfg) {
|
|||
ap.total_action_fees = td::zero_refint();
|
||||
ap.reserved_balance.set_zero();
|
||||
|
||||
td::Ref<vm::Cell> old_code = new_code, old_data = new_data, old_library = new_library;
|
||||
auto enforce_state_size_limits = [&]() {
|
||||
if (account.is_special) {
|
||||
return true;
|
||||
}
|
||||
if (!check_state_size_limit(cfg)) {
|
||||
// Rollback changes to state, fail action phase
|
||||
LOG(INFO) << "Account state size exceeded limits";
|
||||
new_storage_stat.clear();
|
||||
new_code = old_code;
|
||||
new_data = old_data;
|
||||
new_library = old_library;
|
||||
ap.result_code = 50;
|
||||
ap.state_size_too_big = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
int n = 0;
|
||||
while (true) {
|
||||
ap.action_list.push_back(list);
|
||||
|
@ -1196,9 +1219,21 @@ bool Transaction::prepare_action_phase(const ActionPhaseConfig& cfg) {
|
|||
ap.no_funds = true;
|
||||
}
|
||||
LOG(DEBUG) << "invalid action " << ap.result_arg << " in action list: error code " << ap.result_code;
|
||||
// This is reuqired here because changes to libraries are applied even if actipn phase fails
|
||||
enforce_state_size_limits();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
end_lt = ap.end_lt;
|
||||
if (ap.new_code.not_null()) {
|
||||
new_code = ap.new_code;
|
||||
}
|
||||
new_data = compute_phase->new_data; // tentative persistent data update applied
|
||||
if (!enforce_state_size_limits()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ap.result_arg = 0;
|
||||
ap.result_code = 0;
|
||||
CHECK(ap.remaining_balance.grams->sgn() >= 0);
|
||||
|
@ -1212,12 +1247,7 @@ bool Transaction::prepare_action_phase(const ActionPhaseConfig& cfg) {
|
|||
was_deleted = true;
|
||||
}
|
||||
ap.success = true;
|
||||
end_lt = ap.end_lt;
|
||||
out_msgs = std::move(ap.out_msgs);
|
||||
if (ap.new_code.not_null()) {
|
||||
new_code = ap.new_code;
|
||||
}
|
||||
new_data = compute_phase->new_data; // tentative persistent data update applied
|
||||
total_fees +=
|
||||
ap.total_action_fees; // NB: forwarding fees are not accounted here (they are not collected by the validators in this transaction)
|
||||
balance = ap.remaining_balance;
|
||||
|
@ -1272,6 +1302,11 @@ int Transaction::try_action_change_library(vm::CellSlice& cs, ActionPhase& ap, c
|
|||
// library code not found
|
||||
return 41;
|
||||
}
|
||||
vm::CellStorageStat sstat;
|
||||
sstat.compute_used_storage(lib_ref);
|
||||
if (sstat.cells > cfg.size_limits.max_library_cells) {
|
||||
return 43;
|
||||
}
|
||||
vm::CellBuilder cb;
|
||||
CHECK(cb.store_bool_bool(rec.mode >> 1) && cb.store_ref_bool(std::move(lib_ref)));
|
||||
CHECK(dict.set_builder(hash, cb));
|
||||
|
@ -1546,7 +1581,7 @@ int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap,
|
|||
sstat.add_used_storage(info.value->prefetch_ref());
|
||||
}
|
||||
LOG(DEBUG) << "storage paid for a message: " << sstat.cells << " cells, " << sstat.bits << " bits";
|
||||
if (sstat.bits > max_msg_bits || sstat.cells > max_msg_cells) {
|
||||
if (sstat.bits > cfg.size_limits.max_msg_bits || sstat.cells > cfg.size_limits.max_msg_cells) {
|
||||
LOG(DEBUG) << "message too large, invalid";
|
||||
return skip_invalid ? 0 : 40;
|
||||
}
|
||||
|
@ -1801,6 +1836,35 @@ int Transaction::try_action_reserve_currency(vm::CellSlice& cs, ActionPhase& ap,
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool Transaction::check_state_size_limit(const ActionPhaseConfig& cfg) {
|
||||
auto cell_equal = [](const td::Ref<vm::Cell>& a, const td::Ref<vm::Cell>& b) -> bool {
|
||||
if (a.is_null()) {
|
||||
return b.is_null();
|
||||
}
|
||||
if (b.is_null()) {
|
||||
return false;
|
||||
}
|
||||
return a->get_hash() == b->get_hash();
|
||||
};
|
||||
if (cell_equal(account.code, new_code) && cell_equal(account.data, new_data) &&
|
||||
cell_equal(account.library, new_library)) {
|
||||
return true;
|
||||
}
|
||||
// new_storage_stat is used here beause these stats will be reused in compute_state()
|
||||
new_storage_stat.limit_cells = cfg.size_limits.max_acc_state_cells;
|
||||
new_storage_stat.limit_bits = cfg.size_limits.max_acc_state_bits;
|
||||
new_storage_stat.add_used_storage(new_code);
|
||||
new_storage_stat.add_used_storage(new_data);
|
||||
new_storage_stat.add_used_storage(new_library);
|
||||
if (acc_status == Account::acc_active) {
|
||||
new_storage_stat.clear_limit();
|
||||
} else {
|
||||
new_storage_stat.clear();
|
||||
}
|
||||
return new_storage_stat.cells <= cfg.size_limits.max_acc_state_cells &&
|
||||
new_storage_stat.bits <= cfg.size_limits.max_acc_state_bits;
|
||||
}
|
||||
|
||||
bool Transaction::prepare_bounce_phase(const ActionPhaseConfig& cfg) {
|
||||
if (in_msg.is_null() || !bounce_enabled) {
|
||||
return false;
|
||||
|
@ -1924,6 +1988,32 @@ bool Account::store_acc_status(vm::CellBuilder& cb, int acc_status) const {
|
|||
return cb.store_long_bool(v, 2);
|
||||
}
|
||||
|
||||
static td::optional<vm::CellStorageStat> try_update_storage_stat(const vm::CellStorageStat& old_stat,
|
||||
td::Ref<vm::CellSlice> old_cs,
|
||||
td::Ref<vm::Cell> new_cell) {
|
||||
if (old_stat.cells == 0 || old_cs.is_null()) {
|
||||
return {};
|
||||
}
|
||||
vm::CellSlice new_cs = vm::CellSlice(vm::NoVm(), new_cell);
|
||||
if (old_cs->size_refs() != new_cs.size_refs()) {
|
||||
return {};
|
||||
}
|
||||
for (unsigned i = 0; i < old_cs->size_refs(); ++i) {
|
||||
if (old_cs->prefetch_ref(i)->get_hash() != new_cs.prefetch_ref(i)->get_hash()) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
if (old_stat.bits < old_cs->size()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
vm::CellStorageStat new_stat;
|
||||
new_stat.cells = old_stat.cells;
|
||||
new_stat.bits = old_stat.bits - old_cs->size() + new_cs.size();
|
||||
new_stat.public_cells = old_stat.public_cells;
|
||||
return new_stat;
|
||||
}
|
||||
|
||||
bool Transaction::compute_state() {
|
||||
if (new_total_state.not_null()) {
|
||||
return true;
|
||||
|
@ -1985,6 +2075,7 @@ bool Transaction::compute_state() {
|
|||
// code:(Maybe ^Cell) data:(Maybe ^Cell) library:(HashmapE 256 SimpleLib)
|
||||
}
|
||||
auto storage = cb.finalize();
|
||||
new_storage = td::Ref<vm::CellSlice>(true, vm::NoVm(), storage);
|
||||
if (si_pos) {
|
||||
auto cs_ref = load_cell_slice_ref(storage);
|
||||
CHECK(cs_ref.unique_write().skip_ext(si_pos));
|
||||
|
@ -1993,7 +2084,16 @@ bool Transaction::compute_state() {
|
|||
new_inner_state.clear();
|
||||
}
|
||||
vm::CellStorageStat& stats = new_storage_stat;
|
||||
CHECK(stats.compute_used_storage(Ref<vm::Cell>(storage)));
|
||||
auto new_stats = try_update_storage_stat(account.storage_stat, account.storage, storage);
|
||||
if (new_stats) {
|
||||
stats = new_stats.unwrap();
|
||||
} else {
|
||||
td::Timer timer;
|
||||
CHECK(stats.add_used_storage(Ref<vm::Cell>(storage)));
|
||||
if (timer.elapsed() > 0.1) {
|
||||
LOG(INFO) << "Compute used storage took " << timer.elapsed() << "s";
|
||||
}
|
||||
}
|
||||
CHECK(cb.store_long_bool(1, 1) // account$1
|
||||
&& cb.append_cellslice_bool(account.my_addr) // addr:MsgAddressInt
|
||||
&& block::store_UInt7(cb, stats.cells) // storage_used$_ cells:(VarUInteger 7)
|
||||
|
@ -2265,9 +2365,15 @@ bool Transaction::would_fit(unsigned cls, const block::BlockLimitStatus& blimst)
|
|||
return blimst.would_fit(cls, end_lt, gas_used(), &extra);
|
||||
}
|
||||
|
||||
bool Transaction::update_limits(block::BlockLimitStatus& blimst) const {
|
||||
return blimst.update_lt(end_lt) && blimst.update_gas(gas_used()) && blimst.add_proof(new_total_state) &&
|
||||
blimst.add_cell(root) && blimst.add_transaction() && blimst.add_account(is_first);
|
||||
bool Transaction::update_limits(block::BlockLimitStatus& blimst, bool with_size) const {
|
||||
if (!(blimst.update_lt(end_lt) && blimst.update_gas(gas_used()))) {
|
||||
return false;
|
||||
}
|
||||
if (with_size) {
|
||||
return blimst.add_proof(new_total_state) && blimst.add_cell(root) && blimst.add_transaction() &&
|
||||
blimst.add_account(is_first);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -2296,6 +2402,7 @@ Ref<vm::Cell> Transaction::commit(Account& acc) {
|
|||
acc.last_trans_hash_ = root->get_hash().bits();
|
||||
acc.last_paid = last_paid;
|
||||
acc.storage_stat = new_storage_stat;
|
||||
acc.storage = new_storage;
|
||||
acc.balance = std::move(balance);
|
||||
acc.due_payment = std::move(due_payment);
|
||||
acc.total_state = std::move(new_total_state);
|
||||
|
|
|
@ -107,6 +107,7 @@ struct ComputePhaseConfig {
|
|||
Ref<vm::Cell> global_config;
|
||||
td::BitArray<256> block_rand_seed;
|
||||
bool with_vm_log{false};
|
||||
td::uint16 max_vm_data_depth = 512;
|
||||
ComputePhaseConfig(td::uint64 _gas_price = 0, td::uint64 _gas_limit = 0, td::uint64 _gas_credit = 0)
|
||||
: gas_price(_gas_price), gas_limit(_gas_limit), special_gas_limit(_gas_limit), gas_credit(_gas_credit) {
|
||||
compute_threshold();
|
||||
|
@ -143,6 +144,7 @@ struct ActionPhaseConfig {
|
|||
int bounce_msg_body{0}; // usually 0 or 256 bits
|
||||
MsgPrices fwd_std;
|
||||
MsgPrices fwd_mc; // from/to masterchain
|
||||
SizeLimitsConfig size_limits;
|
||||
const WorkchainSet* workchains{nullptr};
|
||||
const MsgPrices& fetch_msg_prices(bool is_masterchain) const {
|
||||
return is_masterchain ? fwd_mc : fwd_std;
|
||||
|
@ -182,6 +184,7 @@ struct ActionPhase {
|
|||
bool code_changed{false};
|
||||
bool action_list_invalid{false};
|
||||
bool acc_delete_req{false};
|
||||
bool state_size_too_big{false};
|
||||
enum { acst_unchanged = 0, acst_frozen = 2, acst_deleted = 3 };
|
||||
int acc_status_change{acst_unchanged};
|
||||
td::RefInt256 total_fwd_fees; // all fees debited from the account
|
||||
|
@ -235,6 +238,7 @@ struct Account {
|
|||
td::RefInt256 due_payment;
|
||||
Ref<vm::Cell> orig_total_state; // ^Account
|
||||
Ref<vm::Cell> total_state; // ^Account
|
||||
Ref<vm::CellSlice> storage; // AccountStorage
|
||||
Ref<vm::CellSlice> inner_state; // StateInit
|
||||
ton::Bits256 state_hash; // hash of StateInit for frozen accounts
|
||||
Ref<vm::Cell> code, data, library, orig_library;
|
||||
|
@ -283,7 +287,6 @@ struct Account {
|
|||
};
|
||||
|
||||
struct Transaction {
|
||||
static constexpr unsigned max_msg_bits = (1 << 21), max_msg_cells = (1 << 13);
|
||||
enum {
|
||||
tr_none,
|
||||
tr_ord,
|
||||
|
@ -323,6 +326,7 @@ struct Transaction {
|
|||
ton::UnixTime last_paid;
|
||||
Ref<vm::Cell> root;
|
||||
Ref<vm::Cell> new_total_state;
|
||||
Ref<vm::CellSlice> new_storage;
|
||||
Ref<vm::CellSlice> new_inner_state;
|
||||
Ref<vm::Cell> new_code, new_data, new_library;
|
||||
Ref<vm::Cell> in_msg, in_msg_state;
|
||||
|
@ -348,6 +352,7 @@ struct Transaction {
|
|||
std::vector<Ref<vm::Cell>> compute_vm_libraries(const ComputePhaseConfig& cfg);
|
||||
bool prepare_compute_phase(const ComputePhaseConfig& cfg);
|
||||
bool prepare_action_phase(const ActionPhaseConfig& cfg);
|
||||
bool check_state_size_limit(const ActionPhaseConfig& cfg);
|
||||
bool prepare_bounce_phase(const ActionPhaseConfig& cfg);
|
||||
bool compute_state();
|
||||
bool serialize();
|
||||
|
@ -359,7 +364,7 @@ struct Transaction {
|
|||
const vm::NewCellStorageStat& store_stat, const vm::CellUsageTree* usage_tree) const;
|
||||
bool update_block_storage_profile(vm::NewCellStorageStat& store_stat, const vm::CellUsageTree* usage_tree) const;
|
||||
bool would_fit(unsigned cls, const block::BlockLimitStatus& blk_lim_st) const;
|
||||
bool update_limits(block::BlockLimitStatus& blk_lim_st) const;
|
||||
bool update_limits(block::BlockLimitStatus& blk_lim_st, bool with_size = true) const;
|
||||
|
||||
Ref<vm::Cell> commit(Account& _account); // _account should point to the same account
|
||||
LtCellRef extract_out_msg(unsigned i);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue