11use std:: path:: PathBuf ;
22
33use discv5:: enr:: NodeId ;
4- use ethportal_api:: types:: network:: Subnetwork ;
4+ use ethportal_api:: types:: { distance :: Distance , network:: Subnetwork } ;
55use r2d2:: Pool ;
66use r2d2_sqlite:: SqliteConnectionManager ;
77
@@ -54,6 +54,7 @@ impl PortalStorageConfigFactory {
5454 pub fn create (
5555 & self ,
5656 subnetwork : & Subnetwork ,
57+ max_radius : Distance ,
5758 ) -> Result < PortalStorageConfig , ContentStoreError > {
5859 let capacity_bytes = match & self . capacity_config {
5960 StorageCapacityConfig :: Combined {
@@ -104,6 +105,7 @@ impl PortalStorageConfigFactory {
104105 node_data_dir : self . node_data_dir . clone ( ) ,
105106 distance_fn : DistanceFunction :: Xor ,
106107 sql_connection_pool : self . sql_connection_pool . clone ( ) ,
108+ max_radius,
107109 } )
108110 }
109111
@@ -124,6 +126,7 @@ pub struct PortalStorageConfig {
124126 pub node_data_dir : PathBuf ,
125127 pub distance_fn : DistanceFunction ,
126128 pub sql_connection_pool : Pool < SqliteConnectionManager > ,
129+ pub max_radius : Distance ,
127130}
128131
129132#[ cfg( test) ]
@@ -167,11 +170,11 @@ mod tests {
167170 . unwrap ( ) ;
168171 match expected_capacity_bytes {
169172 Some ( expected_capacity_bytes) => {
170- let config = factory. create ( & subnetwork) . unwrap ( ) ;
173+ let config = factory. create ( & subnetwork, Distance :: MAX ) . unwrap ( ) ;
171174 assert_eq ! ( config. storage_capacity_bytes, expected_capacity_bytes) ;
172175 }
173176 None => assert ! (
174- factory. create( & subnetwork) . is_err( ) ,
177+ factory. create( & subnetwork, Distance :: MAX ) . is_err( ) ,
175178 "Storage config is expected to fail"
176179 ) ,
177180 }
@@ -193,21 +196,21 @@ mod tests {
193196 . unwrap ( ) ;
194197 assert_eq ! (
195198 factory
196- . create( & Subnetwork :: Beacon )
199+ . create( & Subnetwork :: Beacon , Distance :: MAX )
197200 . unwrap( )
198201 . storage_capacity_bytes,
199202 100_000_000 ,
200203 ) ;
201204 assert_eq ! (
202205 factory
203- . create( & Subnetwork :: History )
206+ . create( & Subnetwork :: History , Distance :: MAX )
204207 . unwrap( )
205208 . storage_capacity_bytes,
206209 200_000_000 ,
207210 ) ;
208211 assert_eq ! (
209212 factory
210- . create( & Subnetwork :: State )
213+ . create( & Subnetwork :: State , Distance :: MAX )
211214 . unwrap( )
212215 . storage_capacity_bytes,
213216 300_000_000 ,
@@ -230,17 +233,17 @@ mod tests {
230233 . unwrap ( ) ;
231234 assert_eq ! (
232235 factory
233- . create( & Subnetwork :: History )
236+ . create( & Subnetwork :: History , Distance :: MAX )
234237 . unwrap( )
235238 . storage_capacity_bytes,
236239 100_000_000 ,
237240 ) ;
238241 assert ! (
239- factory. create( & Subnetwork :: Beacon ) . is_err( ) ,
242+ factory. create( & Subnetwork :: Beacon , Distance :: MAX ) . is_err( ) ,
240243 "Creating for Beacon should fail"
241244 ) ;
242245 assert ! (
243- factory. create( & Subnetwork :: State ) . is_err( ) ,
246+ factory. create( & Subnetwork :: State , Distance :: MAX ) . is_err( ) ,
244247 "Creating for State should fail"
245248 ) ;
246249 temp_dir. close ( ) . unwrap ( ) ;
@@ -261,19 +264,19 @@ mod tests {
261264 . unwrap ( ) ;
262265 assert_eq ! (
263266 factory
264- . create( & Subnetwork :: Beacon )
267+ . create( & Subnetwork :: Beacon , Distance :: MAX )
265268 . unwrap( )
266269 . storage_capacity_bytes,
267270 0 ,
268271 ) ;
269272 assert_eq ! (
270273 factory
271- . create( & Subnetwork :: History )
274+ . create( & Subnetwork :: History , Distance :: MAX )
272275 . unwrap( )
273276 . storage_capacity_bytes,
274277 100_000_000 ,
275278 ) ;
276- assert ! ( factory. create( & Subnetwork :: State ) . is_err( ) ) ;
279+ assert ! ( factory. create( & Subnetwork :: State , Distance :: MAX ) . is_err( ) ) ;
277280 temp_dir. close ( ) . unwrap ( ) ;
278281 }
279282}
0 commit comments