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

Move TxContext implementation via natives and sponsor #21245

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dariorussi
Copy link
Contributor

@dariorussi dariorussi commented Feb 16, 2025

Description

This enables Move TxContext to use native functions. It also expose a fun sponsor(self: &TxContext): Option<address> that returns the address of the sponsor if the transaction was sponsored.

tx_context.rs has all the changes to allow gas_price, gas_budget and sponsor.
I moved TransactionContext (the struct pushed to NativeContextExtension) in its own directory like crypto and object_runtime. In time TransactionContext may evolve to have a richer API so it made sense to have it in its own directory.

Test plan

Sponsor test coming


Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • gRPC:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:

Copy link

vercel bot commented Feb 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 5, 2025 3:19pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Mar 5, 2025 3:19pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Mar 5, 2025 3:19pm

@dariorussi dariorussi temporarily deployed to sui-typescript-aws-kms-test-env February 16, 2025 20:40 — with GitHub Actions Inactive
@dariorussi dariorussi temporarily deployed to sui-typescript-aws-kms-test-env February 17, 2025 16:27 — with GitHub Actions Inactive
@dariorussi dariorussi temporarily deployed to sui-typescript-aws-kms-test-env February 17, 2025 18:09 — with GitHub Actions Inactive
@dariorussi dariorussi temporarily deployed to sui-typescript-aws-kms-test-env February 18, 2025 19:45 — with GitHub Actions Inactive
@dariorussi dariorussi temporarily deployed to sui-typescript-aws-kms-test-env February 19, 2025 16:40 — with GitHub Actions Inactive
@dariorussi dariorussi temporarily deployed to sui-typescript-aws-kms-test-env February 19, 2025 23:35 — with GitHub Actions Inactive
@dariorussi dariorussi temporarily deployed to sui-typescript-aws-kms-test-env February 21, 2025 15:57 — with GitHub Actions Inactive
@dariorussi dariorussi temporarily deployed to sui-typescript-aws-kms-test-env February 21, 2025 18:35 — with GitHub Actions Inactive
@dariorussi dariorussi temporarily deployed to sui-typescript-aws-kms-test-env February 22, 2025 14:21 — with GitHub Actions Inactive
@dariorussi dariorussi temporarily deployed to sui-typescript-aws-kms-test-env February 23, 2025 17:10 — with GitHub Actions Inactive
@@ -3254,7 +3283,19 @@ impl ProtocolConfig {
cfg.feature_flags.passkey_auth = true;
}
}
76 => {}
76 => {
cfg.feature_flags.move_native_context = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why value 30?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see answer to @tnowacki 's same comment

@@ -338,11 +355,77 @@ impl NativesCostTable {
.transfer_share_object_cost_base()
.into(),
},
// tx_context
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about the meaning of this comment (is it cut short?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can remove it but it was to highlight that the API below is for the tx_context and other part of this code do the same, so it was to replicate what is there already and to mark where that API is

pub fn fresh_id(&mut self) -> ObjectID {
let id = ObjectID::derive_id(self.digest(), self.ids_created);
pub fn sender(&self) -> SuiAddress {
SuiAddress::from(ObjectID(self.sender))
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend self.sender.into() or possibly SuiAddress:from(self.sender) here. Going through ObjectID to get there feels just wasteful lol

76 => {
cfg.feature_flags.move_native_context = false;

cfg.tx_context_fresh_id_cost_base = Some(30);
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be the same as tx_context_derive_id_cost_base. You could even reuse that one instead of this one possibly if you wanted to?

Copy link
Contributor Author

@dariorussi dariorussi Feb 26, 2025

Choose a reason for hiding this comment

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

fair, I will put that value in here for now, good point.
Later we will tune if we need to.
I did not want to reuse that value because I am not sure how those functions will evolve.
The derived_id may disappear, not sure

* native fun fresh_id
* Implementation of the Move native function `fun fresh_id(): address`
**************************************************************************************************/
pub fn fresh_id(
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, what even is this function? Is it fresh_object_address? Why isn't that kept in Move?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see comment about that above (as an asnwer to @tzakian) we need to compute the fresh id in the new model and that is all in rust.
How could we do that in Move code?

@dariorussi dariorussi temporarily deployed to sui-typescript-aws-kms-test-env February 27, 2025 03:16 — with GitHub Actions Inactive
@dariorussi dariorussi changed the title Rust TxContext changes and Move native functions implementation Move TxContext implementation via natives and sponsor Feb 27, 2025
@dariorussi dariorussi temporarily deployed to sui-typescript-aws-kms-test-env February 27, 2025 04:05 — with GitHub Actions Inactive
@dariorussi dariorussi temporarily deployed to sui-typescript-aws-kms-test-env February 28, 2025 15:51 — with GitHub Actions Inactive
@dariorussi dariorussi temporarily deployed to sui-typescript-aws-kms-test-env March 1, 2025 13:13 — with GitHub Actions Inactive
@dariorussi dariorussi temporarily deployed to sui-typescript-aws-kms-test-env March 1, 2025 20:54 — with GitHub Actions Inactive
@dariorussi dariorussi temporarily deployed to sui-typescript-aws-kms-test-env March 1, 2025 22:23 — with GitHub Actions Inactive
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.

4 participants