Skip to content

Commit

Permalink
feat: release v1.2.0 (#667)
Browse files Browse the repository at this point in the history
Zetaclient fixes for keygen
  • Loading branch information
kingpinXD authored May 31, 2023
1 parent 18fa391 commit 1dce243
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 42 deletions.
9 changes: 6 additions & 3 deletions cmd/zetaclientd/keygen_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"github.com/pkg/errors"
"github.com/rs/zerolog"
mc "github.com/zeta-chain/zetacore/zetaclient"
"github.com/zeta-chain/zetacore/zetaclient/config"
Expand All @@ -16,9 +15,13 @@ func keygenTss(cfg *config.Config, tss *mc.TSS, logger zerolog.Logger) error {
var req keygen.Request
req = keygen.NewRequest(cfg.KeyGenPubKeys, cfg.KeygenBlock, "0.14.0")
res, err := tss.Server.Keygen(req)
if err != nil || res.Status != tsscommon.Success || res.PubKey == "" {
if res.Status != tsscommon.Success || res.PubKey == "" {
keygenLogger.Error().Msgf("keygen fail: reason %s blame nodes %s", res.Blame.FailReason, res.Blame.BlameNodes)
return errors.Wrap(err, fmt.Sprintf("Keygen fail: reason %s blame nodes %s", res.Blame.FailReason, res.Blame.BlameNodes))
return fmt.Errorf("keygen fail: reason %s blame nodes %s", res.Blame.FailReason, res.Blame.BlameNodes)
}
if err != nil {
keygenLogger.Error().Msgf("keygen fail: reason %s ", err.Error())
return err
}
tss.CurrentPubkey = res.PubKey

Expand Down
72 changes: 40 additions & 32 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,15 @@ func start(_ *cobra.Command, _ []string) error {
time.Sleep((time.Duration(cfg.ConfigUpdateTicker) + 1) * time.Second)
startLogger.Info().Msgf("Config is updated from ZetaCore %s", cfg.String())
if len(cfg.ChainsEnabled) == 0 {
startLogger.Info().Msgf("No chains enabled, exiting")
return nil
startLogger.Error().Msgf("No chains enabled in updated config %s ", cfg.String())
}

// Generate TSS address . The Tss address is generated through Keygen ceremony. The TSS key is used to sign all outbound transactions .
// Each node processes a portion of the key stored in ~/.tss by default . Custom location can be specified in config file during init.
// After generating the key , the address is set on the zetacore
bridgePk, err := zetaBridge.GetKeys().GetPrivateKey()
if err != nil {
startLogger.Error().Err(err).Msg("GetKeys GetPrivateKey error:")
startLogger.Error().Err(err).Msg("zetabridge getPrivateKey error")
}
startLogger.Debug().Msgf("bridgePk %s", bridgePk.String())
if len(bridgePk.Bytes()) != 32 {
Expand Down Expand Up @@ -117,6 +116,7 @@ func start(_ *cobra.Command, _ []string) error {
startLogger.Error().Err(err).Msg("NewTSS error")
return err
}

// If Keygen block is set it will try to generate new TSS at the block
// This is a blocking thread and will wait until the ceremony is complete successfully
// If the TSS generation is unsuccessful , it will loop indefinitely until a new TSS is generated
Expand All @@ -131,6 +131,7 @@ func start(_ *cobra.Command, _ []string) error {
// Break out of loop only when TSS is generated successfully , either at the keygenBlock or if it has been generated already , Block set as zero in genesis file
// 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.

if cfg.KeyGenStatus == crosschaintypes.KeygenStatus_KeyGenSuccess {
break
}
Expand All @@ -140,48 +141,55 @@ func start(_ *cobra.Command, _ []string) error {
continue
}
// Try generating TSS at keygen block , only when status is pending keygen and generation has not been tried at the block
if cfg.KeyGenStatus == crosschaintypes.KeygenStatus_PendingKeygen && !triedKeygenAtBlock {
if cfg.KeyGenStatus == crosschaintypes.KeygenStatus_PendingKeygen {
// Return error if RPC is not working
currentBlock, err := zetaBridge.GetZetaBlockHeight()
if err != nil {
startLogger.Error().Err(err).Msg("GetZetaBlockHeight RPC error")
continue
}
// If not at keygen block do not try to generate TSS
if currentBlock != cfg.KeygenBlock {
if currentBlock > lastBlock {
lastBlock = currentBlock
startLogger.Info().Msgf("Waiting For Keygen Block to arrive or new keygen block to be set. Keygen Block : %d", cfg.KeygenBlock)
}
continue
// Reset the flag if the keygen block has passed and a new keygen block has been set . This condition is only reached if the older keygen is stuck at PendingKeygen for some reason
if cfg.KeygenBlock > currentBlock {
triedKeygenAtBlock = false
}
// Try keygen only once at a particular block, irrespective of whether it is successful or failure
triedKeygenAtBlock = true
err = keygenTss(cfg, tss, masterLogger)
if err != nil {
startLogger.Error().Err(err).Msg("keygenTss error")
tssFailedVoteHash, err := zetaBridge.SetTSS("", cfg.KeygenBlock, common.ReceiveStatus_Failed)
if !triedKeygenAtBlock {
// If not at keygen block do not try to generate TSS
if currentBlock != cfg.KeygenBlock {
if currentBlock > lastBlock {
lastBlock = currentBlock
startLogger.Info().Msgf("Waiting For Keygen Block to arrive or new keygen block to be set. Keygen Block : %d Current Block : %d", cfg.KeygenBlock, currentBlock)
}
continue
}
// Try keygen only once at a particular block, irrespective of whether it is successful or failure
triedKeygenAtBlock = true
err = keygenTss(cfg, tss, masterLogger)
if err != nil {
startLogger.Error().Err(err).Msg("keygenTss error")
tssFailedVoteHash, err := zetaBridge.SetTSS("", cfg.KeygenBlock, common.ReceiveStatus_Failed)
if err != nil {
startLogger.Error().Err(err).Msg("Failed to broadcast Failed TSS Vote to zetacore")
return err
}
startLogger.Info().Msgf("TSS Failed Vote: %s", tssFailedVoteHash)
continue
}

// If TSS is successful , broadcast the vote to zetacore and set Pubkey
tssSuccessVoteHash, err := zetaBridge.SetTSS(tss.CurrentPubkey, cfg.KeygenBlock, common.ReceiveStatus_Success)
if err != nil {
startLogger.Error().Err(err).Msg("Failed to broadcast Failed TSS Vote to zetacore")
startLogger.Error().Err(err).Msg("TSS successful but unable to broadcast vote to zeta-core")
return err
}
startLogger.Info().Msgf("TSS Failed Vote: %s", tssFailedVoteHash)
startLogger.Info().Msgf("TSS successful Vote: %s", tssSuccessVoteHash)
err = SetTSSPubKey(tss, masterLogger)
if err != nil {
startLogger.Error().Err(err).Msg("SetTSSPubKey error")
}
continue
}

// If TSS is successful , broadcast the vote to zetacore and set Pubkey
tssSuccessVoteHash, err := zetaBridge.SetTSS(tss.CurrentPubkey, cfg.KeygenBlock, common.ReceiveStatus_Success)
if err != nil {
startLogger.Error().Err(err).Msg("TSS successful but unable to broadcast vote to zeta-core")
return err
}
startLogger.Info().Msgf("TSS successful Vote: %s", tssSuccessVoteHash)
err = SetTSSPubKey(tss, masterLogger)
if err != nil {
startLogger.Error().Err(err).Msg("SetTSSPubKey error")
}
continue
}
startLogger.Debug().Msgf("Waiting for TSS to be generated or Current Keygen to be be finalized. Keygen Block : %d ", cfg.KeygenBlock)
}
err = TestTSS(tss, masterLogger)
if err != nil {
Expand Down
17 changes: 12 additions & 5 deletions zetaclient/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package zetaclient

import (
"context"
"fmt"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/types/query"
tmtypes "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/x/crosschain/types"
zetaObserverTypes "github.com/zeta-chain/zetacore/x/observer/types"
"google.golang.org/grpc"
"time"
)

func (b *ZetaCoreBridge) GetInboundPermissions() (types.PermissionFlags, error) {
Expand All @@ -32,11 +34,16 @@ func (b *ZetaCoreBridge) GetCoreParamsForChainID(externalChainID int64) (*zetaOb

func (b *ZetaCoreBridge) GetCoreParams() ([]*zetaObserverTypes.CoreParams, error) {
client := zetaObserverTypes.NewQueryClient(b.grpcConn)
resp, err := client.GetCoreParams(context.Background(), &zetaObserverTypes.QueryGetCoreParamsRequest{})
if err != nil {
return nil, err
}
return resp.CoreParams.CoreParams, nil
err := error(nil)
resp := &zetaObserverTypes.QueryGetCoreParamsResponse{}
for i := 0; i <= DefaultRetryCount; i++ {
resp, err = client.GetCoreParams(context.Background(), &zetaObserverTypes.QueryGetCoreParamsRequest{})
if err == nil {
return resp.CoreParams.CoreParams, nil
}
time.Sleep(DefaultRetryInterval * time.Second)
}
return nil, fmt.Errorf("failed to get core params | err %s", err.Error())
}

func (b *ZetaCoreBridge) GetObserverParams() (zetaObserverTypes.Params, error) {
Expand Down
8 changes: 8 additions & 0 deletions zetaclient/tss_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/base64"
"encoding/hex"
"fmt"
peer2 "github.com/libp2p/go-libp2p/core/peer"
"github.com/zeta-chain/zetacore/zetaclient/config"
"gitlab.com/thorchain/tss/go-tss/p2p"
"path"
Expand Down Expand Up @@ -404,6 +405,13 @@ func SetupTSSServer(peer p2p.AddrList, privkey tmcrypto.PrivKey, preParams *keyg
}

log.Info().Msgf("LocalID: %v", tssServer.GetLocalPeerID())
if tssServer.GetLocalPeerID() == "" ||
tssServer.GetLocalPeerID() == "0" ||
tssServer.GetLocalPeerID() == "000000000000000000000000000000" ||
tssServer.GetLocalPeerID() == peer2.ID("").String() {
log.Error().Msg("tss server start error")
return nil, nil, fmt.Errorf("tss server start error")
}

s := NewHTTPServer(tssServer.GetLocalPeerID())
go func() {
Expand Down
5 changes: 3 additions & 2 deletions zetaclient/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/authz"
"github.com/pkg/errors"
"github.com/zeta-chain/zetacore/zetaclient/config"
"math/big"
"time"
Expand All @@ -23,6 +22,7 @@ const (
PostReceiveConfirmationGasLimit = 200_000
DefaultGasLimit = 200_000
DefaultRetryCount = 5
DefaultRetryInterval = 5
)

func (b *ZetaCoreBridge) WrapMessageWithAuthz(msg sdk.Msg) (sdk.Msg, AuthZSigner) {
Expand Down Expand Up @@ -120,8 +120,9 @@ func (b *ZetaCoreBridge) SetTSS(tssPubkey string, keyGenZetaHeight int64, status
if err == nil {
return zetaTxHash, nil
}
time.Sleep(DefaultRetryInterval * time.Second)
}
return "", errors.Wrap(err, "set tss failed")
return "", fmt.Errorf("set tss failed | err %s", err.Error())
}

func (b *ZetaCoreBridge) ConfigUpdater(cfg *config.Config) {
Expand Down

0 comments on commit 1dce243

Please sign in to comment.