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
						d082ac36b0
					
				
					 261 changed files with 24449 additions and 1791 deletions
				
			
		|  | @ -1594,90 +1594,19 @@ bool Collator::init_lt() { | |||
| } | ||||
| 
 | ||||
| bool Collator::fetch_config_params() { | ||||
|   auto res = impl_fetch_config_params(std::move(config_), &old_mparams_, &storage_prices_, &storage_phase_cfg_, | ||||
|                                       &rand_seed_, &compute_phase_cfg_, &action_phase_cfg_, &masterchain_create_fee_, | ||||
|                                       &basechain_create_fee_, workchain(), now_); | ||||
|   auto res = block::FetchConfigParams::fetch_config_params(*config_, | ||||
|                                       &old_mparams_, &storage_prices_, &storage_phase_cfg_, | ||||
|                                       &rand_seed_, &compute_phase_cfg_, &action_phase_cfg_, | ||||
|                                       &masterchain_create_fee_, &basechain_create_fee_, | ||||
|                                       workchain(), now_ | ||||
|                                      ); | ||||
|   if (res.is_error()) { | ||||
|     return fatal_error(res.move_as_error()); | ||||
|   } | ||||
|   config_ = res.move_as_ok(); | ||||
|   compute_phase_cfg_.libraries = std::make_unique<vm::Dictionary>(config_->get_libraries_root(), 256); | ||||
|   return true; | ||||
| } | ||||
| 
 | ||||
