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

Tweaks to upgrade #50

Merged
merged 10 commits into from
Jun 27, 2024
Merged

Tweaks to upgrade #50

merged 10 commits into from
Jun 27, 2024

Conversation

sgc-code
Copy link
Contributor

@sgc-code sgc-code commented Jun 26, 2024

Uses structs to try to achieve the following:

  • Make sure all 3 storage variable are upgrade atomically and there is no slot left behind
  • Easier to check if there was a pending upgrade
  • More info on event: in case there are two events with the same classhash but different data

Also i tweaked the error messages:

  • Trying to cancel when there's no proposed upgrade: upgrade/no-new-implementation to `'upgrade/no-pending-upgrade'
  • Calling upgrade when there's no pending upgrade: upgrade/invalid-calldata to upgrade/no-pending-upgrade

@sgc-code sgc-code changed the base branch from feat/grand-rename to develop June 26, 2024 14:10
@sgc-code sgc-code requested review from Leonard-Pat and gaetbout and removed request for Leonard-Pat June 26, 2024 14:14
@sgc-code sgc-code changed the title tweaks to upgrade Tweaks to upgrade Jun 26, 2024
Comment on lines 164 to 173
impl PendingUpgradeZero of core::num::traits::Zero<PendingUpgrade> {
fn zero() -> PendingUpgrade {
PendingUpgrade { implementation: Zero::zero(), ready_at: 0, calldata_hash: 0 }
}
fn is_zero(self: @PendingUpgrade) -> bool {
*self.calldata_hash == 0
}
fn is_non_zero(self: @PendingUpgrade) -> bool {
!self.is_zero()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually since we never use is_zero() I would optimize is_non_zero() instead.
Although now that I think about it, maybe it makes more sense to derive Default and just compare against Default::default()?

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 like it, Default seems more appropriate 👍

@sgc-code sgc-code requested a review from gaetbout June 27, 2024 08:57
@sgc-code
Copy link
Contributor Author

please @gaetbout take another look, i did some more changes, including the Updated event, i removed the ready_at field from it as it won't be easy to include in the upgrade

Comment on lines 161 to 162

fn reset_storage(ref self: ComponentState<TContractState>) {
self.pending_implementation.write(Zero::zero());
self.ready_at.write(0);
self.calldata_hash.write(0);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fn reset_storage(ref self: ComponentState<TContractState>) {
self.pending_implementation.write(Zero::zero());
self.ready_at.write(0);
self.calldata_hash.write(0);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

there is just an extra line return 🤣

}

#[derive(Drop, starknet::Event)]
struct Upgraded {
new_implementation: ClassHash
struct UpgradedExecuted {
Copy link
Contributor

Choose a reason for hiding this comment

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

UpgradeExecuted*

Copy link
Contributor

@gaetbout gaetbout Jun 27, 2024

Choose a reason for hiding this comment

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

This event is actually never emitted

Copy link
Contributor

Choose a reason for hiding this comment

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

guessing it should be emitted by the callback impl?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's supposed to be emitted by the next implementatio

Copy link
Contributor

Choose a reason for hiding this comment

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

i just meant the spelling is wrong is should be UpgradeExecuted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it

@gaetbout
Copy link
Contributor

i removed the ready_at field from it as it won't be easy to include in the upgrade

Not sure I follow that sentence 🤔

Copy link
Contributor

@gaetbout gaetbout left a comment

Choose a reason for hiding this comment

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

reverting approval

@sgc-code
Copy link
Contributor Author

i removed the ready_at field from it as it won't be easy to include in the upgrade

Not sure I follow that sentence 🤔

In some previous commits the event after the upgrade used to have a field called 'ready_at' but it's gone now

Copy link
Contributor

Choose a reason for hiding this comment

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

why did the asserts change to == and not should.equal..

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'm not a big fan of chai, feels like reinventing the wheel trying to replace all the stuff we use with functions.
> -> .isBelow
=== -> equals but there is also deep.equals , eq and eql
await -> eventually

i'm not really sure having to introducing all this stuff is worth it to get slightly better errors
i leave my rant here but i changed it to align with the rest of the project and get this merged

#[derive(Serde, Drop, Copy, Default, PartialEq, starknet::Store)]
struct PendingUpgrade {
// Gets the classhash after
implementation: ClassHash,
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be proposed implementation ?
also dont get the comment of 'gets classhash after?'
nit: 0 if no upgrade ongoing ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated, i drop the proposed_ since it's already in a struct called PendingUpgrade, calldata would also be proposed_

@Leonard-Pat
Copy link
Contributor

Feel free to ignore but if we insantiate Default::default() on multiple lines would it be better to have:

let empty_uprade: PendingUpgrade = Default::default();
...

then use empty upgrade?

Really doesnt matter but im curious

@sgc-code sgc-code merged commit 50c52e7 into develop Jun 27, 2024
5 checks passed
@sgc-code sgc-code deleted the tweaks-to-upgrade branch July 5, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants