Skip to content

refactor: Extract Mint and Burn PolicyManager into their own component#2821

Open
onurinanc wants to merge 28 commits into0xMiden:nextfrom
onurinanc:mint-burn-extraction
Open

refactor: Extract Mint and Burn PolicyManager into their own component#2821
onurinanc wants to merge 28 commits into0xMiden:nextfrom
onurinanc:mint-burn-extraction

Conversation

@onurinanc
Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Contributor

@bobbinth bobbinth 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! Thank you! I think this basically covers the functionality we need. I left some comments inline - but they are mostly about naming.

It did take me a little time to wrap my head around how everything works - so, I wonder if there is a way to simplify things somehow - but I don't have concrete suggestions on this (maybe not using generics for policy manager could make it easier to understand - but I'm not sure about this).

Comment on lines +27 to +28
/// The name of the component.
pub const NAME: &'static str = "miden::standards::components::policies::mint::mod";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Having mod in the component name feel a bit weird. I think is should probably be miden::standards::components::policies::mint::allow_all - but then the question is what should we name the procedure. One option could be check_policy (or something similar) and then the full procedure path would be:

miden::standards::components::policies::mint::allow_all::check_policy

Comment on lines +28 to +31
pub const NAME: &'static str =
"miden::standards::components::policies::burn::owner_controlled::owner_only";

const PROC_NAME: &str = "owner_only";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Related to the above comment, maybe the procedure name here should also be just check_policy or something similar?

Comment on lines +28 to +30
pub const NAME: &'static str = "miden::standards::components::policies::burn::mod";

const PROC_NAME: &str = "allow_all";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Related to the above comments. I'd probably rename the name to miden::standards::components::policies::burn::allow_all and the procedure name something like check_policy (or could be execute).

Comment on lines +150 to +151
/// Registers an additional policy root in the allowed-policies list.
pub fn with_allowed_policy(mut self, policy_root: Word) -> Self {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I would probably mention in the comment that if the policy is already in the set, this is a noop.

Comment on lines 179 to +194
let account = AccountBuilder::new(init_seed)
.account_type(AccountType::FungibleFaucet)
.storage_mode(AccountStorageMode::Network)
.with_auth_component(auth_component)
.with_component(metadata)
.with_component(NetworkFungibleFaucet)
.with_component(access_control)
.with_component(MintOwnerControlled::owner_only())
.with_component(BurnOwnerControlled::allow_all())
.with_component(mint::PolicyManager::owner_controlled(
mint::owner_controlled::Config::OwnerOnly,
))
.with_component(mint::owner_controlled::OwnerOnly)
.with_component(burn::PolicyManager::owner_controlled(
burn::owner_controlled::Config::AllowAll,
))
.with_component(burn::owner_controlled::OwnerOnly)
.with_component(burn::AllowAll)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it may be worth adding a comment here explaining the dependency graph (hopefully, in the future we'll have this enforced, but since we don't have this yet, we should document it). The way I understand it, the graph looks like so:

  • NetworkFungibleFaucet requires mint::PolicyManager and burn::PolicyManager.
  • These policy managers require policies, and are instantiated as follows:
    • mint::PolicyManager is instantiated with OwnerOnly.
    • burn::PolicyManager is instantiated with AllowAll and OwnerOnly (with AllowAll being set by default).
  • OwnerOnly policies (for both mint and burn) require Ownable2Step.

Comment on lines +32 to +33
const COMPONENT_NAME: &'static str =
"miden::standards::components::policies::mint::policy_manager";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we need to have components in the component name - or at least I don't think we do this for other components. So, the name could be:

miden::standards::policies::mint::policy_manager

Or we could also make it more specific:

miden::standards::faucets::policies::mint::policy_manager

Also, we should make sure storage slot names are consistent with the component names. For the above component names, slot names would be:

miden::standards::policies::mint::policy_manager::policy_authority
miden::standards::policies::mint::policy_manager::active_policy_proc_root
miden::standards::policies::mint::policy_manager::allowed_policy_proc_roots

Comment on lines +32 to +33
const COMPONENT_NAME: &'static str =
"miden::standards::components::policies::burn::policy_manager";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same comment a above but for burn policies.

Comment on lines +27 to +29
/// The name of the component.
pub const NAME: &'static str =
"miden::standards::components::policies::mint::owner_controlled::owner_only";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same comment as above re using component in the name.

/// policy is active when the faucet is first created. Future owner-controlled mint policies will
/// show up here as additional variants.
#[derive(Debug, Clone, Copy, Default)]
pub enum Config {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Config feels a bit too generic here. I know we can use a module path, but I'd probably name this something like OwnerControlledPolicyConfig.

/// policies so the owner can switch between them at runtime via `set_burn_policy`. This enum only
/// selects the **initial active** policy.
#[derive(Debug, Clone, Copy, Default)]
pub enum Config {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same comment as above re using less generic name for Config.

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.

2 participants