@@ -58,6 +58,19 @@ impl MinimumValue {
5858 }
5959 }
6060
61+ fn get_expected_value ( & self , agora_query : & AgoraQuery ) -> anyhow:: Result < u128 > {
62+ // get agora model for the allocation_id
63+ let mut cache = self . cost_model_cache . lock ( ) . unwrap ( ) ;
64+ // on average, we'll have zero or one model
65+ let models = cache. get_mut ( & agora_query. deployment_id ) ;
66+
67+ let expected_value = models
68+ . map ( |cache| cache. cost ( agora_query) )
69+ . unwrap_or_default ( ) ;
70+
71+ Ok ( expected_value)
72+ }
73+
6174 async fn cost_models_watcher (
6275 _pgpool : PgPool ,
6376 mut pglistener : PgListener ,
@@ -131,20 +144,26 @@ impl MinimumValue {
131144 }
132145 }
133146 }
134- }
135-
136- impl MinimumValue {
137- fn get_expected_value ( & self , agora_query : & AgoraQuery ) -> anyhow:: Result < u128 > {
138- // get agora model for the allocation_id
139- let mut cache = self . cost_model_cache . lock ( ) . unwrap ( ) ;
140- // on average, we'll have zero or one model
141- let models = cache. get_mut ( & agora_query. deployment_id ) ;
142147
143- let expected_value = models
144- . map ( |cache| cache. cost ( agora_query) )
145- . unwrap_or_default ( ) ;
148+ async fn sender_denylist_reload (
149+ pgpool : PgPool ,
150+ cost_model_cache : Arc < Mutex < HashMap < DeploymentId , CostModelCache > > > ,
151+ ) -> anyhow:: Result < ( ) > {
152+ // Fetch the denylist from the DB
153+ let sender_denylist = sqlx:: query!(
154+ r#"
155+ SELECT sender_address FROM scalar_tap_denylist
156+ "#
157+ )
158+ . fetch_all ( & pgpool)
159+ . await ?
160+ . iter ( )
161+ . map ( |row| Address :: from_str ( & row. sender_address ) )
162+ . collect :: < Result < HashSet < _ > , _ > > ( ) ?;
163+
164+ * ( denylist_rwlock. write ( ) . unwrap ( ) ) = sender_denylist;
146165
147- Ok ( expected_value )
166+ Ok ( ( ) )
148167 }
149168}
150169
@@ -279,3 +298,23 @@ impl CostModelCache {
279298 . unwrap_or_default ( )
280299 }
281300}
301+
302+ #[ cfg( test) ]
303+ mod tests {
304+ use sqlx:: PgPool ;
305+
306+ #[ sqlx:: test( migrations = "../migrations" ) ]
307+ async fn initialize_check ( pg_pool : PgPool ) { }
308+
309+ #[ sqlx:: test( migrations = "../migrations" ) ]
310+ async fn should_initialize_check_with_caches ( pg_pool : PgPool ) { }
311+
312+ #[ sqlx:: test( migrations = "../migrations" ) ]
313+ async fn should_add_model_to_cache_on_insert ( pg_pool : PgPool ) { }
314+
315+ #[ sqlx:: test( migrations = "../migrations" ) ]
316+ async fn should_expire_old_model ( pg_pool : PgPool ) { }
317+
318+ #[ sqlx:: test( migrations = "../migrations" ) ]
319+ async fn should_verify_global_model ( pg_pool : PgPool ) { }
320+ }
0 commit comments