-
Notifications
You must be signed in to change notification settings - Fork 664
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
Conversation
d807d7b
to
9edff75
Compare
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
9edff75
to
a2e35d0
Compare
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.
Looks good!
version: current_protocol_version, | ||
}); | ||
} | ||
if action.code.len() as u64 > limit_config.max_contract_size { |
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.
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?
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.
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
@@ -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")] |
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.
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
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.
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
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.
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, |
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.
Why not add it to nightly?
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 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
core/primitives/src/views.rs
Outdated
let code = hash(&action.code).as_ref().to_vec(); | ||
ActionView::DeployGlobalContract { code, link_account: action.link_account } |
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.
nit: Can you rename code in DeployGlobalContract
to code_hash
please? Or even better rename it and change the type to CryptoHash.
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.
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.
core/primitives/src/action/mod.rs
Outdated
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, | ||
} |
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.
This seems like a design choice, I'm not familiar enough to comment on this.
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.
let me know if it is unclear, maybe I'd better rename this or add more comment
core/primitives/src/action/mod.rs
Outdated
|
||
/// Enables global contract code to referenced by owner account id | ||
/// instead of code hash | ||
pub link_account: bool, |
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.
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(_) => {} |
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.
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.
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.
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.
I've just pushed 650d9aa with the following changes:
|
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.