refactor: move storage schema component into a separate file#2603
refactor: move storage schema component into a separate file#2603
Conversation
| static STORAGE_SCHEMA_LIBRARY: LazyLock<Library> = LazyLock::new(|| { | ||
| let bytes = include_bytes!(concat!( | ||
| env!("OUT_DIR"), | ||
| "/assets/account_components/metadata/schema_commitment.masl" | ||
| )); | ||
| Library::read_from_bytes(bytes).expect("Shipped Storage Schema library is well-formed") | ||
| }); |
There was a problem hiding this comment.
I think we should start moving these into their corresponding module, and eventually, try to get rid of the StandardAccountComponent (I may be forgetting something, but it is not clear to me why we need it).
| /// Name of the component is set to match the path of the corresponding module in the standards | ||
| /// library. | ||
| const NAME: &str = "miden::standards::metadata::storage_schema"; |
There was a problem hiding this comment.
I changed the name of the component to be the same as its module path in the standards library.
| static SCHEMA_COMMITMENT_SLOT_NAME: LazyLock<StorageSlotName> = LazyLock::new(|| { | ||
| StorageSlotName::new("miden::standards::metadata::storage_schema::commitment") | ||
| .expect("storage slot name should be valid") | ||
| }); |
There was a problem hiding this comment.
Also, changed the name of the storage slot to make it consistent with the name of the component.
| let storage_schema = StorageSchema::new([( | ||
| Self::schema_commitment_slot().clone(), | ||
| StorageSlotSchema::value( | ||
| "Commitment to the storage schema of an account", | ||
| WordSchema::new_simple(SchemaType::native_word()), | ||
| ), | ||
| )]) | ||
| .expect("storage schema should be valid"); | ||
|
|
||
| AccountComponentMetadata::new(Self::NAME, AccountType::all()) | ||
| .with_description("Component exposing the account storage schema commitment") | ||
| .with_storage_schema(storage_schema) |
There was a problem hiding this comment.
Previously, we were building AccountComponentMetadata without storage schema. I didn't remember if this was intentional, but couldn't come up with a good reason why this component shouldn't have storage schema. cc @igamigo in case I'm missing something.
| AccountComponent::new(STORAGE_SCHEMA_LIBRARY.clone(), storage, metadata) | ||
| .expect("AccountSchemaCommitment is a valid account component") |
There was a problem hiding this comment.
It seems like AccountComponent::new() does not verify consistency between storage and metadata. @igamigo - is this intentional? If not, let's create an issue and fix it.
This PR moves the
AccountSchemaComponentinto a separate module. The main intent here is to make the diff in #2439 smaller, but it also fixes a couple of things in the component (see inline comments).