Skip to content

Commit

Permalink
feat: tss-history (#1031)
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD authored Aug 30, 2023
1 parent df96df3 commit 3046a78
Show file tree
Hide file tree
Showing 68 changed files with 2,349 additions and 675 deletions.
2 changes: 2 additions & 0 deletions app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

Expand All @@ -19,6 +20,7 @@ func SetupHandlers(app *App) {
vm[m] = mb.ConsensusVersion()
}
vm[observertypes.ModuleName] = vm[observertypes.ModuleName] - 1
vm[crosschaintypes.ModuleName] = vm[crosschaintypes.ModuleName] - 1
SetParams(app, ctx)
return app.mm.RunMigrations(ctx, app.configurator, vm)
})
Expand Down
13 changes: 6 additions & 7 deletions cmd/zetaclientd/aux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@ func CreateAuthzSigner(granter string, grantee sdk.AccAddress) {
zetaclient.SetupAuthZSignerList(granter, grantee)
}

func CreateZetaBridge(chainHomeFolder string, config *config.Config) (*zetaclient.ZetaCoreBridge, error) {
signerPass := "password"
chainIP := config.ZetaCoreURL
kb, err := zetaclient.GetKeyringKeybase(config.AuthzHotkey, chainHomeFolder, signerPass)
func CreateZetaBridge(cfg *config.Config) (*zetaclient.ZetaCoreBridge, error) {
chainIP := cfg.ZetaCoreURL
kb, _, err := zetaclient.GetKeyringKeybase(cfg)
if err != nil {
return nil, err
}
granterAddreess, err := cosmos.AccAddressFromBech32(config.AuthzGranter)
granterAddreess, err := cosmos.AccAddressFromBech32(cfg.AuthzGranter)
if err != nil {
return nil, err
}
k := zetaclient.NewKeysWithKeybase(kb, granterAddreess, config.AuthzHotkey, signerPass)
bridge, err := zetaclient.NewZetaCoreBridge(k, chainIP, config.AuthzHotkey, config.ChainID)
k := zetaclient.NewKeysWithKeybase(kb, granterAddreess, cfg.AuthzHotkey, cfg.SignerPass)
bridge, err := zetaclient.NewZetaCoreBridge(k, chainIP, cfg.AuthzHotkey, cfg.ChainID)
if err != nil {
return nil, err
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/zetaclientd/keygen_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/tendermint/crypto/sha3"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/x/crosschain/types"
observerTypes "github.com/zeta-chain/zetacore/x/observer/types"
mc "github.com/zeta-chain/zetacore/zetaclient"
"github.com/zeta-chain/zetacore/zetaclient/config"
Expand All @@ -19,9 +20,9 @@ import (
"gitlab.com/thorchain/tss/go-tss/p2p"
)

func GenerateTss(logger zerolog.Logger, cfg *config.Config, zetaBridge *mc.ZetaCoreBridge, peers p2p.AddrList, priKey secp256k1.PrivKey, ts *mc.TelemetryServer) (*mc.TSS, error) {
func GenerateTss(logger zerolog.Logger, cfg *config.Config, zetaBridge *mc.ZetaCoreBridge, peers p2p.AddrList, priKey secp256k1.PrivKey, ts *mc.TelemetryServer, tssHistoricalList []types.TSS) (*mc.TSS, error) {
keygenLogger := logger.With().Str("module", "keygen").Logger()
tss, err := mc.NewTSS(peers, priKey, preParams, cfg, zetaBridge)
tss, err := mc.NewTSS(peers, priKey, preParams, cfg, zetaBridge, tssHistoricalList)
if err != nil {
keygenLogger.Error().Err(err).Msg("NewTSS error")
return nil, err
Expand Down Expand Up @@ -143,6 +144,7 @@ func keygenTss(cfg *config.Config, tss *mc.TSS, keygenLogger zerolog.Logger) err
keygenLogger.Error().Msgf("keygen fail: reason %s ", err.Error())
return err
}
// Keeping this line here for now, but this is redundant as CurrentPubkey is updated from zeta-core
tss.CurrentPubkey = res.PubKey
tss.Signers = keyGen.GranteePubkeys

Expand Down
60 changes: 54 additions & 6 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"
"os/signal"
"path/filepath"
"syscall"
"time"

"github.com/libp2p/go-libp2p/core"
maddr "github.com/multiformats/go-multiaddr"
Expand All @@ -16,6 +17,8 @@ import (
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/x/crosschain/types"
observerTypes "github.com/zeta-chain/zetacore/x/observer/types"
mc "github.com/zeta-chain/zetacore/zetaclient"
"github.com/zeta-chain/zetacore/zetaclient/config"
metrics2 "github.com/zeta-chain/zetacore/zetaclient/metrics"
Expand Down Expand Up @@ -60,7 +63,7 @@ func start(_ *cobra.Command, _ []string) error {

// CreateZetaBridge: Zetabridge is used for all communication to zetacore , which this client connects to.
// Zetacore accumulates votes , and provides a centralized source of truth for all clients
zetaBridge, err := CreateZetaBridge(rootArgs.zetaCoreHome, cfg)
zetaBridge, err := CreateZetaBridge(cfg)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -120,9 +123,14 @@ func start(_ *cobra.Command, _ []string) error {
startLogger.Error().Err(err).Msg("telemetryServer error")
}
}()
var tssHistoricalList []types.TSS
tssHistoricalList, err = zetaBridge.GetTssHistory()
if err != nil {
startLogger.Error().Err(err).Msg("GetTssHistory error")
}

telemetryServer.SetIPAddress(cfg.PublicIP)
tss, err := GenerateTss(masterLogger, cfg, zetaBridge, peers, priKey, telemetryServer)
tss, err := GenerateTss(masterLogger, cfg, zetaBridge, peers, priKey, telemetryServer, tssHistoricalList)
if err != nil {
return err
}
Expand All @@ -133,10 +141,50 @@ func start(_ *cobra.Command, _ []string) error {
}
}

// Wait for TSS keygen to be successful before proceeding, This is a blocking thread
ticker := time.NewTicker(time.Second * 1)
for range ticker.C {
if cfg.Keygen.Status != observerTypes.KeygenStatus_KeyGenSuccess {
startLogger.Info().Msgf("Waiting for TSS Keygen to be a success, current status %s", cfg.Keygen.Status)
continue
}
break
}

// Update Current TSS value from zetacore, if TSS keygen is successful, the TSS address is set on zeta-core
// Returns err if the RPC call fails as zeta client needs the current TSS address to be set
// This is only needed in case of a new Keygen , as the TSS address is set on zetacore only after the keygen is successful i.e enough votes have been broadcast
currentTss, err := zetaBridge.GetCurrentTss()
if err != nil {
startLogger.Error().Err(err).Msg("GetCurrentTSS error")
return err
}

tss.CurrentPubkey = currentTss.TssPubkey
startLogger.Info().Msgf("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())
}

// 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.Clone(), telemetryServer)
observerList, err := zetaBridge.GetObserverList(cfg.ChainsEnabled[0])
if err != nil {
startLogger.Error().Err(err).Msg("GetObserverList error")
return err
}
isNodeActive := false
for _, observer := range observerList {
if observer == zetaBridge.GetKeys().GetOperatorAddress().String() {
startLogger.Info().Msgf("Observer %s is active", zetaBridge.GetKeys().GetOperatorAddress().String())
isNodeActive = true
break
}
}
if !isNodeActive {
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
signerMap, err := CreateSignerMap(tss, masterLogger, cfg, telemetryServer)
if err != nil {
log.Error().Err(err).Msg("CreateSignerMap")
return err
Expand Down Expand Up @@ -210,7 +258,7 @@ func initPreParams(path string) {
if err != nil {
log.Error().Err(err).Msg("open pre-params file failed; skip")
} else {
bz, err := ioutil.ReadAll(preParamsFile)
bz, err := io.ReadAll(preParamsFile)
if err != nil {
log.Error().Err(err).Msg("read pre-params file failed; skip")
} else {
Expand Down
48 changes: 15 additions & 33 deletions common/pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"encoding/json"
"errors"
"fmt"
"sort"
"strings"
Expand All @@ -11,6 +12,8 @@ import (

"github.com/btcsuite/btcutil/bech32"
"github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"

eth "github.com/ethereum/go-ethereum/crypto"
"github.com/tendermint/tendermint/crypto"
Expand Down Expand Up @@ -208,36 +211,15 @@ func NewPubKeySet(secp256k1, ed25519 PubKey) PubKeySet {
}
}

//
//// IsEmpty will determinate whether PubKeySet is an empty
//func (pks PubKeySet) IsEmpty() bool {
// return pks.Secp256k1.IsEmpty() || pks.Ed25519.IsEmpty()
//}
//
//// Equals check whether two PubKeySet are the same
//func (pks PubKeySet) Equals(pks1 PubKeySet) bool {
// return pks.Ed25519.Equals(pks1.Ed25519) && pks.Secp256k1.Equals(pks1.Secp256k1)
//}
//
//func (pks PubKeySet) Contains(pk PubKey) bool {
// return pks.Ed25519.Equals(pk) || pks.Secp256k1.Equals(pk)
//}
//
//// String implement fmt.Stinger
//func (pks PubKeySet) String() string {
// return fmt.Sprintf(`
// secp256k1: %s
// ed25519: %s
//`, pks.Secp256k1.String(), pks.Ed25519.String())
//}
//
//// GetAddress
//func (pks PubKeySet) GetAddress(chain Chain) (Address, error) {
// switch chain.GetSigningAlgo() {
// case SigningAlgoSecp256k1:
// return pks.Secp256k1.GetAddress(chain)
// case SigningAlgoEd25519:
// return pks.Ed25519.GetAddress(chain)
// }
// return NoAddress, fmt.Errorf("unknow signing algorithm")
//}
func GetPubkeyBech32FromRecord(record *keyring.Record) (string, error) {
pk, ok := record.PubKey.GetCachedValue().(cryptotypes.PubKey)
if !ok {
return "", errors.New("unable to cast any to cryptotypes.PubKey")
}

s, err := cosmos.Bech32ifyPubKey(cosmos.Bech32PubKeyTypeAccPub, pk)
if err != nil {
return "", err
}
return s, nil
}
26 changes: 26 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27227,6 +27227,20 @@ paths:
$ref: '#/definitions/googlerpcStatus'
tags:
- Query
/zeta-chain/crosschain/tssHistory: |
get:
operationId: Query_TssHistory
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/crosschainQueryTssHistoryResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
tags:
- Query
/zeta-chain/observer/all_observer_mappers: |
get:
operationId: Query_AllObserverMappers
Expand Down Expand Up @@ -50213,6 +50227,8 @@ definitions:
type: object
crosschainMsgRemoveFromOutTxTrackerResponse:
type: object
crosschainMsgUpdateTssAddressResponse:
type: object
crosschainMsgVoteOnObservedInboundTxResponse:
type: object
crosschainMsgVoteOnObservedOutboundTxResponse:
Expand Down Expand Up @@ -50266,6 +50282,8 @@ definitions:
outbound_tx_observed_external_height:
type: string
format: uint64
tss_pubkey:
type: string
crosschainPendingNonces:
type: object
properties:
Expand Down Expand Up @@ -50440,6 +50458,14 @@ definitions:
properties:
feeInZeta:
type: string
crosschainQueryTssHistoryResponse:
type: object
properties:
tss_list:
type: array
items:
type: object
$ref: '#/definitions/crosschainTSS'
crosschainTSS:
type: object
properties:
Expand Down
9 changes: 9 additions & 0 deletions docs/spec/crosschain/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,12 @@ message MsgWhitelistERC20 {
}
```

## MsgUpdateTssAddress

```proto
message MsgUpdateTssAddress {
string creator = 1;
string tss_pubkey = 2;
}
```

1 change: 1 addition & 0 deletions docs/spec/observer/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ message MsgAddObserver {
string creator = 1;
string observer_address = 2;
string zetaclient_grantee_pubkey = 3;
bool add_node_account_only = 4;
}
```

Expand Down
1 change: 1 addition & 0 deletions proto/crosschain/cross_chain_tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ message OutboundTxParams {
string outbound_tx_hash = 8;
string outbound_tx_ballot_index = 9;
uint64 outbound_tx_observed_external_height = 10;
string tss_pubkey = 11;
}

message Status {
Expand Down
1 change: 1 addition & 0 deletions proto/crosschain/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ message GenesisState {

repeated LastBlockHeight lastBlockHeightList = 8;
repeated InTxHashToCctx inTxHashToCctxList = 9 [(gogoproto.nullable) = false];
repeated TSS tss_history = 10 [(gogoproto.nullable) = false];
}
10 changes: 10 additions & 0 deletions proto/crosschain/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ service Query {
rpc LastZetaHeight(QueryLastZetaHeightRequest) returns (QueryLastZetaHeightResponse) {
option (google.api.http).get = "/zeta-chain/crosschain/lastZetaHeight";
}

rpc TssHistory(QueryTssHistoryRequest) returns (QueryTssHistoryResponse) {
option (google.api.http).get = "/zeta-chain/crosschain/tssHistory";
}
}

message QueryTssHistoryRequest {}

message QueryTssHistoryResponse {
repeated TSS tss_list = 1 [(gogoproto.nullable) = false];
}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand Down
7 changes: 7 additions & 0 deletions proto/crosschain/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ service Msg {
rpc VoteOnObservedOutboundTx(MsgVoteOnObservedOutboundTx) returns (MsgVoteOnObservedOutboundTxResponse);
rpc VoteOnObservedInboundTx(MsgVoteOnObservedInboundTx) returns (MsgVoteOnObservedInboundTxResponse);
rpc WhitelistERC20(MsgWhitelistERC20) returns (MsgWhitelistERC20Response);
rpc UpdateTssAddress(MsgUpdateTssAddress) returns (MsgUpdateTssAddressResponse);
}

message MsgUpdateTssAddress {
string creator = 1;
string tss_pubkey = 2;
}

message MsgUpdateTssAddressResponse {}
message MsgWhitelistERC20 {
string creator = 1;
string erc20_address = 2;
Expand Down
1 change: 1 addition & 0 deletions proto/observer/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ message MsgAddObserver {
string creator = 1;
string observer_address = 2;
string zetaclient_grantee_pubkey = 3;
bool add_node_account_only = 4;
}

message MsgAddObserverResponse {}
Expand Down
1 change: 1 addition & 0 deletions standalone-network/cctx/cctx-creator-goerili.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ zetacored tx crosschain create-tss-voter tsspubkey 5 0 --from=zeta --keyring-bac
zetacored tx crosschain gas-price-voter 1337 10000000000 100 100 --from=mario --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta
zetacored tx crosschain create-tss-voter tsspubkey 5 0 --from=mario --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta

exit 0
zetacored tx crosschain inbound-voter \
0x96B05C238b99768F349135de0653b687f9c13fEE \
1337 \
Expand Down
Loading

0 comments on commit 3046a78

Please sign in to comment.