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 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
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.
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