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 trie key global contract code #12766

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pugachAG
Copy link
Contributor

Part of #12715.

For each global contract we store its code replicated on every shard. This PR adds a trie key to support that.

@pugachAG pugachAG requested a review from a team as a code owner January 21, 2025 18:22
@pugachAG pugachAG force-pushed the global-contracts-trie-storage branch from 63ce420 to d7a65e6 Compare January 21, 2025 19:04
@pugachAG pugachAG force-pushed the global-contracts-trie-storage branch from d7a65e6 to e1d15ac Compare January 21, 2025 22:19
Copy link

codecov bot commented Jan 21, 2025

Codecov Report

Attention: Patch coverage is 6.25000% with 30 lines in your changes missing coverage. Please review.

Project coverage is 70.52%. Comparing base (9d97226) to head (e1d15ac).

Files with missing lines Patch % Lines
core/primitives/src/trie_key.rs 0.00% 29 Missing ⚠️
core/primitives/src/types.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #12766   +/-   ##
=======================================
  Coverage   70.51%   70.52%           
=======================================
  Files         846      846           
  Lines      174633   174665   +32     
  Branches   174633   174665   +32     
=======================================
+ Hits       123149   123175   +26     
  Misses      46262    46262           
- Partials     5222     5228    +6     
Flag Coverage Δ
backward-compatibility 0.16% <0.00%> (-0.01%) ⬇️
db-migration 0.16% <0.00%> (-0.01%) ⬇️
genesis-check 1.35% <0.00%> (?)
linux 68.91% <6.25%> (+0.02%) ⬆️
linux-nightly 70.09% <6.25%> (-0.04%) ⬇️
pytests 1.65% <0.00%> (+0.18%) ⬆️
sanity-checks 1.46% <0.00%> (-0.01%) ⬇️
unittests 70.35% <6.25%> (-0.02%) ⬇️
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.

Comment on lines +371 to +372
// Global contract code is not a part of account, so ignoring it as well.
TrieKey::GlobalContractCode { .. } => {}
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking of a global contract as the same thing as a normal contract but deployed on all shards so I imagined the handling would be similar for TrieKey::ContractCode and TrieKey::GlobalContractCode

What exactly do you mean by "not a part of account"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

StateChanges represents to updates to some parts of user account, global contract is more of a part of a global shard state, so it handled differently

@pugachAG pugachAG requested a review from wacban January 22, 2025 12:57
@@ -193,6 +230,9 @@ pub enum TrieKey {
receiving_shard: ShardId,
index: u64,
},
GlobalContractCode {
identifier: GlobalContractCodeIdentifier,
Copy link
Member

Choose a reason for hiding this comment

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

Would be great to add a few tests for this new key and its implementation

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.

Can you add a test for the resharding logic? For reference please see the resharding_v3 testloop. I think it should be sufficient to deploy a global contract before resharing and call it in both children after resharding.

cc @staffik This may also trigger the negative refcount issue / wrong refcount accounting during resharding.

@@ -62,6 +62,7 @@ pub mod col {
pub const BUFFERED_RECEIPT_GROUPS_QUEUE_DATA: u8 = 16;
/// A single item of `ReceiptGroupsQueue`. Values are of type `ReceiptGroup`.
pub const BUFFERED_RECEIPT_GROUPS_QUEUE_ITEM: u8 = 17;
pub const GLOBAL_CONTRACT_CODE: u8 = 18;
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 add a comment including the value type (like above), please?

}
}

pub fn append_into(&self, buf: &mut Vec<u8>) {
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 use borsh::to_vec().unwrap() here instead of defining functions like append_into, discriminator, etc.?

Copy link
Contributor

Choose a reason for hiding this comment

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

TrieKey::AccessKey has a similar pattern

@@ -53,7 +53,8 @@ fn boundary_account_to_intervals(
col::DELAYED_RECEIPT_OR_INDICES
| col::PROMISE_YIELD_INDICES
| col::PROMISE_YIELD_TIMEOUT
| col::BANDWIDTH_SCHEDULER_STATE => {
| col::BANDWIDTH_SCHEDULER_STATE
| col::GLOBAL_CONTRACT_CODE => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if you hit the // Poor man's exhaustive check for handling all column types. 😛

@shreyan-gupta
Copy link
Contributor

Can you add a test for the resharding logic? For reference please see the resharding_v3 testloop. I think it should be sufficient to deploy a global contract before resharing and call it in both children after resharding.

Might not be super necessary as we have a test in core/store/src/trie/ops/resharding.rs to check if the key, value are copied to both children.

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!

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.

5 participants