Benjamin Kurrek
Benjamin Kurrek

Reputation: 1094

Different GAS limits on NEAR

I'm seeing an error when doing my function calls that state:

"FunctionCallError": { 
    "ExecutionError": "Exceeded the maximum amount of gas allowed to burn per contract." 
}

I've seen other stack overflow posts regarding an error for exceeding the prepaid gas but this seems to be a different error. I'm wondering what this error is and what causes it. How is it different than the exceeded prepaid GAS error and how can I solve it?

Upvotes: 1

Views: 371

Answers (1)

Benjamin Kurrek
Benjamin Kurrek

Reputation: 1094

For context, it's important to think of GAS in terms of wall-clock time. NEAR GAS values are tuned to correlate with wall-clock time; 1 Tgas being approximately 1 ms.

In general, there are three GAS limits you should be aware of:

  • transaction limit (300 TGas: 0.03 $NEAR & 300ms wall-clock time). Actual value found here in nearcore.
  • receipt limit (300 TGas: 0.03 $NEAR & 300ms wall-clock time). Actual value found here in nearcore. Note that it says 200 TGas but has been updated to be 300 TGas as shown here.
  • block limit (1_000 TGas: 0.1 $NEAR & 1s wall-clock time). Actual value found here in nearcore.

NOTE: the limits are subject to change. The numbers I've listed here are based on the protocol configuration at the time of writing this post.

Every transaction on NEAR can currently burn a maximum of 300 TGas (0.03 $NEAR) which equates to roughly 300ms of wall-clock time. This is enforced by not allowing users to attach more than 300 TGas to any given transaction. If you try to attach, for example, 400 TGas, you'll be thrown a server error:

"TotalPrepaidGasExceeded":{"limit":300000000000000,"total_prepaid_gas":4000000000000000}

This means that the sum of all the burnt GAS for every receipt in the transaction cannot exceed 300 TGas.

This is different than the receipt limit which outlines the maximum amount of GAS that can be burnt by any given receipt. This limit is currently the same as the transaction limit (300 TGas). You can have a transaction that is made up of many different receipts. The sum of all the burnt GAS across all receipts cannot exceed 300 TGas but any one receipt cannot burn more than 300 TGas.

Historically, the transaction and receipt limits were different. The receipt limit used to be 200 TGas but that has recently changed. This means that it will be impossible for any given receipt to use up more than 300 TGas due to the cap on how much GAS you can attach to the transaction as a whole. This means that your error should never happen.

"ExecutionError": "Exceeded the maximum amount of gas allowed to burn per contract." 

This error is thrown when the burnt GAS exceeds the receipt limit. In the past, this limit was 200 TGas and it was possible to exceed the limit if any of the receipts in your transaction were extremely computational and used up more than 200 TGas. This, however, shouldn't be an issue now with the changes to the limits.

The last limit is the block limit which outlines the maximum amount of GAS that can be burnt per block. This limit is currently 1 PetaGAS or 1_000 TGas (0.1 $NEAR). This equates to a maximum of ~1 second per block. Therefore, the 1_000 Tgas block limit is simply reinforcing the 1 second block time NEAR wants to have.

These limits are different than the exceeding the prepaid gas errors as they're hard coded limits that can't be exceeded. The exceeding prepaid GAS error occurs when you attempt to burn more GAS than what was attached to the current receipt.

Upvotes: 3

Related Questions