@@ -2,6 +2,7 @@ pub use rocksdb::Direction as IteratorDirection;
2
2
use {
3
3
crate :: {
4
4
blockstore_meta,
5
+ blockstore_meta:: MerkleRootMeta ,
5
6
blockstore_metrics:: {
6
7
maybe_enable_rocksdb_perf, report_rocksdb_read_perf, report_rocksdb_write_perf,
7
8
BlockstoreRocksDbColumnFamilyMetrics , PerfSamplingStatus , PERF_METRIC_OP_NAME_GET ,
@@ -102,6 +103,8 @@ const BLOCK_HEIGHT_CF: &str = "block_height";
102
103
const PROGRAM_COSTS_CF : & str = "program_costs" ;
103
104
/// Column family for optimistic slots
104
105
const OPTIMISTIC_SLOTS_CF : & str = "optimistic_slots" ;
106
+ /// Column family for merkle roots
107
+ const MERKLE_ROOT_META_CF : & str = "merkle_root_meta" ;
105
108
106
109
#[ derive( Error , Debug ) ]
107
110
pub enum BlockstoreError {
@@ -322,6 +325,19 @@ pub mod columns {
322
325
/// * value type: [`blockstore_meta::OptimisticSlotMetaVersioned`]
323
326
pub struct OptimisticSlots ;
324
327
328
+ #[ derive( Debug ) ]
329
+ /// The merkle root meta column
330
+ ///
331
+ /// Each merkle shred is part of a merkle tree for
332
+ /// its FEC set. This column stores that merkle root and associated
333
+ /// meta information about the first shred received.
334
+ ///
335
+ /// Its index type is (Slot, fec_set_index).
336
+ ///
337
+ /// * index type: `crate::shred::ErasureSetId` `(Slot, fec_set_index: u32)`
338
+ /// * value type: [`blockstore_meta::MerkleRootMeta`]`
339
+ pub struct MerkleRootMeta ;
340
+
325
341
// When adding a new column ...
326
342
// - Add struct below and implement `Column` and `ColumnName` traits
327
343
// - Add descriptor in Rocks::cf_descriptors() and name in Rocks::columns()
@@ -446,6 +462,7 @@ impl Rocks {
446
462
new_cf_descriptor:: <BlockHeight >( options, oldest_slot) ,
447
463
new_cf_descriptor:: <ProgramCosts >( options, oldest_slot) ,
448
464
new_cf_descriptor:: <OptimisticSlots >( options, oldest_slot) ,
465
+ new_cf_descriptor:: <MerkleRootMeta >( options, oldest_slot) ,
449
466
]
450
467
}
451
468
@@ -473,6 +490,7 @@ impl Rocks {
473
490
BlockHeight :: NAME ,
474
491
ProgramCosts :: NAME ,
475
492
OptimisticSlots :: NAME ,
493
+ MerkleRootMeta :: NAME ,
476
494
]
477
495
}
478
496
@@ -1072,6 +1090,39 @@ impl TypedColumn for columns::OptimisticSlots {
1072
1090
type Type = blockstore_meta:: OptimisticSlotMetaVersioned ;
1073
1091
}
1074
1092
1093
+ impl Column for columns:: MerkleRootMeta {
1094
+ type Index = ( Slot , /*fec_set_index:*/ u32 ) ;
1095
+
1096
+ fn index ( key : & [ u8 ] ) -> Self :: Index {
1097
+ let slot = BigEndian :: read_u64 ( & key[ ..8 ] ) ;
1098
+ let fec_set_index = BigEndian :: read_u32 ( & key[ 8 ..] ) ;
1099
+
1100
+ ( slot, fec_set_index)
1101
+ }
1102
+
1103
+ fn key ( ( slot, fec_set_index) : Self :: Index ) -> Vec < u8 > {
1104
+ let mut key = vec ! [ 0 ; 12 ] ;
1105
+ BigEndian :: write_u64 ( & mut key[ ..8 ] , slot) ;
1106
+ BigEndian :: write_u32 ( & mut key[ 8 ..] , fec_set_index) ;
1107
+ key
1108
+ }
1109
+
1110
+ fn primary_index ( ( slot, _fec_set_index) : Self :: Index ) -> Slot {
1111
+ slot
1112
+ }
1113
+
1114
+ fn as_index ( slot : Slot ) -> Self :: Index {
1115
+ ( slot, 0 )
1116
+ }
1117
+ }
1118
+
1119
+ impl ColumnName for columns:: MerkleRootMeta {
1120
+ const NAME : & ' static str = MERKLE_ROOT_META_CF ;
1121
+ }
1122
+ impl TypedColumn for columns:: MerkleRootMeta {
1123
+ type Type = MerkleRootMeta ;
1124
+ }
1125
+
1075
1126
#[ derive( Debug ) ]
1076
1127
pub struct Database {
1077
1128
backend : Arc < Rocks > ,
0 commit comments