@@ -7,6 +7,24 @@ mod states;
7
7
pub mod storage;
8
8
mod time;
9
9
10
+ // std
11
+ use core:: fmt:: Debug ;
12
+ use futures:: StreamExt ;
13
+ use std:: collections:: BTreeSet ;
14
+ use std:: hash:: Hash ;
15
+ use std:: path:: PathBuf ;
16
+ // Crates
17
+ use rand:: { RngCore , SeedableRng } ;
18
+ use serde:: { de:: DeserializeOwned , Deserialize , Serialize } ;
19
+ use serde_with:: serde_as;
20
+ use thiserror:: Error ;
21
+ pub use time:: Config as TimeConfig ;
22
+ use tokio:: sync:: oneshot:: Sender ;
23
+ use tokio:: sync:: { broadcast, oneshot} ;
24
+ use tokio_stream:: wrappers:: IntervalStream ;
25
+ use tracing:: { error, info, instrument, span, Level } ;
26
+ use tracing_futures:: Instrument ;
27
+ // Internal
10
28
use crate :: leadership:: Leader ;
11
29
use crate :: relays:: CryptarchiaConsensusRelays ;
12
30
use crate :: states:: {
@@ -15,9 +33,7 @@ use crate::states::{
15
33
} ;
16
34
use crate :: storage:: adapters:: StorageAdapter ;
17
35
use crate :: storage:: StorageAdapter as _;
18
- use core:: fmt:: Debug ;
19
36
use cryptarchia_engine:: Slot ;
20
- use futures:: StreamExt ;
21
37
pub use leadership:: LeaderConfig ;
22
38
use network:: NetworkAdapter ;
23
39
use nomos_core:: da:: blob:: {
@@ -41,22 +57,9 @@ use nomos_storage::{backends::StorageBackend, StorageMsg, StorageService};
41
57
use overwatch_rs:: services:: relay:: { OutboundRelay , Relay , RelayMessage } ;
42
58
use overwatch_rs:: services:: { ServiceCore , ServiceData , ServiceId } ;
43
59
use overwatch_rs:: { DynError , OpaqueServiceStateHandle } ;
44
- use rand:: { RngCore , SeedableRng } ;
45
- use serde:: { de:: DeserializeOwned , Deserialize , Serialize } ;
46
- use serde_with:: serde_as;
47
60
use services_utils:: overwatch:: lifecycle;
48
61
use services_utils:: overwatch:: recovery:: backends:: FileBackendSettings ;
49
62
use services_utils:: overwatch:: { JsonFileBackend , RecoveryOperator } ;
50
- use std:: collections:: BTreeSet ;
51
- use std:: hash:: Hash ;
52
- use std:: path:: PathBuf ;
53
- use thiserror:: Error ;
54
- pub use time:: Config as TimeConfig ;
55
- use tokio:: sync:: oneshot:: Sender ;
56
- use tokio:: sync:: { broadcast, oneshot} ;
57
- use tokio_stream:: wrappers:: IntervalStream ;
58
- use tracing:: { error, info, instrument, span, Level } ;
59
- use tracing_futures:: Instrument ;
60
63
61
64
type MempoolRelay < Payload , Item , Key > = OutboundRelay < MempoolMsg < HeaderId , Payload , Item , Key > > ;
62
65
type SamplingRelay < BlobId > = OutboundRelay < DaSamplingServiceMsg < BlobId > > ;
@@ -853,13 +856,30 @@ where
853
856
}
854
857
855
858
/// Retrieves the blocks in the range from `from` to `to` from the storage.
856
- /// Both `from` and `to` are included in the range and must be valid headers.
859
+ /// Both `from` and `to` are included in the range.
860
+ /// This is implemented here, and not as a method of `StorageAdapter`, to simplify the panic
861
+ /// and error message handling.
862
+ ///
863
+ /// # Panics
864
+ ///
865
+ /// Panics if any of the blocks in the range are not found in the storage.
866
+ ///
867
+ /// # Parameters
868
+ ///
869
+ /// * `from` - The header id of the first block in the range. Must be a valid header.
870
+ /// * `to` - The header id of the last block in the range. Must be a valid header.
871
+ ///
872
+ /// # Returns
873
+ ///
874
+ /// A vector of blocks in the range from `from` to `to`.
875
+ /// If no blocks are found, returns an empty vector.
876
+ /// If any of the HeaderId are invalid, returns an error with the first invalid header id.
857
877
async fn get_blocks_in_range (
858
878
from : HeaderId ,
859
879
to : HeaderId ,
860
880
storage_adapter : & StorageAdapter < Storage , TxS :: Tx , BS :: BlobId > ,
861
881
) -> Vec < Block < ClPool :: Item , DaPool :: Item > > {
862
- // ` blocks` is in `to..from` order
882
+ // Due to the blocks traversal order, this yields `to..from` order
863
883
let blocks = futures:: stream:: unfold ( to, |header_id| async move {
864
884
if header_id == from {
865
885
None
@@ -875,7 +895,7 @@ where
875
895
}
876
896
} ) ;
877
897
878
- // To avoid confusion, the order is reversed so it fits in the natural `from..to` order
898
+ // To avoid confusion, the order is reversed so it fits the natural `from..to` order
879
899
blocks. collect :: < Vec < _ > > ( ) . await . into_iter ( ) . rev ( ) . collect ( )
880
900
}
881
901
0 commit comments