-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into refactor-tss-vote
- Loading branch information
Showing
5 changed files
with
106 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package tss | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/rs/zerolog" | ||
"github.com/zeta-chain/zetacore/zetaclient/metrics" | ||
) | ||
|
||
// ConcurrentKeysignsTracker keeps track of concurrent keysigns performed by go-tss | ||
type ConcurrentKeysignsTracker struct { | ||
numActiveMsgSigns int64 | ||
mu sync.Mutex | ||
Logger zerolog.Logger | ||
} | ||
|
||
// NewKeysignsTracker - constructor | ||
func NewKeysignsTracker(logger zerolog.Logger) *ConcurrentKeysignsTracker { | ||
return &ConcurrentKeysignsTracker{ | ||
numActiveMsgSigns: 0, | ||
mu: sync.Mutex{}, | ||
Logger: logger.With().Str("submodule", "ConcurrentKeysignsTracker").Logger(), | ||
} | ||
} | ||
|
||
// StartMsgSign is incrementing the number of active signing ceremonies as well as updating the prometheus metric | ||
func (k *ConcurrentKeysignsTracker) StartMsgSign() { | ||
k.mu.Lock() | ||
defer k.mu.Unlock() | ||
k.numActiveMsgSigns++ | ||
metrics.NumActiveMsgSigns.Inc() | ||
k.Logger.Debug().Msgf("Start TSS message sign, numActiveMsgSigns: %d", k.numActiveMsgSigns) | ||
} | ||
|
||
// EndMsgSign is decrementing the number of active signing ceremonies as well as updating the prometheus metric | ||
func (k *ConcurrentKeysignsTracker) EndMsgSign() { | ||
k.mu.Lock() | ||
defer k.mu.Unlock() | ||
if k.numActiveMsgSigns > 0 { | ||
k.numActiveMsgSigns-- | ||
metrics.NumActiveMsgSigns.Dec() | ||
} | ||
k.Logger.Debug().Msgf("End TSS message sign, numActiveMsgSigns: %d", k.numActiveMsgSigns) | ||
} | ||
|
||
// GetNumActiveMessageSigns gets the current number of active signing ceremonies | ||
func (k *ConcurrentKeysignsTracker) GetNumActiveMessageSigns() int64 { | ||
return k.numActiveMsgSigns | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package tss | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/rs/zerolog" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestKeySignManager_StartMsgSign(t *testing.T) { | ||
ksman := NewKeysignsTracker(zerolog.Logger{}) | ||
ksman.StartMsgSign() | ||
ksman.StartMsgSign() | ||
ksman.StartMsgSign() | ||
ksman.StartMsgSign() | ||
require.Equal(t, int64(4), ksman.GetNumActiveMessageSigns()) | ||
} | ||
|
||
func TestKeySignManager_EndMsgSign(t *testing.T) { | ||
ksman := NewKeysignsTracker(zerolog.Logger{}) | ||
ksman.StartMsgSign() | ||
ksman.StartMsgSign() | ||
ksman.EndMsgSign() | ||
ksman.EndMsgSign() | ||
ksman.EndMsgSign() | ||
require.Equal(t, int64(0), ksman.GetNumActiveMessageSigns()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters