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

fix(zetaclient): orchestrator: signer resolution #3139

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -21,6 +21,7 @@
### Fixes
* [3041](https://github.com/zeta-chain/node/pull/3041) - replace libp2p public DHT with private gossip peer discovery and connection gater for inbound connections
* [3106](https://github.com/zeta-chain/node/pull/3106) - prevent blocked CCTX on out of gas during omnichain calls
* [3139](https://github.com/zeta-chain/node/pull/3139) - fix config resolution in orchestrator

## v21.0.0

Expand Down
48 changes: 37 additions & 11 deletions zetaclient/chains/evm/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,43 +108,69 @@

// SetZetaConnectorAddress sets the zeta connector address
func (signer *Signer) SetZetaConnectorAddress(addr ethcommon.Address) {
// noop
if (addr == ethcommon.Address{}) || signer.zetaConnectorAddress == addr {
return
}

Check warning on line 114 in zetaclient/chains/evm/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/signer/signer.go#L113-L114

Added lines #L113 - L114 were not covered by tests

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()
swift1337 marked this conversation as resolved.
Show resolved Hide resolved
}

// SetERC20CustodyAddress sets the erc20 custody address
func (signer *Signer) SetERC20CustodyAddress(addr ethcommon.Address) {
// noop
if (addr == ethcommon.Address{}) || signer.er20CustodyAddress == addr {
return
}

Check warning on line 131 in zetaclient/chains/evm/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/signer/signer.go#L130-L131

Added lines #L130 - L131 were not covered by tests

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()
swift1337 marked this conversation as resolved.
Show resolved Hide resolved
}

// SetGatewayAddress sets the gateway address
func (signer *Signer) SetGatewayAddress(addr string) {
func (signer *Signer) SetGatewayAddress(addrRaw string) {
addr := ethcommon.HexToAddress(addrRaw)

swift1337 marked this conversation as resolved.
Show resolved Hide resolved
// noop
if (addr == ethcommon.Address{}) || signer.gatewayAddress == addr {
return
}

Check warning on line 150 in zetaclient/chains/evm/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/signer/signer.go#L144-L150

Added lines #L144 - L150 were not covered by tests

signer.Logger().Std.Info().
Str("signer.old_gateway_address", signer.gatewayAddress.String()).
Str("signer.new_gateway_address", addr.String()).
Msg("Updated gateway address")

Check warning on line 156 in zetaclient/chains/evm/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/signer/signer.go#L152-L156

Added lines #L152 - L156 were not covered by tests
signer.Lock()
defer signer.Unlock()
signer.gatewayAddress = ethcommon.HexToAddress(addr)
signer.gatewayAddress = addr
signer.Unlock()

Check warning on line 159 in zetaclient/chains/evm/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/signer/signer.go#L158-L159

Added lines #L158 - L159 were not covered by tests
swift1337 marked this conversation as resolved.
Show resolved Hide resolved
}

// 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()
}

Expand Down
23 changes: 17 additions & 6 deletions zetaclient/chains/solana/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,25 +258,36 @@

// SetGatewayAddress sets the gateway address
func (signer *Signer) SetGatewayAddress(address string) {
// noop
if address == "" || signer.gatewayID.String() == address {
return
}

Check warning on line 264 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L263-L264

Added lines #L263 - L264 were not covered by tests

// 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
}

Check warning on line 276 in zetaclient/chains/solana/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/signer/signer.go#L275-L276

Added lines #L275 - L276 were not covered by tests

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()
}

Expand Down
7 changes: 6 additions & 1 deletion zetaclient/chains/ton/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
// 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 {

Check warning on line 281 in zetaclient/chains/ton/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/ton/signer/signer.go#L281

Added line #L281 was not covered by tests
return
}

Expand All @@ -288,6 +288,11 @@
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")

Check warning on line 295 in zetaclient/chains/ton/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/ton/signer/signer.go#L291-L295

Added lines #L291 - L295 were not covered by tests
s.Lock()
s.gateway = toncontracts.NewGateway(acc)
s.Unlock()
Expand Down
46 changes: 6 additions & 40 deletions zetaclient/orchestrator/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
swift1337 marked this conversation as resolved.
Show resolved Hide resolved
swift1337 marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
Loading