diff --git a/cmd/zetaclientd/keygen_tss.go b/cmd/zetaclientd/keygen_tss.go index 5d7216e815..b9ee0e8238 100644 --- a/cmd/zetaclientd/keygen_tss.go +++ b/cmd/zetaclientd/keygen_tss.go @@ -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" @@ -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 diff --git a/cmd/zetaclientd/start.go b/cmd/zetaclientd/start.go index ef7f94e4c3..e71c84ce2d 100644 --- a/cmd/zetaclientd/start.go +++ b/cmd/zetaclientd/start.go @@ -79,8 +79,7 @@ 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 . @@ -88,7 +87,7 @@ func start(_ *cobra.Command, _ []string) error { // 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 { @@ -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 @@ -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 } @@ -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 { diff --git a/zetaclient/query.go b/zetaclient/query.go index d5c03304e9..f11a28c085 100644 --- a/zetaclient/query.go +++ b/zetaclient/query.go @@ -2,6 +2,7 @@ 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" @@ -9,6 +10,7 @@ import ( "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) { @@ -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) { diff --git a/zetaclient/tss_signer.go b/zetaclient/tss_signer.go index b84b800d2b..be3da1af12 100644 --- a/zetaclient/tss_signer.go +++ b/zetaclient/tss_signer.go @@ -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" @@ -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() { diff --git a/zetaclient/tx.go b/zetaclient/tx.go index 632ba1b6ed..4b0b4f74d9 100644 --- a/zetaclient/tx.go +++ b/zetaclient/tx.go @@ -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" @@ -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) { @@ -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) {