Skip to content

Commit

Permalink
fix: v9.0.1 (#1073)
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD authored Aug 31, 2023
1 parent 3046a78 commit 473a9ed
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 23 deletions.
18 changes: 11 additions & 7 deletions cmd/zetaclientd/aux.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -45,7 +44,8 @@ func CreateSignerMap(tss zetaclient.TSSSigner, logger zerolog.Logger, cfg *confi
erc20CustodyAddress := ethcommon.HexToAddress(evmConfig.CoreParams.Erc20CustodyContractAddress)
signer, err := zetaclient.NewEVMSigner(evmConfig.Chain, evmConfig.Endpoint, tss, config.GetConnectorABI(), config.GetERC20CustodyABI(), mpiAddress, erc20CustodyAddress, logger, ts)
if err != nil {
return nil, errors.Wrapf(err, "NewEVMSigner error for chain %s", evmConfig.Chain.String())
logger.Error().Err(err).Msgf("NewEVMSigner error for chain %s", evmConfig.Chain.String())
continue
}
signerMap[evmConfig.Chain] = signer
}
Expand All @@ -54,9 +54,10 @@ func CreateSignerMap(tss zetaclient.TSSSigner, logger zerolog.Logger, cfg *confi
if enabled {
signer, err := zetaclient.NewBTCSigner(btcConfig, tss, logger, ts)
if err != nil {
return nil, errors.Wrapf(err, "NewBTCSigner error for chain %s", btcChain.String())
logger.Error().Err(err).Msgf("NewBTCSigner error for chain %s", btcChain.String())
} else {
signerMap[btcChain] = signer
}
signerMap[btcChain] = signer
}

return signerMap, nil
Expand All @@ -71,7 +72,8 @@ func CreateChainClientMap(bridge *zetaclient.ZetaCoreBridge, tss zetaclient.TSSS
}
co, err := zetaclient.NewEVMChainClient(bridge, tss, dbpath, metrics, logger, cfg, *evmConfig, ts)
if err != nil {
return nil, errors.Wrapf(err, "NewEVMChainClient error for chain %s", evmConfig.Chain.String())
logger.Error().Err(err).Msgf("NewEVMChainClient error for chain %s", evmConfig.Chain.String())
continue
}
clientMap[evmConfig.Chain] = co
}
Expand All @@ -80,9 +82,11 @@ func CreateChainClientMap(bridge *zetaclient.ZetaCoreBridge, tss zetaclient.TSSS
if enabled {
co, err := zetaclient.NewBitcoinClient(btcChain, bridge, tss, dbpath, metrics, logger, btcConfig, ts)
if err != nil {
return nil, errors.Wrapf(err, "NewBitcoinClient error for chain %s", btcChain.String())
logger.Error().Err(err).Msgf("NewBitcoinClient error for chain %s", btcChain.String())

} else {
clientMap[btcChain] = co
}
clientMap[btcChain] = co
}

return clientMap, nil
Expand Down
24 changes: 18 additions & 6 deletions cmd/zetaclientd/keygen_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,17 @@ func GenerateTss(logger zerolog.Logger, cfg *config.Config, zetaBridge *mc.ZetaC
// Set TSS block to 0 using genesis file to disable this feature
// Note : The TSS generation is done through the "hotkey" or "Zeta-clientGrantee" This key needs to be present on the machine for the TSS signing to happen .
// "ZetaClientGrantee" key is different from the "operator" key .The "Operator" key gives all zetaclient related permissions such as TSS generation ,reporting and signing, INBOUND and OUTBOUND vote signing, to the "ZetaClientGrantee" key.
// The votes to signify a successful TSS generation(Or unsuccessful) is signed by the operator key and broadcast to zetacore by the zetcalientGrantee key on behalf of the operator .
// The votes to signify a successful TSS generation (Or unsuccessful) is signed by the operator key and broadcast to zetacore by the zetcalientGrantee key on behalf of the operator .
ticker := time.NewTicker(time.Second * 1)
triedKeygenAtBlock := false
lastBlock := int64(0)
for range ticker.C {
// 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
// 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 keygen is unsuccessful, it will reset the triedKeygenAtBlock flag and try again at a new keygen block.

keyGen := cfg.GetKeygen()
if keyGen.Status == observerTypes.KeygenStatus_KeyGenSuccess {
cfg.TestTssKeysign = true
return tss, nil
}
// Arrive at this stage only if keygen is unsuccessfully reported by every node . This will reset the flag and to try again at a new keygen block
Expand Down Expand Up @@ -88,8 +87,17 @@ func GenerateTss(logger zerolog.Logger, cfg *config.Config, zetaBridge *mc.ZetaC
continue
}

newTss := mc.TSS{
Server: tss.Server,
Keys: tss.Keys,
CurrentPubkey: tss.CurrentPubkey,
Signers: tss.Signers,
CoreBridge: nil,
Metrics: nil,
}

// If TSS is successful , broadcast the vote to zetacore and set Pubkey
tssSuccessVoteHash, err := zetaBridge.SetTSS(tss.CurrentPubkey, keyGen.BlockNumber, common.ReceiveStatus_Success)
tssSuccessVoteHash, err := zetaBridge.SetTSS(newTss.CurrentPubkey, keyGen.BlockNumber, common.ReceiveStatus_Success)
if err != nil {
keygenLogger.Error().Err(err).Msg("TSS successful but unable to broadcast vote to zeta-core")
return nil, err
Expand All @@ -99,6 +107,10 @@ func GenerateTss(logger zerolog.Logger, cfg *config.Config, zetaBridge *mc.ZetaC
if err != nil {
keygenLogger.Error().Err(err).Msg("SetTSSPubKey error")
}
err = TestTSS(&newTss, keygenLogger)
if err != nil {
keygenLogger.Error().Err(err).Msgf("TestTSS error: %s", newTss.CurrentPubkey)
}
continue
}
}
Expand Down Expand Up @@ -166,7 +178,7 @@ func SetTSSPubKey(tss *mc.TSS, logger zerolog.Logger) error {
func TestTSS(tss *mc.TSS, logger zerolog.Logger) error {
keygenLogger := logger.With().Str("module", "test-keygen").Logger()
keygenLogger.Info().Msgf("KeyGen success ! Doing a Key-sign test")
// KeySign can fail even if TSS keygen is successful , just logging the error here to break out of outer loop and report TSS
// KeySign can fail even if TSS keygen is successful, just logging the error here to break out of outer loop and report TSS
err := mc.TestKeysign(tss.CurrentPubkey, tss.Server)
if err != nil {
return err
Expand Down
22 changes: 18 additions & 4 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -71,6 +72,17 @@ func start(_ *cobra.Command, _ []string) error {
startLogger.Info().Msgf("ZetaBridge is ready")
zetaBridge.SetAccountNumber(common.ZetaClientGranteeKey)

// cross check chainid
res, err := zetaBridge.GetNodeInfo()
if err != nil {
panic(err)
}

if strings.Compare(res.GetDefaultNodeInfo().Network, cfg.ChainID) != 0 {
startLogger.Warn().Msgf("chain id mismatch, zeta-core chain id %s, zeta client chain id %s; reset zeta client chain id", res.GetDefaultNodeInfo().Network, cfg.ChainID)
cfg.ChainID = res.GetDefaultNodeInfo().Network
}

// CreateAuthzSigner : which is used to sign all authz messages . All votes broadcast to zetacore are wrapped in authz exec .
// This is to ensure that the user does not need to keep their operator key online , and can use a cold key to sign votes
CreateAuthzSigner(zetaBridge.GetKeys().GetOperatorAddress().String(), zetaBridge.GetKeys().GetAddress())
Expand Down Expand Up @@ -137,11 +149,12 @@ func start(_ *cobra.Command, _ []string) error {
if cfg.TestTssKeysign {
err = TestTSS(tss, masterLogger)
if err != nil {
startLogger.Error().Err(err).Msg("TestTSS error")
startLogger.Error().Err(err).Msgf("TestTSS error : %s", tss.CurrentPubkey)
}
}

// Wait for TSS keygen to be successful before proceeding, This is a blocking thread
// Wait for TSS keygen to be successful before proceeding, This is a blocking thread only for a new keygen.
// For existing keygen, this should directly proceed to the next step
ticker := time.NewTicker(time.Second * 1)
for range ticker.C {
if cfg.Keygen.Status != observerTypes.KeygenStatus_KeyGenSuccess {
Expand All @@ -160,8 +173,9 @@ func start(_ *cobra.Command, _ []string) error {
return err
}

// Defensive check: Make sure the tss address is set to the current TSS address and not the newly generated one
tss.CurrentPubkey = currentTss.TssPubkey
startLogger.Info().Msgf("TSS address \n ETH : %s \n BTC : %s \n PubKey : %s ", tss.EVMAddress(), tss.BTCAddress(), tss.CurrentPubkey)
startLogger.Info().Msgf("Current TSS address \n ETH : %s \n BTC : %s \n PubKey : %s ", tss.EVMAddress(), tss.BTCAddress(), tss.CurrentPubkey)
if len(cfg.ChainsEnabled) == 0 {
startLogger.Error().Msgf("No chains enabled in updated config %s ", cfg.String())
}
Expand All @@ -183,7 +197,7 @@ func start(_ *cobra.Command, _ []string) error {
startLogger.Error().Msgf("Node %s is not an active observer", zetaBridge.GetKeys().GetOperatorAddress().String())
return errors.New("Node is not an active observer")
}
// CreateSignerMap : This creates a map of all signers for each chain . Each signer is responsible for signing transactions for a particular chain
// CreateSignerMap: This creates a map of all signers for each chain . Each signer is responsible for signing transactions for a particular chain
signerMap, err := CreateSignerMap(tss, masterLogger, cfg, telemetryServer)
if err != nil {
log.Error().Err(err).Msg("CreateSignerMap")
Expand Down
Empty file added standalone-network/gov/gov.sh
Empty file.
58 changes: 58 additions & 0 deletions standalone-network/gov/gov_observer_params_supported_chains.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"title": "Observer Param Change",
"description": "Update observer params",
"changes": [
{
"subspace": "observer",
"key": "ObserverParams",
"value": [
{
"chain": {
"chain_name": 6,
"chain_id": 5
},
"ballot_threshold": "0.660000000000000000",
"min_observer_delegation": "10000000000.000000000000000000",
"is_supported": "true"
},
{
"chain": {
"chain_name": 11,
"chain_id": 7001
},
"ballot_threshold": "0.660000000000000000",
"min_observer_delegation": "10000000000.000000000000000000",
"is_supported": "true"
},
{
"chain": {
"chain_name": 10,
"chain_id": 97
},
"ballot_threshold": "0.660000000000000000",
"min_observer_delegation": "10000000000.000000000000000000",
"is_supported": "true"
},
{
"chain": {
"chain_name": 12,
"chain_id": 18332
},
"ballot_threshold": "0.660000000000000000",
"min_observer_delegation": "10000000000.000000000000000000",
"is_supported": "true"
},
{
"chain": {
"chain_name": 7,
"chain_id": 80001
},
"ballot_threshold": "0.660000000000000000",
"min_observer_delegation": "10000000000.000000000000000000",
"is_supported": "true"
}
]
}
],
"deposit": "10000000azeta"
}
4 changes: 2 additions & 2 deletions x/crosschain/client/cli/query_get_tss_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
func CmdGetTssAddress() *cobra.Command {
cmd := &cobra.Command{
Use: "get-tss-address",
Short: "Query getTssAddress",
Args: cobra.ExactArgs(2),
Short: "Query current tss address",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) (err error) {

clientCtx, err := client.GetClientTxContext(cmd)
Expand Down
21 changes: 18 additions & 3 deletions zetaclient/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,13 @@ func (b *ZetaCoreBridge) GetObserverList(chain common.Chain) ([]string, error) {
resp, err := client.ObserversByChain(context.Background(), &zetaObserverTypes.QueryObserversByChainRequest{
ObservationChain: chain.ChainName.String(),
})
if err != nil {
return nil, err
for i := 0; i <= DefaultRetryCount; i++ {
if err == nil {
return resp.Observers, nil
}
time.Sleep(DefaultRetryInterval * time.Second)
}
return resp.Observers, nil
return nil, err
}

func (b *ZetaCoreBridge) GetAllPendingCctx(chainID uint64) ([]*types.CrossChainTx, error) {
Expand Down Expand Up @@ -161,6 +164,18 @@ func (b *ZetaCoreBridge) GetLatestZetaBlock() (*tmtypes.Block, error) {
return res.Block, nil
}

func (b *ZetaCoreBridge) GetNodeInfo() (*tmservice.GetNodeInfoResponse, error) {
client := tmservice.NewServiceClient(b.grpcConn)
res, err := client.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
for i := 0; i <= DefaultRetryCount; i++ {
if err == nil {
return res, nil
}
time.Sleep(DefaultRetryInterval * time.Second)
}
return nil, err
}

func (b *ZetaCoreBridge) GetLastBlockHeightByChain(chain common.Chain) (*types.LastBlockHeight, error) {
client := types.NewQueryClient(b.grpcConn)
resp, err := client.LastBlockHeight(context.Background(), &types.QueryGetLastBlockHeightRequest{Index: chain.ChainName.String()})
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/zetabridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (b *ZetaCoreBridge) UpdateConfigFromCore(cfg *config.Config, init bool) err
for i, params := range coreParams {
err := config.ValidateCoreParams(params)
if err != nil {
return err
b.logger.Err(err).Msgf("Invalid core params for chain %s", common.GetChainFromChainID(params.ChainId).ChainName)
}
newChains[i] = *common.GetChainFromChainID(params.ChainId)
if common.IsBitcoinChain(params.ChainId) {
Expand Down

0 comments on commit 473a9ed

Please sign in to comment.