@@ -48,7 +48,7 @@ pub(crate) struct DagState {
48
48
49
49
// Contains recent blocks within CACHED_ROUNDS from the last committed round per authority.
50
50
// Note: all uncommitted blocks are kept in memory.
51
- recent_blocks : BTreeMap < BlockRef , BlockInfo > ,
51
+ recent_blocks : BTreeMap < BlockRef , VerifiedBlockHeader > ,
52
52
53
53
// Indexes recent block refs by their authorities.
54
54
// Vec position corresponds to the authority index.
@@ -257,8 +257,7 @@ impl DagState {
257
257
/// Updates internal metadata for a block.
258
258
fn update_block_metadata ( & mut self , block : & VerifiedBlockHeader ) {
259
259
let block_ref = block. reference ( ) ;
260
- self . recent_blocks
261
- . insert ( block_ref, BlockInfo :: new ( block. clone ( ) ) ) ;
260
+ self . recent_blocks . insert ( block_ref, block. clone ( ) ) ;
262
261
self . recent_refs_by_authority [ block_ref. author ] . insert ( block_ref) ;
263
262
self . threshold_clock . add_block ( block_ref) ;
264
263
self . highest_accepted_round = max ( self . highest_accepted_round , block. round ( ) ) ;
@@ -315,8 +314,8 @@ impl DagState {
315
314
}
316
315
continue ;
317
316
}
318
- if let Some ( block_info ) = self . recent_blocks . get ( block_ref) {
319
- blocks[ index] = Some ( block_info . block . clone ( ) ) ;
317
+ if let Some ( block ) = self . recent_blocks . get ( block_ref) {
318
+ blocks[ index] = Some ( block. clone ( ) ) ;
320
319
continue ;
321
320
}
322
321
missing. push ( ( index, block_ref) ) ;
@@ -348,31 +347,6 @@ impl DagState {
348
347
blocks
349
348
}
350
349
351
- // Sets the block as committed in the cache. If the block is set as committed
352
- // for first time, then true is returned, otherwise false is returned instead.
353
- // Method will panic if the block is not found in the cache.
354
- pub ( crate ) fn set_committed ( & mut self , block_ref : & BlockRef ) -> bool {
355
- if let Some ( block_info) = self . recent_blocks . get_mut ( block_ref) {
356
- if !block_info. committed {
357
- block_info. committed = true ;
358
- return true ;
359
- }
360
- false
361
- } else {
362
- panic ! (
363
- "Block {:?} not found in cache to set as committed." ,
364
- block_ref
365
- ) ;
366
- }
367
- }
368
-
369
- pub ( crate ) fn is_committed ( & self , block_ref : & BlockRef ) -> bool {
370
- self . recent_blocks
371
- . get ( block_ref)
372
- . unwrap_or_else ( || panic ! ( "Attempted to query for commit status for a block not in cached data {block_ref}" ) )
373
- . committed
374
- }
375
-
376
350
/// Gets all uncommitted blocks in a slot.
377
351
/// Uncommitted blocks must exist in memory, so only in-memory blocks are
378
352
/// checked.
@@ -382,7 +356,7 @@ impl DagState {
382
356
// to edge cases.
383
357
384
358
let mut blocks = vec ! [ ] ;
385
- for ( _block_ref, block_info ) in self . recent_blocks . range ( (
359
+ for ( _block_ref, block ) in self . recent_blocks . range ( (
386
360
Included ( BlockRef :: new (
387
361
slot. round ,
388
362
slot. authority ,
@@ -394,7 +368,7 @@ impl DagState {
394
368
BlockHeaderDigest :: MAX ,
395
369
) ) ,
396
370
) ) {
397
- blocks. push ( block_info . block . clone ( ) )
371
+ blocks. push ( block. clone ( ) )
398
372
}
399
373
blocks
400
374
}
@@ -408,7 +382,7 @@ impl DagState {
408
382
}
409
383
410
384
let mut blocks = vec ! [ ] ;
411
- for ( _block_ref, block_info ) in self . recent_blocks . range ( (
385
+ for ( _block_ref, block ) in self . recent_blocks . range ( (
412
386
Included ( BlockRef :: new (
413
387
round,
414
388
AuthorityIndex :: ZERO ,
@@ -420,7 +394,7 @@ impl DagState {
420
394
BlockHeaderDigest :: MIN ,
421
395
) ) ,
422
396
) ) {
423
- blocks. push ( block_info . block . clone ( ) )
397
+ blocks. push ( block. clone ( ) )
424
398
}
425
399
blocks
426
400
}
@@ -480,7 +454,6 @@ impl DagState {
480
454
. recent_blocks
481
455
. get ( last)
482
456
. expect ( "Block should be found in recent blocks" )
483
- . block
484
457
. clone ( ) ;
485
458
}
486
459
@@ -508,11 +481,11 @@ impl DagState {
508
481
Included ( BlockRef :: new ( start, authority, BlockHeaderDigest :: MIN ) ) ,
509
482
Unbounded ,
510
483
) ) {
511
- let block_info = self
484
+ let block = self
512
485
. recent_blocks
513
486
. get ( block_ref)
514
487
. expect ( "Block should exist in recent blocks" ) ;
515
- blocks. push ( block_info . block . clone ( ) ) ;
488
+ blocks. push ( block. clone ( ) ) ;
516
489
}
517
490
blocks
518
491
}
@@ -547,9 +520,7 @@ impl DagState {
547
520
) )
548
521
. last ( ) ?;
549
522
550
- self . recent_blocks
551
- . get ( block_ref)
552
- . map ( |block_info| block_info. block . clone ( ) )
523
+ self . recent_blocks . get ( block_ref) . cloned ( )
553
524
}
554
525
555
526
/// Returns the last block proposed per authority with `evicted round <
@@ -611,11 +582,11 @@ impl DagState {
611
582
for block_ref in block_ref_iter {
612
583
if last_round == 0 {
613
584
last_round = block_ref. round ;
614
- let block_info = self
585
+ let block = self
615
586
. recent_blocks
616
587
. get ( block_ref)
617
588
. expect ( "Block should exist in recent blocks" ) ;
618
- blocks[ authority_index] = block_info . block . clone ( ) ;
589
+ blocks[ authority_index] = block. clone ( ) ;
619
590
continue ;
620
591
}
621
592
if block_ref. round < last_round {
@@ -1026,22 +997,6 @@ impl DagState {
1026
997
self . last_commit = Some ( commit) ;
1027
998
}
1028
999
}
1029
-
1030
- struct BlockInfo {
1031
- block : VerifiedBlockHeader ,
1032
- // Whether the block has been committed
1033
- committed : bool ,
1034
- }
1035
-
1036
- impl BlockInfo {
1037
- fn new ( block : VerifiedBlockHeader ) -> Self {
1038
- Self {
1039
- block,
1040
- committed : false ,
1041
- }
1042
- }
1043
- }
1044
-
1045
1000
#[ cfg( test) ]
1046
1001
mod test {
1047
1002
use std:: vec;
@@ -1674,44 +1629,6 @@ mod test {
1674
1629
assert_eq ! ( dag_state. scoring_subdags_count( ) , 5 ) ;
1675
1630
}
1676
1631
1677
- #[ tokio:: test]
1678
- async fn test_block_info_as_committed ( ) {
1679
- let num_authorities: u32 = 4 ;
1680
- let ( context, _) = Context :: new_for_test ( num_authorities as usize ) ;
1681
- let context = Arc :: new ( context) ;
1682
-
1683
- let store = Arc :: new ( MemStore :: new ( ) ) ;
1684
- let mut dag_state = DagState :: new ( context. clone ( ) , store. clone ( ) ) ;
1685
-
1686
- // Accept a block
1687
- let block = VerifiedBlockHeader :: new_for_test (
1688
- TestBlockHeader :: new ( 1 , 0 )
1689
- . set_timestamp_ms ( 1000 )
1690
- . set_ancestors ( vec ! [ ] )
1691
- . build ( ) ,
1692
- ) ;
1693
-
1694
- dag_state. accept_block ( block. clone ( ) ) ;
1695
-
1696
- // Query is committed
1697
- assert ! ( !dag_state. is_committed( & block. reference( ) ) ) ;
1698
-
1699
- // Set block as committed for first time should return true
1700
- assert ! (
1701
- dag_state. set_committed( & block. reference( ) ) ,
1702
- "Block should be successfully set as committed for first time"
1703
- ) ;
1704
-
1705
- // Now it should appear as committed
1706
- assert ! ( dag_state. is_committed( & block. reference( ) ) ) ;
1707
-
1708
- // Trying to set the block as committed again, it should return false.
1709
- assert ! (
1710
- !dag_state. set_committed( & block. reference( ) ) ,
1711
- "Block should not be successfully set as committed"
1712
- ) ;
1713
- }
1714
-
1715
1632
#[ tokio:: test]
1716
1633
async fn test_get_cached_blocks ( ) {
1717
1634
let ( mut context, _) = Context :: new_for_test ( 4 ) ;
0 commit comments