Skip to content

Commit 44340e8

Browse files
committed
fixup
1 parent bf86c5c commit 44340e8

File tree

11 files changed

+85
-51
lines changed

11 files changed

+85
-51
lines changed

crates/proof_system/global_merkle_root/storage/src/column.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,50 +59,54 @@ impl TableColumn {
5959
/// in the case of malicious block.
6060
#[repr(u32)]
6161
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
62-
pub enum Column {
62+
pub enum Column<TC: core::fmt::Debug> {
6363
/// The column with the specific data.
64-
TableColumn(TableColumn),
64+
TableColumn(TC),
6565
/// The column with the merkle tree nodes.
66-
MerkleDataColumn(TableColumn),
66+
MerkleDataColumn(TC),
6767
/// The merkle metadata column.
6868
MerkleMetadataColumn,
6969
}
7070

71-
impl Column {
71+
impl<TC> Column<TC>
72+
where
73+
TC: StorageColumn,
74+
{
7275
/// The total count of variants in the enum.
7376
pub const COUNT: usize = TableColumn::COUNT + TableColumn::COUNT + 1;
7477

7578
/// The start of the merkle data columns.
7679
pub const MERKLE_DATA_COLUMNS_START: u32 = u16::MAX as u32;
7780

7881
/// Returns the `usize` representation of the `Column`.
79-
pub fn as_u32(&self) -> u32 {
82+
pub fn as_u32(&self) -> usize {
8083
match self {
81-
Self::TableColumn(column) => column.as_u32(),
82-
Self::MerkleDataColumn(column) => {
83-
Self::MERKLE_DATA_COLUMNS_START.wrapping_add(column.as_u32())
84-
}
85-
Self::MerkleMetadataColumn => u32::MAX,
84+
Self::TableColumn(column) => column.as_usize(),
85+
Self::MerkleDataColumn(column) => Self::MERKLE_DATA_COLUMNS_START
86+
.wrapping_add(column.as_usize() as u32)
87+
as usize,
88+
Self::MerkleMetadataColumn => u32::MAX as usize,
8689
}
8790
}
8891
}
8992

90-
impl StorageColumn for Column {
93+
impl<TC> StorageColumn for Column<TC>
94+
where
95+
TC: core::fmt::Debug + Copy,
96+
{
9197
fn name(&self) -> String {
9298
match self {
9399
Self::TableColumn(column) => {
94-
let str: &str = column.into();
95-
str.to_string()
100+
format!("{:?}", column)
96101
}
97102
Self::MerkleDataColumn(column) => {
98-
let str: &str = column.into();
99-
format!("Merkle{}", str)
103+
format!("Merkle{:?}", column)
100104
}
101105
Column::MerkleMetadataColumn => "MerkleMetadata".to_string(),
102106
}
103107
}
104108

105109
fn id(&self) -> u32 {
106-
self.as_u32()
110+
self.as_usize() as u32
107111
}
108112
}

crates/proof_system/global_merkle_root/storage/src/compute.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ use fuel_core_types::{
2828
};
2929

3030
use crate::{
31-
column::Column,
31+
column::{
32+
Column,
33+
TableColumn,
34+
},
3235
merkle::{
3336
DummyStorage,
3437
Merkleized,
@@ -44,14 +47,14 @@ pub trait ComputeStateRoot {
4447
/// Compute the merkle root of the specific table
4548
fn merkle_root<Table>(&self) -> Result<MerkleRoot, StorageError>
4649
where
47-
Table: Mappable + MerkleizedTableColumn,
50+
Table: Mappable + MerkleizedTableColumn<TableColumn = TableColumn>,
4851
Table: TableWithBlueprint,
49-
Table::Blueprint: BlueprintInspect<Table, DummyStorage<Column>>;
52+
Table::Blueprint: BlueprintInspect<Table, DummyStorage<Column<TableColumn>>>;
5053
}
5154

5255
impl<Storage> ComputeStateRoot for StorageTransaction<Storage>
5356
where
54-
Storage: KeyValueInspect<Column = Column>,
57+
Storage: KeyValueInspect<Column = Column<TableColumn>>,
5558
{
5659
fn state_root(&self) -> Result<Bytes32, StorageError> {
5760
let roots = [
@@ -77,9 +80,9 @@ where
7780

7881
fn merkle_root<Table>(&self) -> Result<MerkleRoot, StorageError>
7982
where
80-
Table: Mappable + MerkleizedTableColumn,
83+
Table: Mappable + MerkleizedTableColumn<TableColumn = TableColumn>,
8184
Table: TableWithBlueprint,
82-
Table::Blueprint: BlueprintInspect<Table, DummyStorage<Column>>,
85+
Table::Blueprint: BlueprintInspect<Table, DummyStorage<Column<TableColumn>>>,
8386
{
8487
<Self as MerkleRootStorage<u32, Merkleized<Table>>>::root(
8588
self,

crates/proof_system/global_merkle_root/storage/src/merkle.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::column::{
2-
Column,
3-
TableColumn,
4-
};
1+
use crate::column::Column;
52
use alloc::borrow::Cow;
63
use fuel_core_storage::{
74
blueprint::{
@@ -50,8 +47,10 @@ pub struct Merkleized<Table>(core::marker::PhantomData<Table>);
5047
/// Implementation of this trait for the table, inherits
5148
/// the Merkle implementation for the [`Merkleized`] table.
5249
pub trait MerkleizedTableColumn {
50+
/// The table column type
51+
type TableColumn;
5352
/// Get the table column
54-
fn table_column() -> TableColumn;
53+
fn table_column() -> Self::TableColumn;
5554
}
5655

5756
impl<Table> Mappable for Merkleized<Table>
@@ -64,30 +63,33 @@ where
6463
type OwnedValue = <Table as Mappable>::OwnedValue;
6564
}
6665

67-
type KeyCodec<Table> = <<Table as TableWithBlueprint>::Blueprint as BlueprintInspect<
68-
Table,
69-
DummyStorage<Column>,
70-
>>::KeyCodec;
66+
type KeyCodec<Table, TC> =
67+
<<Table as TableWithBlueprint>::Blueprint as BlueprintInspect<
68+
Table,
69+
DummyStorage<Column<TC>>,
70+
>>::KeyCodec;
7171

72-
type ValueCodec<Table> = <<Table as TableWithBlueprint>::Blueprint as BlueprintInspect<
73-
Table,
74-
DummyStorage<Column>,
75-
>>::ValueCodec;
72+
type ValueCodec<Table, TC> =
73+
<<Table as TableWithBlueprint>::Blueprint as BlueprintInspect<
74+
Table,
75+
DummyStorage<Column<TC>>,
76+
>>::ValueCodec;
7677

77-
impl<Table> TableWithBlueprint for Merkleized<Table>
78+
impl<Table, TC> TableWithBlueprint for Merkleized<Table>
7879
where
79-
Table: Mappable + MerkleizedTableColumn,
80+
Table: Mappable + MerkleizedTableColumn<TableColumn = TC>,
8081
Table: TableWithBlueprint,
81-
Table::Blueprint: BlueprintInspect<Table, DummyStorage<Column>>,
82+
TC: core::fmt::Debug + Copy,
83+
Table::Blueprint: BlueprintInspect<Table, DummyStorage<Column<TC>>>,
8284
{
8385
type Blueprint = Sparse<
84-
KeyCodec<Table>,
85-
ValueCodec<Table>,
86+
KeyCodec<Table, TC>,
87+
ValueCodec<Table, TC>,
8688
MerkleMetadata,
8789
MerkleData<Table>,
8890
KeyConverter<Table>,
8991
>;
90-
type Column = Column;
92+
type Column = Column<TC>;
9193

9294
fn column() -> Self::Column {
9395
Column::TableColumn(Table::table_column())

crates/proof_system/global_merkle_root/storage/src/merkle/smt.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use crate::{
2-
column::Column,
2+
column::{
3+
Column,
4+
TableColumn,
5+
},
36
merkle::MerkleizedTableColumn,
47
};
58
use fuel_core_storage::{
@@ -25,14 +28,15 @@ impl<Table> Mappable for MerkleData<Table> {
2528
type OwnedValue = Self::Value;
2629
}
2730

28-
impl<Table> TableWithBlueprint for MerkleData<Table>
31+
impl<Table, TC> TableWithBlueprint for MerkleData<Table>
2932
where
30-
Table: MerkleizedTableColumn,
33+
Table: MerkleizedTableColumn<TableColumn = TC>,
34+
TC: core::fmt::Debug + Copy,
3135
{
3236
type Blueprint = Plain<Raw, Postcard>;
33-
type Column = Column;
37+
type Column = Column<TC>;
3438

35-
fn column() -> Column {
39+
fn column() -> Column<TC> {
3640
Column::MerkleDataColumn(Table::table_column())
3741
}
3842
}
@@ -49,9 +53,9 @@ impl Mappable for MerkleMetadata {
4953

5054
impl TableWithBlueprint for MerkleMetadata {
5155
type Blueprint = Plain<Primitive<4>, Postcard>;
52-
type Column = Column;
56+
type Column = Column<TableColumn>;
5357

54-
fn column() -> Column {
58+
fn column() -> Self::Column {
5559
Column::MerkleMetadataColumn
5660
}
5761
}

crates/proof_system/global_merkle_root/storage/src/structured_storage/blobs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use crate::{
55
use fuel_core_storage::tables::BlobData;
66

77
impl MerkleizedTableColumn for BlobData {
8+
type TableColumn = TableColumn;
9+
810
fn table_column() -> TableColumn {
911
TableColumn::Blobs
1012
}

crates/proof_system/global_merkle_root/storage/src/structured_storage/coins.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use crate::{
55
use fuel_core_storage::tables::Coins;
66

77
impl MerkleizedTableColumn for Coins {
8+
type TableColumn = TableColumn;
9+
810
fn table_column() -> TableColumn {
911
TableColumn::Coins
1012
}

crates/proof_system/global_merkle_root/storage/src/structured_storage/contracts.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ use fuel_core_storage::tables::{
88
};
99

1010
impl MerkleizedTableColumn for ContractsRawCode {
11+
type TableColumn = TableColumn;
12+
1113
fn table_column() -> TableColumn {
1214
TableColumn::ContractsRawCode
1315
}
1416
}
1517

1618
impl MerkleizedTableColumn for ContractsLatestUtxo {
19+
type TableColumn = TableColumn;
20+
1721
fn table_column() -> TableColumn {
1822
TableColumn::ContractsLatestUtxo
1923
}

crates/proof_system/global_merkle_root/storage/src/structured_storage/messages.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use crate::{
55
use fuel_core_storage::tables::Messages;
66

77
impl MerkleizedTableColumn for Messages {
8+
type TableColumn = TableColumn;
9+
810
fn table_column() -> TableColumn {
911
TableColumn::Messages
1012
}

crates/proof_system/global_merkle_root/storage/src/structured_storage/transactions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use crate::{
55
use fuel_core_storage::tables::ProcessedTransactions;
66

77
impl MerkleizedTableColumn for ProcessedTransactions {
8+
type TableColumn = TableColumn;
9+
810
fn table_column() -> TableColumn {
911
TableColumn::ProcessedTransactions
1012
}

crates/proof_system/global_merkle_root/storage/src/structured_storage/upgrades.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@ use fuel_core_storage::tables::{
99
};
1010

1111
impl MerkleizedTableColumn for ConsensusParametersVersions {
12+
type TableColumn = TableColumn;
13+
1214
fn table_column() -> TableColumn {
1315
TableColumn::ConsensusParametersVersions
1416
}
1517
}
1618

1719
impl MerkleizedTableColumn for StateTransitionBytecodeVersions {
20+
type TableColumn = TableColumn;
21+
1822
fn table_column() -> TableColumn {
1923
TableColumn::StateTransitionBytecodeVersions
2024
}
2125
}
2226

2327
impl MerkleizedTableColumn for UploadedBytecodes {
28+
type TableColumn = TableColumn;
29+
2430
fn table_column() -> TableColumn {
2531
TableColumn::UploadedBytecodes
2632
}

0 commit comments

Comments
 (0)