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(pkg/chains): deprecate ChainName field in Chain object #2541

Merged
merged 11 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
* [2428](https://github.com/zeta-chain/node/pull/2428) - propagate context across codebase & refactor zetacore client
* [2464](https://github.com/zeta-chain/node/pull/2464) - move common voting logic to voting.go and add new function VoteOnBallot
* [2515](https://github.com/zeta-chain/node/pull/2515) - replace chainName by chainID for ChainNonces indexing
* [2541](https://github.com/zeta-chain/node/pull/2541) - deprecate ChainName field in Chain object

### Tests

Expand Down
11 changes: 9 additions & 2 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56946,7 +56946,9 @@ definitions:
title: ChainId is the unique identifier of the chain
chain_name:
$ref: '#/definitions/chainsChainName'
title: ChainName is the name of the chain
title: |-
ChainName is the name of the chain
Deprecated(v19): replaced with Name
network:
$ref: '#/definitions/chainsNetwork'
title: Network is the network of the chain
Expand All @@ -56965,6 +56967,9 @@ definitions:
cctx_gateway:
$ref: '#/definitions/chainsCCTXGateway'
title: CCTXGateway is the gateway used to handle CCTX outbounds
name:
type: string
title: Name is the name of the chain
title: |-
Chain represents static data about a blockchain network
it is identified by a unique chain ID
Expand Down Expand Up @@ -56994,7 +56999,9 @@ definitions:
- solana_devnet
- solana_localnet
default: empty
title: ChainName represents the name of the chain
title: |-
ChainName represents the name of the chain
Deprecated(v19): replaced with Chain.Name as string
chainsConsensus:
type: string
enum:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# V17 Breaking Changes
# V19 Breaking Changes

### Verification Flags update

Expand Down Expand Up @@ -62,3 +62,7 @@
### `MsgAddBlameVote` renaming

* `MsgAddBlameVote` has been renamed to `MsgVoteBlame` to maintain consistency with other voting messages

### `Chain.ChainName` deprecated

* `Chain.ChainName` has been deprecated and will be removed from the `Chain` structure. The `Chain.Name` should be used instead.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# V17 Observer Migration Guide
# V19 Observer Migration Guide

## Authorizations Update

Expand Down
9 changes: 5 additions & 4 deletions pkg/chains/chain.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package chains

import (
"errors"
"fmt"
"strings"

Expand All @@ -15,10 +16,6 @@ func (chain Chain) Validate() error {
return fmt.Errorf("chain ID must be positive")
}

if _, ok := ChainName_name[int32(chain.ChainName)]; !ok {
return fmt.Errorf("invalid chain name %d", int32(chain.ChainName))
}

if _, ok := Network_name[int32(chain.Network)]; !ok {
return fmt.Errorf("invalid network %d", int32(chain.Network))
}
Expand All @@ -35,6 +32,10 @@ func (chain Chain) Validate() error {
return fmt.Errorf("invalid consensus %d", int32(chain.Consensus))
}

if chain.Name == "" {
return errors.New("chain name cannot be empty")
}

return nil
}

Expand Down
23 changes: 11 additions & 12 deletions pkg/chains/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestChain_Validate(t *testing.T) {
name: "should pass if chain is valid",
chain: chains.Chain{
ChainId: 42,
ChainName: chains.ChainName_empty,
Name: "foo",
Network: chains.Network_optimism,
NetworkType: chains.NetworkType_testnet,
Vm: chains.Vm_evm,
Expand All @@ -33,7 +33,7 @@ func TestChain_Validate(t *testing.T) {
name: "should error if chain ID is zero",
chain: chains.Chain{
ChainId: 0,
ChainName: chains.ChainName_empty,
Name: "foo",
Network: chains.Network_optimism,
NetworkType: chains.NetworkType_testnet,
Vm: chains.Vm_evm,
Expand All @@ -46,7 +46,7 @@ func TestChain_Validate(t *testing.T) {
name: "should error if chain ID is negative",
chain: chains.Chain{
ChainId: 0,
ChainName: chains.ChainName_empty,
Name: "foo",
Network: chains.Network_optimism,
NetworkType: chains.NetworkType_testnet,
Vm: chains.Vm_evm,
Expand All @@ -56,23 +56,23 @@ func TestChain_Validate(t *testing.T) {
errStr: "chain ID must be positive",
},
{
name: "should error if chain name invalid",
name: "should error if chain name empty",
chain: chains.Chain{
ChainId: 42,
ChainName: chains.ChainName_solana_localnet + 1,
Name: "",
Network: chains.Network_optimism,
NetworkType: chains.NetworkType_testnet,
Vm: chains.Vm_evm,
Consensus: chains.Consensus_op_stack,
IsExternal: true,
},
errStr: "invalid chain name",
errStr: "chain name cannot be empty",
},
{
name: "should error if network invalid",
chain: chains.Chain{
ChainId: 42,
ChainName: chains.ChainName_empty,
Name: "foo",
Network: chains.Network_solana + 1,
NetworkType: chains.NetworkType_testnet,
Vm: chains.Vm_evm,
Expand All @@ -85,7 +85,7 @@ func TestChain_Validate(t *testing.T) {
name: "should error if network type invalid",
chain: chains.Chain{
ChainId: 42,
ChainName: chains.ChainName_empty,
Name: "foo",
Network: chains.Network_base,
NetworkType: chains.NetworkType_devnet + 1,
Vm: chains.Vm_evm,
Expand All @@ -98,7 +98,7 @@ func TestChain_Validate(t *testing.T) {
name: "should error if vm invalid",
chain: chains.Chain{
ChainId: 42,
ChainName: chains.ChainName_empty,
Name: "foo",
Network: chains.Network_base,
NetworkType: chains.NetworkType_devnet,
Vm: chains.Vm_svm + 1,
Expand All @@ -111,7 +111,7 @@ func TestChain_Validate(t *testing.T) {
name: "should error if consensus invalid",
chain: chains.Chain{
ChainId: 42,
ChainName: chains.ChainName_empty,
Name: "foo",
Network: chains.Network_base,
NetworkType: chains.NetworkType_devnet,
Vm: chains.Vm_evm,
Expand Down Expand Up @@ -191,8 +191,7 @@ func TestChain_EncodeAddress(t *testing.T) {
{
name: "should error if chain not supported",
chain: chains.Chain{
ChainName: 999,
ChainId: 999,
ChainId: 999,
},
b: ethcommon.Hex2Bytes("0x321"),
want: "",
Expand Down
23 changes: 23 additions & 0 deletions pkg/chains/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (
Consensus: Consensus_tendermint,
IsExternal: false,
CctxGateway: CCTXGateway_zevm,
Name: "zeta_mainnet",
}

// Ethereum is Ethereum mainnet
Expand All @@ -29,6 +30,7 @@ var (
Consensus: Consensus_ethereum,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "eth_mainnet",
}

// BscMainnet is Binance Smart Chain mainnet
Expand All @@ -41,6 +43,7 @@ var (
Consensus: Consensus_ethereum,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "bsc_mainnet",
}

// BitcoinMainnet is Bitcoin mainnet
Expand All @@ -53,6 +56,7 @@ var (
Consensus: Consensus_bitcoin,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "btc_mainnet",
}

// Polygon is Polygon mainnet
Expand All @@ -65,6 +69,7 @@ var (
Consensus: Consensus_ethereum,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "polygon_mainnet",
}

// OptimismMainnet is Optimism mainnet
Expand All @@ -77,6 +82,7 @@ var (
Consensus: Consensus_op_stack,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "optimism_mainnet",
}

// BaseMainnet is Base mainnet
Expand All @@ -89,6 +95,7 @@ var (
Consensus: Consensus_op_stack,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "base_mainnet",
}

// SolanaMainnet is Solana mainnet
Expand All @@ -103,6 +110,7 @@ var (
Consensus: Consensus_solana_consensus,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "solana_mainnet",
}

/**
Expand All @@ -119,6 +127,7 @@ var (
Consensus: Consensus_tendermint,
IsExternal: false,
CctxGateway: CCTXGateway_zevm,
Name: "zeta_testnet",
}

// Sepolia is Ethereum sepolia testnet
Expand All @@ -131,6 +140,7 @@ var (
Consensus: Consensus_ethereum,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "sepolia_testnet",
}

// BscTestnet is Binance Smart Chain testnet
Expand All @@ -143,6 +153,7 @@ var (
Consensus: Consensus_ethereum,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "bsc_testnet",
}

// BitcoinTestnet is Bitcoin testnet3
Expand All @@ -155,6 +166,7 @@ var (
Consensus: Consensus_bitcoin,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "btc_testnet",
}

// Amoy is Polygon amoy testnet
Expand All @@ -167,6 +179,7 @@ var (
Consensus: Consensus_ethereum,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "amoy_testnet",
}

// OptimismSepolia is Optimism sepolia testnet
Expand All @@ -179,6 +192,7 @@ var (
Consensus: Consensus_op_stack,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "optimism_sepolia",
}

// BaseSepolia is Base sepolia testnet
Expand All @@ -191,6 +205,7 @@ var (
Consensus: Consensus_op_stack,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "base_sepolia",
}

// SolanaDevnet is Solana devnet
Expand All @@ -207,6 +222,7 @@ var (
Consensus: Consensus_solana_consensus,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "solana_devnet",
}

/**
Expand All @@ -224,6 +240,7 @@ var (
Consensus: Consensus_tendermint,
IsExternal: false,
CctxGateway: CCTXGateway_zevm,
Name: "zeta_mainnet",
}

/**
Expand All @@ -240,6 +257,7 @@ var (
Consensus: Consensus_tendermint,
IsExternal: false,
CctxGateway: CCTXGateway_zevm,
Name: "zeta_mainnet",
}

// BitcoinRegtest is Bitcoin regtest (localnet)
Expand All @@ -252,6 +270,7 @@ var (
Consensus: Consensus_bitcoin,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "btc_regtest",
}

// GoerliLocalnet is Ethereum local goerli (localnet)
Expand All @@ -264,6 +283,7 @@ var (
Consensus: Consensus_ethereum,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "goerli_localnet",
}

// SolanaLocalnet is Solana localnet
Expand All @@ -278,6 +298,7 @@ var (
Consensus: Consensus_solana_consensus,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "solana_localnet",
}

/**
Expand All @@ -294,6 +315,7 @@ var (
Consensus: Consensus_ethereum,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "goerli_testnet",
}

// Mumbai is Polygon mumbai testnet (deprecated for amoy)
Expand All @@ -306,6 +328,7 @@ var (
Consensus: Consensus_ethereum,
IsExternal: true,
CctxGateway: CCTXGateway_observers,
Name: "mumbai_testnet",
}
)

Expand Down
Loading
Loading