ton-society / grants-and-bounties

TON Foundation invites talent to imagine and realize projects that have the potential to integrate with the daily lives of users.
https://ton.org/grants
293 stars 132 forks source link

Article: How to manage your contract gas #20

Open talkol opened 2 years ago

talkol commented 2 years ago

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

Deliverables

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

Definition of Done

Reward

Hiyorimi commented 2 years ago

Can it be merged with Issue#9?

talkol commented 2 years ago

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 commented 2 years ago

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

talkol commented 2 years ago

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

talkol commented 2 years ago

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 commented 1 year ago

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 commented 1 year ago

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

Gusarich commented 1 year ago

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

delovoyhomie commented 11 months ago

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

mbaneshi commented 11 months ago

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 commented 11 months ago

@delovoyhomie Thank you.

mbaneshi commented 11 months ago

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

delovoyhomie commented 11 months ago

@mbaneshi, thank you for following the bounty guideline!

delovoyhomie commented 11 months ago

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

mbaneshi commented 11 months ago

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 commented 11 months ago

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

mbaneshi commented 10 months ago

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

mbaneshi commented 10 months ago

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 :

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 commented 10 months ago

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 commented 10 months ago

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

mbaneshi commented 10 months ago

@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 commented 10 months ago

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

mbaneshi commented 9 months ago

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

mbaneshi commented 5 months ago

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

mbaneshi commented 3 months ago

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