Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Jul 2, 2024
1 parent c09b769 commit d066959
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 60 deletions.
12 changes: 0 additions & 12 deletions pkg/chains/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,6 @@ func IsZetaChain(chainID int64, additionalChains []Chain) bool {
return ChainIDInChainList(chainID, ChainListByNetwork(Network_zeta, additionalChains))
}

// IsHeaderSupportedChain returns true if the chain's consensus supports block header-based verification
// additionalChains is a list of additional chains to search from
// in practice, it is used in the protocol to dynamically support new chains without doing an upgrade
func IsHeaderSupportedChain(chainID int64, additionalChains []Chain) bool {
return ChainIDInChainList(chainID, ChainListForHeaderSupport(additionalChains))
}

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

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

func TestIsHeaderSupportedChain(t *testing.T) {
tests := []struct {
name string
chainID int64
want bool
}{
{"Ethereum Mainnet", chains.Ethereum.ChainId, true},
{"Goerli Testnet", chains.Goerli.ChainId, true},
{"Goerli Localnet", chains.GoerliLocalnet.ChainId, true},
{"Sepolia Testnet", chains.Sepolia.ChainId, true},
{"BSC Testnet", chains.BscTestnet.ChainId, true},
{"BSC Mainnet", chains.BscMainnet.ChainId, true},
{"BTC", chains.BitcoinMainnet.ChainId, true},
{"Zeta Mainnet", chains.ZetaChainMainnet.ChainId, false},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.want, chains.IsHeaderSupportedChain(tt.chainID, []chains.Chain{}))
})
}
}

func TestSupportMerkleProof(t *testing.T) {
tests := []struct {
name string
chain chains.Chain
want bool
}{
{"Ethereum Mainnet", chains.Ethereum, true},
{"BSC Testnet", chains.BscTestnet, true},
{"BSC Mainnet", chains.BscMainnet, true},
{"Non-EVM", chains.BitcoinMainnet, true},
{"Zeta Mainnet", chains.ZetaChainMainnet, false},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.want, tt.chain.SupportMerkleProof([]chains.Chain{}))
})
}
}

func TestIsBitcoinChain(t *testing.T) {
tests := []struct {
name string
Expand Down
4 changes: 1 addition & 3 deletions pkg/chains/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,11 @@ func CombineDefaultChainsList(chains []Chain) []Chain {

// CombineChainList combines a list of chains with a list of chains
// duplicated chain ID are overwritten by the second list
// TODO: remove pointers
// https://github.com/zeta-chain/node/issues/2080
func CombineChainList(base []Chain, additional []Chain) []Chain {
combined := make([]Chain, 0, len(base)+len(additional))
combined = append(combined, base...)

// map chain ID in chains1 to index in the list
// map chain ID in combined to index in the list
chainIDIndexMap := make(map[int64]int)
for i, chain := range combined {
chainIDIndexMap[chain.ChainId] = i
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/types/message_add_inbound_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (msg *MsgAddInboundTracker) ValidateBasic() error {

_, ok := coin.CoinType_value[msg.CoinType.String()]
if !ok {
return errorsmod.Wrapf(ErrProofVerificationFail, "coin-type not supported")
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "coin-type not supported")
}
return nil
}
2 changes: 1 addition & 1 deletion x/crosschain/types/message_add_inbound_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestMsgAddInboundTracker_ValidateBasic(t *testing.T) {
ChainId: chains.ZetaChainTestnet.ChainId,
CoinType: 5,
},
err: errorsmod.Wrapf(types.ErrProofVerificationFail, "coin-type not supported"),
err: errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "coin-type not supported"),
},
{
name: "valid",
Expand Down
4 changes: 4 additions & 0 deletions x/observer/types/chain_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func ValidateChainParams(params *ChainParams) error {
if params == nil {
return fmt.Errorf("chain params cannot be nil")
}

// TODO: ZetaChain chain params should be completely removed
// Once removed, this check is no longer necessary as all chasin params would need the same checks
// https://github.com/zeta-chain/node/issues/2419
_, err := chains.ZetaChainFromChainID(params.ChainId)
if err == nil {
// zeta chain skips the rest of the checks for now
Expand Down

0 comments on commit d066959

Please sign in to comment.