Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace common package with pkg #1936

Merged
merged 49 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
685622d
Add address tests
skosito Mar 15, 2024
8fb2498
Add authz tx types tests
skosito Mar 15, 2024
3654bcf
Add bitcoin tests
skosito Mar 15, 2024
1e47e3b
Add chain id tests
skosito Mar 15, 2024
bc5849c
Add tss tests
skosito Mar 15, 2024
3554f4c
Add utils test
skosito Mar 15, 2024
eff53a5
Add gas limits tests
skosito Mar 15, 2024
4137f91
Add chains test
skosito Mar 15, 2024
9bf4e32
Add coin tests
skosito Mar 15, 2024
8f63009
Increase headers test coverage
skosito Mar 15, 2024
37f4c25
Increase eth proofs test coverage
skosito Mar 15, 2024
ff132dc
Add more chain tests
skosito Mar 15, 2024
3d258ff
Merge branch 'develop' into test-common-package
skosito Mar 18, 2024
2b2cbb1
Add more pubkey tests
skosito Mar 18, 2024
73856de
Add more chain tests
skosito Mar 18, 2024
0817b0d
Missing eth proof test
skosito Mar 18, 2024
a346f2b
Add more tests
skosito Mar 18, 2024
768beab
Fix test
skosito Mar 18, 2024
014f752
Fix test
skosito Mar 18, 2024
9899724
Add tests for common proof eth proofs
skosito Mar 18, 2024
cce926d
Add bitcoin proof test
skosito Mar 18, 2024
cff5322
Add more bitcoin proof tests
skosito Mar 18, 2024
9293b72
Add case for put key
skosito Mar 18, 2024
0e2189f
Add witness program chain tests
skosito Mar 18, 2024
26b22c8
Cleanup
skosito Mar 18, 2024
220cf27
Cleanup test data a bit
skosito Mar 18, 2024
95632b5
Merge branch 'develop' into test-common-package
skosito Mar 20, 2024
ec58766
Merge branch 'develop' into test-common-package
skosito Mar 21, 2024
238fbbc
Merge branch 'develop' into test-common-package
skosito Mar 21, 2024
18218af
Rename folder to pkg
skosito Mar 21, 2024
e40b992
Fix package in pkg
skosito Mar 21, 2024
2a672d9
Use pkg everywhere instead of common
skosito Mar 21, 2024
99de7e8
Use pkg
skosito Mar 21, 2024
8d32488
Rename common proto
skosito Mar 22, 2024
0155866
Merge branch 'test-common-package' into refactor-common-package-rename
skosito Mar 22, 2024
e481cd9
Fixes after merge
skosito Mar 22, 2024
ea20419
Move pkg proto to proto package
skosito Mar 22, 2024
f0776c8
Merge branch 'develop' into refactor-common-package-rename
skosito Mar 25, 2024
cf9fb0d
Reorganize protos and pkg subpackages
skosito Mar 25, 2024
5b51e10
Make generate
skosito Mar 25, 2024
a1c1d32
Changelog
skosito Mar 25, 2024
c248954
Fix tests
skosito Mar 25, 2024
42a234e
Merge branch 'develop' into refactor-common-package-rename
skosito Mar 26, 2024
dcb3b5a
Cleanup cosmos pkg
skosito Mar 26, 2024
9ba365f
Version fixes
skosito Mar 26, 2024
a409b74
PR comments
skosito Mar 26, 2024
f9683c7
Lint fix
skosito Mar 26, 2024
222adeb
PR comments
skosito Mar 26, 2024
fcc1383
Merge branch 'develop' into refactor-common-package-rename
skosito Mar 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* [1885](https://github.com/zeta-chain/node/pull/1885) - change important metrics on port 8123 to be prometheus compatible
* [1863](https://github.com/zeta-chain/node/pull/1863) - remove duplicate ValidateChainParams function
* [1914](https://github.com/zeta-chain/node/pull/1914) - move crosschain flags to core context in zetaclient
* [1936](https://github.com/zeta-chain/node/pull/1936) - refactor common package into subpackages and rename to pkg

### Features

Expand Down
27 changes: 14 additions & 13 deletions cmd/zetaclientd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

"github.com/ethereum/go-ethereum/ethclient"
"github.com/onrik/ethrpc"
"github.com/zeta-chain/zetacore/pkg/chains"
"github.com/zeta-chain/zetacore/pkg/coin"
"github.com/zeta-chain/zetacore/zetaclient/bitcoin"
corecontext "github.com/zeta-chain/zetacore/zetaclient/core_context"
"github.com/zeta-chain/zetacore/zetaclient/evm"
Expand All @@ -22,7 +24,6 @@ import (
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/testutil/sample"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
"github.com/zeta-chain/zetacore/zetaclient/config"
Expand Down Expand Up @@ -90,12 +91,12 @@ func DebugCmd() *cobra.Command {
return err
}

chain := common.GetChainFromChainID(chainID)
chain := chains.GetChainFromChainID(chainID)
if chain == nil {
return fmt.Errorf("invalid chain id")
}

if common.IsEVMChain(chain.ChainId) {
if chains.IsEVMChain(chain.ChainId) {

ob := evm.ChainClient{
Mu: &sync.Mutex{},
Expand All @@ -104,7 +105,7 @@ func DebugCmd() *cobra.Command {
ob.WithLogger(chainLogger)
var ethRPC *ethrpc.EthRPC
var client *ethclient.Client
coinType := common.CoinType_Cmd
coinType := coin.CoinType_Cmd
for chain, evmConfig := range cfg.GetAllEVMConfigs() {
if chainID == chain {
ethRPC = ethrpc.NewEthRPC(evmConfig.Endpoint)
Expand All @@ -114,7 +115,7 @@ func DebugCmd() *cobra.Command {
}
ob.WithEvmClient(client)
ob.WithEvmJSONRPC(ethRPC)
ob.WithChain(*common.GetChainFromChainID(chainID))
ob.WithChain(*chains.GetChainFromChainID(chainID))
}
}
hash := ethcommon.HexToHash(txHash)
Expand Down Expand Up @@ -144,29 +145,29 @@ func DebugCmd() *cobra.Command {
}
evmChainParams.ZetaTokenContractAddress = chainParams.ZetaTokenContractAddress
if strings.EqualFold(tx.To, chainParams.ConnectorContractAddress) {
coinType = common.CoinType_Zeta
coinType = coin.CoinType_Zeta
} else if strings.EqualFold(tx.To, chainParams.Erc20CustodyContractAddress) {
coinType = common.CoinType_ERC20
coinType = coin.CoinType_ERC20
} else if strings.EqualFold(tx.To, tssEthAddress) {
coinType = common.CoinType_Gas
coinType = coin.CoinType_Gas
}
}
}

switch coinType {
case common.CoinType_Zeta:
case coin.CoinType_Zeta:
ballotIdentifier, err = ob.CheckAndVoteInboundTokenZeta(tx, receipt, false)
if err != nil {
return err
}

case common.CoinType_ERC20:
case coin.CoinType_ERC20:
ballotIdentifier, err = ob.CheckAndVoteInboundTokenERC20(tx, receipt, false)
if err != nil {
return err
}

case common.CoinType_Gas:
case coin.CoinType_Gas:
ballotIdentifier, err = ob.CheckAndVoteInboundTokenGas(tx, receipt, false)
if err != nil {
return err
Expand All @@ -175,13 +176,13 @@ func DebugCmd() *cobra.Command {
fmt.Println("CoinType not detected")
}
fmt.Println("CoinType : ", coinType)
} else if common.IsBitcoinChain(chain.ChainId) {
} else if chains.IsBitcoinChain(chain.ChainId) {
obBtc := bitcoin.BTCChainClient{
Mu: &sync.Mutex{},
}
obBtc.WithZetaClient(bridge)
obBtc.WithLogger(chainLogger)
obBtc.WithChain(*common.GetChainFromChainID(chainID))
obBtc.WithChain(*chains.GetChainFromChainID(chainID))
connCfg := &rpcclient.ConnConfig{
Host: cfg.BitcoinConfig.RPCHost,
User: cfg.BitcoinConfig.RPCUsername,
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetaclientd/hsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra"
keystone "github.com/zeta-chain/keystone/keys"
"github.com/zeta-chain/zetacore/cmd"
"github.com/zeta-chain/zetacore/common/cosmos"
"github.com/zeta-chain/zetacore/pkg/cosmos"
"github.com/zeta-chain/zetacore/zetaclient/hsm"
)

Expand Down
8 changes: 4 additions & 4 deletions cmd/zetaclientd/keygen_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
tsscommon "github.com/zeta-chain/go-tss/common"
"github.com/zeta-chain/go-tss/keygen"
"github.com/zeta-chain/go-tss/p2p"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/pkg/chains"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
"github.com/zeta-chain/zetacore/zetaclient/metrics"
)
Expand All @@ -37,7 +37,7 @@ func GenerateTss(
// Bitcoin chain ID is currently used for using the correct signature format
// TODO: remove this once we have a better way to determine the signature format
// https://github.com/zeta-chain/node/issues/1397
bitcoinChainID := common.BtcRegtestChain().ChainId
bitcoinChainID := chains.BtcRegtestChain().ChainId
btcChain, _, btcEnabled := appContext.GetBTCChainAndConfig()
if btcEnabled {
bitcoinChainID = btcChain.ChainId
Expand Down Expand Up @@ -109,7 +109,7 @@ func GenerateTss(
err = keygenTss(keyGen, tss, keygenLogger)
if err != nil {
keygenLogger.Error().Err(err).Msg("keygenTss error")
tssFailedVoteHash, err := zetaBridge.SetTSS("", keyGen.BlockNumber, common.ReceiveStatus_Failed)
tssFailedVoteHash, err := zetaBridge.SetTSS("", keyGen.BlockNumber, chains.ReceiveStatus_Failed)
if err != nil {
keygenLogger.Error().Err(err).Msg("Failed to broadcast Failed TSS Vote to zetacore")
return nil, err
Expand All @@ -127,7 +127,7 @@ func GenerateTss(
}

// If TSS is successful , broadcast the vote to zetacore and set Pubkey
tssSuccessVoteHash, err := zetaBridge.SetTSS(newTss.CurrentPubkey, keyGen.BlockNumber, common.ReceiveStatus_Success)
tssSuccessVoteHash, err := zetaBridge.SetTSS(newTss.CurrentPubkey, keyGen.BlockNumber, chains.ReceiveStatus_Success)
if err != nil {
keygenLogger.Error().Err(err).Msg("TSS successful but unable to broadcast vote to zeta-core")
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetaclientd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/zeta-chain/zetacore/zetaclient/config"

"github.com/zeta-chain/zetacore/cmd"
"github.com/zeta-chain/zetacore/common/cosmos"
"github.com/zeta-chain/zetacore/pkg/cosmos"

//mcconfig "github.com/Meta-Protocol/zetacore/metaclient/config"
"github.com/cosmos/cosmos-sdk/types"
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetaclientd/p2p_diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/rs/zerolog"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/zeta-chain/go-tss/p2p"
"github.com/zeta-chain/zetacore/common/cosmos"
"github.com/zeta-chain/zetacore/pkg/cosmos"
"github.com/zeta-chain/zetacore/zetaclient/config"
)

Expand Down
7 changes: 4 additions & 3 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/zeta-chain/go-tss/p2p"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/pkg"
"github.com/zeta-chain/zetacore/pkg/authz"
observerTypes "github.com/zeta-chain/zetacore/x/observer/types"
mc "github.com/zeta-chain/zetacore/zetaclient"
appcontext "github.com/zeta-chain/zetacore/zetaclient/app_context"
Expand Down Expand Up @@ -99,7 +100,7 @@ func start(_ *cobra.Command, _ []string) error {
}
zetaBridge.WaitForCoreToCreateBlocks()
startLogger.Info().Msgf("ZetaBridge is ready")
zetaBridge.SetAccountNumber(common.ZetaClientGranteeKey)
zetaBridge.SetAccountNumber(authz.ZetaClientGranteeKey)

// cross-check chainid
res, err := zetaBridge.GetNodeInfo()
Expand Down Expand Up @@ -169,7 +170,7 @@ func start(_ *cobra.Command, _ []string) error {
}
m.Start()

metrics.Info.WithLabelValues(common.Version).Set(1)
metrics.Info.WithLabelValues(pkg.Version).Set(1)
metrics.LastStartTime.SetToCurrentTime()

var tssHistoricalList []observerTypes.TSS
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetaclientd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
sdk "github.com/cosmos/cosmos-sdk/types"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/zeta-chain/zetacore/common/cosmos"
"github.com/zeta-chain/zetacore/pkg/cosmos"
appcontext "github.com/zeta-chain/zetacore/zetaclient/app_context"
"github.com/zeta-chain/zetacore/zetaclient/authz"
"github.com/zeta-chain/zetacore/zetaclient/bitcoin"
Expand Down
4 changes: 2 additions & 2 deletions cmd/zetaclientd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/pkg"
)

var VersionCmd = &cobra.Command{
Expand All @@ -14,6 +14,6 @@ var VersionCmd = &cobra.Command{
}

func Version(_ *cobra.Command, _ []string) error {
fmt.Printf(common.Version)
fmt.Printf(pkg.Version)
return nil
}
10 changes: 5 additions & 5 deletions cmd/zetacored/get_pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto"
"github.com/spf13/cobra"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/common/cosmos"
"github.com/zeta-chain/zetacore/pkg/cosmos"
zetacrypto "github.com/zeta-chain/zetacore/pkg/crypto"
)

func GetPubKeyCmd() *cobra.Command {
Expand All @@ -33,8 +33,8 @@ func GetPubKeyCmd() *cobra.Command {
return cmd
}

func GetPubKeySet(clientctx client.Context, tssAccountName, password string) (common.PubKeySet, error) {
pubkeySet := common.PubKeySet{
func GetPubKeySet(clientctx client.Context, tssAccountName, password string) (zetacrypto.PubKeySet, error) {
pubkeySet := zetacrypto.PubKeySet{
Secp256k1: "",
Ed25519: "",
}
Expand All @@ -52,7 +52,7 @@ func GetPubKeySet(clientctx client.Context, tssAccountName, password string) (co
if err != nil {
return pubkeySet, err
}
pubkey, err := common.NewPubKey(s)
pubkey, err := zetacrypto.NewPubKey(s)
if err != nil {
return pubkeySet, err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/zetacored/observer_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/spf13/cobra"
"github.com/zeta-chain/zetacore/app"
"github.com/zeta-chain/zetacore/cmd/zetacored/config"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/pkg/crypto"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
"github.com/zeta-chain/zetacore/x/observer/types"
)
Expand Down Expand Up @@ -115,11 +115,11 @@ func AddObserverAccountsCmd() *cobra.Command {

observerSet.ObserverList = append(observerSet.ObserverList, info.ObserverAddress)
if info.ZetaClientGranteePubKey != "" {
pubkey, err := common.NewPubKey(info.ZetaClientGranteePubKey)
pubkey, err := crypto.NewPubKey(info.ZetaClientGranteePubKey)
if err != nil {
panic(err)
}
pubkeySet := common.PubKeySet{
pubkeySet := crypto.PubKeySet{
Secp256k1: pubkey,
Ed25519: "",
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/zetatool/filterdeposit/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/spf13/cobra"
"github.com/zeta-chain/zetacore/cmd/zetatool/config"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/pkg"
)

func NewBtcCmd() *cobra.Command {
Expand Down Expand Up @@ -162,7 +162,7 @@ func getHashList(cfg *config.Config, tssAddress string) ([]Deposit, error) {
if err != nil {
continue
}
if bytes.Equal(memoBytes, []byte(common.DonationMessage)) {
if bytes.Equal(memoBytes, []byte(pkg.DonationMessage)) {
continue
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions cmd/zetatool/filterdeposit/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/erc20custody.sol"
"github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zetaconnector.non-eth.sol"
"github.com/zeta-chain/zetacore/cmd/zetatool/config"
zetacommon "github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/pkg"
)

const (
Expand Down Expand Up @@ -202,7 +202,7 @@ func getTSSDeposits(tssAddress string, startBlock uint64, endBlock uint64, apiKe

for _, tx := range txns {
if tx.To == tssAddress {
if strings.Compare(tx.Input, zetacommon.DonationMessage) == 0 {
if strings.Compare(tx.Input, pkg.DonationMessage) == 0 {
continue // skip donation tx
}
if tx.TxReceiptStatus != "1" {
Expand Down
Loading
Loading