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: add receipt action for deploying global contract code #12737

Merged
merged 4 commits into from
Jan 16, 2025

Conversation

pugachAG
Copy link
Contributor

This PR includes mostly wiring, actual implementation will be added separately to make it easier to review.
I explicitly don't want to introduce compile time feature for this as it makes code much harder to work with. validate_action makes sure that newly added action cannot be used before stabilisation.

Part of #12715.

@pugachAG pugachAG requested a review from a team as a code owner January 14, 2025 20:18
@pugachAG pugachAG force-pushed the add-deploy-global-contract-action branch from d807d7b to 9edff75 Compare January 14, 2025 20:21
Copy link

codecov bot commented Jan 14, 2025

Codecov Report

Attention: Patch coverage is 1.31579% with 75 lines in your changes missing coverage. Please review.

Project coverage is 70.70%. Comparing base (8806e63) to head (2dde6f9).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
runtime/runtime/src/verifier.rs 0.00% 22 Missing ⚠️
core/primitives/src/action/mod.rs 0.00% 16 Missing ⚠️
core/primitives/src/views.rs 0.00% 15 Missing ⚠️
runtime/runtime/src/actions.rs 0.00% 9 Missing ⚠️
runtime/runtime/src/config.rs 0.00% 6 Missing ⚠️
chain/rosetta-rpc/src/adapters/mod.rs 0.00% 3 Missing ⚠️
runtime/runtime/src/lib.rs 0.00% 2 Missing ⚠️
core/primitives-core/src/version.rs 0.00% 1 Missing ⚠️
tools/state-viewer/src/contract_accounts.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12737      +/-   ##
==========================================
- Coverage   70.74%   70.70%   -0.04%     
==========================================
  Files         848      848              
  Lines      174301   174376      +75     
  Branches   174301   174376      +75     
==========================================
- Hits       123303   123288      -15     
- Misses      45856    45943      +87     
- Partials     5142     5145       +3     
Flag Coverage Δ
backward-compatibility 0.16% <0.00%> (-0.01%) ⬇️
db-migration 0.16% <0.00%> (-0.01%) ⬇️
genesis-check 1.35% <0.00%> (-0.01%) ⬇️
linux 69.19% <1.31%> (-0.05%) ⬇️
linux-nightly 70.26% <1.31%> (-0.05%) ⬇️
pytests 1.65% <0.00%> (-0.01%) ⬇️
sanity-checks 1.46% <0.00%> (-0.01%) ⬇️
unittests 70.53% <1.31%> (-0.04%) ⬇️
upgradability 0.20% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pugachAG pugachAG force-pushed the add-deploy-global-contract-action branch from 9edff75 to a2e35d0 Compare January 14, 2025 20:49
@pugachAG pugachAG requested a review from nagisa January 15, 2025 11:16
Copy link
Contributor

@shreyan-gupta shreyan-gupta left a comment

Choose a reason for hiding this comment

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

Looks good!

