mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Merge branch 'testnet' into block-generation
This commit is contained in:
commit
e4e77c16c5
463 changed files with 29976 additions and 2517 deletions
|
@ -2292,5 +2292,37 @@ bool Aug_ShardFees::eval_leaf(vm::CellBuilder& cb, vm::CellSlice& cs) const {
|
|||
|
||||
const Aug_ShardFees aug_ShardFees;
|
||||
|
||||
bool validate_message_libs(const td::Ref<vm::Cell> &cell) {
|
||||
gen::Message::Record rec;
|
||||
if (!type_unpack_cell(cell, gen::t_Message_Any, rec)) {
|
||||
return false;
|
||||
}
|
||||
vm::CellSlice& state_init = rec.init.write();
|
||||
if (!state_init.fetch_long(1)) {
|
||||
return true;
|
||||
}
|
||||
if (state_init.fetch_long(1)) {
|
||||
return gen::t_StateInitWithLibs.validate_ref(state_init.prefetch_ref());
|
||||
} else {
|
||||
return gen::t_StateInitWithLibs.validate_csr(rec.init);
|
||||
}
|
||||
}
|
||||
|
||||
bool validate_message_relaxed_libs(const td::Ref<vm::Cell> &cell) {
|
||||
gen::MessageRelaxed::Record rec;
|
||||
if (!type_unpack_cell(cell, gen::t_MessageRelaxed_Any, rec)) {
|
||||
return false;
|
||||
}
|
||||
vm::CellSlice& state_init = rec.init.write();
|
||||
if (!state_init.fetch_long(1)) {
|
||||
return true;
|
||||
}
|
||||
if (state_init.fetch_long(1)) {
|
||||
return gen::t_StateInitWithLibs.validate_ref(state_init.prefetch_ref());
|
||||
} else {
|
||||
return gen::t_StateInitWithLibs.validate_csr(rec.init);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace tlb
|
||||
} // namespace block
|
||||
|
|
|
@ -1113,5 +1113,9 @@ struct Aug_ShardFees final : AugmentationCheckData {
|
|||
|
||||
extern const Aug_ShardFees aug_ShardFees;
|
||||
|
||||
// Validate dict of libraries in message: used when sending and receiving message
|
||||
bool validate_message_libs(const td::Ref<vm::Cell> &cell);
|
||||
bool validate_message_relaxed_libs(const td::Ref<vm::Cell> &cell);
|
||||
|
||||
} // namespace tlb
|
||||
} // namespace block
|
||||
|
|
|
@ -715,7 +715,7 @@ td::uint64 BlockLimitStatus::estimate_block_size(const vm::NewCellStorageStat::S
|
|||
sum += *extra;
|
||||
}
|
||||
return 2000 + (sum.bits >> 3) + sum.cells * 12 + sum.internal_refs * 3 + sum.external_refs * 40 + accounts * 200 +
|
||||
transactions * 200 + (extra ? 200 : 0);
|
||||
transactions * 200 + (extra ? 200 : 0) + extra_out_msgs * 300;
|
||||
}
|
||||
|
||||
int BlockLimitStatus::classify() const {
|
||||
|
@ -1364,42 +1364,61 @@ std::ostream& operator<<(std::ostream& os, const CurrencyCollection& cc) {
|
|||
bool ValueFlow::set_zero() {
|
||||
return from_prev_blk.set_zero() && to_next_blk.set_zero() && imported.set_zero() && exported.set_zero() &&
|
||||
fees_collected.set_zero() && fees_imported.set_zero() && recovered.set_zero() && created.set_zero() &&
|
||||
minted.set_zero();
|
||||
minted.set_zero() && burned.set_zero();
|
||||
}
|
||||
|
||||
bool ValueFlow::validate() const {
|
||||
return is_valid() && from_prev_blk + imported + fees_imported + created + minted + recovered ==
|
||||
to_next_blk + exported + fees_collected;
|
||||
to_next_blk + exported + fees_collected + burned;
|
||||
}
|
||||
|
||||
bool ValueFlow::store(vm::CellBuilder& cb) const {
|
||||
vm::CellBuilder cb2;
|
||||
return cb.store_long_bool(block::gen::ValueFlow::cons_tag[0], 32) // value_flow ^[
|
||||
&& from_prev_blk.store(cb2) // from_prev_blk:CurrencyCollection
|
||||
&& to_next_blk.store(cb2) // to_next_blk:CurrencyCollection
|
||||
&& imported.store(cb2) // imported:CurrencyCollection
|
||||
&& exported.store(cb2) // exported:CurrencyCollection
|
||||
&& cb.store_ref_bool(cb2.finalize()) // ]
|
||||
&& fees_collected.store(cb) // fees_collected:CurrencyCollection
|
||||
&& fees_imported.store(cb2) // ^[ fees_imported:CurrencyCollection
|
||||
&& recovered.store(cb2) // recovered:CurrencyCollection
|
||||
&& created.store(cb2) // created:CurrencyCollection
|
||||
&& minted.store(cb2) // minted:CurrencyCollection
|
||||
&& cb.store_ref_bool(cb2.finalize()); // ] = ValueFlow;
|
||||
auto type = burned.is_zero() ? block::gen::ValueFlow::value_flow : block::gen::ValueFlow::value_flow_v2;
|
||||
return cb.store_long_bool(block::gen::ValueFlow::cons_tag[type], 32) // ^[
|
||||
&& from_prev_blk.store(cb2) // from_prev_blk:CurrencyCollection
|
||||
&& to_next_blk.store(cb2) // to_next_blk:CurrencyCollection
|
||||
&& imported.store(cb2) // imported:CurrencyCollection
|
||||
&& exported.store(cb2) // exported:CurrencyCollection
|
||||
&& cb.store_ref_bool(cb2.finalize()) // ]
|
||||
&& fees_collected.store(cb) // fees_collected:CurrencyCollection
|
||||
&& (burned.is_zero() || burned.store(cb)) // fees_burned:CurrencyCollection
|
||||
&& fees_imported.store(cb2) // ^[ fees_imported:CurrencyCollection
|
||||
&& recovered.store(cb2) // recovered:CurrencyCollection
|
||||
&& created.store(cb2) // created:CurrencyCollection
|
||||
&& minted.store(cb2) // minted:CurrencyCollection
|
||||
&& cb.store_ref_bool(cb2.finalize()); // ] = ValueFlow;
|
||||
}
|
||||
|
||||
bool ValueFlow::fetch(vm::CellSlice& cs) {
|
||||
block::gen::ValueFlow::Record f;
|
||||
if (!(tlb::unpack(cs, f) && from_prev_blk.validate_unpack(std::move(f.r1.from_prev_blk)) &&
|
||||
to_next_blk.validate_unpack(std::move(f.r1.to_next_blk)) &&
|
||||
imported.validate_unpack(std::move(f.r1.imported)) && exported.validate_unpack(std::move(f.r1.exported)) &&
|
||||
fees_collected.validate_unpack(std::move(f.fees_collected)) &&
|
||||
fees_imported.validate_unpack(std::move(f.r2.fees_imported)) &&
|
||||
recovered.validate_unpack(std::move(f.r2.recovered)) && created.validate_unpack(std::move(f.r2.created)) &&
|
||||
minted.validate_unpack(std::move(f.r2.minted)))) {
|
||||
if (cs.size() < 32) {
|
||||
return invalidate();
|
||||
}
|
||||
return true;
|
||||
auto tag = cs.prefetch_ulong(32);
|
||||
block::gen::ValueFlow::Record_value_flow f1;
|
||||
if (tag == block::gen::ValueFlow::cons_tag[block::gen::ValueFlow::value_flow] && tlb::unpack(cs, f1) &&
|
||||
from_prev_blk.validate_unpack(std::move(f1.r1.from_prev_blk)) &&
|
||||
to_next_blk.validate_unpack(std::move(f1.r1.to_next_blk)) &&
|
||||
imported.validate_unpack(std::move(f1.r1.imported)) && exported.validate_unpack(std::move(f1.r1.exported)) &&
|
||||
fees_collected.validate_unpack(std::move(f1.fees_collected)) && burned.set_zero() &&
|
||||
fees_imported.validate_unpack(std::move(f1.r2.fees_imported)) &&
|
||||
recovered.validate_unpack(std::move(f1.r2.recovered)) && created.validate_unpack(std::move(f1.r2.created)) &&
|
||||
minted.validate_unpack(std::move(f1.r2.minted))) {
|
||||
return true;
|
||||
}
|
||||
block::gen::ValueFlow::Record_value_flow_v2 f2;
|
||||
if (tag == block::gen::ValueFlow::cons_tag[block::gen::ValueFlow::value_flow_v2] && tlb::unpack(cs, f2) &&
|
||||
from_prev_blk.validate_unpack(std::move(f2.r1.from_prev_blk)) &&
|
||||
to_next_blk.validate_unpack(std::move(f2.r1.to_next_blk)) &&
|
||||
imported.validate_unpack(std::move(f2.r1.imported)) && exported.validate_unpack(std::move(f2.r1.exported)) &&
|
||||
fees_collected.validate_unpack(std::move(f2.fees_collected)) &&
|
||||
burned.validate_unpack(std::move(f2.burned)) &&
|
||||
fees_imported.validate_unpack(std::move(f2.r2.fees_imported)) &&
|
||||
recovered.validate_unpack(std::move(f2.r2.recovered)) && created.validate_unpack(std::move(f2.r2.created)) &&
|
||||
minted.validate_unpack(std::move(f2.r2.minted))) {
|
||||
return true;
|
||||
}
|
||||
return invalidate();
|
||||
}
|
||||
|
||||
bool ValueFlow::unpack(Ref<vm::CellSlice> csr) {
|
||||
|
@ -1424,7 +1443,8 @@ bool ValueFlow::show(std::ostream& os) const {
|
|||
show_one(os, " to_next_blk:", to_next_blk) && show_one(os, " imported:", imported) &&
|
||||
show_one(os, " exported:", exported) && show_one(os, " fees_collected:", fees_collected) &&
|
||||
show_one(os, " fees_imported:", fees_imported) && show_one(os, " recovered:", recovered) &&
|
||||
show_one(os, " created:", created) && show_one(os, " minted:", minted) && say(os, ")")) ||
|
||||
show_one(os, " created:", created) && show_one(os, " minted:", minted) &&
|
||||
(burned.is_zero() || show_one(os, " burned:", burned)) && say(os, ")")) ||
|
||||
(say(os, "...<invalid-value-flow>)") && false);
|
||||
}
|
||||
|
||||
|
|
|
@ -261,7 +261,7 @@ struct BlockLimitStatus {
|
|||
ton::LogicalTime cur_lt;
|
||||
td::uint64 gas_used{};
|
||||
vm::NewCellStorageStat st_stat;
|
||||
unsigned accounts{}, transactions{};
|
||||
unsigned accounts{}, transactions{}, extra_out_msgs{};
|
||||
BlockLimitStatus(const BlockLimits& limits_, ton::LogicalTime lt = 0)
|
||||
: limits(limits_), cur_lt(std::max(limits_.start_lt, lt)) {
|
||||
}
|
||||
|
@ -270,6 +270,7 @@ struct BlockLimitStatus {
|
|||
st_stat.set_zero();
|
||||
transactions = accounts = 0;
|
||||
gas_used = 0;
|
||||
extra_out_msgs = 0;
|
||||
}
|
||||
td::uint64 estimate_block_size(const vm::NewCellStorageStat::Stat* extra = nullptr) const;
|
||||
int classify() const;
|
||||
|
@ -455,7 +456,7 @@ struct ShardState {
|
|||
struct ValueFlow {
|
||||
struct SetZero {};
|
||||
CurrencyCollection from_prev_blk, to_next_blk, imported, exported, fees_collected, fees_imported, recovered, created,
|
||||
minted;
|
||||
minted, burned;
|
||||
ValueFlow() = default;
|
||||
ValueFlow(SetZero)
|
||||
: from_prev_blk{0}
|
||||
|
@ -466,7 +467,8 @@ struct ValueFlow {
|
|||
, fees_imported{0}
|
||||
, recovered{0}
|
||||
, created{0}
|
||||
, minted{0} {
|
||||
, minted{0}
|
||||
, burned{0} {
|
||||
}
|
||||
bool is_valid() const {
|
||||
return from_prev_blk.is_valid() && minted.is_valid();
|
||||
|
|
|
@ -143,8 +143,13 @@ tick_tock$_ tick:Bool tock:Bool = TickTock;
|
|||
|
||||
_ split_depth:(Maybe (## 5)) special:(Maybe TickTock)
|
||||
code:(Maybe ^Cell) data:(Maybe ^Cell)
|
||||
library:(HashmapE 256 SimpleLib) = StateInit;
|
||||
|
||||
library:(Maybe ^Cell) = StateInit;
|
||||
|
||||
// StateInitWithLibs is used to validate sent and received messages
|
||||
_ split_depth:(Maybe (## 5)) special:(Maybe TickTock)
|
||||
code:(Maybe ^Cell) data:(Maybe ^Cell)
|
||||
library:(HashmapE 256 SimpleLib) = StateInitWithLibs;
|
||||
|
||||
simple_lib$_ public:Bool root:^Cell = SimpleLib;
|
||||
|
||||
message$_ {X:Type} info:CommonMsgInfo
|
||||
|
@ -379,7 +384,7 @@ action_reserve_currency#36e6b809 mode:(## 8)
|
|||
currency:CurrencyCollection = OutAction;
|
||||
libref_hash$0 lib_hash:bits256 = LibRef;
|
||||
libref_ref$1 library:^Cell = LibRef;
|
||||
action_change_library#26fa1dd4 mode:(## 7) { mode <= 2 }
|
||||
action_change_library#26fa1dd4 mode:(## 7)
|
||||
libref:LibRef = OutAction;
|
||||
|
||||
out_list_node$_ prev:^Cell action:OutAction = OutListNode;
|
||||
|
@ -467,6 +472,19 @@ value_flow#b8e48dfb ^[ from_prev_blk:CurrencyCollection
|
|||
minted:CurrencyCollection
|
||||
] = ValueFlow;
|
||||
|
||||
value_flow_v2#3ebf98b7 ^[ from_prev_blk:CurrencyCollection
|
||||
to_next_blk:CurrencyCollection
|
||||
imported:CurrencyCollection
|
||||
exported:CurrencyCollection ]
|
||||
fees_collected:CurrencyCollection
|
||||
burned:CurrencyCollection
|
||||
^[
|
||||
fees_imported:CurrencyCollection
|
||||
recovered:CurrencyCollection
|
||||
created:CurrencyCollection
|
||||
minted:CurrencyCollection
|
||||
] = ValueFlow;
|
||||
|
||||
//
|
||||
//
|
||||
bt_leaf$0 {X:Type} leaf:X = BinTree X;
|
||||
|
@ -590,6 +608,11 @@ _ minter_addr:bits256 = ConfigParam 2; // ConfigParam 0 is used if absent
|
|||
_ fee_collector_addr:bits256 = ConfigParam 3; // ConfigParam 1 is used if absent
|
||||
_ dns_root_addr:bits256 = ConfigParam 4; // root TON DNS resolver
|
||||
|
||||
burning_config#01
|
||||
blackhole_addr:(Maybe bits256)
|
||||
fee_burn_nom:# fee_burn_denom:# { fee_burn_nom <= fee_burn_denom } { fee_burn_denom >= 1 } = BurningConfig;
|
||||
_ BurningConfig = ConfigParam 5;
|
||||
|
||||
_ mint_new_price:Grams mint_add_price:Grams = ConfigParam 6;
|
||||
_ to_mint:ExtraCurrencyCollection = ConfigParam 7;
|
||||
|
||||
|
@ -663,6 +686,8 @@ _#cc utime_since:uint32 bit_price_ps:uint64 cell_price_ps:uint64
|
|||
mc_bit_price_ps:uint64 mc_cell_price_ps:uint64 = StoragePrices;
|
||||
_ (Hashmap 32 StoragePrices) = ConfigParam 18;
|
||||
|
||||
_ global_id:int32 = ConfigParam 19;
|
||||
|
||||
gas_prices#dd gas_price:uint64 gas_limit:uint64 gas_credit:uint64
|
||||
block_gas_limit:uint64 freeze_due_limit:uint64 delete_due_limit:uint64
|
||||
= GasLimitsPrices;
|
||||
|
@ -783,8 +808,8 @@ jetton_bridge_params_v0#00 bridge_address:bits256 oracles_address:bits256 oracle
|
|||
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
|
||||
_ JettonBridgeParams = ConfigParam 81; // BNB->TON token bridge
|
||||
_ JettonBridgeParams = ConfigParam 82; // Polygon->TON token bridge
|
||||
|
||||
|
||||
//
|
||||
|
|
|
@ -855,11 +855,12 @@ Ref<McShardHash> McShardHash::from_block(Ref<vm::Cell> block_root, const ton::Fi
|
|||
ton::RootHash rhash = block_root->get_hash().bits();
|
||||
CurrencyCollection fees_collected, funds_created;
|
||||
if (init_fees) {
|
||||
block::gen::ValueFlow::Record flow;
|
||||
if (!(tlb::unpack_cell(rec.value_flow, flow) && fees_collected.unpack(flow.fees_collected) &&
|
||||
funds_created.unpack(flow.r2.created))) {
|
||||
block::ValueFlow flow;
|
||||
if (!flow.unpack(vm::load_cell_slice_ref(rec.value_flow))) {
|
||||
return {};
|
||||
}
|
||||
fees_collected = flow.fees_collected;
|
||||
funds_created = flow.created;
|
||||
}
|
||||
return Ref<McShardHash>(true, ton::BlockId{ton::ShardIdFull(shard), (unsigned)info.seq_no}, info.start_lt,
|
||||
info.end_lt, info.gen_utime, rhash, fhash, fees_collected, funds_created, ~0U,
|
||||
|
@ -909,11 +910,12 @@ Ref<McShardDescr> McShardDescr::from_block(Ref<vm::Cell> block_root, Ref<vm::Cel
|
|||
ton::RootHash rhash = block_root->get_hash().bits();
|
||||
CurrencyCollection fees_collected, funds_created;
|
||||
if (init_fees) {
|
||||
block::gen::ValueFlow::Record flow;
|
||||
if (!(tlb::unpack_cell(rec.value_flow, flow) && fees_collected.unpack(flow.fees_collected) &&
|
||||
funds_created.unpack(flow.r2.created))) {
|
||||
block::ValueFlow flow;
|
||||
if (!flow.unpack(vm::load_cell_slice_ref(rec.value_flow))) {
|
||||
return {};
|
||||
}
|
||||
fees_collected = flow.fees_collected;
|
||||
funds_created = flow.created;
|
||||
}
|
||||
auto res = Ref<McShardDescr>(true, ton::BlockId{ton::ShardIdFull(shard), (unsigned)info.seq_no}, info.start_lt,
|
||||
info.end_lt, info.gen_utime, rhash, fhash, fees_collected, funds_created, ~0U,
|
||||
|
@ -1954,6 +1956,24 @@ std::unique_ptr<vm::Dictionary> Config::get_suspended_addresses(ton::UnixTime no
|
|||
return std::make_unique<vm::Dictionary>(rec.addresses->prefetch_ref(), 288);
|
||||
}
|
||||
|
||||
BurningConfig Config::get_burning_config() const {
|
||||
td::Ref<vm::Cell> param = get_config_param(5);
|
||||
gen::BurningConfig::Record rec;
|
||||
if (param.is_null() || !tlb::unpack_cell(param, rec)) {
|
||||
return {};
|
||||
}
|
||||
BurningConfig c;
|
||||
c.fee_burn_nom = rec.fee_burn_nom;
|
||||
c.fee_burn_denom = rec.fee_burn_denom;
|
||||
vm::CellSlice& addr = rec.blackhole_addr.write();
|
||||
if (addr.fetch_long(1)) {
|
||||
td::Bits256 x;
|
||||
addr.fetch_bits_to(x.bits(), 256);
|
||||
c.blackhole_addr = x;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
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");
|
||||
|
@ -2200,6 +2220,44 @@ Ref<vm::Cell> ConfigInfo::lookup_library(td::ConstBitPtr root_hash) const {
|
|||
return lib;
|
||||
}
|
||||
|
||||
td::Result<Ref<vm::Tuple>> ConfigInfo::get_prev_blocks_info() const {
|
||||
// [ wc:Integer shard:Integer seqno:Integer root_hash:Integer file_hash:Integer] = BlockId;
|
||||
// [ last_mc_blocks:[BlockId...]
|
||||
// prev_key_block:BlockId ] : PrevBlocksInfo
|
||||
auto block_id_to_tuple = [](const ton::BlockIdExt& block_id) -> vm::Ref<vm::Tuple> {
|
||||
td::RefInt256 shard = td::make_refint(block_id.id.shard);
|
||||
if (shard->sgn() < 0) {
|
||||
shard &= ((td::make_refint(1) << 64) - 1);
|
||||
}
|
||||
return vm::make_tuple_ref(
|
||||
td::make_refint(block_id.id.workchain),
|
||||
std::move(shard),
|
||||
td::make_refint(block_id.id.seqno),
|
||||
td::bits_to_refint(block_id.root_hash.bits(), 256),
|
||||
td::bits_to_refint(block_id.file_hash.bits(), 256));
|
||||
};
|
||||
std::vector<vm::StackEntry> last_mc_blocks;
|
||||
|
||||
last_mc_blocks.push_back(block_id_to_tuple(block_id));
|
||||
for (ton::BlockSeqno seqno = block_id.id.seqno; seqno > 0 && last_mc_blocks.size() < 16; ) {
|
||||
--seqno;
|
||||
ton::BlockIdExt block_id;
|
||||
if (!get_old_mc_block_id(seqno, block_id)) {
|
||||
return td::Status::Error("cannot fetch old mc block");
|
||||
}
|
||||
last_mc_blocks.push_back(block_id_to_tuple(block_id));
|
||||
}
|
||||
|
||||
ton::BlockIdExt last_key_block;
|
||||
ton::LogicalTime last_key_block_lt;
|
||||
if (!get_last_key_block(last_key_block, last_key_block_lt)) {
|
||||
return td::Status::Error("cannot fetch last key block");
|
||||
}
|
||||
return vm::make_tuple_ref(
|
||||
td::make_cnt_ref<std::vector<vm::StackEntry>>(std::move(last_mc_blocks)),
|
||||
block_id_to_tuple(last_key_block));
|
||||
}
|
||||
|
||||
CollatorConfig Config::get_collator_config(bool need_collator_nodes) const {
|
||||
CollatorConfig collator_config;
|
||||
gen::CollatorConfig::Record rec;
|
||||
|
|
|
@ -504,6 +504,22 @@ class ShardConfig {
|
|||
bool set_shard_info(ton::ShardIdFull shard, Ref<vm::Cell> value);
|
||||
};
|
||||
|
||||
struct BurningConfig {
|
||||
td::optional<td::Bits256> blackhole_addr;
|
||||
td::uint32 fee_burn_nom = 0, fee_burn_denom = 1;
|
||||
|
||||
td::RefInt256 calculate_burned_fees(const td::RefInt256& x) const {
|
||||
if (x.is_null()) {
|
||||
return x;
|
||||
}
|
||||
return x * fee_burn_nom / td::make_refint(fee_burn_denom);
|
||||
}
|
||||
|
||||
CurrencyCollection calculate_burned_fees(const CurrencyCollection& x) const {
|
||||
return CurrencyCollection{calculate_burned_fees(x.grams)};
|
||||
}
|
||||
};
|
||||
|
||||
struct CollatorNodeDescr {
|
||||
ton::ShardIdFull shard;
|
||||
ton::NodeIdShort adnl_id;
|
||||
|
@ -629,6 +645,7 @@ class Config {
|
|||
CollatorConfig get_collator_config(bool need_collator_nodes) const;
|
||||
td::Result<SizeLimitsConfig> get_size_limits_config() const;
|
||||
std::unique_ptr<vm::Dictionary> get_suspended_addresses(ton::UnixTime now) const;
|
||||
BurningConfig get_burning_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,
|
||||
|
@ -733,6 +750,7 @@ class ConfigInfo : public Config, public ShardConfig {
|
|||
ton::CatchainSeqno* cc_seqno_delta = nullptr) const;
|
||||
std::vector<ton::ValidatorDescr> compute_validator_set_cc(ton::ShardIdFull shard, ton::UnixTime time,
|
||||
ton::CatchainSeqno* cc_seqno_delta = nullptr) const;
|
||||
td::Result<Ref<vm::Tuple>> get_prev_blocks_info() const;
|
||||
static td::Result<std::unique_ptr<ConfigInfo>> extract_config(std::shared_ptr<vm::StaticBagOfCellsDb> static_boc,
|
||||
int mode = 0);
|
||||
static td::Result<std::unique_ptr<ConfigInfo>> extract_config(Ref<vm::Cell> mc_state_root, int mode = 0);
|
||||
|
|
|
@ -478,7 +478,7 @@ void add_partial_storage_payment(td::BigInt256& payment, ton::UnixTime delta, co
|
|||
b.mul_short(prices.bit_price);
|
||||
}
|
||||
b += c;
|
||||
b.mul_short(delta);
|
||||
b.mul_short(delta).normalize();
|
||||
CHECK(b.sgn() >= 0);
|
||||
payment += b;
|
||||
}
|
||||
|
@ -506,8 +506,7 @@ td::RefInt256 StoragePrices::compute_storage_fees(ton::UnixTime now, const std::
|
|||
}
|
||||
upto = valid_until;
|
||||
}
|
||||
total.unique_write().rshift(16, 1); // divide by 2^16 with ceil rounding to obtain nanograms
|
||||
return total;
|
||||
return td::rshift(total, 16, 1); // divide by 2^16 with ceil rounding to obtain nanograms
|
||||
}
|
||||
|
||||
td::RefInt256 Account::compute_storage_fees(ton::UnixTime now, const std::vector<block::StoragePrices>& pricing) const {
|
||||
|
@ -635,14 +634,15 @@ bool Transaction::unpack_input_msg(bool ihr_delivered, const ActionPhaseConfig*
|
|||
vm::CellBuilder cb;
|
||||
if (!(cs.advance(2) && block::gen::t_StateInit.fetch_to(cs, state_init) &&
|
||||
cb.append_cellslice_bool(std::move(state_init)) && cb.finalize_to(in_msg_state) &&
|
||||
block::gen::t_StateInit.validate_ref(in_msg_state))) {
|
||||
block::gen::t_StateInitWithLibs.validate_ref(in_msg_state))) {
|
||||
LOG(DEBUG) << "cannot parse StateInit in inbound message";
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: { // (just$1 (right$1 _:^StateInit ))
|
||||
if (!(cs.advance(2) && cs.fetch_ref_to(in_msg_state) && block::gen::t_StateInit.validate_ref(in_msg_state))) {
|
||||
if (!(cs.advance(2) && cs.fetch_ref_to(in_msg_state) &&
|
||||
block::gen::t_StateInitWithLibs.validate_ref(in_msg_state))) {
|
||||
LOG(DEBUG) << "cannot parse ^StateInit in inbound message";
|
||||
return false;
|
||||
}
|
||||
|
@ -671,6 +671,12 @@ bool Transaction::unpack_input_msg(bool ihr_delivered, const ActionPhaseConfig*
|
|||
return false;
|
||||
}
|
||||
total_fees += in_fwd_fee;
|
||||
if (account.workchain == ton::masterchainId && cfg->mc_blackhole_addr &&
|
||||
cfg->mc_blackhole_addr.value() == account.addr) {
|
||||
blackhole_burned.grams = msg_balance_remaining.grams;
|
||||
msg_balance_remaining.grams = td::zero_refint();
|
||||
LOG(DEBUG) << "Burning " << blackhole_burned.grams << " nanoton (blackhole address)";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -724,6 +730,9 @@ bool Transaction::prepare_storage_phase(const StoragePhaseConfig& cfg, bool forc
|
|||
}
|
||||
break;
|
||||
}
|
||||
if (cfg.enable_due_payment) {
|
||||
due_payment = total_due;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (adjust_msg_value && msg_balance_remaining.grams > balance.grams) {
|
||||
|
@ -917,7 +926,7 @@ Ref<vm::Tuple> Transaction::prepare_vm_c7(const ComputePhaseConfig& cfg) const {
|
|||
throw CollatorError{"cannot generate valid SmartContractInfo"};
|
||||
return {};
|
||||
}
|
||||
auto tuple = vm::make_tuple_ref(
|
||||
std::vector<vm::StackEntry> tuple = {
|
||||
td::make_refint(0x076ef1ea), // [ magic:0x076ef1ea
|
||||
td::zero_refint(), // actions:Integer
|
||||
td::zero_refint(), // msgs_sent:Integer
|
||||
|
@ -926,10 +935,27 @@ Ref<vm::Tuple> Transaction::prepare_vm_c7(const ComputePhaseConfig& cfg) const {
|
|||
td::make_refint(start_lt), // trans_lt:Integer
|
||||
std::move(rand_seed_int), // rand_seed:Integer
|
||||
balance.as_vm_tuple(), // balance_remaining:[Integer (Maybe Cell)]
|
||||
my_addr, // myself:MsgAddressInt
|
||||
vm::StackEntry::maybe(cfg.global_config)); // global_config:(Maybe Cell) ] = SmartContractInfo;
|
||||
LOG(DEBUG) << "SmartContractInfo initialized with " << vm::StackEntry(tuple).to_string();
|
||||
return vm::make_tuple_ref(std::move(tuple));
|
||||
my_addr, // myself:MsgAddressInt
|
||||
vm::StackEntry::maybe(cfg.global_config) // global_config:(Maybe Cell) ] = SmartContractInfo;
|
||||
};
|
||||
if (cfg.global_version >= 4) {
|
||||
tuple.push_back(new_code); // code:Cell
|
||||
if (msg_balance_remaining.is_valid()) {
|
||||
tuple.push_back(msg_balance_remaining.as_vm_tuple()); // in_msg_value:[Integer (Maybe Cell)]
|
||||
} else {
|
||||
tuple.push_back(block::CurrencyCollection::zero().as_vm_tuple());
|
||||
}
|
||||
tuple.push_back(storage_phase->fees_collected); // storage_fees:Integer
|
||||
|
||||
// See crypto/block/mc-config.cpp#2115 (get_prev_blocks_info)
|
||||
// [ wc:Integer shard:Integer seqno:Integer root_hash:Integer file_hash:Integer] = BlockId;
|
||||
// [ last_mc_blocks:[BlockId...]
|
||||
// prev_key_block:BlockId ] : PrevBlocksInfo
|
||||
tuple.push_back(cfg.prev_blocks_info.not_null() ? vm::StackEntry(cfg.prev_blocks_info) : vm::StackEntry());
|
||||
}
|
||||
auto tuple_ref = td::make_cnt_ref<std::vector<vm::StackEntry>>(std::move(tuple));
|
||||
LOG(DEBUG) << "SmartContractInfo initialized with " << vm::StackEntry(tuple_ref).to_string();
|
||||
return vm::make_tuple_ref(std::move(tuple_ref));
|
||||
}
|
||||
|
||||
int output_actions_count(Ref<vm::Cell> list) {
|
||||
|
@ -1074,12 +1100,19 @@ bool Transaction::prepare_compute_phase(const ComputePhaseConfig& cfg) {
|
|||
if (cfg.vm_log_verbosity > 1) {
|
||||
vm_log.log_mask |= vm::VmLog::ExecLocation;
|
||||
if (cfg.vm_log_verbosity > 2) {
|
||||
vm_log.log_mask |= vm::VmLog::DumpStack | vm::VmLog::GasRemaining;
|
||||
vm_log.log_mask |= vm::VmLog::GasRemaining;
|
||||
if (cfg.vm_log_verbosity > 3) {
|
||||
vm_log.log_mask |= vm::VmLog::DumpStack;
|
||||
if (cfg.vm_log_verbosity > 4) {
|
||||
vm_log.log_mask |= vm::VmLog::DumpStackVerbose;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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_global_version(cfg.global_version);
|
||||
vm.set_c7(prepare_vm_c7(cfg)); // tuple with SmartContractInfo
|
||||
vm.set_chksig_always_succeed(cfg.ignore_chksig);
|
||||
// vm.incr_stack_trace(1); // enable stack dump after each step
|
||||
|
@ -1161,6 +1194,7 @@ bool Transaction::prepare_action_phase(const ActionPhaseConfig& cfg) {
|
|||
ap.total_fwd_fees = td::zero_refint();
|
||||
ap.total_action_fees = td::zero_refint();
|
||||
ap.reserved_balance.set_zero();
|
||||
ap.action_fine = td::zero_refint();
|
||||
|
||||
td::Ref<vm::Cell> old_code = new_code, old_data = new_data, old_library = new_library;
|
||||
auto enforce_state_limits = [&]() {
|
||||
|
@ -1227,6 +1261,7 @@ bool Transaction::prepare_action_phase(const ActionPhaseConfig& cfg) {
|
|||
int tag = block::gen::t_OutAction.get_tag(cs);
|
||||
CHECK(tag >= 0);
|
||||
int err_code = 34;
|
||||
ap.need_bounce_on_fail = false;
|
||||
switch (tag) {
|
||||
case block::gen::OutAction::action_set_code:
|
||||
err_code = try_action_set_code(cs, ap, cfg);
|
||||
|
@ -1257,12 +1292,24 @@ 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 action phase fails
|
||||
// This is reuqired here because changes to libraries are applied even if actipn phase fails
|
||||
enforce_state_limits();
|
||||
if (cfg.action_fine_enabled) {
|
||||
ap.action_fine = std::min(ap.action_fine, balance.grams);
|
||||
ap.total_action_fees = ap.action_fine;
|
||||
balance.grams -= ap.action_fine;
|
||||
total_fees += ap.action_fine;
|
||||
}
|
||||
if (ap.need_bounce_on_fail) {
|
||||
ap.bounce = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (cfg.action_fine_enabled) {
|
||||
ap.total_action_fees += ap.action_fine;
|
||||
}
|
||||
end_lt = ap.end_lt;
|
||||
if (ap.new_code.not_null()) {
|
||||
new_code = ap.new_code;
|
||||
|
@ -1308,7 +1355,17 @@ int Transaction::try_action_change_library(vm::CellSlice& cs, ActionPhase& ap, c
|
|||
if (!tlb::unpack_exact(cs, rec)) {
|
||||
return -1;
|
||||
}
|
||||
// mode: +0 = remove library, +1 = add private library, +2 = add public library
|
||||
// mode: +0 = remove library, +1 = add private library, +2 = add public library, +16 - bounce on fail
|
||||
if (rec.mode & 16) {
|
||||
if (!cfg.bounce_on_fail_enabled) {
|
||||
return -1;
|
||||
}
|
||||
ap.need_bounce_on_fail = true;
|
||||
rec.mode &= ~16;
|
||||
}
|
||||
if (rec.mode > 2) {
|
||||
return -1;
|
||||
}
|
||||
Ref<vm::Cell> lib_ref = rec.libref->prefetch_ref();
|
||||
ton::Bits256 hash;
|
||||
if (lib_ref.not_null()) {
|
||||
|
@ -1522,9 +1579,22 @@ bool Transaction::check_rewrite_dest_addr(Ref<vm::CellSlice>& dest_addr, const A
|
|||
int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap, const ActionPhaseConfig& cfg,
|
||||
int redoing) {
|
||||
block::gen::OutAction::Record_action_send_msg act_rec;
|
||||
// mode: +128 = attach all remaining balance, +64 = attach all remaining balance of the inbound message, +32 = delete smart contract if balance becomes zero, +1 = pay message fees, +2 = skip if message cannot be sent
|
||||
// mode:
|
||||
// +128 = attach all remaining balance
|
||||
// +64 = attach all remaining balance of the inbound message
|
||||
// +32 = delete smart contract if balance becomes zero
|
||||
// +1 = pay message fees
|
||||
// +2 = skip if message cannot be sent
|
||||
// +16 = bounce if action fails
|
||||
vm::CellSlice cs{cs0};
|
||||
if (!tlb::unpack_exact(cs, act_rec) || (act_rec.mode & ~0xe3) || (act_rec.mode & 0xc0) == 0xc0) {
|
||||
if (!tlb::unpack_exact(cs, act_rec)) {
|
||||
return -1;
|
||||
}
|
||||
if ((act_rec.mode & 16) && cfg.bounce_on_fail_enabled) {
|
||||
act_rec.mode &= ~16;
|
||||
ap.need_bounce_on_fail = true;
|
||||
}
|
||||
if ((act_rec.mode & ~0xe3) || (act_rec.mode & 0xc0) == 0xc0) {
|
||||
return -1;
|
||||
}
|
||||
bool skip_invalid = (act_rec.mode & 2);
|
||||
|
@ -1534,6 +1604,10 @@ int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap,
|
|||
if (!tlb::type_unpack_cell(act_rec.out_msg, block::gen::t_MessageRelaxed_Any, msg)) {
|
||||
return -1;
|
||||
}
|
||||
if (!block::tlb::validate_message_relaxed_libs(act_rec.out_msg)) {
|
||||
LOG(DEBUG) << "outbound message has invalid libs in StateInit";
|
||||
return -1;
|
||||
}
|
||||
if (redoing >= 1) {
|
||||
if (msg.init->size_refs() >= 2) {
|
||||
LOG(DEBUG) << "moving the StateInit of a suggested outbound message into a separate cell";
|
||||
|
@ -1547,7 +1621,7 @@ int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap,
|
|||
&& cb.store_long_bool(3, 2) // (just (right ... ))
|
||||
&& cb.store_ref_bool(std::move(cell)) // z:^StateInit
|
||||
&& cb.finalize_to(cell));
|
||||
msg.init = vm::load_cell_slice_ref(std::move(cell));
|
||||
msg.init = vm::load_cell_slice_ref(cell);
|
||||
} else {
|
||||
redoing = 2;
|
||||
}
|
||||
|
@ -1564,7 +1638,7 @@ int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap,
|
|||
&& cb.store_long_bool(1, 1) // (right ... )
|
||||
&& cb.store_ref_bool(std::move(cell)) // x:^X
|
||||
&& cb.finalize_to(cell));
|
||||
msg.body = vm::load_cell_slice_ref(std::move(cell));
|
||||
msg.body = vm::load_cell_slice_ref(cell);
|
||||
}
|
||||
|
||||
block::gen::CommonMsgInfoRelaxed::Record_int_msg_info info;
|
||||
|
@ -1612,30 +1686,84 @@ int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap,
|
|||
|
||||
// fetch message pricing info
|
||||
const MsgPrices& msg_prices = cfg.fetch_msg_prices(to_mc || account.is_masterchain());
|
||||
// If action fails, account is required to pay fine_per_cell for every visited cell
|
||||
// Number of visited cells is limited depending on available funds
|
||||
unsigned max_cells = cfg.size_limits.max_msg_cells;
|
||||
td::uint64 fine_per_cell = 0;
|
||||
if (cfg.action_fine_enabled && !account.is_special) {
|
||||
fine_per_cell = (msg_prices.cell_price >> 16) / 4;
|
||||
td::RefInt256 funds = ap.remaining_balance.grams;
|
||||
if (!ext_msg && !(act_rec.mode & 0x80) && !(act_rec.mode & 1)) {
|
||||
if (!block::tlb::t_CurrencyCollection.validate_csr(info.value)) {
|
||||
LOG(DEBUG) << "invalid value:CurrencyCollection in proposed outbound message";
|
||||
return skip_invalid ? 0 : 37;
|
||||
}
|
||||
block::CurrencyCollection value;
|
||||
CHECK(value.unpack(info.value));
|
||||
CHECK(value.grams.not_null());
|
||||
td::RefInt256 new_funds = value.grams;
|
||||
if (act_rec.mode & 0x40) {
|
||||
if (msg_balance_remaining.is_valid()) {
|
||||
new_funds += msg_balance_remaining.grams;
|
||||
}
|
||||
if (compute_phase) {
|
||||
new_funds -= compute_phase->gas_fees;
|
||||
}
|
||||
new_funds -= ap.action_fine;
|
||||
if (new_funds->sgn() < 0) {
|
||||
LOG(DEBUG)
|
||||
<< "not enough value to transfer with the message: all of the inbound message value has been consumed";
|
||||
return skip_invalid ? 0 : 37;
|
||||
}
|
||||
}
|
||||
funds = std::min(funds, new_funds);
|
||||
}
|
||||
if (funds->cmp(max_cells * fine_per_cell) < 0) {
|
||||
max_cells = static_cast<unsigned>((funds / td::make_refint(fine_per_cell))->to_long());
|
||||
}
|
||||
}
|
||||
// compute size of message
|
||||
vm::CellStorageStat sstat; // for message size
|
||||
vm::CellStorageStat sstat(max_cells); // for message size
|
||||
// preliminary storage estimation of the resulting message
|
||||
unsigned max_merkle_depth = 0;
|
||||
auto add_used_storage = [&](const auto& x, unsigned skip_root_count) {
|
||||
auto add_used_storage = [&](const auto& x, unsigned skip_root_count) -> td::Status {
|
||||
if (x.not_null()) {
|
||||
auto res = sstat.add_used_storage(x, true, skip_root_count).move_as_ok();
|
||||
TRY_RESULT(res, sstat.add_used_storage(x, true, skip_root_count));
|
||||
max_merkle_depth = std::max(max_merkle_depth, res.max_merkle_depth);
|
||||
}
|
||||
return td::Status::OK();
|
||||
};
|
||||
add_used_storage(msg.init, 3); // message init
|
||||
add_used_storage(msg.body, 3); // message body (the root cell itself is not counted)
|
||||
if (!ext_msg) {
|
||||
add_used_storage(info.value->prefetch_ref(), 0);
|
||||
}
|
||||
LOG(DEBUG) << "storage paid for a message: " << sstat.cells << " cells, " << sstat.bits << " bits";
|
||||
if (sstat.bits > cfg.size_limits.max_msg_bits || sstat.cells > cfg.size_limits.max_msg_cells) {
|
||||
auto collect_fine = [&] {
|
||||
if (cfg.action_fine_enabled && !account.is_special) {
|
||||
td::uint64 fine = fine_per_cell * std::min<td::uint64>(max_cells, sstat.cells);
|
||||
if (ap.remaining_balance.grams->cmp(fine) < 0) {
|
||||
fine = ap.remaining_balance.grams->to_long();
|
||||
}
|
||||
ap.action_fine += fine;
|
||||
ap.remaining_balance.grams -= fine;
|
||||
}
|
||||
};
|
||||
if (sstat.cells > max_cells && max_cells < cfg.size_limits.max_msg_cells) {
|
||||
LOG(DEBUG) << "not enough funds to process a message (max_cells=" << max_cells << ")";
|
||||
collect_fine();
|
||||
return skip_invalid ? 0 : 40;
|
||||
}
|
||||
if (sstat.bits > cfg.size_limits.max_msg_bits || sstat.cells > max_cells) {
|
||||
LOG(DEBUG) << "message too large, invalid";
|
||||
collect_fine();
|
||||
return skip_invalid ? 0 : 40;
|
||||
}
|
||||
if (max_merkle_depth > max_allowed_merkle_depth) {
|
||||
LOG(DEBUG) << "message has too big merkle depth, invalid";
|
||||
collect_fine();
|
||||
return skip_invalid ? 0 : 40;
|
||||
}
|
||||
LOG(DEBUG) << "storage paid for a message: " << sstat.cells << " cells, " << sstat.bits << " bits";
|
||||
|
||||
// compute forwarding fees
|
||||
auto fees_c = msg_prices.compute_fwd_ihr_fees(sstat.cells, sstat.bits, info.ihr_disabled);
|
||||
|
@ -1664,6 +1792,7 @@ int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap,
|
|||
// ...
|
||||
if (!block::tlb::t_CurrencyCollection.validate_csr(info.value)) {
|
||||
LOG(DEBUG) << "invalid value:CurrencyCollection in proposed outbound message";
|
||||
collect_fine();
|
||||
return skip_invalid ? 0 : 37;
|
||||
}
|
||||
if (info.ihr_disabled) {
|
||||
|
@ -1682,11 +1811,15 @@ int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap,
|
|||
} else if (act_rec.mode & 0x40) {
|
||||
// attach all remaining balance of the inbound message (in addition to the original value)
|
||||
req += msg_balance_remaining;
|
||||
if (!(act_rec.mode & 1) && compute_phase) {
|
||||
req -= compute_phase->gas_fees;
|
||||
if (!(act_rec.mode & 1)) {
|
||||
req -= ap.action_fine;
|
||||
if (compute_phase) {
|
||||
req -= compute_phase->gas_fees;
|
||||
}
|
||||
if (!req.is_valid()) {
|
||||
LOG(DEBUG)
|
||||
<< "not enough value to transfer with the message: all of the inbound message value has been consumed";
|
||||
collect_fine();
|
||||
return skip_invalid ? 0 : 37;
|
||||
}
|
||||
}
|
||||
|
@ -1702,6 +1835,7 @@ int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap,
|
|||
// receiver pays the fees (but cannot)
|
||||
LOG(DEBUG) << "not enough value attached to the message to pay forwarding fees : have " << req.grams << ", need "
|
||||
<< fees_total;
|
||||
collect_fine();
|
||||
return skip_invalid ? 0 : 37; // not enough grams
|
||||
} else {
|
||||
// decrease message value
|
||||
|
@ -1712,6 +1846,7 @@ int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap,
|
|||
if (ap.remaining_balance.grams < req_grams_brutto) {
|
||||
LOG(DEBUG) << "not enough grams to transfer with the message : remaining balance is "
|
||||
<< ap.remaining_balance.to_str() << ", need " << req_grams_brutto << " (including forwarding fees)";
|
||||
collect_fine();
|
||||
return skip_invalid ? 0 : 37; // not enough grams
|
||||
}
|
||||
|
||||
|
@ -1721,6 +1856,7 @@ int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap,
|
|||
LOG(DEBUG) << "not enough extra currency to send with the message: "
|
||||
<< block::CurrencyCollection{0, req.extra}.to_str() << " required, only "
|
||||
<< block::CurrencyCollection{0, ap.remaining_balance.extra}.to_str() << " available";
|
||||
collect_fine();
|
||||
return skip_invalid ? 0 : 38; // not enough (extra) funds
|
||||
}
|
||||
if (ap.remaining_balance.extra.not_null() || req.extra.not_null()) {
|
||||
|
@ -1743,7 +1879,11 @@ int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap,
|
|||
vm::CellBuilder cb;
|
||||
if (!tlb::type_pack(cb, block::gen::t_MessageRelaxed_Any, msg)) {
|
||||
LOG(DEBUG) << "outbound message does not fit into a cell after rewriting";
|
||||
return redoing < 2 ? -2 : (skip_invalid ? 0 : 39);
|
||||
if (redoing == 2) {
|
||||
collect_fine();
|
||||
return skip_invalid ? 0 : 39;
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
new_msg_bits = cb.size();
|
||||
|
@ -1765,6 +1905,7 @@ int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap,
|
|||
// external messages also have forwarding fees
|
||||
if (ap.remaining_balance.grams < fwd_fee) {
|
||||
LOG(DEBUG) << "not enough funds to pay for an outbound external message";
|
||||
collect_fine();
|
||||
return skip_invalid ? 0 : 37; // not enough grams
|
||||
}
|
||||
// repack message
|
||||
|
@ -1778,7 +1919,11 @@ int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap,
|
|||
vm::CellBuilder cb;
|
||||
if (!tlb::type_pack(cb, block::gen::t_MessageRelaxed_Any, msg)) {
|
||||
LOG(DEBUG) << "outbound message does not fit into a cell after rewriting";
|
||||
return redoing < 2 ? -2 : (skip_invalid ? 0 : 39);
|
||||
if (redoing == 2) {
|
||||
collect_fine();
|
||||
return (skip_invalid ? 0 : 39);
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
new_msg_bits = cb.size();
|
||||
|
@ -1793,12 +1938,14 @@ int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap,
|
|||
|
||||
if (!block::tlb::t_Message.validate_ref(new_msg)) {
|
||||
LOG(ERROR) << "generated outbound message is not a valid (Message Any) according to hand-written check";
|
||||
collect_fine();
|
||||
return -1;
|
||||
}
|
||||
if (!block::gen::t_Message_Any.validate_ref(new_msg)) {
|
||||
LOG(ERROR) << "generated outbound message is not a valid (Message Any) according to automated check";
|
||||
block::gen::t_Message_Any.print_ref(std::cerr, new_msg);
|
||||
vm::load_cell_slice(new_msg).print_rec(std::cerr);
|
||||
collect_fine();
|
||||
return -1;
|
||||
}
|
||||
if (verbosity > 2) {
|
||||
|
@ -1826,7 +1973,14 @@ int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap,
|
|||
|
||||
int Transaction::try_action_reserve_currency(vm::CellSlice& cs, ActionPhase& ap, const ActionPhaseConfig& cfg) {
|
||||
block::gen::OutAction::Record_action_reserve_currency rec;
|
||||
if (!tlb::unpack_exact(cs, rec) || (rec.mode & ~15)) {
|
||||
if (!tlb::unpack_exact(cs, rec)) {
|
||||
return -1;
|
||||
}
|
||||
if ((rec.mode & 16) && cfg.bounce_on_fail_enabled) {
|
||||
rec.mode &= ~16;
|
||||
ap.need_bounce_on_fail = true;
|
||||
}
|
||||
if (rec.mode & ~15) {
|
||||
return -1;
|
||||
}
|
||||
int mode = rec.mode;
|
||||
|
@ -1973,6 +2127,9 @@ bool Transaction::prepare_bounce_phase(const ActionPhaseConfig& cfg) {
|
|||
if (compute_phase && compute_phase->gas_fees.not_null()) {
|
||||
msg_balance.grams -= compute_phase->gas_fees;
|
||||
}
|
||||
if (action_phase && action_phase->action_fine.not_null()) {
|
||||
msg_balance.grams -= action_phase->action_fine;
|
||||
}
|
||||
if ((msg_balance.grams < 0) ||
|
||||
(msg_balance.grams->signed_fits_bits(64) && msg_balance.grams->to_long() < (long long)bp.fwd_fees)) {
|
||||
// not enough funds
|
||||
|
@ -2553,17 +2710,27 @@ bool Account::libraries_changed() const {
|
|||
}
|
||||
}
|
||||
|
||||
td::Status FetchConfigParams::fetch_config_params(const block::Config& config,
|
||||
Ref<vm::Cell>* old_mparams,
|
||||
std::vector<block::StoragePrices>* storage_prices,
|
||||
block::StoragePhaseConfig* storage_phase_cfg,
|
||||
td::BitArray<256>* rand_seed,
|
||||
block::ComputePhaseConfig* compute_phase_cfg,
|
||||
block::ActionPhaseConfig* action_phase_cfg,
|
||||
td::RefInt256* masterchain_create_fee,
|
||||
td::RefInt256* basechain_create_fee,
|
||||
ton::WorkchainId wc,
|
||||
ton::UnixTime now) {
|
||||
td::Status FetchConfigParams::fetch_config_params(
|
||||
const block::ConfigInfo& config, Ref<vm::Cell>* old_mparams, std::vector<block::StoragePrices>* storage_prices,
|
||||
StoragePhaseConfig* storage_phase_cfg, td::BitArray<256>* rand_seed, ComputePhaseConfig* compute_phase_cfg,
|
||||
ActionPhaseConfig* action_phase_cfg, td::RefInt256* masterchain_create_fee, td::RefInt256* basechain_create_fee,
|
||||
ton::WorkchainId wc, ton::UnixTime now) {
|
||||
auto prev_blocks_info = config.get_prev_blocks_info();
|
||||
if (prev_blocks_info.is_error()) {
|
||||
return prev_blocks_info.move_as_error_prefix(
|
||||
td::Status::Error(-668, "cannot fetch prev blocks info from masterchain configuration: "));
|
||||
}
|
||||
return fetch_config_params(config, prev_blocks_info.move_as_ok(), old_mparams, storage_prices, storage_phase_cfg,
|
||||
rand_seed, compute_phase_cfg, action_phase_cfg, masterchain_create_fee,
|
||||
basechain_create_fee, wc, now);
|
||||
}
|
||||
|
||||
td::Status FetchConfigParams::fetch_config_params(
|
||||
const block::Config& config, td::Ref<vm::Tuple> prev_blocks_info, Ref<vm::Cell>* old_mparams,
|
||||
std::vector<block::StoragePrices>* storage_prices, StoragePhaseConfig* storage_phase_cfg,
|
||||
td::BitArray<256>* rand_seed, ComputePhaseConfig* compute_phase_cfg, ActionPhaseConfig* action_phase_cfg,
|
||||
td::RefInt256* masterchain_create_fee, td::RefInt256* basechain_create_fee, ton::WorkchainId wc,
|
||||
ton::UnixTime now) {
|
||||
*old_mparams = config.get_config_param(9);
|
||||
{
|
||||
auto res = config.get_storage_prices();
|
||||
|
@ -2588,9 +2755,14 @@ td::Status FetchConfigParams::fetch_config_params(const block::Config& config,
|
|||
storage_phase_cfg->delete_due_limit)) {
|
||||
return td::Status::Error(-668, "cannot unpack current gas prices and limits from masterchain configuration");
|
||||
}
|
||||
storage_phase_cfg->enable_due_payment = config.get_global_version() >= 4;
|
||||
compute_phase_cfg->block_rand_seed = *rand_seed;
|
||||
compute_phase_cfg->max_vm_data_depth = size_limits.max_vm_data_depth;
|
||||
compute_phase_cfg->global_config = config.get_root_cell();
|
||||
compute_phase_cfg->global_version = config.get_global_version();
|
||||
if (compute_phase_cfg->global_version >= 4) {
|
||||
compute_phase_cfg->prev_blocks_info = std::move(prev_blocks_info);
|
||||
}
|
||||
compute_phase_cfg->suspended_addresses = config.get_suspended_addresses(now);
|
||||
}
|
||||
{
|
||||
|
@ -2613,6 +2785,9 @@ td::Status FetchConfigParams::fetch_config_params(const block::Config& config,
|
|||
action_phase_cfg->workchains = &config.get_workchain_list();
|
||||
action_phase_cfg->bounce_msg_body = (config.has_capability(ton::capBounceMsgBody) ? 256 : 0);
|
||||
action_phase_cfg->size_limits = size_limits;
|
||||
action_phase_cfg->action_fine_enabled = config.get_global_version() >= 4;
|
||||
action_phase_cfg->bounce_on_fail_enabled = config.get_global_version() >= 4;
|
||||
action_phase_cfg->mc_blackhole_addr = config.get_burning_config().blackhole_addr;
|
||||
}
|
||||
{
|
||||
// fetch block_grams_created
|
||||
|
|
|
@ -80,6 +80,7 @@ struct StoragePhaseConfig {
|
|||
const std::vector<block::StoragePrices>* pricing{nullptr};
|
||||
td::RefInt256 freeze_due_limit;
|
||||
td::RefInt256 delete_due_limit;
|
||||
bool enable_due_payment{false};
|
||||
StoragePhaseConfig() = default;
|
||||
StoragePhaseConfig(const std::vector<block::StoragePrices>* _pricing, td::RefInt256 freeze_limit = {},
|
||||
td::RefInt256 delete_limit = {})
|
||||
|
@ -112,8 +113,11 @@ struct ComputePhaseConfig {
|
|||
bool ignore_chksig{false};
|
||||
bool with_vm_log{false};
|
||||
td::uint16 max_vm_data_depth = 512;
|
||||
int global_version = 0;
|
||||
Ref<vm::Tuple> prev_blocks_info;
|
||||
std::unique_ptr<vm::Dictionary> suspended_addresses;
|
||||
int vm_log_verbosity = 0;
|
||||
|
||||
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();
|
||||
|
@ -153,6 +157,9 @@ struct ActionPhaseConfig {
|
|||
MsgPrices fwd_mc; // from/to masterchain
|
||||
SizeLimitsConfig size_limits;
|
||||
const WorkchainSet* workchains{nullptr};
|
||||
bool action_fine_enabled{false};
|
||||
bool bounce_on_fail_enabled{false};
|
||||
td::optional<td::Bits256> mc_blackhole_addr;
|
||||
const MsgPrices& fetch_msg_prices(bool is_masterchain) const {
|
||||
return is_masterchain ? fwd_mc : fwd_std;
|
||||
}
|
||||
|
@ -209,6 +216,9 @@ struct ActionPhase {
|
|||
std::vector<Ref<vm::Cell>> out_msgs;
|
||||
ton::LogicalTime end_lt;
|
||||
unsigned long long tot_msg_bits{0}, tot_msg_cells{0};
|
||||
td::RefInt256 action_fine;
|
||||
bool need_bounce_on_fail = false;
|
||||
bool bounce = false;
|
||||
};
|
||||
|
||||
struct BouncePhase {
|
||||
|
@ -332,6 +342,7 @@ struct Transaction {
|
|||
td::RefInt256 due_payment;
|
||||
td::RefInt256 in_fwd_fee, msg_fwd_fees;
|
||||
block::CurrencyCollection total_fees{0};
|
||||
block::CurrencyCollection blackhole_burned{0};
|
||||
ton::UnixTime last_paid;
|
||||
Ref<vm::Cell> root;
|
||||
Ref<vm::Cell> new_total_state;
|
||||
|
@ -400,17 +411,18 @@ struct Transaction {
|
|||
} // namespace transaction
|
||||
|
||||
struct FetchConfigParams {
|
||||
static td::Status fetch_config_params(const block::Config& config,
|
||||
Ref<vm::Cell>* old_mparams,
|
||||
std::vector<block::StoragePrices>* storage_prices,
|
||||
StoragePhaseConfig* storage_phase_cfg,
|
||||
td::BitArray<256>* rand_seed,
|
||||
ComputePhaseConfig* compute_phase_cfg,
|
||||
ActionPhaseConfig* action_phase_cfg,
|
||||
td::RefInt256* masterchain_create_fee,
|
||||
td::RefInt256* basechain_create_fee,
|
||||
ton::WorkchainId wc,
|
||||
ton::UnixTime now);
|
||||
static td::Status fetch_config_params(const block::ConfigInfo& config, Ref<vm::Cell>* old_mparams,
|
||||
std::vector<block::StoragePrices>* storage_prices,
|
||||
StoragePhaseConfig* storage_phase_cfg, td::BitArray<256>* rand_seed,
|
||||
ComputePhaseConfig* compute_phase_cfg, ActionPhaseConfig* action_phase_cfg,
|
||||
td::RefInt256* masterchain_create_fee, td::RefInt256* basechain_create_fee,
|
||||
ton::WorkchainId wc, ton::UnixTime now);
|
||||
static td::Status fetch_config_params(const block::Config& config, Ref<vm::Tuple> prev_blocks_info,
|
||||
Ref<vm::Cell>* old_mparams, std::vector<block::StoragePrices>* storage_prices,
|
||||
StoragePhaseConfig* storage_phase_cfg, td::BitArray<256>* rand_seed,
|
||||
ComputePhaseConfig* compute_phase_cfg, ActionPhaseConfig* action_phase_cfg,
|
||||
td::RefInt256* masterchain_create_fee, td::RefInt256* basechain_create_fee,
|
||||
ton::WorkchainId wc, ton::UnixTime now);
|
||||
};
|
||||
|
||||
} // namespace block
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue