TransactionGasLimit error during contract method call

Hi guys, I encountered a half problem ValidationError(TransactionGasLimit) when calling one of my contract methods

I tried to solve the problem like this, but it didn’t work

market
 .methods()
 .absorb(addresses)
 .set_contracts(contract_ids)
 .tx_params(TxParameters::new(None, Some(100_000_000_000), None))
 .call_params(CallParameters::new(None, None, Some(100_000_000_000))
 .call()
 .await

Does anyone know how to solve this?

4 Likes

Can you share the repo and branch to reproduce this?

git clone git@github.com:sway-gang/sway-lend.git 
cd sway-lend 
git checkout tests
cd ./contracts/market/ 
git checkout tests 
forc build  
cargo test --package market --test integration_tests -- local_tests::main_test::main_test --exact --nocapture 
1 Like

Are there any updates? :nerd_face:

This particular error is caused by the gas being over the max limit for a transaction. You can see a related post here: How do I check the max gas allowed for a transaction?

However I’m getting a different gas-related error if I reduce the amount to less than the max limit, so unfortunately I don’t have a solution for you yet. Still working on this though!

How do I check the max gas allowed for a transaction of my local node?
I mean the one that launches with launch_custom_provider_and_get_wallets.
Maybe you know how to increase its limit?

Another question - how do I know what my gas consumption of the absorb function is?


If you examine launch_custom_provider_and_get_wallets, you will notice that a limit is set here. Only I have not been able to set it, maybe there is some tutorial?


I also noticed that there was a discussion thread on discord about a similar problem, but I did not see a solution there. Maybe you know how it ended?

Haven’t had the chance to run the code myself, so forgive me if I’m missing something.

Is this being run against a public testnet or with a custom node that you’re running locally?

If public, then the max_gas_per_tx is a value that’s set by the node itself; you cannot change it.

If you’re running your own node, then yes, that value can be tweaked.

Once you know the max_gas_per_tx, make sure your sending at most that value as gas, otherwise, you’re going to get that error.

Note: I plan on checking the code and run it myself when I have the time

2 Likes

I guess it’s local_testnet and according to the default network parameters the limit is 100_000_000. I tried to change it to 500_000_000 as follows

async fn init_wallets() -> Vec<WalletUnlocked> {
    let chain_config = ChainConfig::default();
    chain_config
        .transaction_parameters
        .with_max_gas_per_tx(500_000_000);
    launch_custom_provider_and_get_wallets(
        WalletsConfig::new(
            Some(4), /* Single wallet */
            Some(1), /* Single coin (UTXO) */
            Some(1_000_000_000), /* Amount per coin */
        ),
        None,
        Some(chain_config,)
    )
    .await
}

But ran into this error

thread 'local_tests::main_test::main_test' panicked at 'called `Result::unwrap()` on an `Err` value: ProviderError('Response errors; not enough resources to fit the target')', tests/utils/local_tests_utils/oracle.rs:81:6
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test local_tests::main_test::main_test ... FAILED

Right, that makes sense. It seems like this error is related to you not having that amount of coins in your test wallet. This is weird because you’re passing 1_000_000_000 to the WalletsConfig. I need to sit down and investigate this further.

Okay, thank you very much. I really appreciate your help.
By the way, you can write me on discord, and I will answer faster there Alexey Nagorny#3977.v

1 Like

Are there any updates? :nerd_face:

So… this is a tricky one and a multifaceted problem.

I see two problems here. First, it seems the absorb() contract method is super resource-intensive. I’m unsure whether there’s room for optimization in it; I haven’t looked at the actual Sway code underneath it. I noticed it’s resource-intensive because whenever I raised the gas per transaction limit, the gas per block limit, and the gas being forwarded to this specific absorb() call, I ran into

thread 'local_tests::main_test::main_test' panicked at 'called 
`Result::unwrap()` on an `Err` value: RevertTransactionError("OutOfGas", 
[Call { id:  // ....

So… not enough gas to cover all the computation going into this absorb method.

This leads to the second problem, and that’s on the SDK side: while debugging, I had to increase the amount going into the test wallets and noticed that that wasn’t working as intended. So, at the moment, if you try what I did, it won’t work because the SDK needs to be patched with this fix I did locally – I’ll attend to this soon.

In the meantime, I’d take a hard look into this absorb method and see what’s going on that’s causing it to use this much compute.

Edit: we’re tracking this coin configuration issue here `launch_custom_provider_and_get_wallets` ignores coin configuration if `ChainConfig` is `Some` · Issue #793 · FuelLabs/fuels-rs · GitHub. Once that’s done, you’ll be able to pass a proper ChainConfig with higher gas configuration values and higher amounts of coin to your WalletConfig. Once you do this, you’ll run into this OutOfGas issue until the underlying problem is solved. We’ll get there, though; I’ll take a look at the Sway code once I get some more time.

2 Likes

Got it, thank you very much!!!

And how do I know how much gas my function will consume?
Does the number of functions in the contract affect the gas of this particular function?
Where can I read more about gas consumption?

@digorithm
By commenting on the lines one by one I managed to find out that for some reason continue is eating up half of the allowable gas, perhaps there is a bug

Here is a screenshot of the code and the result of the execution when we have continue

Here is the result without `continue

Demm bro, the problem was in the if block, I forgot to increment the counter

    if seize_amount == 0 {
            i += 1;
            continue;
        }
2 Likes

Hahaha, this is a funny one; honest mistake, though!

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.