Skip to content

Commit

Permalink
Cleanup keygen core context pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Mar 4, 2024
1 parent 5086f8c commit 4e2c07c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 28 deletions.
5 changes: 1 addition & 4 deletions cmd/zetaclientd/keygen_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ func GenerateTss(
// This loop will try keygen at the keygen block and then wait for keygen to be successfully reported by all nodes before breaking out of the loop.
// If keygen is unsuccessful, it will reset the triedKeygenAtBlock flag and try again at a new keygen block.

keyGen, found := appContext.ZetaCoreContext().GetKeygen()
if !found {
return nil, fmt.Errorf("keygen not found")
}
keyGen := appContext.ZetaCoreContext().GetKeygen()
if keyGen.Status == observertypes.KeygenStatus_KeyGenSuccess {
return tss, nil
}
Expand Down
5 changes: 1 addition & 4 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,7 @@ func start(_ *cobra.Command, _ []string) error {
// For existing keygen, this should directly proceed to the next step
ticker := time.NewTicker(time.Second * 1)
for range ticker.C {
keyGen, found := appContext.ZetaCoreContext().GetKeygen()
if !found {
return fmt.Errorf("keygen not found")
}
keyGen := appContext.ZetaCoreContext().GetKeygen()
if keyGen.Status != observerTypes.KeygenStatus_KeyGenSuccess {
startLogger.Info().Msgf("Waiting for TSS Keygen to be a success, current status %s", keyGen.Status)
continue
Expand Down
18 changes: 4 additions & 14 deletions zetaclient/core_context/zeta_core_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// these are initialized and updated at runtime at every height
type ZetaCoreContext struct {
coreContextLock *sync.RWMutex
keygen *observertypes.Keygen
keygen observertypes.Keygen
chainsEnabled []common.Chain
evmChainParams map[int64]*observertypes.ChainParams
bitcoinChainParams *observertypes.ChainParams
Expand All @@ -41,21 +41,11 @@ func NewZetaCoreContext(cfg config.Config) *ZetaCoreContext {
}
}

func (c *ZetaCoreContext) GetKeygen() (observertypes.Keygen, bool) {
func (c *ZetaCoreContext) GetKeygen() observertypes.Keygen {
c.coreContextLock.RLock()
defer c.coreContextLock.RUnlock()

if c.keygen == nil {
return observertypes.Keygen{}, false
}
copiedPubkeys := make([]string, len(c.keygen.GranteePubkeys))
copy(copiedPubkeys, c.keygen.GranteePubkeys)

return observertypes.Keygen{
Status: c.keygen.Status,
GranteePubkeys: copiedPubkeys,
BlockNumber: c.keygen.BlockNumber,
}, true
return c.keygen
}

func (c *ZetaCoreContext) GetCurrentTssPubkey() string {
Expand Down Expand Up @@ -148,7 +138,7 @@ func (c *ZetaCoreContext) Update(
}
}
}
c.keygen = keygen
c.keygen = *keygen
c.chainsEnabled = newChains
// update chain params for bitcoin if it has config in file
if c.bitcoinChainParams != nil && btcChainParams != nil {
Expand Down
9 changes: 3 additions & 6 deletions zetaclient/core_context/zeta_core_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ func TestNewZetaCoreContext(t *testing.T) {
require.NotNil(t, zetaContext)

// assert keygen
keyGen, keyGenFound := zetaContext.GetKeygen()
require.False(t, keyGenFound)
keyGen := zetaContext.GetKeygen()
require.Equal(t, observertypes.Keygen{}, keyGen)

// assert enabled chains
Expand Down Expand Up @@ -136,8 +135,7 @@ func TestUpdateZetaCoreContext(t *testing.T) {
)

// assert keygen updated
keyGen, keyGenFound := zetaContext.GetKeygen()
require.True(t, keyGenFound)
keyGen := zetaContext.GetKeygen()
require.Equal(t, keyGenToUpdate, keyGen)

// assert enabled chains updated
Expand Down Expand Up @@ -223,8 +221,7 @@ func TestUpdateZetaCoreContext(t *testing.T) {
)

// assert keygen updated
keyGen, keyGenFound := zetaContext.GetKeygen()
require.True(t, keyGenFound)
keyGen := zetaContext.GetKeygen()
require.Equal(t, keyGenToUpdate, keyGen)

// assert enabled chains updated
Expand Down

0 comments on commit 4e2c07c

Please sign in to comment.