Skip to content

Commit abd1d73

Browse files
Merge pull request #905 from rsksmart/feat/fly2158/transfer_to_cold_wallet_watcher
feat/fly2158/cold to hot wallet transfer 2 Merging this PR (part 2 of the feature) because part 1 (#901) was initially created to give room to colleagues to review it in parallel with the development of this part 2. Since nobody reviewed part 1, this second part is being merged so the full context of the feature is in one PR with everything together.
2 parents 4b4fdd3 + ba0a5ff commit abd1d73

File tree

13 files changed

+1442
-18
lines changed

13 files changed

+1442
-18
lines changed

internal/adapters/entrypoints/watcher/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
rskEclipseCheckInterval = 15 * time.Second
2222
btcReleaseCheckInterval = 3 * time.Minute
2323
assetMetricsUpdateInterval = 1 * time.Minute
24+
transferColdWalletInterval = 5 * time.Minute
2425
)
2526

2627
type Watcher interface {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package monitoring
2+
3+
import (
4+
"context"
5+
6+
"github.com/rsksmart/liquidity-provider-server/internal/entities"
7+
"github.com/rsksmart/liquidity-provider-server/internal/entities/cold_wallet"
8+
log "github.com/sirupsen/logrus"
9+
)
10+
11+
type ColdWalletMetricsWatcher struct {
12+
appMetrics *Metrics
13+
eventBus entities.EventBus
14+
closeChannel chan struct{}
15+
}
16+
17+
func NewColdWalletMetricsWatcher(
18+
appMetrics *Metrics,
19+
eventBus entities.EventBus,
20+
) *ColdWalletMetricsWatcher {
21+
closeChannel := make(chan struct{}, 1)
22+
return &ColdWalletMetricsWatcher{
23+
appMetrics: appMetrics,
24+
eventBus: eventBus,
25+
closeChannel: closeChannel,
26+
}
27+
}
28+
29+
func (watcher *ColdWalletMetricsWatcher) Prepare(ctx context.Context) error {
30+
return nil
31+
}
32+
33+
// nolint: cyclop
34+
func (watcher *ColdWalletMetricsWatcher) Start() {
35+
rbtcThresholdChannel := watcher.eventBus.Subscribe(cold_wallet.RbtcTransferredDueToThresholdEventId)
36+
btcThresholdChannel := watcher.eventBus.Subscribe(cold_wallet.BtcTransferredDueToThresholdEventId)
37+
rbtcTimeForcingChannel := watcher.eventBus.Subscribe(cold_wallet.RbtcTransferredDueToTimeForcingEventId)
38+
btcTimeForcingChannel := watcher.eventBus.Subscribe(cold_wallet.BtcTransferredDueToTimeForcingEventId)
39+
40+
metricLoop:
41+
for {
42+
select {
43+
case event := <-rbtcThresholdChannel:
44+
if typedEvent, ok := event.(cold_wallet.RbtcTransferredDueToThresholdEvent); ok {
45+
watcher.appMetrics.ColdWalletTransfersMetric.WithLabelValues("rbtc", "threshold").Inc()
46+
watcher.appMetrics.ColdWalletLastAmountMetric.WithLabelValues("rbtc").Set(weiToBtcFloat64(typedEvent.Amount))
47+
}
48+
case event := <-btcThresholdChannel:
49+
if typedEvent, ok := event.(cold_wallet.BtcTransferredDueToThresholdEvent); ok {
50+
watcher.appMetrics.ColdWalletTransfersMetric.WithLabelValues("btc", "threshold").Inc()
51+
watcher.appMetrics.ColdWalletLastAmountMetric.WithLabelValues("btc").Set(weiToBtcFloat64(typedEvent.Amount))
52+
}
53+
case event := <-rbtcTimeForcingChannel:
54+
if typedEvent, ok := event.(cold_wallet.RbtcTransferredDueToTimeForcingEvent); ok {
55+
watcher.appMetrics.ColdWalletTransfersMetric.WithLabelValues("rbtc", "time_forcing").Inc()
56+
watcher.appMetrics.ColdWalletLastAmountMetric.WithLabelValues("rbtc").Set(weiToBtcFloat64(typedEvent.Amount))
57+
}
58+
case event := <-btcTimeForcingChannel:
59+
if typedEvent, ok := event.(cold_wallet.BtcTransferredDueToTimeForcingEvent); ok {
60+
watcher.appMetrics.ColdWalletTransfersMetric.WithLabelValues("btc", "time_forcing").Inc()
61+
watcher.appMetrics.ColdWalletLastAmountMetric.WithLabelValues("btc").Set(weiToBtcFloat64(typedEvent.Amount))
62+
}
63+
case <-watcher.closeChannel:
64+
close(watcher.closeChannel)
65+
break metricLoop
66+
}
67+
}
68+
}
69+
70+
func (watcher *ColdWalletMetricsWatcher) Shutdown(closeChannel chan<- bool) {
71+
watcher.closeChannel <- struct{}{}
72+
closeChannel <- true
73+
log.Debug("Cold wallet metrics watcher shutdown completed")
74+
}

0 commit comments

Comments
 (0)