-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Gas calculation pattern #619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
To fix the formatting issues:
npx remark -o --silent --silently-ignore guidebook/debug.mdx techniques/gas.mdx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice PR, can we add link to gas-utility file?
Thanks for the update to the techniques docs. One high‑severity fix is needed before merge. Findings (1)High (1)[HIGH] Missing frontmatter; page title rendered as body textDescription: Suggestion: -## title: "Estimate gas usage in TON contracts"
+---
+title: "Estimate gas usage in TON contracts"
+--- |
To fix the formatting issues:
npx remark -o --silent --silently-ignore guidebook/debug.mdx techniques/gas.mdx |
To fix the formatting issues:
npx remark -o --silent --silently-ignore guidebook/debug.mdx standard/tokens/airdrop.mdx techniques/gas.mdx |
To fix the formatting issues:
npx remark -o --silent --silently-ignore guidebook/debug.mdx standard/tokens/airdrop.mdx techniques/gas.mdx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice pr!
Can we add may be more pics
I have several suggestions:
@skywardboundd sure, examples in ts will be added as part of #620 |
To fix the formatting issues:
npx remark -o --silent --silently-ignore guidebook/debug.mdx techniques/gas.mdx |
To fix the formatting issues:
npx remark -o --silent --silently-ignore guidebook/debug.mdx techniques/gas.mdx |
# Conflicts: # extra.css # techniques/gas.mdx
Thanks for the update to the gas techniques doc. I found several high‑severity style and link issues that need fixes before merge, all localized to Findings (8)High (8)[HIGH] Disallowed
|
<Warning> | |
`computeDataSize()` function consumes large, unpredictable amount of gas. If at all it is possible to precompute the size, it is recommended to do so. | |
</Warning> |
Description:
The page imports and uses Aside
for callouts, but lines 118–120 use an unsupported <Warning>
component. Unsupported admonitions may not render and break consistency across the docs.
Suggestion:
Replace the <Warning>
block with a supported Aside
callout.
-<Warning>
- `computeDataSize()` function consumes large, unpredictable amount of gas. If at all it is possible to precompute the size, it is recommended to do so.
-</Warning>
+<Aside type="caution">
+ `computeDataSize()` consumes a large, unpredictable amount of gas. Precompute the size when possible.
+</Aside>
[HIGH] Broken internal link to limits page (/ton/limits
)
Location:
Line 111 in 603beae
ComputeDataSize have the second argument - maximum number of cells to visit. If it is ok to set in in _8192_ since it is the [limit for message size](/ton/limits#message-and-transaction-limits). |
Description:
The link points to /ton/limits#message-and-transaction-limits
, but the page lives under /foundations/limits
in this repo. Broken or incorrect internal links are disallowed.
Suggestion:
Update the link path to point to the existing page.
-ComputeDataSize have the second argument - maximum number of cells to visit. If it is ok to set in in _8192_ since it is the [limit for message size](/ton/limits#message-and-transaction-limits).
+ComputeDataSize have the second argument - maximum number of cells to visit. If it is ok to set in in _8192_ since it is the [limit for message size](/foundations/limits#message-and-transaction-limits).
[HIGH] Broken internal link to config page (/ton/config
)
Location:
Line 225 in 603beae
In the worst case the storage fee for a single message is [`freeze_due_limit`](/ton/config#param-20-and-21%3A-gas-prices). Otherwise, the contract likely is already frozen and a transaction chain is likely to fail anyway. |
Description:
The link for freeze_due_limit
targets /ton/config#param-20-and-21%3A-gas-prices
, but the canonical page is foundations/config.mdx
. Broken/misrouted internal links are disallowed.
Suggestion:
Fix the link to the correct internal location.
-In the worst case the storage fee for a single message is [`freeze_due_limit`](/ton/config#param-20-and-21%3A-gas-prices). Otherwise, the contract likely is already frozen and a transaction chain is likely to fail anyway.
+In the worst case the storage fee for a single message is [`freeze_due_limit`](/foundations/config#param-20-and-21). Otherwise, the contract likely is already frozen and a transaction chain is likely to fail anyway.
[HIGH] Broken internal link to “Phases and fees” (/ton/phases-and-fees
)
Location:
Line 374 in 603beae
- [Phases and fees](/ton/phases-and-fees) — TON fee structure and components |
Description:
The link points to /ton/phases-and-fees
, but the page is under foundations/phases-and-fees.mdx
in this repository. Linking to a non-existent path breaks navigation and is disallowed.
Suggestion:
Correct the link path.
-- [Phases and fees](/ton/phases-and-fees) — TON fee structure and components
+- [Phases and fees](/foundations/phases-and-fees) — TON fee structure and components
[HIGH] Incorrect TVM instruction name (GETSIMPLEFORWARDFEE
)
Location:
Line 143 in 603beae
For this case, we can use `getSimpleForwardFee()` which uses [`GETSIMPLEFORWARDFEE`](/tvm/instructions#f83c-getforwardfeesimple). This function does not add basePrice (called `lump_price` in config) into account. |
Description:
The instruction is referred to as GETSIMPLEFORWARDFEE
, which is not the canonical name. The correct name is GETFORWARDFEESIMPLE
. Incorrect identifiers reduce searchability and can mislead readers.
Suggestion:
Use the correct instruction name while keeping the existing (correct) anchor.
-For this case, we can use `getSimpleForwardFee()` which uses [`GETSIMPLEFORWARDFEE`](/tvm/instructions#f83c-getforwardfeesimple). This function does not add basePrice (called `lump_price` in config) into account.
+For this case, we can use `getSimpleForwardFee()` which uses [`GETFORWARDFEESIMPLE`](/tvm/instructions#f83c-getforwardfeesimple). This function does not add basePrice (called `lump_price` in config) into account.
[HIGH] Literal ellipses used inside code (invalid, non-copyable)
Location:
Line 71 in 603beae
const result = await contract.send(...); |
Description:
The snippet uses await contract.send(...);
with a literal ellipsis, which is syntactically invalid and not copy‑pasteable. Similar issues also appear at techniques/gas.mdx:212
and techniques/gas.mdx:257
(let otherFees = ...;
). The style guide disallows literal ...
in code.
Suggestion:
Replace ellipses with comments or placeholder values to keep code copy‑pasteable.
-const result = await contract.send(...);
+const result = await contract.send(/* params */);
Also update other instances in the file:
- let otherFees = ...;
+ let otherFees = /* compute other fees */;
- let otherFees = ...;
+ let otherFees = /* compute other fees */;
[HIGH] Unlabeled fenced code blocks
Location:
Lines 137 to 139 in 603beae
``` | |
fwdFee = basePrice + priceForCells * cells + priceForBits * bits | |
``` |
Description:
Some fenced code blocks lack a language tag, e.g., the formula block at L137–L139 and the Tact block beginning at L205. The style guide requires language tags for syntax highlighting and tooling.
Suggestion:
Add appropriate language tags to each affected fence.
@@
-```
+```text
fwdFee = basePrice + priceForCells * cells + priceForBits * bits
-```
+```
@@
-```
+```tact
const secondsInFiveYears: Int = 5 * 365 * 24 * 60 * 60;
receive(msg: UserIn) {
// Suppose trace will be *in* -> *A* -> *B*
let storageForA = getStorageFee(maxCellsInA, maxBitsInA, secondsInFiveYears, isAccountInMasterchain);
let storageForB = getStorageFee(maxCellsInB, maxBitsInB, secondsInFiveYears, isAccountInMasterchain);
let totalStorageFees = storageForA + storageForB;
let otherFees = /* compute other fees */;
require(messageValue() >= totalStorageFees + otherFees, "Not enough toncoins");
}
-```
+```
[HIGH] Broken MDX import to a missing snippet
Location:
Line 6 in 603beae
import {CellCalculator} from "/snippets/cell-calculator.tsx"; |
Description:
The page imports CellCalculator
from /snippets/cell-calculator.tsx
, but no such file exists under snippets/
. This causes a build/runtime error and blocks page rendering. The imported component is not referenced elsewhere, so it’s safe to remove.
Suggestion:
Remove the unused import line.
-import {CellCalculator} from "/snippets/cell-calculator.tsx";
To fix the formatting issues:
npx remark -o --silent --silently-ignore techniques/gas.mdx |
Closes #175