Skip to content
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

Article: How to manage your contract gas #20

Open
talkol opened this issue Jul 12, 2022 · 25 comments
Open

Article: How to manage your contract gas #20

talkol opened this issue Jul 12, 2022 · 25 comments
Assignees
Labels
Approved This proposal is approved by the committee Education Related to educational resources or initiatives

Comments

@talkol
Copy link

talkol commented Jul 12, 2022

Summary

Teach FunC smart contract developers how to manage gas in the contracts they're writing.

Context

TON contract gas model is very unique and quite different from the EVM model. Contract developers must design a gas strategy. If they won't do this well, the contract can run out of TON balance for rent and be removed. Messages that the contract sends might not have enough gas and be rejected. This is an advanced topic, not an introductory one.

Goals

  • Help FunC developers write better smart contracts.
  • Help FunC developers avoid gas handling mistakes in their code.
  • Target audience - experienced FunC developers that already know FunC basics.
  • Help teams that are actively working on contracts mature faster and become production ready.

Deliverables

A markdown article in a form of a GitHub gist or GitHub repository

Definition of Done

  • A well-written article about the general idea and motivation behind TON's gas model for smart contracts.
  • Article lists pit falls where developers can make a gas mistake and render their contract un-usable.
  • Article gives best practices (do's and don'ts) for handling gas in FunC. Example: How much balance should be left for paying rent (storage fees)? How are storage fees calculated and what is the storage fee per cell per year.
  • Article shows all of the above in practice with multiple hands-on code examples.

Reward

  • Standard TON Footstep NFT
  • 400$ in TON equivalent
@talkol talkol added the footstep This is a TON Footstep issue label Jul 12, 2022
@Hiyorimi
Copy link
Contributor

Can it be merged with Issue#9?

@talkol
Copy link
Author

talkol commented Jul 13, 2022

Can it be merged with Issue#9?

I saw it, it seemed like a different target audience: "Make sure person with little or no blockchain literacy understands how fees work on TON."

This blog post is aimed at hard core FunC developers and will show a lot of code

@Hiyorimi
Copy link
Contributor

Can we reflect the target audience explicitly in the issue then?

@talkol
Copy link
Author

talkol commented Jul 13, 2022

No problem, clarified the target audience in multiple places in the issue

@Hiyorimi Hiyorimi added the Approved This proposal is approved by the committee label Jul 13, 2022
@talkol
Copy link
Author

talkol commented Jul 15, 2022

Why do we need this post? I reviewed my team's contracts and I see that they leave 0.01 TON for storage fees. I then ask why 0.01 TON? Why not more or less? The answer is usually that this is what we saw in the Jetton contract. The purpose of this blog post is to explain these things in detail and explain how these "magic" values came to be and what's the logic behind them.

@Gusarich
Copy link
Contributor

I suggest to add some Toncoin reward to this Footstep. Let's say $300 or $500, based on the rewards for other articles in previous Footsteps.
What do you think? @Hiyorimi

@delovoyhomie
Copy link
Collaborator

$400 would be optimal for this article. We are calling on experienced developers to cover this issue.
@Gusarich, what do you think?

@Gusarich
Copy link
Contributor

Gusarich commented Apr 2, 2023

I agree with you. I've just set the reward to $400.

@delovoyhomie delovoyhomie added Education Related to educational resources or initiatives and removed documentation footstep This is a TON Footstep issue labels Oct 6, 2023
@delovoyhomie
Copy link
Collaborator

@talkol, @Gusarich, @Hiyorimi, who would you suggest as a candidate to perform this bounty?

@mbaneshi
Copy link
Contributor

Hi
I acknowledge that delving into advanced topics requires some prior experience and expertise. However, I am fully committed to investing the necessary time and effort to grasp the intricacies of this subject matter. My readiness to engage in this endeavor is unwavering.

@mbaneshi
Copy link
Contributor

@delovoyhomie Thank you.

@mbaneshi
Copy link
Contributor

Following the comprehensive guidelines provided in the project proposal guide ,I successfully submitted my proposal, and it is now accessible here

@delovoyhomie
Copy link
Collaborator

@mbaneshi, thank you for following the bounty guideline!

@delovoyhomie
Copy link
Collaborator

@SwiftAdviser, @reveloper, could you please advise where in the documentation this article would best fit?

@mbaneshi
Copy link
Contributor

Dear @talkol,I have sent you a direct message on Telegram. Could you please take a moment to review it at your earliest convenience? Thank you for your attention.

@delovoyhomie
Copy link
Collaborator

@mbaneshi, could I ask you to write me in DM on Telegram?

@mbaneshi
Copy link
Contributor

Hi, soon I will have an update here. Important one.

