Skip to content

Commit

Permalink
Fix setting gas limits in transaction.cpp (#864)
Browse files Browse the repository at this point in the history
Co-authored-by: SpyCheese <[email protected]>
  • Loading branch information
EmelyanenkoK and SpyCheese authored Jan 17, 2024
1 parent 6f277b4 commit b1f2160
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions crypto/block/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,18 +1220,19 @@ 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;
} else {
// 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;
Expand Down
5 changes: 3 additions & 2 deletions validator/impl/external-message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::tuple<td::Ref<vm::CellSlice>, UnixTime, LogicalTime, std::unique_ptr<block::ConfigInfo>>>
res) mutable {
if (res.is_error()) {
Expand All @@ -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));
Expand Down

0 comments on commit b1f2160

Please sign in to comment.