version: current_protocol_version,
});
}
if action.code.len() as u64 > limit_config.max_contract_size {
Copy link
Contributor

Choose a reason for hiding this comment

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

Confirming, is this the only check we need in the verifier? I'm guessing it's based off the above validate_deploy_contract_action function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I've copied this from verifier for the regular deploy contract action, I believe we should enforce the same limits for the global contract code

tools/protocol-schema-check/res/protocol_schema.toml Outdated Show resolved Hide resolved
@@ -216,6 +247,7 @@ pub enum Action {
DeleteKey(Box<DeleteKeyAction>),
DeleteAccount(DeleteAccountAction),
Delegate(Box<delegate::SignedDelegateAction>),
DeployGlobalContract(DeployGlobalContractAction),
#[cfg(feature = "protocol_feature_nonrefundable_transfer_nep491")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like protocol_feature_nonrefundable_transfer_nep491 isn't stable yet and only potentially as part of nightly. Just wanted to make sure the ordering is not going to mess up BorshSerialize

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct, since nonrefundable_transfer is not stable yet we want to add our feature before that, otherwise stabilising nonrefundable_transfer later will break borsch serialization

Copy link
Contributor

@wacban wacban left a comment

Choose a reason for hiding this comment

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

LGTM assuming the design part is agreed upon.

@@ -286,6 +287,7 @@ impl ProtocolFeature {
ProtocolFeature::ExcludeExistingCodeFromWitnessForCodeLen => 148,
ProtocolFeature::BlockHeightForReceiptId => 149,
// Place features that are not yet in Nightly below this line.
ProtocolFeature::GlobalContracts => 200,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not add it to nightly?

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 wanted to move it to the nightly separately when I have the complete implementation, to avoid dealing with potential test failures because of unimplemented todos

Comment on lines 1216 to 1217
let code = hash(&action.code).as_ref().to_vec();
ActionView::DeployGlobalContract { code, link_account: action.link_account }
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can you rename code in DeployGlobalContract to code_hash please? Or even better rename it and change the type to CryptoHash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the weird part I've copied from DeployContract action that I don't really understand: when converting action to the view we hash the contract, but when converting view to action we do not. I assume it works somehow, so I preserved the logic.

Comment on lines 121 to 129
pub struct DeployGlobalContractAction {
/// WebAssembly binary
#[serde_as(as = "Base64")]
pub code: Vec<u8>,

/// Enables global contract code to referenced by owner account id
/// instead of code hash
pub link_account: bool,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a design choice, I'm not familiar enough to comment on this.

Copy link
Contributor Author

@pugachAG pugachAG Jan 15, 2025

Choose a reason for hiding this comment

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

let me know if it is unclear, maybe I'd better rename this or add more comment


/// Enables global contract code to referenced by owner account id
/// instead of code hash
pub link_account: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than a bool, consider a field of bitflags. Those are more extensible without affecting the protocol as much in case we want to implement additional behaviours for the action.

@@ -189,7 +189,8 @@ impl ReceiptPreparationPipeline {
| Action::Stake(_)
| Action::AddKey(_)
| Action::DeleteKey(_)
| Action::DeleteAccount(_) => {}
| Action::DeleteAccount(_)
| Action::DeployGlobalContract(_) => {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to ensure that any of the FunctionCall actions involving the contract deployed by DeployGlobalContract in the current chunk are not pipelined (see the blocking logic for regular deploys.) Probably alright to punt on the implementation here to later, but putting it alongside the "no handling for these" chunk of actions runs a significant risk of forgetting about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Global contract deploys only take effect in the next block, so those won't affect pipelining. The actual deploy (saving to the state) will be implemented with a separate receipt type later, and I will add proper handling for that in the pipelining code.

@pugachAG
Copy link
Contributor Author

pugachAG commented Jan 15, 2025

I've just pushed 650d9aa with the following changes:

  • use enum instead of bool flag
  • split the view into 2 separate actions for deploying by code hash and by account id to keep user-facing API more neat

@pugachAG pugachAG added this pull request to the merge queue Jan 15, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 15, 2025
@pugachAG pugachAG added this pull request to the merge queue Jan 15, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 15, 2025
@pugachAG pugachAG added this pull request to the merge queue Jan 15, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 15, 2025
@pugachAG pugachAG enabled auto-merge January 15, 2025 20:01
@pugachAG pugachAG added this pull request to the merge queue Jan 15, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 15, 2025
@pugachAG pugachAG added this pull request to the merge queue Jan 16, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 16, 2025
@wacban wacban added this pull request to the merge queue Jan 16, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 16, 2025
@pugachAG pugachAG added this pull request to the merge queue Jan 16, 2025
Merged via the queue into master with commit 0a57709 Jan 16, 2025
26 of 28 checks passed
@pugachAG pugachAG deleted the add-deploy-global-contract-action branch January 16, 2025 15:13
github-merge-queue bot pushed a commit that referenced this pull request Jan 16, 2025
This PR is similar to #12737, but for using global contracts. 

Part of #12716.
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