@mbaneshi
Copy link
Contributor

mbaneshi commented Nov 20, 2023

Hi all
Hope this message finds you well.
I have some concerns, about finishing this content. After a bit of struggling with myself, I find it will be beneficial to propose it here.

First, this is my first formal community contribution, In response to given community's trust in me as a newbie, I put my all in to bring valuable content.
I noticed the majority of the expected content to answer this issue, is already available in the TON doc.

of course, it suffers from :

  1. scattering into diverse parts.
  2. absence of some fundamental complementary text.
    That isn’t a surprise because the issue belongs to a bit past and some content would have been added since then.
    So I concluded this issue is still valid to proceed.

But my point is not this, I call for changing the issue title, and adjusting the content as follows :

Proposed title :
“ TON smart contract, gas optimization tips and tricks”

What does it mean?

General idea

Maybe we could indicate this article as the essence of TON development in general. Gas is a quantities unit, well-designed, well defined and we can sense its footsteps all around the TON development concepts and process.
In fact, it can play a role as glue to address the complexity of the system and bring comprehensive guidelines written by the developer for the developer.

The problem :

Gas in TON is not just calculating its fee or a consideration precaution to avoid pitfalls, such as the issue is meant to be addressed, in fact, It is an engineering indicator for writing code and utilizing the network optimally.
This issue addresses just a tiny importance of it.

I wrote this article many times, and when I came back and read it, I noticed that it was not complete. It neglects many important facts, avoiding redundancy and integrity with the previously presented content was a small challenge, finding a complementary text from, many hard-to-find resources was a medium challenge and the main concern was the fact :

  1. Some gas consumption improvements reside in the core concept of TON
  2. We have serious barriers to figure it out.
    3 . Just a few know how things work. This was confessed here .

Let’s bring some examples.

Example 1 :

The Tonkeeper wallet developer team recently optimized the storage fee to 95 percent. You can find more information here.
The idea was simple, Offloading business logic to the share library in the master chain and referring to it in the TVM context. Well, it needs to know Cells, TVM, Master chain, and base chain relation.
If you consider it simple! , it is not. This is version 5 of Wallet. Why not sooner?
It is worth noting, that the aforementioned team is the most experienced, active, and rewarded and inspiring one, who won the most rewards last year. So if for a seasoned, senior developer this simple concept of TON happens such late, to apply for a product, please consider others. In this way maybe you better grasp my idea.

Example 2 :

In an article that deals with TVM instruction for reducing gas computation fees, we have an interesting example There, it writes a new assembly word to avoid unnecessary use of intermediary data store leading to 500 units of gas savings.
But to deal with such a trick you should know the following :

  • How TVM works
  • What is Fift
  • Which capability does Fift have that made our hand open for this extensibility?

Now, consider the fact that everywhere the Doc has been addressing Fift, it indicates, this is low-level staff, for Braves.

More importantly, the fact that some traditional approaches to developing apps,(Monolithic, Microservice) here are a waste of time, money, and energy and even worse unused and impossible. This refers to the nature of TON, I mean we are faced with a novel system, that deserves a change in our mindset due to the design principle of the system.
I will be glad to hear from you. I also have a plan to address this concern and am open to discussion.

@mbaneshi
Copy link
Contributor

mbaneshi commented Nov 20, 2023

In short:

What I am looking for :

  1. Broaden issue understanding by considering the entire system, not just Func.

  2. Extend the timeframe by three weeks for a deeper dive into the rough concepts.

  3. Consider doubling the reward to cover the needed time and effort.

Meanwhile, you can check the index of accumulated data and sense of ongoing tasks, summarization of all TON blog posts and whitepapers pdf and tutorial Here, for developing this issue.

Checking this issue may be also useful.

@mbaneshi
Copy link
Contributor

Please check this post in the China TON dev group, to figure out how developers face problems.
here

@mbaneshi
Copy link
Contributor

mbaneshi commented Nov 28, 2023

@delovoyhomie and @reveloper please let me know your point of view regarding this issue, specifically the latest update. Thank you.
@reveloper please review this issue #374 as well, I think your comment can make help as well.

@delovoyhomie
Copy link
Collaborator

@mbaneshi, I will try to connect you with @talkol for assistance in this matter.

@mbaneshi
Copy link
Contributor

@delovoyhomie, It seems @talkol is busy, could you reach him? I sent him a message too, but no answer yet.

@mbaneshi
Copy link
Contributor

Hi , sorry for long delay ,it will publish soon.

@mbaneshi
Copy link
Contributor

Hi there, Below is the effort I made.
Please review this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved This proposal is approved by the committee Education Related to educational resources or initiatives
Projects
None yet
Development

No branches or pull requests

5 participants