-
Notifications
You must be signed in to change notification settings - Fork 363
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
Add optional delay to AccessControl role grants #1317
base: main
Are you sure you want to change the base?
Conversation
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 left a small suggestion besides the missing tests that still need to be added.
delay: u64, | ||
) { | ||
assert(delay > 0, Errors::INVALID_DELAY); | ||
if !self.is_role_granted(role, 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.
Since now users may want to use the grant_role_function to update a delay, or the grant_role function to remove the delay, these functions silently passing may confuse them. What do you think about adding an error on the else condition stating that the user already has the role?
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.
So far, so good @immrsd! I left a few minor comments
assert(authorized, Errors::MISSING_ROLE); | ||
} | ||
|
||
/// Returns whether the account can act as the given role. | ||
/// | ||
/// The account can act as the role if it is active and the effective from time is before |
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.
/// The account can act as the role if it is active and the effective from time is before | |
/// The account can act as the role if it is active and the AccountRoleInfo::effective_from time is before |
I think this reads a little easier. It wasn't obvious at first what "effective from time" meant
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.
Or even something like effective_from
#[starknet::interface] | ||
pub trait IAccessControlWithDelay<TState> { | ||
fn grant_role_with_delay(ref self: TState, role: felt252, account: ContractAddress, delay: 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.
We should also add this to the ABI, no?
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.
Also, I wonder if there's some value in having a new src5 id for this. I really don't think it's worth it, but I'm asking out loud just in case
/// 1. `effective_from` is stored at range [187,250] (0-indexed starting from the most | ||
/// significant bits). | ||
/// 2. `is_active` is stored at range [251, 251], following `effective_from`. |
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.
👍
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1317 +/- ##
==========================================
- Coverage 92.26% 89.59% -2.68%
==========================================
Files 59 83 +24
Lines 1811 3557 +1746
==========================================
+ Hits 1671 3187 +1516
- Misses 140 370 +230
... and 80 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Notable changes since the last update:
Now, the functions work in such way that the state after the call is consistent with the last executed call:
|
Fixes #1261
Continues the work started in #1262
This implementation is backward compatible. Contracts using the existing AccessControl component should be able to upgrade to this implementation without breaking the storage or the logic since they will have effective_from set as 0 by default for existing roles, and the AccountRoleInfo active member layout is compatible with the current boolean.
NOTE: This is a POC, so it lacks tests and documentation yet. MUST NOT be used as it is until is finished.
PR Checklist