99 "encoding/binary"
1010 "encoding/json"
1111 "fmt"
12+ "time"
1213
1314 "decred.org/dcrdex/client/asset"
1415 "decred.org/dcrdex/dex"
@@ -105,7 +106,7 @@ type eventLogDB interface {
105106 // storeEvent stores/updates a market making event.
106107 storeEvent (startTime int64 , mkt * MarketWithHost , e * MarketMakingEvent , fs * BalanceState )
107108 // endRun stores the time that a market making run was ended.
108- endRun (startTime int64 , mkt * MarketWithHost , endTime int64 ) error
109+ endRun (startTime int64 , mkt * MarketWithHost ) error
109110 // runs returns a list of runs in the database. If n == 0, all of the runs
110111 // will be returned. If refStartTime and refMkt are not nil, the runs
111112 // including and before the run with the start time and market will be
@@ -321,6 +322,11 @@ func (db *boltEventLogDB) updateEvent(update *eventUpdate) {
321322 }
322323 }
323324
325+ err = storeEndTime (runBucket )
326+ if err != nil {
327+ return err
328+ }
329+
324330 // Update the final state.
325331 bsJSON , err := json .Marshal (bs )
326332 if err != nil {
@@ -448,7 +454,15 @@ func (db *boltEventLogDB) storeNewRun(startTime int64, mkt *MarketWithHost, cfg
448454 return err
449455 }
450456
451- runBucket .Put (startTimeKey , encode .Uint64Bytes (uint64 (startTime )))
457+ err = runBucket .Put (startTimeKey , encode .Uint64Bytes (uint64 (startTime )))
458+ if err != nil {
459+ return err
460+ }
461+
462+ err = storeEndTime (runBucket )
463+ if err != nil {
464+ return err
465+ }
452466
453467 if err := db .storeCfgUpdate (runBucket , cfg , startTime ); err != nil {
454468 return err
@@ -616,8 +630,13 @@ func (db *boltEventLogDB) runOverview(startTime int64, mkt *MarketWithHost) (*Ma
616630 })
617631}
618632
633+ // storeEndTime updates the end time of a run to the current time.
634+ func storeEndTime (runBucket * bbolt.Bucket ) error {
635+ return runBucket .Put (endTimeKey , encode .Uint64Bytes (uint64 (time .Now ().Unix ())))
636+ }
637+
619638// endRun stores the time that a market making run was ended.
620- func (db * boltEventLogDB ) endRun (startTime int64 , mkt * MarketWithHost , endTime int64 ) error {
639+ func (db * boltEventLogDB ) endRun (startTime int64 , mkt * MarketWithHost ) error {
621640 return db .Update (func (tx * bbolt.Tx ) error {
622641 botRuns := tx .Bucket (botRunsBucket )
623642 key := runKey (startTime , mkt )
@@ -626,7 +645,7 @@ func (db *boltEventLogDB) endRun(startTime int64, mkt *MarketWithHost, endTime i
626645 return fmt .Errorf ("nil run bucket for key %x" , key )
627646 }
628647
629- return runBucket . Put ( endTimeKey , encode . Uint64Bytes ( uint64 ( endTime )) )
648+ return storeEndTime ( runBucket )
630649 })
631650}
632651
0 commit comments