Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changes/added/2719.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Merklized DA compression temporal registry tables.
4 changes: 3 additions & 1 deletion crates/fuel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,7 @@ fault-proving = [
"fuel-core-storage/fault-proving",
"fuel-core-chain-config/fault-proving",
"fuel-core-database/fault-proving",
"fuel-core-sync/fault-proving",
"fuel-core-sync?/fault-proving",
"fuel-core-importer/fault-proving",
"fuel-core-poa/fault-proving",
]
53 changes: 53 additions & 0 deletions crates/fuel-core/src/graphql_api/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,59 @@ pub enum Column {
AssetsInfo = 25,
/// Index of the coins that are available to spend.
CoinsToSpend = 26,
/// See [`DaCompressionTemporalRegistryAddressV2`](da_compression::v2::address::DaCompressionTemporalRegistryAddressV2)
#[cfg(feature = "fault-proving")]
DaCompressionTemporalRegistryAddressV2 = 27,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalAddressMerkleData = 28,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalAddressMerkleMetadata = 29,
// See [`DaCompressionTemporalRegistryAssetIdV2`](da_compression::v2::asset_id::DaCompressionTemporalRegistryAssetIdV2)
#[cfg(feature = "fault-proving")]
DaCompressionTemporalRegistryAssetIdV2 = 30,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalAssetIdMerkleData = 31,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalAssetIdMerkleMetadata = 32,
/// See [`DaCompressionTemporalRegistryContractIdV2`](da_compression::v2::contract_id::DaCompressionTemporalRegistryContractIdV2)
#[cfg(feature = "fault-proving")]
DaCompressionTemporalRegistryContractIdV2 = 33,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalContractIdMerkleData = 34,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalContractIdMerkleMetadata = 35,
/// See [`DaCompressionTemporalRegistryScriptCodeV2`](da_compression::v2::script_code::DaCompressionTemporalRegistryScriptCodeV2)
#[cfg(feature = "fault-proving")]
DaCompressionTemporalRegistryScriptCodeV2 = 36,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalScriptCodeMerkleData = 37,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalScriptCodeMerkleMetadata = 38,
/// See [`DaCompressionTemporalRegistryPredicateCodeV2`](da_compression::v2::predicate_code::DaCompressionTemporalRegistryPredicateCodeV2)
#[cfg(feature = "fault-proving")]
DaCompressionTemporalRegistryPredicateCodeV2 = 39,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalPredicateCodeMerkleData = 40,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalPredicateCodeMerkleMetadata = 41,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalRegistryIndexV2 = 42,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalRegistryIndexMerkleData = 43,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalRegistryIndexMerkleMetadata = 44,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalRegistryTimestampsV2 = 45,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalRegistryTimestampsMerkleData = 46,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalRegistryTimestampsMerkleMetadata = 47,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalRegistryEvictorCacheV2 = 48,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalRegistryEvictorCacheMerkleData = 49,
#[cfg(feature = "fault-proving")]
DaCompressionTemporalRegistryEvictorCacheMerkleMetadata = 50,
}

impl Column {
Expand Down
3 changes: 3 additions & 0 deletions crates/fuel-core/src/graphql_api/storage/da_compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pub mod reverse_key;
pub mod script_code_codec;
pub mod timestamps;

#[cfg(feature = "fault-proving")]
pub mod v2;
Copy link
Member

Choose a reason for hiding this comment

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

Should this be named something more specific to the feature. I'm not sure I understand what v2 means if it's always going to be hidden behind the fault-proving flag (I assume we are always going to keep it behind the flag because only the fault-proving nodes are going to want to track the extra state).

Perhaps we name it fault-proving-extra-storage or something specific like that?

Copy link
Member Author

Choose a reason for hiding this comment

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

it won't always be behind the fault-proving flag :) we plan to remove the flag once the feature is done, but you're right, da-compression is enabled only on a few nodes.

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed in 4560027

I like the previous naming better though :/

Copy link
Member

Choose a reason for hiding this comment

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

I'm willing to hear you out. If the flag is getting removed in the future, then maybe versioning like that makes more sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

oh okay, will revert the commit with the name change then :)

Copy link
Member Author

Choose a reason for hiding this comment

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

reverted in e54635b


/// The table for the compressed blocks sent to DA.
pub struct DaCompressedBlocks;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ impl rand::distributions::Distribution<ReverseKey> for rand::distributions::Stan
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> ReverseKey {
use strum::EnumCount;
match rng.next_u32() as usize % ReverseKey::COUNT {
0 => ReverseKey::Address(Address::default()),
1 => ReverseKey::AssetId(AssetId::default()),
2 => ReverseKey::ContractId(ContractId::default()),
3 => ReverseKey::ScriptCode(Bytes32::default()),
4 => ReverseKey::PredicateCode(Bytes32::default()),
0 => ReverseKey::Address(rng.gen()),
1 => ReverseKey::AssetId(rng.gen()),
2 => ReverseKey::ContractId(rng.gen()),
3 => ReverseKey::ScriptCode(rng.gen()),
4 => ReverseKey::PredicateCode(rng.gen()),
_ => unreachable!("New reverse key is added but not supported here"),
}
}
Expand Down
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;
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
);
}
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
);
}
Loading
Loading