@@ -2,7 +2,9 @@ package tss
2
2
3
3
import (
4
4
"sync"
5
+ "time"
5
6
7
+ "github.com/prometheus/client_golang/prometheus"
6
8
"github.com/rs/zerolog"
7
9
8
10
"github.com/zeta-chain/zetacore/zetaclient/metrics"
@@ -25,26 +27,37 @@ func NewKeysignsTracker(logger zerolog.Logger) *ConcurrentKeysignsTracker {
25
27
}
26
28
27
29
// StartMsgSign is incrementing the number of active signing ceremonies as well as updating the prometheus metric
28
- func (k * ConcurrentKeysignsTracker ) StartMsgSign () {
30
+ //
31
+ // Call the returned function to signify the signing is complete
32
+ func (k * ConcurrentKeysignsTracker ) StartMsgSign () func (bool ) {
29
33
k .mu .Lock ()
30
34
defer k .mu .Unlock ()
31
35
k .numActiveMsgSigns ++
32
36
metrics .NumActiveMsgSigns .Inc ()
33
37
k .Logger .Debug ().Msgf ("Start TSS message sign, numActiveMsgSigns: %d" , k .numActiveMsgSigns )
34
- }
35
38
36
- // EndMsgSign is decrementing the number of active signing ceremonies as well as updating the prometheus metric
37
- func (k * ConcurrentKeysignsTracker ) EndMsgSign () {
38
- k .mu .Lock ()
39
- defer k .mu .Unlock ()
40
- if k .numActiveMsgSigns > 0 {
41
- k .numActiveMsgSigns --
42
- metrics .NumActiveMsgSigns .Dec ()
39
+ startTime := time .Now ()
40
+
41
+ return func (hasError bool ) {
42
+ k .mu .Lock ()
43
+ defer k .mu .Unlock ()
44
+ if k .numActiveMsgSigns > 0 {
45
+ k .numActiveMsgSigns --
46
+ metrics .NumActiveMsgSigns .Dec ()
47
+ }
48
+ k .Logger .Debug ().Msgf ("End TSS message sign, numActiveMsgSigns: %d" , k .numActiveMsgSigns )
49
+
50
+ result := "success"
51
+ if hasError {
52
+ result = "error"
53
+ }
54
+ metrics .SignLatency .With (prometheus.Labels {"result" : result }).Observe (time .Since (startTime ).Seconds ())
43
55
}
44
- k .Logger .Debug ().Msgf ("End TSS message sign, numActiveMsgSigns: %d" , k .numActiveMsgSigns )
45
56
}
46
57
47
58
// GetNumActiveMessageSigns gets the current number of active signing ceremonies
48
59
func (k * ConcurrentKeysignsTracker ) GetNumActiveMessageSigns () int64 {
60
+ k .mu .Lock ()
61
+ defer k .mu .Unlock ()
49
62
return k .numActiveMsgSigns
50
63
}
0 commit comments