From b1f2160510a5afd2c29c8a67cfc351013ff1028a Mon Sep 17 00:00:00 2001 From: EmelyanenkoK Date: Wed, 17 Jan 2024 12:01:34 +0300 Subject: [PATCH] Fix setting gas limits in transaction.cpp (#864) Co-authored-by: SpyCheese --- crypto/block/transaction.cpp | 11 ++++++----- validator/impl/external-message.cpp | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/crypto/block/transaction.cpp b/crypto/block/transaction.cpp index b4bd648bb..ae50a7100 100644 --- a/crypto/block/transaction.cpp +++ b/crypto/block/transaction.cpp @@ -1220,7 +1220,6 @@ bool Transaction::compute_gas_limits(ComputePhase& cp, const ComputePhaseConfig& } else { cp.gas_max = gas_bought_for(cfg, balance.grams); } - cp.gas_credit = 0; if (trans_type != tr_ord || (account.is_special && cfg.special_gas_full)) { // may use all gas that can be bought using remaining balance cp.gas_limit = cp.gas_max; @@ -1228,10 +1227,12 @@ bool Transaction::compute_gas_limits(ComputePhase& cp, const ComputePhaseConfig& // originally use only gas bought using remaining message balance // if the message is "accepted" by the smart contract, the gas limit will be set to gas_max cp.gas_limit = std::min(gas_bought_for(cfg, msg_balance_remaining.grams), cp.gas_max); - if (!block::tlb::t_Message.is_internal(in_msg)) { - // external messages carry no balance, give them some credit to check whether they are accepted - cp.gas_credit = std::min(cfg.gas_credit, cp.gas_max); - } + } + if (trans_type == tr_ord && !block::tlb::t_Message.is_internal(in_msg)) { + // external messages carry no balance, give them some credit to check whether they are accepted + cp.gas_credit = std::min(cfg.gas_credit, cp.gas_max); + } else { + cp.gas_credit = 0; } LOG(DEBUG) << "gas limits: max=" << cp.gas_max << ", limit=" << cp.gas_limit << ", credit=" << cp.gas_credit; return true; diff --git a/validator/impl/external-message.cpp b/validator/impl/external-message.cpp index 5c1848aab..e7665afc2 100644 --- a/validator/impl/external-message.cpp +++ b/validator/impl/external-message.cpp @@ -102,7 +102,7 @@ void ExtMessageQ::run_message(td::BufferSlice data, block::SizeLimitsConfig::Ext run_fetch_account_state( wc, addr, manager, - [promise = std::move(promise), msg_root = root, wc, + [promise = std::move(promise), msg_root = root, wc, addr, M](td::Result, UnixTime, LogicalTime, std::unique_ptr>> res) mutable { if (res.is_error()) { @@ -114,7 +114,8 @@ void ExtMessageQ::run_message(td::BufferSlice data, block::SizeLimitsConfig::Ext auto utime = std::get<1>(tuple); auto lt = std::get<2>(tuple); auto config = std::move(std::get<3>(tuple)); - if (!acc.unpack(shard_acc, utime, false)) { + bool special = wc == masterchainId && config->is_special_smartcontract(addr); + if (!acc.unpack(shard_acc, utime, special)) { promise.set_error(td::Status::Error(PSLICE() << "Failed to unpack account state")); } else { auto status = run_message_on_account(wc, &acc, utime, lt + 1, msg_root, std::move(config));