Skip to content

Commit

Permalink
debug log
Browse files Browse the repository at this point in the history
  • Loading branch information
YusukeShimizu committed Jun 24, 2024
1 parent 8ed026d commit eb432a7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions lwk/electrumtxwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (r *electrumTxWatcher) StartWatchingTxs() error {
r.mu.Unlock()
log.Debugf("New block received. block height:%d", r.blockHeight)
err = r.subscriber.Update(ctx, r.blockHeight)
log.Debugf("failed to update: %v", err)
if err != nil {
log.Infof("Error notifying tx observers: %v", err)
continue
Expand Down
6 changes: 3 additions & 3 deletions swap/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (s *SwapInReceiverInitAction) Execute(services *SwapServices, swap *SwapDat

toCtx, cancel := context.WithCancel(context.Background())
swap.toCancel = cancel
services.toService.addNewTimeOut(toCtx, 10*time.Minute, swap.GetId().String())
services.toService.addNewTimeOut(toCtx, 1*time.Minute, swap.GetId().String())

return Event_ActionSucceeded
}
Expand Down Expand Up @@ -421,7 +421,7 @@ func (c *CreateSwapOutFromRequestAction) Execute(services *SwapServices, swap *S

toCtx, cancel := context.WithCancel(context.Background())
swap.toCancel = cancel
services.toService.addNewTimeOut(toCtx, 10*time.Minute, swap.GetId().String())
services.toService.addNewTimeOut(toCtx, 1*time.Minute, swap.GetId().String())

return Event_ActionSucceeded
}
Expand Down Expand Up @@ -542,7 +542,7 @@ func (a *CreateSwapRequestAction) Execute(services *SwapServices, swap *SwapData

toCtx, cancel := context.WithCancel(context.Background())
swap.toCancel = cancel
services.toService.addNewTimeOut(toCtx, 10*time.Minute, swap.GetId().String())
services.toService.addNewTimeOut(toCtx, 1*time.Minute, swap.GetId().String())

return Event_ActionSucceeded
}
Expand Down
1 change: 1 addition & 0 deletions swap/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func (s *SwapStateMachine) SendEvent(event EventType, eventCtx EventContext) (bo
}
}

log.Debugf("[FSM] udate db.event:id: %s, %s on %s", s.SwapId.String(), event, s.Current)
err = s.swapServices.swapStore.UpdateData(s)
if err != nil {
return false, err
Expand Down
21 changes: 21 additions & 0 deletions swap/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"os"
"time"

"go.etcd.io/bbolt"
)
Expand Down Expand Up @@ -34,6 +36,25 @@ func NewBboltStore(db *bbolt.DB) (*bboltStore, error) {
if err := tx.Commit(); err != nil {
return nil, err
}
go func() {
// Grab the initial stats.
prev := db.Stats()

for {
// Wait for 10s.
time.Sleep(10 * time.Second)

// Grab the current stats and diff them.
stats := db.Stats()
diff := stats.Sub(&prev)

// Encode stats to JSON and print to STDERR.
json.NewEncoder(os.Stderr).Encode(diff)

// Save stats for the next loop.
prev = stats
}
}()

return &bboltStore{db: db}, nil
}
Expand Down

0 comments on commit eb432a7

Please sign in to comment.