-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fault_proving(merklized_registry): add merklized registry tables (#2719)
## Linked Issues/PRs <!-- List of related issues/PRs --> part 1/4 of #2568 ## Description <!-- List of detailed changes --> Implementation of various V2 temporal registry tables with Merklized encoding. New modules and features for fault-proofing: * [`crates/fuel-core/src/graphql_api/storage/da_compression.rs`](diffhunk://#diff-950254edead884ff443b7cc612f20d04acba8e37d8e6decab435348f84d0c51dR38-R40): Added a new module `v2` under the `da_compression` directory to support fault-proofing. * [`crates/fuel-core/src/graphql_api/storage/da_compression/v2.rs`](diffhunk://#diff-9fb44668f23048acd6709f3532aab5afbdf1297855a03d3bd258b26cf9e9c06aR1-R11): Introduced new modules for `address`, `asset_id`, `contract_id`, `predicate_code`, and `script_code` to handle fault-proofing. Updates to `Column` enum: * [`crates/fuel-core/src/graphql_api/storage.rs`](diffhunk://#diff-f40129b7382c84ff5de9ccbc254350dbdb9cd62c5e23e0f653cdb49d32f2e5e7R126-R160): Added new entries to the `Column` enum to support the new data compression types for fault-proofing. Implementation of V2 tables with Merklized encoding: * [`crates/fuel-core/src/graphql_api/storage/da_compression/v2/address.rs`](diffhunk://#diff-86681ac54c3c34d2cc3c942db5d24cc5002f2d439ed94e3a784a19dd3d259a57R1-R119): Implemented `DaCompressionTemporalRegistryAddressV2` and related structures with Merklized encoding. * [`crates/fuel-core/src/graphql_api/storage/da_compression/v2/asset_id.rs`](diffhunk://#diff-14903aaebdaf9e608a2f2c1fb245001f44f54d09c75c5609cebe0133dbc42efcR1-R117): Implemented `DaCompressionTemporalRegistryAssetIdV2` and related structures with Merklized encoding. * [`crates/fuel-core/src/graphql_api/storage/da_compression/v2/contract_id.rs`](diffhunk://#diff-81f055d34308e9e2b9f0dacc8806ca34068e5c4b4e9d1991c86f898a0a80b254R1-R118): Implemented `DaCompressionTemporalRegistryContractIdV2` and related structures with Merklized encoding. * [`crates/fuel-core/src/graphql_api/storage/da_compression/v2/predicate_code.rs`](diffhunk://#diff-93ccf013d8d2c5d19d7a29ce71e5043249228c48409477290bf753badf25377dR1-R116): Implemented `DaCompressionTemporalRegistryPredicateCodeV2` and related structures with Merklized encoding. * [`crates/fuel-core/src/graphql_api/storage/da_compression/v2/script_code.rs`](diffhunk://#diff-e08f9a8999be7e426ce3ac5688d987be33883998d960073a976dd7248184d29dR1-R118): Implemented `DaCompressionTemporalRegistryScriptCodeV2` and related structures with Merklized encoding. Other changes: * [`crates/fuel-core/Cargo.toml`](diffhunk://#diff-7fc200bcb8e651840f8692da4101cfcdba429acc82847ed81d1d0ed63e0a5bd2R131-R132): Added new fault-proofing dependencies for `fuel-core-importer` and `fuel-core-poa`. * [`crates/storage/src/blueprint/merklized.rs`](diffhunk://#diff-0173b542fbd232931eb6bbbfabbaf4c10ad64b4fb96c76483ac9973607ab0f59L437-R437): Updated the seed value in `basic_merklelized_storage_tests` macro for consistency in tests. [[1]](diffhunk://#diff-0173b542fbd232931eb6bbbfabbaf4c10ad64b4fb96c76483ac9973607ab0f59L437-R437) [[2]](diffhunk://#diff-0173b542fbd232931eb6bbbfabbaf4c10ad64b4fb96c76483ac9973607ab0f59L480-R480) ## Checklist - [ ] Breaking changes are clearly marked as such in the PR description and changelog - [ ] New behavior is reflected in tests - [ ] [The specification](https://github.com/FuelLabs/fuel-specs/) matches the implemented behavior (link update PR if changes are needed) ### Before requesting review - [ ] I have reviewed the code myself - [ ] I have created follow-up issues caused by this PR and linked them here ### After merging, notify other teams [Add or remove entries as needed] - [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/) - [ ] [Sway compiler](https://github.com/FuelLabs/sway/) - [ ] [Platform documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+) (for out-of-organization contributors, the person merging the PR will do this) - [ ] Someone else?
- Loading branch information
Showing
15 changed files
with
1,000 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Merklized DA compression temporal registry tables. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
crates/fuel-core/src/graphql_api/storage/da_compression/v2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pub mod address; | ||
pub mod asset_id; | ||
pub mod contract_id; | ||
pub mod evictor_cache; | ||
pub mod predicate_code; | ||
pub mod registry_index; | ||
pub mod script_code; | ||
pub mod timestamps; |
119 changes: 119 additions & 0 deletions
119
crates/fuel-core/src/graphql_api/storage/da_compression/v2/address.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
use crate::graphql_api::storage::{ | ||
da_compression::RegistryKey, | ||
Column, | ||
}; | ||
use core::borrow::Borrow; | ||
use fuel_core_storage::{ | ||
blueprint::{ | ||
merklized::Merklized, | ||
plain::Plain, | ||
}, | ||
codec::{ | ||
postcard::Postcard, | ||
primitive::Primitive, | ||
raw::Raw, | ||
}, | ||
structured_storage::TableWithBlueprint, | ||
tables::merkle::{ | ||
DenseMerkleMetadata, | ||
DenseMetadataKey, | ||
}, | ||
Mappable, | ||
}; | ||
use fuel_core_types::{ | ||
fuel_merkle::binary, | ||
fuel_tx::{ | ||
Address, | ||
Bytes32, | ||
}, | ||
}; | ||
|
||
pub struct TemporalRegistryAddressMerkleData; | ||
|
||
impl Mappable for TemporalRegistryAddressMerkleData { | ||
type Key = u64; | ||
type OwnedKey = Self::Key; | ||
type Value = binary::Primitive; | ||
type OwnedValue = Self::Value; | ||
} | ||
|
||
impl TableWithBlueprint for TemporalRegistryAddressMerkleData { | ||
type Blueprint = Plain<Primitive<8>, Postcard>; | ||
type Column = Column; | ||
|
||
fn column() -> Column { | ||
Column::DaCompressionTemporalAddressMerkleData | ||
} | ||
} | ||
|
||
/// The metadata table for [`TemporalRegistryAddressMerkleData`] table. | ||
pub struct TemporalRegistryAddressMerkleMetadata; | ||
|
||
impl Mappable for TemporalRegistryAddressMerkleMetadata { | ||
type Key = DenseMetadataKey<RegistryKey>; | ||
type OwnedKey = Self::Key; | ||
type Value = DenseMerkleMetadata; | ||
type OwnedValue = Self::Value; | ||
} | ||
|
||
impl TableWithBlueprint for TemporalRegistryAddressMerkleMetadata { | ||
type Blueprint = Plain<Postcard, Postcard>; | ||
type Column = Column; | ||
|
||
fn column() -> Column { | ||
Column::DaCompressionTemporalAddressMerkleMetadata | ||
} | ||
} | ||
|
||
/// Encoder for the V2 version of the DaCompressionTemporalRegistry for Address. | ||
pub struct DaCompressionTemporalRegistryAddressV2Encoder; | ||
|
||
impl fuel_core_storage::codec::Encode<Address> | ||
for DaCompressionTemporalRegistryAddressV2Encoder | ||
{ | ||
type Encoder<'a> = [u8; Bytes32::LEN]; | ||
|
||
fn encode(value: &Address) -> Self::Encoder<'_> { | ||
*Borrow::<[u8; Bytes32::LEN]>::borrow(value) | ||
} | ||
} | ||
|
||
/// V2 table for storing Address with Merklized encoding. | ||
pub struct DaCompressionTemporalRegistryAddressV2; | ||
|
||
impl Mappable for DaCompressionTemporalRegistryAddressV2 { | ||
type Key = Self::OwnedKey; | ||
type OwnedKey = RegistryKey; | ||
type Value = Self::OwnedValue; | ||
type OwnedValue = Address; | ||
} | ||
|
||
impl TableWithBlueprint for DaCompressionTemporalRegistryAddressV2 { | ||
type Blueprint = Merklized< | ||
Postcard, | ||
Raw, | ||
TemporalRegistryAddressMerkleMetadata, | ||
TemporalRegistryAddressMerkleData, | ||
DaCompressionTemporalRegistryAddressV2Encoder, | ||
>; | ||
type Column = Column; | ||
|
||
fn column() -> Self::Column { | ||
Column::DaCompressionTemporalRegistryAddressV2 | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::fuel_core_graphql_api::storage::da_compression::tests::generate_key; | ||
|
||
#[cfg(test)] | ||
fuel_core_storage::basic_merklelized_storage_tests!( | ||
DaCompressionTemporalRegistryAddressV2, | ||
RegistryKey::ZERO, | ||
<DaCompressionTemporalRegistryAddressV2 as Mappable>::Value::default(), | ||
<DaCompressionTemporalRegistryAddressV2 as Mappable>::Value::default(), | ||
generate_key | ||
); | ||
} |
117 changes: 117 additions & 0 deletions
117
crates/fuel-core/src/graphql_api/storage/da_compression/v2/asset_id.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
use crate::graphql_api::storage::{ | ||
da_compression::RegistryKey, | ||
Column, | ||
}; | ||
use core::borrow::Borrow; | ||
use fuel_core_storage::{ | ||
blueprint::{ | ||
merklized::Merklized, | ||
plain::Plain, | ||
}, | ||
codec::{ | ||
postcard::Postcard, | ||
primitive::Primitive, | ||
raw::Raw, | ||
}, | ||
structured_storage::TableWithBlueprint, | ||
tables::merkle::{ | ||
DenseMerkleMetadata, | ||
DenseMetadataKey, | ||
}, | ||
Mappable, | ||
}; | ||
use fuel_core_types::{ | ||
fuel_merkle::binary, | ||
fuel_tx::{ | ||
AssetId, | ||
Bytes32, | ||
}, | ||
}; | ||
|
||
pub struct TemporalRegistryAssetIdMerkleData; | ||
|
||
impl Mappable for TemporalRegistryAssetIdMerkleData { | ||
type Key = u64; | ||
type OwnedKey = Self::Key; | ||
type Value = binary::Primitive; | ||
type OwnedValue = Self::Value; | ||
} | ||
|
||
impl TableWithBlueprint for TemporalRegistryAssetIdMerkleData { | ||
type Blueprint = Plain<Primitive<8>, Postcard>; | ||
type Column = Column; | ||
|
||
fn column() -> Column { | ||
Column::DaCompressionTemporalAssetIdMerkleData | ||
} | ||
} | ||
|
||
/// The metadata table for [`TemporalRegistryAssetIdMerkleData`] table. | ||
pub struct TemporalRegistryAssetIdMerkleMetadata; | ||
|
||
impl Mappable for TemporalRegistryAssetIdMerkleMetadata { | ||
type Key = DenseMetadataKey<RegistryKey>; | ||
type OwnedKey = Self::Key; | ||
type Value = DenseMerkleMetadata; | ||
type OwnedValue = Self::Value; | ||
} | ||
|
||
impl TableWithBlueprint for TemporalRegistryAssetIdMerkleMetadata { | ||
type Blueprint = Plain<Postcard, Postcard>; | ||
type Column = Column; | ||
|
||
fn column() -> Column { | ||
Column::DaCompressionTemporalAssetIdMerkleMetadata | ||
} | ||
} | ||
|
||
/// Encoder for the V2 version of the DaCompressionTemporalRegistry for AssetId. | ||
pub struct DaCompressionTemporalRegistryAssetIdV2Encoder; | ||
|
||
impl fuel_core_storage::codec::Encode<AssetId> | ||
for DaCompressionTemporalRegistryAssetIdV2Encoder | ||
{ | ||
type Encoder<'a> = [u8; Bytes32::LEN]; | ||
fn encode(value: &AssetId) -> Self::Encoder<'_> { | ||
*Borrow::<[u8; Bytes32::LEN]>::borrow(value) | ||
} | ||
} | ||
|
||
/// V2 table for storing AssetId with Merklized encoding. | ||
pub struct DaCompressionTemporalRegistryAssetIdV2; | ||
|
||
impl Mappable for DaCompressionTemporalRegistryAssetIdV2 { | ||
type Key = Self::OwnedKey; | ||
type OwnedKey = RegistryKey; | ||
type Value = Self::OwnedValue; | ||
type OwnedValue = AssetId; | ||
} | ||
|
||
impl TableWithBlueprint for DaCompressionTemporalRegistryAssetIdV2 { | ||
type Blueprint = Merklized< | ||
Postcard, | ||
Raw, | ||
TemporalRegistryAssetIdMerkleMetadata, | ||
TemporalRegistryAssetIdMerkleData, | ||
DaCompressionTemporalRegistryAssetIdV2Encoder, | ||
>; | ||
type Column = Column; | ||
fn column() -> Self::Column { | ||
Self::Column::DaCompressionTemporalRegistryAssetIdV2 | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::fuel_core_graphql_api::storage::da_compression::tests::generate_key; | ||
|
||
#[cfg(test)] | ||
fuel_core_storage::basic_merklelized_storage_tests!( | ||
DaCompressionTemporalRegistryAssetIdV2, | ||
RegistryKey::ZERO, | ||
<DaCompressionTemporalRegistryAssetIdV2 as Mappable>::Value::default(), | ||
<DaCompressionTemporalRegistryAssetIdV2 as Mappable>::Value::default(), | ||
generate_key | ||
); | ||
} |
Oops, something went wrong.