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: add chain static info to chain struct #2071

Merged
merged 19 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
6 changes: 2 additions & 4 deletions app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
authoritytypes "github.com/zeta-chain/zetacore/x/authority/types"
lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

const releaseVersion = "v15"
const releaseVersion = "v16"

func SetupHandlers(app *App) {
app.UpgradeKeeper.SetUpgradeHandler(releaseVersion, func(ctx sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) {
Expand All @@ -30,7 +28,7 @@ func SetupHandlers(app *App) {
}
if upgradeInfo.Name == releaseVersion && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{authoritytypes.ModuleName, lightclienttypes.ModuleName},
Added: []string{},
}
// Use upgrade store loader for the initial loading of all stores when app starts,
// it checks if version == upgradeHeight and applies store upgrades before loading the stores,
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* [1989](https://github.com/zeta-chain/node/pull/1989) - simplify `IsSendOutTxProcessed` method and add unit tests
* [2013](https://github.com/zeta-chain/node/pull/2013) - rename `GasPriceVoter` message to `VoteGasPrice`
* [2059](https://github.com/zeta-chain/node/pull/2059) - Remove unused params from all functions in zetanode
* [2071](https://github.com/zeta-chain/node/pull/2071) - Modify chains struct to add all chain related information

### Features

Expand Down
47 changes: 47 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53592,6 +53592,18 @@ definitions:
chain_id:
type: string
format: int64
network:
$ref: '#/definitions/chainsNetwork'
network_type:
$ref: '#/definitions/chainsNetworkType'
vm:
$ref: '#/definitions/chainsVm'
consensus:
$ref: '#/definitions/chainsConsensus'
is_external:
type: boolean
is_header_supported:
type: boolean
chainsChainName:
type: string
enum:
Expand All @@ -53613,6 +53625,34 @@ definitions:
- btc_regtest
- amoy_testnet
default: empty
title: ChainName represents the name of the chain
chainsConsensus:
type: string
enum:
- Ethereum
- Tendermint
- Bitcoin
default: Ethereum
title: Consensus represents the consensus algorithm used by the chain
chainsNetwork:
type: string
enum:
- ETH
- ZETA
- BTC
- POLYGON
- BSC
default: ETH
title: Network represents the network type of the chain
chainsNetworkType:
type: string
enum:
- MAINNET
- TESTNET
- PRIVNET
- DEVNET
default: MAINNET
title: NetworkType represents the network type of the chain
chainsReceiveStatus:
type: string
enum:
Expand All @@ -53621,6 +53661,13 @@ definitions:
- Failed
default: Created
title: '- Created: some observer sees inbound tx'
chainsVm:
type: string
enum:
- NO_VM
- EVM
default: NO_VM
title: Vm represents the virtual machine type of the chain to support smart contracts
coinCoinType:
type: string
enum:
Expand Down
64 changes: 19 additions & 45 deletions pkg/chains/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ func (chain Chain) IsEqual(c Chain) bool {
}

func (chain Chain) IsZetaChain() bool {
return chain.InChainList(ZetaChainList())
return chain.Network == Network_ZETA
}
func (chain Chain) IsExternalChain() bool {
return !chain.InChainList(ZetaChainList())
return chain.IsExternal
}

// EncodeAddress bytes representations of address
Expand Down Expand Up @@ -81,62 +81,36 @@ func DecodeAddressFromChainID(chainID int64, addr string) ([]byte, error) {
return nil, fmt.Errorf("chain (%d) not supported", chainID)
}

func IsZetaChain(chainID int64) bool {
return ChainIDInChainList(chainID, ZetaChainList())
// IsEVMChain returns true if the chain is an EVM chain or uses the ethereum consensus mechanism for block finality
func IsEVMChain(chainID int64) bool {
return ChainIDInChainList(chainID, ChainListByConsensus(Consensus_Ethereum))
}

// IsEVMChain returns true if the chain is an EVM chain
// TODO: put this information directly in chain object
// https://github.com/zeta-chain/node-private/issues/63
func IsEVMChain(chainID int64) bool {
return chainID == 5 || // Goerli
chainID == AmoyChain().ChainId ||
chainID == SepoliaChain().ChainId || // Sepolia
chainID == 80001 || // Polygon mumbai
chainID == 97 || // BSC testnet
chainID == 1001 || // klaytn baobab
chainID == 1337 || // eth privnet
chainID == 1 || // eth mainnet
chainID == 56 || // bsc mainnet
chainID == 137 // polygon mainnet
// IsBitcoinChain returns true if the chain is a Bitcoin-based chain or uses the bitcoin consensus mechanism for block finality
func IsBitcoinChain(chainID int64) bool {
return ChainIDInChainList(chainID, ChainListByConsensus(Consensus_Bitcoin))
}

// IsEthereumChain returns true if the chain is an Ethereum chain
func IsEthereumChain(chainID int64) bool {
return ChainIDInChainList(chainID, ChainListByNetwork(Network_ETH))
}

// IsZetaChain returns true if the chain is a Zeta chain
func IsZetaChain(chainID int64) bool {
return ChainIDInChainList(chainID, ChainListByNetwork(Network_ZETA))
}

// IsHeaderSupportedEvmChain returns true if the chain is an EVM chain supporting block header-based verification
// TODO: put this information directly in chain object
// https://github.com/zeta-chain/node-private/issues/63
func IsHeaderSupportedEvmChain(chainID int64) bool {
return chainID == 5 || // Goerli
chainID == SepoliaChain().ChainId || // Sepolia
chainID == 97 || // BSC testnet
chainID == 1337 || // eth privnet
chainID == 1 || // eth mainnet
chainID == 56 // bsc mainnet
return ChainIDInChainList(chainID, ChainListForHeaderSupport())
}

// SupportMerkleProof returns true if the chain supports block header-based verification
func (chain Chain) SupportMerkleProof() bool {
return IsEVMChain(chain.ChainId) || IsBitcoinChain(chain.ChainId)
}

// IsBitcoinChain returns true if the chain is a Bitcoin chain
// TODO: put this information directly in chain object
// https://github.com/zeta-chain/node-private/issues/63
func IsBitcoinChain(chainID int64) bool {
return chainID == 18444 || // regtest
chainID == 18332 || //testnet
chainID == 8332 // mainnet
}

// IsEthereumChain returns true if the chain is an Ethereum chain
// TODO: put this information directly in chain object
// https://github.com/zeta-chain/node-private/issues/63
func IsEthereumChain(chainID int64) bool {
return chainID == 1 || // eth mainnet
chainID == 5 || // Goerli
chainID == SepoliaChain().ChainId || // Sepolia
chainID == 1337 // eth privnet
}

// IsEmpty is to determinate whether the chain is empty
func (chain Chain) IsEmpty() bool {
return strings.TrimSpace(chain.String()) == ""
Expand Down
14 changes: 7 additions & 7 deletions pkg/chains/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ func TestChain_DecodeAddress(t *testing.T) {
}

func TestChain_InChainList(t *testing.T) {
require.True(t, ZetaChainMainnet().InChainList(ZetaChainList()))
require.True(t, ZetaMocknetChain().InChainList(ZetaChainList()))
require.True(t, ZetaPrivnetChain().InChainList(ZetaChainList()))
require.True(t, ZetaTestnetChain().InChainList(ZetaChainList()))
require.False(t, EthChain().InChainList(ZetaChainList()))
require.True(t, ZetaChainMainnet().InChainList(ChainListByNetwork(Network_ZETA)))
require.True(t, ZetaMocknetChain().InChainList(ChainListByNetwork(Network_ZETA)))
require.True(t, ZetaPrivnetChain().InChainList(ChainListByNetwork(Network_ZETA)))
require.True(t, ZetaTestnetChain().InChainList(ChainListByNetwork(Network_ZETA)))
require.False(t, EthChain().InChainList(ChainListByNetwork(Network_ZETA)))
}

func TestIsZetaChain(t *testing.T) {
Expand Down Expand Up @@ -376,6 +376,6 @@ func TestGetBTCChainIDFromChainParams(t *testing.T) {
}

func TestChainIDInChainList(t *testing.T) {
require.True(t, ChainIDInChainList(ZetaChainMainnet().ChainId, ZetaChainList()))
require.False(t, ChainIDInChainList(EthChain().ChainId, ZetaChainList()))
require.True(t, ChainIDInChainList(ZetaChainMainnet().ChainId, ChainListByNetwork(Network_ZETA)))
require.False(t, ChainIDInChainList(EthChain().ChainId, ChainListByNetwork(Network_ZETA)))
}
Loading
Loading