|
1 | 1 | use std::{collections::umap::UHashMap, hash::{BuildHasherDefault, poseidon2::Poseidon2Hasher}};
|
2 | 2 |
|
3 |
| -use super::utils::get_packed_size; |
| 3 | +use super::utils::get_storage_size; |
4 | 4 | use super::utils::is_note;
|
5 | 5 |
|
6 | 6 | /// Stores a map from a module to the name of the struct that describes its storage layout.
|
@@ -30,22 +30,22 @@ pub comptime fn storage(s: StructDefinition) -> Quoted {
|
30 | 30 | for field in s.fields_as_written() {
|
31 | 31 | // FIXME: This doesn't handle field types with generics
|
32 | 32 | let (name, typ) = field;
|
33 |
| - let (storage_field_constructor, serialized_size) = |
| 33 | + let (storage_field_constructor, storage_size) = |
34 | 34 | generate_storage_field_constructor(typ, quote { $slot }, false);
|
35 | 35 | storage_vars_constructors =
|
36 | 36 | storage_vars_constructors.push_back(quote { $name: $storage_field_constructor });
|
37 | 37 | // We have `Storable` in a separate `.nr` file instead of defining it in the last quote of this function
|
38 | 38 | // because that way a dev gets a more reasonable error if he defines a struct with the same name in
|
39 | 39 | // a contract.
|
40 | 40 | storage_layout_fields =
|
41 |
| - storage_layout_fields.push_back(quote { $name: dep::aztec::prelude::Storable }); |
| 41 | + storage_layout_fields.push_back(quote { pub $name: dep::aztec::prelude::Storable }); |
42 | 42 | storage_layout_constructors = storage_layout_constructors.push_back(
|
43 | 43 | quote { $name: dep::aztec::prelude::Storable { slot: $slot } },
|
44 | 44 | );
|
45 | 45 | //let with_context_generic = add_context_generic(typ, context_generic);
|
46 | 46 | //println(with_context_generic);
|
47 | 47 | //new_storage_fields = new_storage_fields.push_back((name, with_context_generic ));
|
48 |
| - slot += serialized_size; |
| 48 | + slot += storage_size; |
49 | 49 | }
|
50 | 50 |
|
51 | 51 | //s.set_fields(new_storage_fields);
|
@@ -119,28 +119,25 @@ comptime fn generate_storage_field_constructor(
|
119 | 119 | generate_storage_field_constructor(generics[1], quote { slot }, true);
|
120 | 120 | (quote { $struct_name::new(context, $slot, | context, slot | { $value_constructor }) }, 1)
|
121 | 121 | } else {
|
122 |
| - let (container_struct, container_struct_generics) = typ.as_struct().unwrap(); |
123 |
| - let container_struct_name = container_struct.name(); |
124 |
| - |
125 |
| - let serialized_size = if parent_is_map { |
| 122 | + let storage_size = if parent_is_map { |
126 | 123 | // Variables inside a map do not require contiguous slots since the map slot derivation is assumed to result
|
127 | 124 | // in slots very far away from one another.
|
128 | 125 | 1
|
129 | 126 | } else {
|
| 127 | + let (_, container_struct_generics) = typ.as_struct().unwrap(); |
130 | 128 | let stored_struct = container_struct_generics[0];
|
131 |
| - if is_note(stored_struct) & (container_struct_name != quote { PublicMutable }) { |
| 129 | + |
| 130 | + if is_note(stored_struct) { |
132 | 131 | // Private notes always occupy a single slot, since the slot is only used as a state variable
|
133 | 132 | // identifier.
|
134 |
| - // Someone could store a Note in PublicMutable for whatever reason though. |
135 |
| - // TODO(#8659): remove the PublicMutable exception above |
136 | 133 | 1
|
137 | 134 | } else {
|
138 |
| - get_packed_size(stored_struct) |
| 135 | + get_storage_size(typ) |
139 | 136 | }
|
140 | 137 | };
|
141 | 138 |
|
142 | 139 | // We assume below that all state variables implement `fn new<Context>(context: Context, slot: Field) -> Self`.
|
143 |
| - (quote { $struct_name::new(context, $slot)}, serialized_size) |
| 140 | + (quote { $struct_name::new(context, $slot)}, storage_size) |
144 | 141 | }
|
145 | 142 | }
|
146 | 143 |
|
|
0 commit comments