@@ -57,35 +57,6 @@ impl<'a> BatchState<'a> {
57
57
let sym_count = self . symbols . len ( ) ;
58
58
let pubkeys: Vec < _ > = self . symbols . iter ( ) . map ( |s| s. price_addr ) . collect ( ) ;
59
59
60
- // Always learn the current on-chain state for each symbol, use None values if lookup fails
61
- let mut new_symbol_states: Vec < Option < PriceAccount > > = match c
62
- . get_multiple_accounts ( & pubkeys)
63
- . await
64
- {
65
- Ok ( acc_opts) => {
66
- acc_opts
67
- . into_iter ( )
68
- . enumerate ( )
69
- . map ( |( idx, opt) | {
70
- // Take each Some(acc), make it None and log on load_price_account() error
71
- opt. and_then ( |acc| {
72
- pyth_sdk_solana:: state:: load_price_account ( & acc. data )
73
- . cloned ( ) // load_price_account() transmutes the data reference into another reference, and owning acc_opts is not enough
74
- . map_err ( |e| {
75
- warn ! ( "Could not parse symbol {}/{}: {}" , idx, sym_count, e) ;
76
- e
77
- } )
78
- . ok ( ) // Err becomes None
79
- } )
80
- } )
81
- . collect ( )
82
- }
83
- Err ( e) => {
84
- warn ! ( "Could not look up any symbols on-chain: {}" , e) ;
85
- vec ! [ None ; sym_count]
86
- }
87
- } ;
88
-
89
60
// min interval
90
61
if self . last_job_finished_at . elapsed ( )
91
62
> Duration :: from_secs ( self . conditions . min_interval_secs )
@@ -96,14 +67,47 @@ impl<'a> BatchState<'a> {
96
67
) ) ;
97
68
}
98
69
99
- for ( idx, old_new_tup) in self
100
- . last_known_symbol_states
101
- . iter_mut ( ) // Borrow mutably to make the update easier
102
- . zip ( new_symbol_states. iter ( ) )
103
- . enumerate ( )
104
- {
105
- // Only evaluate this symbol if a triggering condition is not already met
106
- if ret. is_none ( ) {
70
+ // Only lookup and compare symbols if the conditions require
71
+ if self . conditions . need_onchain_lookup ( ) {
72
+ let mut new_symbol_states: Vec < Option < PriceAccount > > =
73
+ match c. get_multiple_accounts ( & pubkeys) . await {
74
+ Ok ( acc_opts) => {
75
+ acc_opts
76
+ . into_iter ( )
77
+ . enumerate ( )
78
+ . map ( |( idx, opt) | {
79
+ // Take each Some(acc), make it None and log on load_price_account() error
80
+ opt. and_then ( |acc| {
81
+ pyth_sdk_solana:: state:: load_price_account ( & acc. data )
82
+ . cloned ( ) // load_price_account() transmutes the data reference into another reference, and owning acc_opts is not enough
83
+ . map_err ( |e| {
84
+ warn ! (
85
+ "Could not parse symbol {}/{}: {}" ,
86
+ idx, sym_count, e
87
+ ) ;
88
+ e
89
+ } )
90
+ . ok ( ) // Err becomes None
91
+ } )
92
+ } )
93
+ . collect ( )
94
+ }
95
+ Err ( e) => {
96
+ warn ! ( "Could not look up any symbols on-chain: {}" , e) ;
97
+ vec ! [ None ; sym_count]
98
+ }
99
+ } ;
100
+
101
+ for ( idx, old_new_tup) in self
102
+ . last_known_symbol_states
103
+ . iter_mut ( ) // Borrow mutably to make the update easier
104
+ . zip ( new_symbol_states. iter ( ) )
105
+ . enumerate ( )
106
+ {
107
+ // Only evaluate this symbol if a triggering condition is not already met
108
+ if ret. is_some ( ) {
109
+ break ;
110
+ }
107
111
match old_new_tup {
108
112
( Some ( old) , Some ( new) ) => {
109
113
// publish_time_changed
@@ -143,19 +147,18 @@ impl<'a> BatchState<'a> {
143
147
}
144
148
}
145
149
}
146
- }
147
-
148
- // Update with newer state only if a condition was met. We
149
- // don't want to shadow changes that may happen over a larger
150
- // period between state lookups.
151
- if ret. is_some ( ) {
152
- for ( old, new) in self
153
- . last_known_symbol_states
154
- . iter_mut ( )
155
- . zip ( new_symbol_states. into_iter ( ) )
156
- {
157
- if new. is_some ( ) {
158
- * old = new;
150
+ // Update with newer state only if a condition was met. We
151
+ // don't want to shadow changes that may happen over a larger
152
+ // period between state lookups.
153
+ if ret. is_some ( ) {
154
+ for ( old, new) in self
155
+ . last_known_symbol_states
156
+ . iter_mut ( )
157
+ . zip ( new_symbol_states. into_iter ( ) )
158
+ {
159
+ if new. is_some ( ) {
160
+ * old = new;
161
+ }
159
162
}
160
163
}
161
164
}
0 commit comments