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

feat!: optimize and rework send() function #1650

Merged
merged 16 commits into from
Jan 31, 2025
Merged

feat!: optimize and rework send() function #1650

merged 16 commits into from
Jan 31, 2025

Conversation

Shvandre
Copy link
Contributor

Issue

Closes #1649
Closes #1558

Checklist

  • I have updated CHANGELOG.md
  • I have run all the tests locally and no test failure was reported
  • I have run the linter, formatter and spellchecker
  • I did not do unrelated and/or undiscussed refactorings

Results (two last rows):
image

@Shvandre Shvandre requested a review from a team as a code owner January 30, 2025 21:19
@novusnota novusnota added this to the v1.6.0 milestone Jan 30, 2025
@novusnota novusnota changed the title 1558,1649 feat!: optimize and rework send() function Jan 30, 2025
Copy link
Member

@anton-trunov anton-trunov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super-awesome stuff 🎸 Let's update the Jetton benchmarks

@anton-trunov
Copy link
Member

I think all those inline comments make the code harder to read. We should

  • review the functional equivalence of the old and new code
  • make only high-level comments only explaining the approach, if needed

@novusnota
Copy link
Member

novusnota commented Jan 31, 2025

I think all those inline comments make the code harder to read. We should

  • review the functional equivalence of the old and new code
  • make only high-level comments only explaining the approach, if needed

I've edited the context.tact part, see: 736f532. Feel free to comment on that. During this hour I'll edit the send.tact part and address possible comments for context.tact.

By the way, we also need a note on Context.readForwardFee() now working only for the workchains, not the masterchain! I'll add that in.

Shvandre and others added 2 commits January 31, 2025 19:34
@novusnota
Copy link
Member

novusnota commented Jan 31, 2025

By the way, we also need a note on Context.readForwardFee() now working only for the workchains, not the masterchain! I'll add that in.

UPD: Value of first_frac is the same for masterchain and other workchains as of now, so I was technically wrong there. For now.


Now that I think about it, we're (potentially) making a breaking change here compared to the non-asm version of the function: #1650 (comment)

Instead of adding the ZERO GETORIGINALFWDFEE by the end of Context.readForwardFee(), we should probably keep the fwd_fee value that it gives, and only then apply the getOriginalFwdFee() function on top.

Otherwise:

  1. getOriginalFwdFee() is rendered useless, and the example given there gives higher fees than before
  2. Context.readForwardFee() returns not the fwd_fee * 3 / 2 as it used to do (for whatever reason), but the (fwd_fee * 2^16) / first_frac, where first_frac is a value listed in config param 25 of the Blockchain: https://tonscan.org/config#25.

P.S.: But I may be totally off here, so I'll write some tests :)

@Shvandre
Copy link
Contributor Author

I actually left previous behaviour

@novusnota
Copy link
Member

novusnota commented Jan 31, 2025

I actually left previous behaviour

Yeah, and I overlooked it in the previous PR. The behavior prior to all asm changes was:

extends fun readForwardFee(self: Context): Int {
    let sc: Slice = self.raw;
    sc.loadAddress(); // Skip destination
    sc.loadCoins(); // Skip value
    sc.skipBits(1); // Skip extra currency collection
    sc.loadCoins(); // Skip ihr_fee
    return (sc.loadCoins() * 3) / 2;
}

Which, roughly speaking, was producing halved result of the current iteration of .readForwardFee(). Or at least it seems that way to me, assuming TON Docs are correct.

@anton-trunov
Copy link
Member

@novusnota can you please suggest tests to see if your considerations are taken into account here

@novusnota
Copy link
Member

novusnota commented Jan 31, 2025

Hmm, I did some local checks and @Shvandre is right, things are still ok. Sorry everyone, false alarm from me :):

That said, I'll add e2e tests to encode the behavior

@anton-trunov anton-trunov self-assigned this Jan 31, 2025
@anton-trunov anton-trunov merged commit dd48c25 into main Jan 31, 2025
25 checks passed
@anton-trunov anton-trunov deleted the 1558,1649 branch January 31, 2025 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

send() function needs a better implementation Version of send() using SENDRAWMSG instead of SENDMSG
4 participants