From 98d403048ff048c1c6434e19300c2c31f25d5e6c Mon Sep 17 00:00:00 2001 From: Dmitry S <11892559+swift1337@users.noreply.github.com> Date: Mon, 11 Nov 2024 19:08:40 +0100 Subject: [PATCH] Fix signer resolution --- zetaclient/chains/evm/signer/signer.go | 48 +++++++++++++++++------ zetaclient/chains/solana/signer/signer.go | 23 ++++++++--- zetaclient/chains/ton/signer/signer.go | 7 +++- zetaclient/orchestrator/orchestrator.go | 46 +++------------------- 4 files changed, 66 insertions(+), 58 deletions(-) diff --git a/zetaclient/chains/evm/signer/signer.go b/zetaclient/chains/evm/signer/signer.go index 5e046107fb..5cebb323c1 100644 --- a/zetaclient/chains/evm/signer/signer.go +++ b/zetaclient/chains/evm/signer/signer.go @@ -108,43 +108,69 @@ func (signer *Signer) WithEvmClient(client interfaces.EVMRPCClient) { // SetZetaConnectorAddress sets the zeta connector address func (signer *Signer) SetZetaConnectorAddress(addr ethcommon.Address) { + // noop + if (addr == ethcommon.Address{}) || signer.zetaConnectorAddress == addr { + return + } + + signer.Logger().Std.Info(). + Str("signer.old_zeta_connector_address", signer.zetaConnectorAddress.String()). + Str("signer.new_zeta_connector_address", addr.String()). + Msg("Updated zeta connector address") + signer.Lock() - defer signer.Unlock() signer.zetaConnectorAddress = addr + signer.Unlock() } // SetERC20CustodyAddress sets the erc20 custody address func (signer *Signer) SetERC20CustodyAddress(addr ethcommon.Address) { + // noop + if (addr == ethcommon.Address{}) || signer.er20CustodyAddress == addr { + return + } + + signer.Logger().Std.Info(). + Str("signer.old_erc20_custody_address", signer.er20CustodyAddress.String()). + Str("signer.new_erc20_custody_address", addr.String()). + Msg("Updated erc20 custody address") + signer.Lock() - defer signer.Unlock() signer.er20CustodyAddress = addr + signer.Unlock() } // SetGatewayAddress sets the gateway address -func (signer *Signer) SetGatewayAddress(addr string) { +func (signer *Signer) SetGatewayAddress(addrRaw string) { + addr := ethcommon.HexToAddress(addrRaw) + + // noop + if (addr == ethcommon.Address{}) || signer.gatewayAddress == addr { + return + } + + signer.Logger().Std.Info(). + Str("signer.old_gateway_address", signer.gatewayAddress.String()). + Str("signer.new_gateway_address", addr.String()). + Msg("Updated gateway address") + signer.Lock() - defer signer.Unlock() - signer.gatewayAddress = ethcommon.HexToAddress(addr) + signer.gatewayAddress = addr + signer.Unlock() } // GetZetaConnectorAddress returns the zeta connector address func (signer *Signer) GetZetaConnectorAddress() ethcommon.Address { - signer.Lock() - defer signer.Unlock() return signer.zetaConnectorAddress } // GetERC20CustodyAddress returns the erc20 custody address func (signer *Signer) GetERC20CustodyAddress() ethcommon.Address { - signer.Lock() - defer signer.Unlock() return signer.er20CustodyAddress } // GetGatewayAddress returns the gateway address func (signer *Signer) GetGatewayAddress() string { - signer.Lock() - defer signer.Unlock() return signer.gatewayAddress.String() } diff --git a/zetaclient/chains/solana/signer/signer.go b/zetaclient/chains/solana/signer/signer.go index 8e180f8c7f..560a08d2ca 100644 --- a/zetaclient/chains/solana/signer/signer.go +++ b/zetaclient/chains/solana/signer/signer.go @@ -258,25 +258,36 @@ func (signer *Signer) prepareWhitelistTx( // SetGatewayAddress sets the gateway address func (signer *Signer) SetGatewayAddress(address string) { + // noop + if address == "" { + return + } + // parse gateway ID and PDA gatewayID, pda, err := contracts.ParseGatewayIDAndPda(address) if err != nil { - signer.Logger().Std.Error().Err(err).Msgf("cannot parse gateway address: %s", address) + signer.Logger().Std.Error().Err(err).Str("address", address).Msgf("Unable to parse gateway address") return } - // update gateway ID and PDA - signer.Lock() - defer signer.Unlock() + // noop + if signer.gatewayID.Equals(gatewayID) { + return + } + + signer.Logger().Std.Info(). + Str("signer.old_gateway_address", signer.gatewayID.String()). + Str("signer.new_gateway_address", gatewayID.String()). + Msg("Updated gateway address") + signer.Lock() signer.gatewayID = gatewayID signer.pda = pda + signer.Unlock() } // GetGatewayAddress returns the gateway address func (signer *Signer) GetGatewayAddress() string { - signer.Lock() - defer signer.Unlock() return signer.gatewayID.String() } diff --git a/zetaclient/chains/ton/signer/signer.go b/zetaclient/chains/ton/signer/signer.go index bdd25c0c18..689692eece 100644 --- a/zetaclient/chains/ton/signer/signer.go +++ b/zetaclient/chains/ton/signer/signer.go @@ -278,7 +278,7 @@ func (s *Signer) GetGatewayAddress() string { // SetGatewayAddress sets gateway address. Has a check for noop. func (s *Signer) SetGatewayAddress(addr string) { // noop - if s.gateway.AccountID().ToRaw() == addr { + if addr == "" || s.gateway.AccountID().ToRaw() == addr { return } @@ -288,6 +288,11 @@ func (s *Signer) SetGatewayAddress(addr string) { return } + s.Logger().Std.Info(). + Str("signer.old_gateway_address", s.gateway.AccountID().ToRaw()). + Str("signer.new_gateway_address", acc.ToRaw()). + Msg("Updated gateway address") + s.Lock() s.gateway = toncontracts.NewGateway(acc) s.Unlock() diff --git a/zetaclient/orchestrator/orchestrator.go b/zetaclient/orchestrator/orchestrator.go index fe1c26b76a..986b799f72 100644 --- a/zetaclient/orchestrator/orchestrator.go +++ b/zetaclient/orchestrator/orchestrator.go @@ -9,7 +9,7 @@ import ( "time" sdkmath "cosmossdk.io/math" - ethcommon "github.com/ethereum/go-ethereum/common" + eth "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" "github.com/rs/zerolog" "github.com/samber/lo" @@ -164,47 +164,13 @@ func (oc *Orchestrator) resolveSigner(app *zctx.AppContext, chainID int64) (inte params := chain.Params() // update zeta connector, ERC20 custody, and gateway addresses - zetaConnectorAddress := ethcommon.HexToAddress(params.GetConnectorContractAddress()) - if zetaConnectorAddress != signer.GetZetaConnectorAddress() { - signer.SetZetaConnectorAddress(zetaConnectorAddress) - oc.logger.Info(). - Str("signer.connector_address", zetaConnectorAddress.String()). - Msgf("updated zeta connector address for chain %d", chainID) - } - erc20CustodyAddress := ethcommon.HexToAddress(params.GetErc20CustodyContractAddress()) - if erc20CustodyAddress != signer.GetERC20CustodyAddress() { - signer.SetERC20CustodyAddress(erc20CustodyAddress) - oc.logger.Info(). - Str("signer.erc20_custody", erc20CustodyAddress.String()). - Msgf("updated erc20 custody address for chain %d", chainID) - } - if params.GatewayAddress != signer.GetGatewayAddress() { - signer.SetGatewayAddress(params.GatewayAddress) - oc.logger.Info(). - Str("signer.gateway_address", params.GatewayAddress). - Msgf("updated gateway address for chain %d", chainID) - } - + signer.SetZetaConnectorAddress(eth.HexToAddress(params.ConnectorContractAddress)) + signer.SetERC20CustodyAddress(eth.HexToAddress(params.Erc20CustodyContractAddress)) + signer.SetGatewayAddress(params.GatewayAddress) case chain.IsSolana(): - params := chain.Params() - - // update gateway address - if params.GatewayAddress != signer.GetGatewayAddress() { - signer.SetGatewayAddress(params.GatewayAddress) - oc.logger.Info(). - Str("signer.gateway_address", params.GatewayAddress). - Msgf("updated gateway address for chain %d", chainID) - } + signer.SetGatewayAddress(chain.Params().GatewayAddress) case chain.IsTON(): - newAddress := chain.Params().GatewayAddress - - if newAddress != signer.GetGatewayAddress() { - signer.SetGatewayAddress(newAddress) - oc.logger.Info(). - Str("signer.new_gateway_address", newAddress). - Int64("signer.chain_id", chainID). - Msg("set gateway address") - } + signer.SetGatewayAddress(chain.Params().GatewayAddress) } return signer, nil