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
|
@ -682,7 +682,7 @@ bool ValidateQuery::try_unpack_mc_state() {
|
|||
mc_state_root_,
|
||||
block::ConfigInfo::needShardHashes | block::ConfigInfo::needLibraries | block::ConfigInfo::needValidatorSet |
|
||||
block::ConfigInfo::needWorkchainInfo | block::ConfigInfo::needStateExtraRoot |
|
||||
block::ConfigInfo::needCapabilities |
|
||||
block::ConfigInfo::needCapabilities | block::ConfigInfo::needPrevBlocks |
|
||||
(is_masterchain() ? block::ConfigInfo::needAccountsRoot | block::ConfigInfo::needSpecialSmc : 0));
|
||||
if (res.is_error()) {
|
||||
return fatal_error(-666, "cannot extract configuration from reference masterchain state "s + mc_blkid_.to_str() +
|
||||
|
@ -785,10 +785,20 @@ bool ValidateQuery::fetch_config_params() {
|
|||
storage_phase_cfg_.delete_due_limit)) {
|
||||
return fatal_error("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_.libraries = std::make_unique<vm::Dictionary>(config_->get_libraries_root(), 256);
|
||||
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) {
|
||||
auto prev_blocks_info = config_->get_prev_blocks_info();
|
||||
if (prev_blocks_info.is_error()) {
|
||||
return fatal_error(prev_blocks_info.move_as_error_prefix(
|
||||
"cannot fetch prev blocks info from masterchain configuration: "));
|
||||
}
|
||||
compute_phase_cfg_.prev_blocks_info = prev_blocks_info.move_as_ok();
|
||||
}
|
||||
compute_phase_cfg_.suspended_addresses = config_->get_suspended_addresses(now_);
|
||||
}
|
||||
{
|
||||
|
@ -811,6 +821,9 @@ bool ValidateQuery::fetch_config_params() {
|
|||
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
|
||||
|
@ -2193,13 +2206,13 @@ bool ValidateQuery::unpack_block_data() {
|
|||
auto outmsg_cs = vm::load_cell_slice_ref(std::move(extra.out_msg_descr));
|
||||
// run some hand-written checks from block::tlb::
|
||||
// (automatic tests from block::gen:: have been already run for the entire block)
|
||||
if (!block::tlb::t_InMsgDescr.validate_upto(1000000, *inmsg_cs)) {
|
||||
if (!block::tlb::t_InMsgDescr.validate_upto(10000000, *inmsg_cs)) {
|
||||
return reject_query("InMsgDescr of the new block failed to pass handwritten validity tests");
|
||||
}
|
||||
if (!block::tlb::t_OutMsgDescr.validate_upto(1000000, *outmsg_cs)) {
|
||||
if (!block::tlb::t_OutMsgDescr.validate_upto(10000000, *outmsg_cs)) {
|
||||
return reject_query("OutMsgDescr of the new block failed to pass handwritten validity tests");
|
||||
}
|
||||
if (!block::tlb::t_ShardAccountBlocks.validate_ref(1000000, extra.account_blocks)) {
|
||||
if (!block::tlb::t_ShardAccountBlocks.validate_ref(10000000, extra.account_blocks)) {
|
||||
return reject_query("ShardAccountBlocks of the new block failed to pass handwritten validity tests");
|
||||
}
|
||||
in_msg_dict_ = std::make_unique<vm::AugmentedDictionary>(std::move(inmsg_cs), 256, block::tlb::aug_InMsgDescr);
|
||||
|
@ -2243,6 +2256,11 @@ bool ValidateQuery::unpack_precheck_value_flow(Ref<vm::Cell> value_flow_root) {
|
|||
return reject_query("ValueFlow of block "s + id_.to_str() +
|
||||
" is invalid (non-zero recovered value in a non-masterchain block)");
|
||||
}
|
||||
if (!is_masterchain() && !value_flow_.burned.is_zero()) {
|
||||
LOG(INFO) << "invalid value flow: " << os.str();
|
||||
return reject_query("ValueFlow of block "s + id_.to_str() +
|
||||
" is invalid (non-zero burned value in a non-masterchain block)");
|
||||
}
|
||||
if (!value_flow_.recovered.is_zero() && recover_create_msg_.is_null()) {
|
||||
return reject_query("ValueFlow of block "s + id_.to_str() +
|
||||
" has a non-zero recovered fees value, but there is no recovery InMsg");
|
||||
|
@ -2325,15 +2343,10 @@ bool ValidateQuery::unpack_precheck_value_flow(Ref<vm::Cell> value_flow_root) {
|
|||
"cannot unpack CurrencyCollection with total transaction fees from the augmentation of the ShardAccountBlocks "
|
||||
"dictionary");
|
||||
}
|
||||
auto expected_fees = value_flow_.fees_imported + value_flow_.created + transaction_fees_ + import_fees_;
|
||||
if (value_flow_.fees_collected != expected_fees) {
|
||||
return reject_query(PSTRING() << "ValueFlow for " << id_.to_str() << " declares fees_collected="
|
||||
<< value_flow_.fees_collected.to_str() << " but the total message import fees are "
|
||||
<< import_fees_ << ", the total transaction fees are " << transaction_fees_.to_str()
|
||||
<< ", creation fee for this block is " << value_flow_.created.to_str()
|
||||
<< " and the total imported fees from shards are "
|
||||
<< value_flow_.fees_imported.to_str() << " with a total of "
|
||||
<< expected_fees.to_str());
|
||||
if (is_masterchain()) {
|
||||
auto x = config_->get_burning_config().calculate_burned_fees(transaction_fees_ + import_fees_);
|
||||
fees_burned_ += x;
|
||||
total_burned_ += x;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -4588,7 +4601,8 @@ bool ValidateQuery::check_one_transaction(block::Account& account, ton::LogicalT
|
|||
return reject_query(PSTRING() << "cannot re-create action phase of transaction " << lt << " for smart contract "
|
||||
<< addr.to_hex());
|
||||
}
|
||||
if (trs->bounce_enabled && (!trs->compute_phase->success || trs->action_phase->state_exceeds_limits) &&
|
||||
if (trs->bounce_enabled &&
|
||||
(!trs->compute_phase->success || trs->action_phase->state_exceeds_limits || trs->action_phase->bounce) &&
|
||||
!trs->prepare_bounce_phase(action_phase_cfg_)) {
|
||||
return reject_query(PSTRING() << "cannot re-create bounce phase of transaction " << lt << " for smart contract "
|
||||
<< addr.to_hex());
|
||||
|
@ -4646,6 +4660,7 @@ bool ValidateQuery::check_one_transaction(block::Account& account, ton::LogicalT
|
|||
<< "transaction " << lt << " of " << addr.to_hex()
|
||||
<< " is invalid: it has produced a set of outbound messages different from that listed in the transaction");
|
||||
}
|
||||
total_burned_ += trs->blackhole_burned;
|
||||
// check new balance and value flow
|
||||
auto new_balance = account.get_balance();
|
||||
block::CurrencyCollection total_fees;
|
||||
|
@ -4653,12 +4668,14 @@ bool ValidateQuery::check_one_transaction(block::Account& account, ton::LogicalT
|
|||
return reject_query(PSTRING() << "transaction " << lt << " of " << addr.to_hex()
|
||||
<< " has an invalid total_fees value");
|
||||
}
|
||||
if (old_balance + money_imported != new_balance + money_exported + total_fees) {
|
||||
return reject_query(PSTRING() << "transaction " << lt << " of " << addr.to_hex()
|
||||
<< " violates the currency flow condition: old balance=" << old_balance.to_str()
|
||||
<< " + imported=" << money_imported.to_str() << " does not equal new balance="
|
||||
<< new_balance.to_str() << " + exported=" << money_exported.to_str()
|
||||
<< " + total_fees=" << total_fees.to_str());
|
||||
if (old_balance + money_imported != new_balance + money_exported + total_fees + trs->blackhole_burned) {
|
||||
return reject_query(
|
||||
PSTRING() << "transaction " << lt << " of " << addr.to_hex()
|
||||
<< " violates the currency flow condition: old balance=" << old_balance.to_str()
|
||||
<< " + imported=" << money_imported.to_str() << " does not equal new balance=" << new_balance.to_str()
|
||||
<< " + exported=" << money_exported.to_str() << " + total_fees=" << total_fees.to_str()
|
||||
<< (trs->blackhole_burned.is_zero() ? ""
|
||||
: PSTRING() << " burned=" << trs->blackhole_burned.to_str()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -5529,6 +5546,9 @@ bool ValidateQuery::check_mc_block_extra() {
|
|||
return reject_query("invalid fees_imported in value flow: declared "s + value_flow_.fees_imported.to_str() +
|
||||
", correct value is " + fees_imported.to_str());
|
||||
}
|
||||
auto x = config_->get_burning_config().calculate_burned_fees(fees_imported - import_created_);
|
||||
total_burned_ += x;
|
||||
fees_burned_ += x;
|
||||
// ^[ prev_blk_signatures:(HashmapE 16 CryptoSignaturePair)
|
||||
if (prev_signatures_.not_null() && id_.seqno() == 1) {
|
||||
return reject_query("block contains non-empty signature set for the zero state of the masterchain");
|
||||
|
@ -5546,6 +5566,26 @@ bool ValidateQuery::check_mc_block_extra() {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ValidateQuery::postcheck_value_flow() {
|
||||
auto expected_fees =
|
||||
value_flow_.fees_imported + value_flow_.created + transaction_fees_ + import_fees_ - fees_burned_;
|
||||
if (value_flow_.fees_collected != expected_fees) {
|
||||
return reject_query(PSTRING() << "ValueFlow for " << id_.to_str() << " declares fees_collected="
|
||||
<< value_flow_.fees_collected.to_str() << " but the total message import fees are "
|
||||
<< import_fees_ << ", the total transaction fees are " << transaction_fees_.to_str()
|
||||
<< ", creation fee for this block is " << value_flow_.created.to_str()
|
||||
<< ", the total imported fees from shards are " << value_flow_.fees_imported.to_str()
|
||||
<< " and the burned fees are " << fees_burned_.to_str()
|
||||
<< " with a total of " << expected_fees.to_str());
|
||||
}
|
||||
if (total_burned_ != value_flow_.burned) {
|
||||
return reject_query(PSTRING() << "invalid burned in value flow: " << id_.to_str() << " declared "
|
||||
<< value_flow_.burned.to_str() << ", correct value is "
|
||||
<< total_burned_.to_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Ref<vm::Cell> ValidateQuery::get_virt_state_root(td::Bits256 block_root_hash) {
|
||||
auto it = virt_roots_.find(block_root_hash);
|
||||
if (it == virt_roots_.end()) {
|
||||
|
@ -5607,7 +5647,7 @@ bool ValidateQuery::try_validate() {
|
|||
}
|
||||
}
|
||||
LOG(INFO) << "running automated validity checks for block candidate " << id_.to_str();
|
||||
if (!block::gen::t_Block.validate_ref(1000000, block_root_)) {
|
||||
if (!block::gen::t_Block.validate_ref(10000000, block_root_)) {
|
||||
return reject_query("block "s + id_.to_str() + " failed to pass automated validity checks");
|
||||
}
|
||||
if (!fix_all_processed_upto()) {
|
||||
|
@ -5640,9 +5680,10 @@ bool ValidateQuery::try_validate() {
|
|||
if (!check_in_queue()) {
|
||||
return reject_query("cannot check inbound message queues");
|
||||
}
|
||||
if (!check_delivered_dequeued()) {
|
||||
// Excessive check: validity of message in queue is checked elsewhere
|
||||
/*if (!check_delivered_dequeued()) {
|
||||
return reject_query("cannot check delivery status of all outbound messages");
|
||||
}
|
||||
}*/
|
||||
if (!check_transactions()) {
|
||||
return reject_query("invalid collection of account transactions in ShardAccountBlocks");
|
||||
}
|
||||
|
@ -5664,6 +5705,9 @@ bool ValidateQuery::try_validate() {
|
|||
if (!check_mc_state_extra()) {
|
||||
return reject_query("new McStateExtra is invalid");
|
||||
}
|
||||
if (!postcheck_value_flow()) {
|
||||
return reject_query("new ValueFlow is invalid");
|
||||
}
|
||||
} catch (vm::VmError& err) {
|
||||
return fatal_error(-666, err.get_msg());
|
||||
} catch (vm::VmVirtError& err) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue