@@ -129,8 +129,10 @@ func (h *manager) AddSubStatusAction(ctx context.Context, mtx *apitypes.ManagedT
129129 // See if this action exists in the list already since we only want to update the single entry, not
130130 // add a new one
131131 currentSubStatus := mtx .History [len (mtx .History )- 1 ]
132+ alreadyRecordedAction := false
132133 for _ , entry := range currentSubStatus .Actions {
133134 if entry .Action == action {
135+ alreadyRecordedAction = true
134136 entry .Count ++
135137 entry .LastOccurrence = fftypes .Now ()
136138
@@ -142,41 +144,39 @@ func (h *manager) AddSubStatusAction(ctx context.Context, mtx *apitypes.ManagedT
142144 if info != nil {
143145 entry .LastInfo = jsonOrString (info )
144146 }
145-
146- // As we have a possibly indefinite list of sub-status records (which might be a long list and early entries
147- // get purged at some point) we keep a separate list of all the discrete types of sub-status
148- // and action we've we've ever seen for this transaction along with a count of them. This means an early sub-status
149- // (e.g. "queued") with an action that never happens again (e.g. "assignNonce") followed by 100s of different sub-status
150- // types will still be recorded
151- for _ , actionType := range mtx .HistorySummary {
152- if actionType .Action == action {
153- // Just increment the counter and last timestamp
154- actionType .LastOccurrence = fftypes .Now ()
155- actionType .Count ++
156- break
157- }
158- }
159- return
147+ break
160148 }
161149 }
162150
163- // If this is an entirely new status add it to the list
164- newAction := & apitypes.TxHistoryActionEntry {
165- Time : fftypes .Now (),
166- Action : action ,
167- LastOccurrence : fftypes .Now (),
168- Count : 1 ,
169- }
151+ if ! alreadyRecordedAction {
152+ // If this is an entirely new action for this status entry, add it to the list
153+ newAction := & apitypes.TxHistoryActionEntry {
154+ Time : fftypes .Now (),
155+ Action : action ,
156+ LastOccurrence : fftypes .Now (),
157+ Count : 1 ,
158+ }
170159
171- if err != nil {
172- newAction .LastError = jsonOrString (err )
173- newAction .LastErrorTime = fftypes .Now ()
174- }
160+ if err != nil {
161+ newAction .LastError = jsonOrString (err )
162+ newAction .LastErrorTime = fftypes .Now ()
163+ }
175164
176- if info != nil {
177- newAction .LastInfo = jsonOrString (info )
165+ if info != nil {
166+ newAction .LastInfo = jsonOrString (info )
167+ }
168+
169+ currentSubStatus .Actions = append (currentSubStatus .Actions , newAction )
178170 }
179171
180- currentSubStatus .Actions = append (currentSubStatus .Actions , newAction )
172+ // Check if the history summary needs updating
173+ for _ , actionType := range mtx .HistorySummary {
174+ if actionType .Action == action {
175+ // Just increment the counter and last timestamp
176+ actionType .LastOccurrence = fftypes .Now ()
177+ actionType .Count ++
178+ return
179+ }
180+ }
181181 mtx .HistorySummary = append (mtx .HistorySummary , & apitypes.TxHistorySummaryEntry {Action : action , Count : 1 , FirstOccurrence : fftypes .Now (), LastOccurrence : fftypes .Now ()})
182182}
0 commit comments