| td::Result<std::unique_ptr<block::ConfigInfo>> Collator::impl_fetch_config_params( | ||||
|     std::unique_ptr<block::ConfigInfo> 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, WorkchainId wc, UnixTime now) { | ||||
|   *old_mparams = config->get_config_param(9); | ||||
|   { | ||||
|     auto res = config->get_storage_prices(); | ||||
|     if (res.is_error()) { | ||||
|       return res.move_as_error(); | ||||
|     } | ||||
|     *storage_prices = res.move_as_ok(); | ||||
|   } | ||||
|   { | ||||
|     // generate rand seed
 | ||||
|     prng::rand_gen().strong_rand_bytes(rand_seed->data(), 32); | ||||
|     LOG(DEBUG) << "block random seed set to " << rand_seed->to_hex(); | ||||
|   } | ||||
|   TRY_RESULT(size_limits, config->get_size_limits_config()); | ||||
|   { | ||||
|     // compute compute_phase_cfg / storage_phase_cfg
 | ||||
|     auto cell = config->get_config_param(wc == ton::masterchainId ? 20 : 21); | ||||
|     if (cell.is_null()) { | ||||
|       return td::Status::Error(-668, "cannot fetch current gas prices and limits from masterchain configuration"); | ||||
|     } | ||||
|     if (!compute_phase_cfg->parse_GasLimitsPrices(std::move(cell), storage_phase_cfg->freeze_due_limit, | ||||
|                                                   storage_phase_cfg->delete_due_limit)) { | ||||
|       return td::Status::Error(-668, "cannot unpack current gas prices and limits from masterchain configuration"); | ||||
|     } | ||||
|     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->suspended_addresses = config->get_suspended_addresses(now); | ||||
|   } | ||||
|   { | ||||
|     // compute action_phase_cfg
 | ||||
|     block::gen::MsgForwardPrices::Record rec; | ||||
|     auto cell = config->get_config_param(24); | ||||
|     if (cell.is_null() || !tlb::unpack_cell(std::move(cell), rec)) { | ||||
|       return td::Status::Error(-668, "cannot fetch masterchain message transfer prices from masterchain configuration"); | ||||
|     } | ||||
|     action_phase_cfg->fwd_mc = | ||||
|         block::MsgPrices{rec.lump_price,           rec.bit_price,          rec.cell_price, rec.ihr_price_factor, | ||||
|                          (unsigned)rec.first_frac, (unsigned)rec.next_frac}; | ||||
|     cell = config->get_config_param(25); | ||||
|     if (cell.is_null() || !tlb::unpack_cell(std::move(cell), rec)) { | ||||
|       return td::Status::Error(-668, "cannot fetch standard message transfer prices from masterchain configuration"); | ||||
|     } | ||||
|     action_phase_cfg->fwd_std = | ||||
|         block::MsgPrices{rec.lump_price,           rec.bit_price,          rec.cell_price, rec.ihr_price_factor, | ||||
|                          (unsigned)rec.first_frac, (unsigned)rec.next_frac}; | ||||
|     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; | ||||
|   } | ||||
|   { | ||||
|     // fetch block_grams_created
 | ||||
|     auto cell = config->get_config_param(14); | ||||
|     if (cell.is_null()) { | ||||
|       *basechain_create_fee = *masterchain_create_fee = td::zero_refint(); | ||||
|     } else { | ||||
|       block::gen::BlockCreateFees::Record create_fees; | ||||
|       if (!(tlb::unpack_cell(cell, create_fees) && | ||||
|             block::tlb::t_Grams.as_integer_to(create_fees.masterchain_block_fee, *masterchain_create_fee) && | ||||
|             block::tlb::t_Grams.as_integer_to(create_fees.basechain_block_fee, *basechain_create_fee))) { | ||||
|         return td::Status::Error(-668, "cannot unpack BlockCreateFees from configuration parameter #14"); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|   return std::move(config); | ||||
| } | ||||
| 
 | ||||
| bool Collator::compute_minted_amount(block::CurrencyCollection& to_mint) { | ||||
|   if (!is_masterchain()) { | ||||
|     return to_mint.set_zero(); | ||||
|  | @ -2200,8 +2129,8 @@ bool Collator::create_ticktock_transaction(const ton::StdSmcAddress& smc_addr, t | |||
|                                                    << "last transaction time in the state of account " << workchain() | ||||
|                                                    << ":" << smc_addr.to_hex() << " is too large")); | ||||
|   } | ||||
|   std::unique_ptr<block::Transaction> trans = std::make_unique<block::Transaction>( | ||||
|       *acc, mask == 2 ? block::Transaction::tr_tick : block::Transaction::tr_tock, req_start_lt, now_); | ||||
|   std::unique_ptr<block::transaction::Transaction> trans = std::make_unique<block::transaction::Transaction>( | ||||
|       *acc, mask == 2 ? block::transaction::Transaction::tr_tick : block::transaction::Transaction::tr_tock, req_start_lt, now_); | ||||
|   if (!trans->prepare_storage_phase(storage_phase_cfg_, true)) { | ||||
|     return fatal_error(td::Status::Error( | ||||
|         -666, std::string{"cannot create storage phase of a new transaction for smart contract "} + smc_addr.to_hex())); | ||||
|  | @ -2291,7 +2220,7 @@ Ref<vm::Cell> Collator::create_ordinary_transaction(Ref<vm::Cell> msg_root) { | |||
|     fatal_error(std::move(error)); | ||||
|     return {}; | ||||
|   } | ||||
|   std::unique_ptr<block::Transaction> trans = res.move_as_ok(); | ||||
|   std::unique_ptr<block::transaction::Transaction> trans = res.move_as_ok(); | ||||
| 
 | ||||
|   if (!trans->update_limits(*block_limit_status_)) { | ||||
|     fatal_error("cannot update block limit status to include the new transaction"); | ||||
|  | @ -2310,10 +2239,13 @@ Ref<vm::Cell> Collator::create_ordinary_transaction(Ref<vm::Cell> msg_root) { | |||
| 
 | ||||
| // If td::status::error_code == 669 - Fatal Error block can not be produced
 | ||||
| // if td::status::error_code == 701 - Transaction can not be included into block, but it's ok (external or too early internal)
 | ||||
| td::Result<std::unique_ptr<block::Transaction>> Collator::impl_create_ordinary_transaction( | ||||
|     Ref<vm::Cell> msg_root, block::Account* acc, UnixTime utime, LogicalTime lt, | ||||
|     block::StoragePhaseConfig* storage_phase_cfg, block::ComputePhaseConfig* compute_phase_cfg, | ||||
|     block::ActionPhaseConfig* action_phase_cfg, bool external, LogicalTime after_lt) { | ||||
| td::Result<std::unique_ptr<block::transaction::Transaction>> Collator::impl_create_ordinary_transaction(Ref<vm::Cell> msg_root, | ||||
|                                                          block::Account* acc, | ||||
|                                                          UnixTime utime, LogicalTime lt, | ||||
|                                                          block::StoragePhaseConfig* storage_phase_cfg, | ||||
|                                                          block::ComputePhaseConfig* compute_phase_cfg, | ||||
|                                                          block::ActionPhaseConfig* action_phase_cfg, | ||||
|                                                          bool external, LogicalTime after_lt) { | ||||
|   if (acc->last_trans_end_lt_ >= lt && acc->transactions.empty()) { | ||||
|     return td::Status::Error(-669, PSTRING() << "last transaction time in the state of account " << acc->workchain | ||||
|                                              << ":" << acc->addr.to_hex() << " is too large"); | ||||
|  | @ -2324,8 +2256,8 @@ td::Result<std::unique_ptr<block::Transaction>> Collator::impl_create_ordinary_t | |||
|     trans_min_lt = std::max(trans_min_lt, after_lt); | ||||
|   } | ||||
| 
 | ||||
|   std::unique_ptr<block::Transaction> trans = | ||||
|       std::make_unique<block::Transaction>(*acc, block::Transaction::tr_ord, trans_min_lt + 1, utime, msg_root); | ||||
|   std::unique_ptr<block::transaction::Transaction> trans = | ||||
|       std::make_unique<block::transaction::Transaction>(*acc, block::transaction::Transaction::tr_ord, trans_min_lt + 1, utime, msg_root); | ||||
|   bool ihr_delivered = false;  // FIXME
 | ||||
|   if (!trans->unpack_input_msg(ihr_delivered, action_phase_cfg)) { | ||||
|     if (external) { | ||||
|  | @ -2375,7 +2307,7 @@ td::Result<std::unique_ptr<block::Transaction>> Collator::impl_create_ordinary_t | |||
|     return td::Status::Error( | ||||
|         -669, "cannot create action phase of a new transaction for smart contract "s + acc->addr.to_hex()); | ||||
|   } | ||||
|   if (trans->bounce_enabled && (!trans->compute_phase->success || trans->action_phase->state_size_too_big) && | ||||
|   if (trans->bounce_enabled && (!trans->compute_phase->success || trans->action_phase->state_exceeds_limits) && | ||||
|       !trans->prepare_bounce_phase(*action_phase_cfg)) { | ||||
|     return td::Status::Error( | ||||
|         -669, "cannot create bounce phase of a new transaction for smart contract "s + acc->addr.to_hex()); | ||||
|  | @ -3088,7 +3020,7 @@ void Collator::register_new_msg(block::NewOutMsg new_msg) { | |||
|   new_msgs.push(std::move(new_msg)); | ||||
| } | ||||
| 
 | ||||
| void Collator::register_new_msgs(block::Transaction& trans) { | ||||
| void Collator::register_new_msgs(block::transaction::Transaction& trans) { | ||||
|   CHECK(trans.root.not_null()); | ||||
|   for (unsigned i = 0; i < trans.out_msgs.size(); i++) { | ||||
|     register_new_msg(trans.extract_out_msg_ext(i)); | ||||
|  | @ -3755,6 +3687,9 @@ bool Collator::create_shard_state() { | |||
|   } | ||||
|   LOG(INFO) << "creating Merkle update for the ShardState"; | ||||
|   state_update = vm::MerkleUpdate::generate(prev_state_root_, state_root, state_usage_tree_.get()); | ||||
|   if (state_update.is_null()) { | ||||
|     return fatal_error("cannot create Merkle update for ShardState"); | ||||
|   } | ||||
|   if (verbosity > 2) { | ||||
|     std::cerr << "Merkle Update for ShardState: "; | ||||
|     vm::CellSlice cs{vm::NoVm{}, state_update}; | ||||
|  | @ -4074,7 +4009,11 @@ bool Collator::create_collated_data() { | |||
|   } | ||||
|   // 4. Proofs for message queues
 | ||||
|   for (vm::MerkleProofBuilder &mpb : neighbor_proof_builders_) { | ||||
|     Ref<vm::Cell> proof = mpb.extract_proof(); | ||||
|     auto r_proof = mpb.extract_proof(); | ||||
|     if (r_proof.is_error()) { | ||||
|       return fatal_error(r_proof.move_as_error_prefix("cannot generate Merkle proof for neighbor: ")); | ||||
|     } | ||||
|     Ref<vm::Cell> proof = r_proof.move_as_ok(); | ||||
|     if (proof.is_null()) { | ||||
|       return fatal_error("cannot generate Merkle proof for neighbor"); | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue