11use crate :: id:: { NUMBER_OF_COLUMNS , column_indices} ;
22
3- /// Which of a block's columns this node holds, against the set it is responsible
4- /// for.
5- ///
6- /// Both fields are 128-bit presence bitmaps — bit `i` set ⇔ column index `i`:
7- /// - `held`: columns actually stored here.
8- /// - `expected`: columns this node is responsible for (its custody set). For the full-custody MVP
9- /// the store stamps every value with `ALL_COLUMNS_MASK`; once custody groups land it stamps the
10- /// node's actual custody set instead, and the query methods below keep working unchanged.
3+ /// Which of a block's columns this node holds (`held`) against the set it is
4+ /// responsible for (`expected`). Both are 128-bit presence bitmaps: bit `i`
5+ /// set ⇔ column `i`. The full-custody MVP stamps `expected` with
6+ /// `ALL_COLUMNS_MASK`.
117#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
128pub struct DaAvailability {
139 held : u128 ,
@@ -29,26 +25,17 @@ impl DaAvailability {
2925 u64:: from ( self . held . count_ones ( ) )
3026 }
3127
32- /// Whether column `index` is physically held, regardless of custody.
33- ///
34- /// A pure bitmap probe — this is the cheap presence check for callers that
35- /// would otherwise fetch a whole column just to see if it exists. An
36- /// out-of-range index is never held.
28+ /// Whether column `index` is held; an out-of-range index is never held.
3729 pub fn holds ( & self , index : u64 ) -> bool {
3830 index < NUMBER_OF_COLUMNS && self . held & ( 1u128 << index) != 0
3931 }
4032
41- /// Column indices this node is responsible for but does not yet hold, in
42- /// ascending order.
43- ///
44- /// This is the list a fetcher turns into a request for the missing columns
33+ /// Column indices expected but not held, ascending.
4534 pub fn missing_indices ( & self ) -> Vec < u64 > {
4635 column_indices ( self . expected & !self . held )
4736 }
4837
49- /// Column indices physically held, ascending — the list a serving node walks
50- /// to return every column it has for a block. Includes any held outside the
51- /// custody set.
38+ /// Column indices held (including any outside custody), ascending.
5239 pub fn held_indices ( & self ) -> Vec < u64 > {
5340 column_indices ( self . held )
5441 }
@@ -58,14 +45,10 @@ impl DaAvailability {
5845mod tests {
5946 use super :: DaAvailability ;
6047
61- /// A small custody set — columns {0, 1, 2, 3} — keeps the expectations
62- /// readable while still exercising partial/complete logic.
6348 const EXPECTED_FOUR : u128 = 0b1111 ;
6449
6550 #[ test]
6651 fn holds_probes_single_columns ( ) {
67- // Held {0, 2}: bit probes answer per column, and an out-of-range index
68- // (>= NUMBER_OF_COLUMNS) is never held.
6952 let availability = DaAvailability :: new ( 0b0101 , EXPECTED_FOUR ) ;
7053 assert ! ( availability. holds( 0 ) ) ;
7154 assert ! ( !availability. holds( 1 ) ) ;
@@ -92,7 +75,6 @@ mod tests {
9275
9376 #[ test]
9477 fn partial_reports_only_the_gaps ( ) {
95- // Holds columns 0 and 2 of the four expected.
9678 let availability = DaAvailability :: new ( 0b0101 , EXPECTED_FOUR ) ;
9779 assert ! ( !availability. is_complete( ) ) ;
9880 assert_eq ! ( availability. held_count( ) , 2 ) ;
@@ -101,8 +83,6 @@ mod tests {
10183
10284 #[ test]
10385 fn extra_columns_beyond_custody_still_complete ( ) {
104- // Holds column 4 on top of the expected four: a superset, still complete,
105- // and column 4 is never reported as missing.
10686 let availability = DaAvailability :: new ( 0b11111 , EXPECTED_FOUR ) ;
10787 assert ! ( availability. is_complete( ) ) ;
10888 assert_eq ! ( availability. held_count( ) , 5 ) ;
@@ -111,8 +91,6 @@ mod tests {
11191
11292 #[ test]
11393 fn sparse_custody_follows_the_bits_not_the_count ( ) {
114- // Custody indices {5, 70, 99}, plus a held column (9) that lies
115- // OUTSIDE custody.
11694 let expected = ( 1u128 << 5 ) | ( 1u128 << 70 ) | ( 1u128 << 99 ) ;
11795 let held = ( 1u128 << 5 ) | ( 1u128 << 9 ) ;
11896 let availability = DaAvailability :: new ( held, expected) ;
@@ -124,10 +102,8 @@ mod tests {
124102
125103 #[ test]
126104 fn held_indices_lists_every_stored_column_in_order ( ) {
127- // Held {0, 2} within custody plus {9} outside it — all count as held.
128105 let availability = DaAvailability :: new ( ( 1 << 0 ) | ( 1 << 2 ) | ( 1 << 9 ) , EXPECTED_FOUR ) ;
129106 assert_eq ! ( availability. held_indices( ) , vec![ 0 , 2 , 9 ] ) ;
130- // Nothing held -> empty list.
131107 assert ! (
132108 DaAvailability :: new( 0 , EXPECTED_FOUR )
133109 . held_indices( )
0 commit comments