@@ -175,7 +175,7 @@ impl State {
175175 pub fn apply_address_deltas ( & mut self , deltas : & [ AddressDelta ] ) {
176176 let addresses = self . volatile . window . back_mut ( ) . expect ( "window should never be empty" ) ;
177177
178- // Keeps track of previous tx to avoid duplicating tx hashes or overcounting totals tx count
178+ // Keeps track seen txs to avoid overcounting totals tx count and duplicating tx identifiers
179179 let mut seen: HashMap < Address , HashSet < TxIdentifier > > = HashMap :: new ( ) ;
180180
181181 for delta in deltas {
@@ -191,30 +191,31 @@ impl State {
191191 }
192192 }
193193
194- if self . config . store_transactions {
195- let txs = entry. transactions . get_or_insert ( Vec :: new ( ) ) ;
194+ if self . config . store_transactions || self . config . store_totals {
196195 let seen_for_addr = seen. entry ( delta. address . clone ( ) ) . or_default ( ) ;
197196
198- if !seen_for_addr. contains ( & tx_id) {
199- seen_for_addr. insert ( tx_id) ;
200- txs. push ( tx_id) ;
197+ if self . config . store_transactions {
198+ let txs = entry. transactions . get_or_insert ( Vec :: new ( ) ) ;
199+ if !seen_for_addr. contains ( & tx_id) {
200+ txs. push ( tx_id) ;
201+ }
201202 }
202- }
203-
204- if self . config . store_totals {
205- let totals = entry. totals . get_or_insert ( Vec :: new ( ) ) ;
206- let seen_for_addr = seen. entry ( delta. address . clone ( ) ) . or_default ( ) ;
207-
208- if seen_for_addr. contains ( & tx_id) {
209- if let Some ( last_total) = totals. last_mut ( ) {
210- // Create temporary map for summing same tx deltas efficently
211- let mut map = ValueDeltaMap :: from ( last_total. clone ( ) ) ;
212- map += delta. value . clone ( ) ;
213- * last_total = ValueDelta :: from ( map) ;
203+ if self . config . store_totals {
204+ let totals = entry. totals . get_or_insert ( Vec :: new ( ) ) ;
205+
206+ if seen_for_addr. contains ( & tx_id) {
207+ if let Some ( last_total) = totals. last_mut ( ) {
208+ // Create temporary map for summing same tx deltas efficiently
209+ // TODO: Potentially move upstream to address deltas publisher
210+ let mut map = ValueDeltaMap :: from ( last_total. clone ( ) ) ;
211+ map += delta. value . clone ( ) ;
212+ * last_total = ValueDelta :: from ( map) ;
213+ }
214+ } else {
215+ totals. push ( delta. value . clone ( ) ) ;
214216 }
215- } else {
216- totals. push ( delta. value . clone ( ) ) ;
217217 }
218+ seen_for_addr. insert ( tx_id) ;
218219 }
219220 }
220221 }
0 commit comments