@@ -172,7 +172,7 @@ pub fn spawn_exporter(
172
172
network : Network ,
173
173
rpc_url : & str ,
174
174
rpc_timeout : Duration ,
175
- publisher_permissions_rx : mpsc :: Receiver < HashMap < Pubkey , HashMap < Pubkey , MarketSchedule > > > ,
175
+ publisher_permissions_rx : watch :: Receiver < HashMap < Pubkey , HashMap < Pubkey , MarketSchedule > > > ,
176
176
key_store : KeyStore ,
177
177
local_store_tx : Sender < store:: local:: Message > ,
178
178
global_store_tx : Sender < store:: global:: Lookup > ,
@@ -260,7 +260,7 @@ pub struct Exporter {
260
260
inflight_transactions_tx : Sender < Signature > ,
261
261
262
262
/// publisher => { permissioned_price => market hours } as read by the oracle module
263
- publisher_permissions_rx : mpsc :: Receiver < HashMap < Pubkey , HashMap < Pubkey , MarketSchedule > > > ,
263
+ publisher_permissions_rx : watch :: Receiver < HashMap < Pubkey , HashMap < Pubkey , MarketSchedule > > > ,
264
264
265
265
/// Currently known permissioned prices of this publisher along with their market hours
266
266
our_prices : HashMap < Pubkey , MarketSchedule > ,
@@ -287,7 +287,7 @@ impl Exporter {
287
287
global_store_tx : Sender < store:: global:: Lookup > ,
288
288
network_state_rx : watch:: Receiver < NetworkState > ,
289
289
inflight_transactions_tx : Sender < Signature > ,
290
- publisher_permissions_rx : mpsc :: Receiver < HashMap < Pubkey , HashMap < Pubkey , MarketSchedule > > > ,
290
+ publisher_permissions_rx : watch :: Receiver < HashMap < Pubkey , HashMap < Pubkey , MarketSchedule > > > ,
291
291
keypair_request_tx : mpsc:: Sender < KeypairRequest > ,
292
292
logger : Logger ,
293
293
) -> Self {
@@ -556,51 +556,34 @@ impl Exporter {
556
556
/// The loop ensures that we clear the channel and use
557
557
/// only the final, latest message; try_recv() is
558
558
/// non-blocking.
559
- ///
560
- /// Note: This behavior is similar to
561
- /// tokio::sync::watch::channel(), which was not appropriate here
562
- /// because its internal RwLock would complain about not being
563
- /// Send with the HashMap<HashSet<Pubkey>> inside.
564
- /// TODO(2023-05-05): Debug the watch::channel() compilation errors
565
559
fn update_our_prices ( & mut self , publish_pubkey : & Pubkey ) {
566
- loop {
567
- match self . publisher_permissions_rx . try_recv ( ) {
568
- Ok ( publisher_permissions) => {
569
- self . our_prices = publisher_permissions. get ( publish_pubkey) . cloned ( )
570
- . unwrap_or_else ( || {
571
- warn ! (
572
- self . logger,
573
- "Exporter: No permissioned prices were found for the publishing keypair on-chain. This is expected only on startup." ;
574
- "publish_pubkey" => publish_pubkey. to_string( ) ,
575
- ) ;
576
- HashMap :: new ( )
577
- } ) ;
578
- trace ! (
579
- self . logger,
580
- "Exporter: read permissioned price accounts from channel" ;
581
- "new_value" => format!( "{:?}" , self . our_prices) ,
582
- ) ;
583
- }
584
- // Expected failures when channel is empty
585
- Err ( TryRecvError :: Empty ) => {
586
- trace ! (
587
- self . logger,
588
- "Exporter: No more permissioned price accounts in channel, using cached value" ;
589
- ) ;
590
- break ;
591
- }
592
- // Unexpected failures (channel closed, internal errors etc.)
593
- Err ( other) => {
594
- warn ! (
595
- self . logger,
596
- "Exporter: Updating permissioned price accounts failed unexpectedly, using cached value" ;
597
- "cached_value" => format!( "{:?}" , self . our_prices) ,
598
- "error" => other. to_string( ) ,
599
- ) ;
600
- break ;
601
- }
560
+ match self . publisher_permissions_rx . has_changed ( ) {
561
+ Ok ( true ) => { }
562
+ Ok ( false ) => return ,
563
+ Err ( other) => {
564
+ warn ! (
565
+ self . logger,
566
+ "Exporter: Updating permissioned price accounts failed unexpectedly, using cached value" ;
567
+ "cached_value" => format!( "{:?}" , self . our_prices) ,
568
+ "error" => other. to_string( ) ,
569
+ ) ;
570
+ return ;
602
571
}
603
572
}
573
+
574
+ self . our_prices = self
575
+ . publisher_permissions_rx
576
+ . borrow_and_update ( )
577
+ . get ( publish_pubkey)
578
+ . cloned ( )
579
+ . unwrap_or_else ( || {
580
+ warn ! (
581
+ self . logger,
582
+ "Exporter: No permissioned prices were found for the publishing keypair on-chain. This is expected only on startup." ;
583
+ "publish_pubkey" => publish_pubkey. to_string( ) ,
584
+ ) ;
585
+ HashMap :: new ( )
586
+ } ) ;
604
587
}
605
588
606
589
async fn fetch_local_store_contents ( & self ) -> Result < HashMap < PriceIdentifier , PriceInfo > > {
0 commit comments