-
Notifications
You must be signed in to change notification settings - Fork 707
feat: add promise batch host functions for global contracts #13565
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
Conversation
2c3aebb
to
13df8d0
Compare
@@ -76,6 +76,8 @@ extern "C" { | |||
// ####################### | |||
fn promise_batch_action_create_account(promise_index: u64); | |||
fn promise_batch_action_deploy_contract(promise_index: u64, code_len: u64, code_ptr: u64); | |||
fn promise_batch_action_deploy_global_contract(promise_index: u64, code_len: u64, code_ptr: u64); | |||
fn promise_batch_action_deploy_global_contract_by_account_id(promise_index: u64, code_len: u64, code_ptr: u64); |
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.
Huh, why is deploying a global contract by an account id taking a full code to deploy and not the account id to reference?
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.
when deploying global contract by account id we use account id of the signer (receipt's predecessor_id
), also see DeployGlobalContractAction
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.
@pugachAG Do you mean current_account_id where the contract is executed at? It is totally odd to deploy the contract to the signer/predecessor account!!!
Will it actually replace the currently deployed contract on the account_id?
Would you be open to naming it promise_batch_action_deploy_global_contract_identifiable_by_account_id
?
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.
Do you mean current_account_id where the contract is executed at?
Technically this corresponds to the receipt receiver account_id. DeployGlobalContract
action requires predecessor_id
to be equal to the receiver_id
, so those should be the same.
Will it actually replace the currently deployed contract on the account_id?
No, deploying global contract does not replace anything, it just makes the contract available. UseGlobalContract
does that.
Would you be open to naming it
I prefer to keep host function naming consistent with action naming. This name is derived from ActionView::DeployGlobalContractByAccountId
Ah, I guess you may want to gate these host functions by some sort of a protocol feature/config in order to have these become available deterministically. |
promise_batch_action_deploy_global_contract<[promise_index: u64, code_len: u64, code_ptr: u64] -> []>, | ||
promise_batch_action_deploy_global_contract_by_account_id<[promise_index: u64, code_len: u64, code_ptr: u64] -> []>, |
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.
promise_batch_action_deploy_global_contract<[promise_index: u64, code_len: u64, code_ptr: u64] -> []>, | |
promise_batch_action_deploy_global_contract_by_account_id<[promise_index: u64, code_len: u64, code_ptr: u64] -> []>, | |
#[deploy_global_host_fns] promise_batch_action_deploy_global_contract<[promise_index: u64, code_len: u64, code_ptr: u64] -> []>, | |
#[deploy_global_host_fns] promise_batch_action_deploy_global_contract_by_account_id<[promise_index: u64, code_len: u64, code_ptr: u64] -> []>, |
or something along these lines. This will require a new field in the Config
.
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.
added global_contract_host_fns
parameter
41d9998
to
b2336c4
Compare
2d0e0f8
to
ed0f375
Compare
@@ -76,6 +76,10 @@ extern "C" { | |||
// ####################### | |||
fn promise_batch_action_create_account(promise_index: u64); | |||
fn promise_batch_action_deploy_contract(promise_index: u64, code_len: u64, code_ptr: u64); | |||
fn promise_batch_action_deploy_global_contract(promise_index: u64, code_len: u64, code_ptr: u64); |
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.
I assume deploys the global contract that is identifiable by its hash, right?
What should be the receiver_account_id for the promise? Anything? Or MUST it be the current_account_id (like the regular deploy action)?
Will it replace the currently deployed contract on the signer, predecessor, or receiver account id?
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.
I assume deploys the global contract that is identifiable by its hash, right?
that is correct
What should be the receiver_account_id for the promise? Anything? Or MUST it be the current_account_id (like the regular deploy action)?
receiver should be the same as predecessor, see check_actor_permissions
for DeployGlobalContract
action
Will it replace the currently deployed contract on the signer, predecessor, or receiver account id?
promise_batch_action_deploy_global_contract
doesn't replace anything, global contracts deployed by hash are not associated with any account. In case of promise_batch_action_deploy_global_contract_by_account_id
it replaces current contract deployed under receiver account id (which is required to be the same as predecessor).
Currently we copy `backwards_compatible_rs_contract.wasm` from `res` directory. This is no longer necessary since we no longer support old protocol versions. This PR changes that to make it compiled from `test-contract-rs` without `latest_protocol` feature enabled. This way we can make changes test contract in backward compatible way using `#[cfg(feature = "latest_protocol")]`. `backwards_compatible_rs_contract.wasm` is renamed to `legacy_backwards_compatible_rs_contract.wasm`, we keep it for the `test_near_vm_artifact_output_stability` test. We also change `resharding_v3` tests to use `backwards_compatible_rs_contract` instead of `rs_contract` because that test suite uses non-latest protocol version. So it imports host functions that might not yet be exposed in that protocol version which breaks it (#13565 is one example). Backward compatible contract should be used in such cases. --------- Co-authored-by: Simonas Kazlauskas <git@kazlauskas.me>
392d662
to
1513598
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #13565 +/- ##
===========================================
+ Coverage 1.62% 69.43% +67.81%
===========================================
Files 661 856 +195
Lines 115296 168433 +53137
Branches 115296 168433 +53137
===========================================
+ Hits 1873 116957 +115084
+ Misses 113367 46687 -66680
- Partials 56 4789 +4733
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This PR introduces host functions for deploying and using global contracts:
We use separate functions for deployments by hash and by account id to keep it consistent with
DeployGlobalContract
andDeployGlobalContractByAccountId
action views. The same applies for using global contract by hash and by account_id.Implementation is "monkey see, monkey do" based on other
promise_batch_action_deploy_contract
.global_contract_host_fns
runtime config param is added to ensure that new functions become available as part of protocol version 78.Closes #13373.