Skip to content

Commit

Permalink
fix merge error
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Jul 2, 2024
1 parent ab4ccf4 commit c09b769
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 309 deletions.
16 changes: 8 additions & 8 deletions cmd/zetaclientd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,28 @@ func debugCmd(_ *cobra.Command, args []string) error {
if err != nil {
return err
}
chain := chains.GetChainFromChainID(chainID, appContext)
if chain == nil {
chain, found := chains.GetChainFromChainID(chainID, appContext.GetAdditionalChains())
if !found {
return fmt.Errorf("invalid chain id")
}

// get ballot identifier according to the chain type
if chains.IsEVMChain(chain.ChainId) {
if chains.IsEVMChain(chain.ChainId, appContext.GetAdditionalChains()) {
evmObserver := evmobserver.Observer{}
evmObserver.WithZetacoreClient(client)
var ethRPC *ethrpc.EthRPC
var client *ethclient.Client
coinType := coin.CoinType_Cmd
for chain, evmConfig := range cfg.GetAllEVMConfigs() {
if chainID == chain {
for chainIDFromConfig, evmConfig := range cfg.GetAllEVMConfigs() {
if chainIDFromConfig == chainID {
ethRPC = ethrpc.NewEthRPC(evmConfig.Endpoint)
client, err = ethclient.Dial(evmConfig.Endpoint)
if err != nil {
return err
}
evmObserver.WithEvmClient(client)
evmObserver.WithEvmJSONRPC(ethRPC)
evmObserver.WithChain(*chains.GetChainFromChainID(chainID))
evmObserver.WithChain(chain)
}
}
hash := ethcommon.HexToHash(inboundHash)
Expand Down Expand Up @@ -168,10 +168,10 @@ func debugCmd(_ *cobra.Command, args []string) error {
fmt.Println("CoinType not detected")
}
fmt.Println("CoinType : ", coinType)
} else if chains.IsBitcoinChain(chain.ChainId) {
} else if chains.IsBitcoinChain(chain.ChainId, appContext.GetAdditionalChains()) {
btcObserver := btcobserver.Observer{}
btcObserver.WithZetacoreClient(client)
btcObserver.WithChain(*chains.GetChainFromChainID(chainID))
btcObserver.WithChain(chain)
connCfg := &rpcclient.ConnConfig{
Host: cfg.BitcoinConfig.RPCHost,
User: cfg.BitcoinConfig.RPCUsername,
Expand Down
4 changes: 2 additions & 2 deletions zetaclient/chains/base/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ type Signer struct {
// NewSigner creates a new base signer
func NewSigner(
chain chains.Chain,
zetacoreContext *context.AppContext,
appContext *context.AppContext,
tss interfaces.TSSSigner,
ts *metrics.TelemetryServer,
logger Logger,
) *Signer {
return &Signer{
chain: chain,
appContext: zetacoreContext,
appContext: appContext,
tss: tss,
ts: ts,
logger: Logger{
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/chains/evm/observer/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ func (ob *Observer) BuildInboundVoteMsgForZetaSentEvent(
) *types.MsgVoteInbound {
destChain, found := chains.GetChainFromChainID(
event.DestinationChainId.Int64(),
ob.ZetacoreContext().GetAdditionalChains(),
ob.AppContext().GetAdditionalChains(),
)
if !found {
ob.Logger().Inbound.Warn().Msgf("chain id not supported %d", event.DestinationChainId.Int64())
Expand Down
4 changes: 2 additions & 2 deletions zetaclient/chains/evm/signer/outbound_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (txData *OutboundData) SetupGas(
// cctx will be skipped and false otherwise.
// 3. error
func NewOutboundData(
coreContext *clientcontext.ZetacoreContext,
appontext *clientcontext.AppContext,
cctx *types.CrossChainTx,
evmObserver *observer.Observer,
evmRPC interfaces.EVMRPCClient,
Expand All @@ -134,7 +134,7 @@ func NewOutboundData(
return nil, true, nil
}

toChain, found := chains.GetChainFromChainID(txData.toChainID.Int64(), coreContext.GetAdditionalChains())
toChain, found := chains.GetChainFromChainID(txData.toChainID.Int64(), appontext.GetAdditionalChains())
if !found {
return nil, true, fmt.Errorf("unknown chain: %d", txData.toChainID.Int64())
}
Expand Down
8 changes: 4 additions & 4 deletions zetaclient/chains/evm/signer/outbound_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestSigner_NewOutboundData(t *testing.T) {
t.Run("NewOutboundData success", func(t *testing.T) {
cctx := getCCTX(t)
_, skip, err := NewOutboundData(
evmSigner.ZetacoreContext(),
evmSigner.AppContext(),
cctx,
mockObserver,
evmSigner.EvmClient(),
Expand All @@ -91,7 +91,7 @@ func TestSigner_NewOutboundData(t *testing.T) {
cctx := getCCTX(t)
cctx.CctxStatus.Status = types.CctxStatus_Aborted
_, skip, err := NewOutboundData(
evmSigner.ZetacoreContext(),
evmSigner.AppContext(),
cctx,
mockObserver,
evmSigner.EvmClient(),
Expand All @@ -106,7 +106,7 @@ func TestSigner_NewOutboundData(t *testing.T) {
cctx := getInvalidCCTX(t)
require.NoError(t, err)
_, skip, err := NewOutboundData(
evmSigner.ZetacoreContext(),
evmSigner.AppContext(),
cctx,
mockObserver,
evmSigner.EvmClient(),
Expand All @@ -122,7 +122,7 @@ func TestSigner_NewOutboundData(t *testing.T) {
require.NoError(t, err)
cctx.GetCurrentOutboundParam().GasPrice = "invalidGasPrice"
_, skip, err := NewOutboundData(
evmSigner.ZetacoreContext(),
evmSigner.AppContext(),
cctx,
mockObserver,
evmSigner.EvmClient(),
Expand Down
6 changes: 3 additions & 3 deletions zetaclient/chains/evm/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func (signer *Signer) TryProcessOutbound(
}

// Setup Transaction input
txData, skipTx, err := NewOutboundData(signer.ZetacoreContext(), cctx, evmObserver, signer.client, logger, height)
txData, skipTx, err := NewOutboundData(signer.AppContext(), cctx, evmObserver, signer.client, logger, height)
if err != nil {
logger.Err(err).Msg("error setting up transaction input fields")
return
Expand All @@ -374,7 +374,7 @@ func (signer *Signer) TryProcessOutbound(

toChain, found := chains.GetChainFromChainID(
txData.toChainID.Int64(),
signer.ZetacoreContext().GetAdditionalChains(),
signer.AppContext().GetAdditionalChains(),
)
if !found {
logger.Warn().Msgf("unknown chain: %d", txData.toChainID.Int64())
Expand Down Expand Up @@ -547,7 +547,7 @@ func (signer *Signer) BroadcastOutbound(
// Get destination chain for logging
toChain, found := chains.GetChainFromChainID(
txData.toChainID.Int64(),
signer.ZetacoreContext().GetAdditionalChains(),
signer.AppContext().GetAdditionalChains(),
)
if !found {
logger.Warn().Msgf("BroadcastOutbound: unknown chain %d", txData.toChainID.Int64())
Expand Down
18 changes: 9 additions & 9 deletions zetaclient/chains/evm/signer/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestSigner_SignOutbound(t *testing.T) {
mockObserver, err := getNewEvmChainObserver(t, tss)
require.NoError(t, err)
txData, skip, err := NewOutboundData(
evmSigner.ZetacoreContext(),
evmSigner.AppContext(),
cctx,
mockObserver,
evmSigner.EvmClient(),
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestSigner_SignRevertTx(t *testing.T) {
mockObserver, err := getNewEvmChainObserver(t, tss)
require.NoError(t, err)
txData, skip, err := NewOutboundData(
evmSigner.ZetacoreContext(),
evmSigner.AppContext(),
cctx,
mockObserver,
evmSigner.EvmClient(),
Expand Down Expand Up @@ -267,7 +267,7 @@ func TestSigner_SignCancelTx(t *testing.T) {
mockObserver, err := getNewEvmChainObserver(t, tss)
require.NoError(t, err)
txData, skip, err := NewOutboundData(
evmSigner.ZetacoreContext(),
evmSigner.AppContext(),
cctx,
mockObserver,
evmSigner.EvmClient(),
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestSigner_SignWithdrawTx(t *testing.T) {
mockObserver, err := getNewEvmChainObserver(t, tss)
require.NoError(t, err)
txData, skip, err := NewOutboundData(
evmSigner.ZetacoreContext(),
evmSigner.AppContext(),
cctx,
mockObserver,
evmSigner.EvmClient(),
Expand Down Expand Up @@ -355,7 +355,7 @@ func TestSigner_SignCommandTx(t *testing.T) {
mockObserver, err := getNewEvmChainObserver(t, nil)
require.NoError(t, err)
txData, skip, err := NewOutboundData(
evmSigner.ZetacoreContext(),
evmSigner.AppContext(),
cctx,
mockObserver,
evmSigner.EvmClient(),
Expand Down Expand Up @@ -407,7 +407,7 @@ func TestSigner_SignERC20WithdrawTx(t *testing.T) {
mockObserver, err := getNewEvmChainObserver(t, tss)
require.NoError(t, err)
txData, skip, err := NewOutboundData(
evmSigner.ZetacoreContext(),
evmSigner.AppContext(),
cctx,
mockObserver,
evmSigner.EvmClient(),
Expand Down Expand Up @@ -452,7 +452,7 @@ func TestSigner_BroadcastOutbound(t *testing.T) {
mockObserver, err := getNewEvmChainObserver(t, nil)
require.NoError(t, err)
txData, skip, err := NewOutboundData(
evmSigner.ZetacoreContext(),
evmSigner.AppContext(),
cctx,
mockObserver,
evmSigner.EvmClient(),
Expand Down Expand Up @@ -509,7 +509,7 @@ func TestSigner_SignWhitelistERC20Cmd(t *testing.T) {
mockObserver, err := getNewEvmChainObserver(t, tss)
require.NoError(t, err)
txData, skip, err := NewOutboundData(
evmSigner.ZetacoreContext(),
evmSigner.AppContext(),
cctx,
mockObserver,
evmSigner.EvmClient(),
Expand Down Expand Up @@ -559,7 +559,7 @@ func TestSigner_SignMigrateTssFundsCmd(t *testing.T) {
mockObserver, err := getNewEvmChainObserver(t, tss)
require.NoError(t, err)
txData, skip, err := NewOutboundData(
evmSigner.ZetacoreContext(),
evmSigner.AppContext(),
cctx,
mockObserver,
evmSigner.EvmClient(),
Expand Down
19 changes: 16 additions & 3 deletions zetaclient/context/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ type AppContext struct {
currentTssPubkey string
crosschainFlags observertypes.CrosschainFlags

// additionalChains is a list of additional static chain information to use when searching from chain IDs
// it is stored in the protocol to dynamically support new chains without doing an upgrade
additionalChain []chains.Chain

// blockHeaderEnabledChains is used to store the list of chains that have block header verification enabled
// All chains in this list will have Enabled flag set to true
blockHeaderEnabledChains []lightclienttypes.HeaderSupportedChain
Expand Down Expand Up @@ -173,12 +177,12 @@ func (a *AppContext) GetBTCChainParams() (chains.Chain, *observertypes.ChainPara
return chains.Chain{}, nil, false
}

chain := chains.GetChainFromChainID(a.bitcoinChainParams.ChainId)
if chain == nil {
chain, found := chains.GetChainFromChainID(a.bitcoinChainParams.ChainId, a.additionalChain)
if !found {
return chains.Chain{}, nil, false
}

return *chain, a.bitcoinChainParams, true
return chain, a.bitcoinChainParams, true
}

// GetCrossChainFlags returns crosschain flags
Expand All @@ -189,6 +193,13 @@ func (a *AppContext) GetCrossChainFlags() observertypes.CrosschainFlags {
return a.crosschainFlags
}

// GetAdditionalChains returns additional chains
func (a *AppContext) GetAdditionalChains() []chains.Chain {
a.mu.RLock()
defer a.mu.RUnlock()
return a.additionalChain
}

// GetAllHeaderEnabledChains returns all verification flags
func (a *AppContext) GetAllHeaderEnabledChains() []lightclienttypes.HeaderSupportedChain {
a.mu.RLock()
Expand Down Expand Up @@ -220,6 +231,7 @@ func (a *AppContext) Update(
btcChainParams *observertypes.ChainParams,
tssPubKey string,
crosschainFlags observertypes.CrosschainFlags,
additionalChains []chains.Chain,
blockHeaderEnabledChains []lightclienttypes.HeaderSupportedChain,
init bool,
) {
Expand Down Expand Up @@ -249,6 +261,7 @@ func (a *AppContext) Update(

a.chainsEnabled = newChains
a.crosschainFlags = crosschainFlags
a.additionalChain = additionalChains
a.blockHeaderEnabledChains = blockHeaderEnabledChains

// update chain params for bitcoin if it has config in file
Expand Down
37 changes: 37 additions & 0 deletions zetaclient/context/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ func TestGetBTCChainAndConfig(t *testing.T) {
&observertypes.ChainParams{ChainId: 123},
"",
observertypes.CrosschainFlags{},
[]chains.Chain{},
nil,
true,
)
Expand All @@ -428,6 +429,7 @@ func TestGetBTCChainAndConfig(t *testing.T) {
&observertypes.ChainParams{ChainId: chains.BitcoinMainnet.ChainId},
"",
observertypes.CrosschainFlags{},
[]chains.Chain{},
nil,
true,
)
Expand Down Expand Up @@ -471,6 +473,7 @@ func TestGetBlockHeaderEnabledChains(t *testing.T) {
&observertypes.ChainParams{ChainId: chains.BitcoinMainnet.ChainId},
"",
observertypes.CrosschainFlags{},
[]chains.Chain{},
[]lightclienttypes.HeaderSupportedChain{
{ChainId: 1, Enabled: true},
},
Expand All @@ -493,6 +496,39 @@ func TestGetBlockHeaderEnabledChains(t *testing.T) {
assert.Empty(t, chain)
}

func TestGetAdditionalChains(t *testing.T) {
// ARRANGE
// Given app config
appContext := context.New(config.New(), zerolog.Nop())

additionalChains := []chains.Chain{
sample.Chain(1),
sample.Chain(2),
sample.Chain(3),
}

// That was eventually updated
appContext.Update(
&observertypes.Keygen{},
[]chains.Chain{},
nil,
&observertypes.ChainParams{},
"",
observertypes.CrosschainFlags{},
additionalChains,
[]lightclienttypes.HeaderSupportedChain{
{ChainId: 1, Enabled: true},
},
true,
)

// ACT
found := appContext.GetAdditionalChains()

// ASSERT
assert.EqualValues(t, additionalChains, found)
}

func makeAppContext(
evmChain chains.Chain,
evmChainParams *observertypes.ChainParams,
Expand All @@ -519,6 +555,7 @@ func makeAppContext(
nil,
"",
ccFlags,
[]chains.Chain{},
headerSupportedChains,
true,
)
Expand Down
Loading

0 comments on commit c09b769

Please sign in to comment.