diff --git a/zetaclient/chains/evm/observer/inbound.go b/zetaclient/chains/evm/observer/inbound.go index d7632ac192..493a4e3c18 100644 --- a/zetaclient/chains/evm/observer/inbound.go +++ b/zetaclient/chains/evm/observer/inbound.go @@ -145,35 +145,34 @@ func (ob *Observer) ProcessInboundTrackers(ctx context.Context) error { } ob.Logger().Inbound.Info().Msgf("checking tracker for inbound %s chain %d", tracker.TxHash, ob.Chain().ChainId) - // if the transaction is sent to the gateway, this is a v2 inbound - gatewayAddr, gateway, err := ob.GetGatewayContract() - if err != nil { - ob.Logger().Inbound.Debug().Err(err).Msg("error getting gateway contract for processing inbound tracker") + // try processing the tracker for v2 inbound + // filter error if event is not found, in this case we run v1 tracker process + if err := ob.ProcessInboundTrackerV2(ctx, tx, receipt); err != nil && + !errors.Is(err, ErrEventNotFound) && !errors.Is(err, ErrGatewayNotSet) { + return err + } else if err == nil { + // continue with next tracker + continue } - if err == nil && tx != nil && ethcommon.HexToAddress(tx.To) == gatewayAddr { - if err := ob.ProcessInboundTrackerV2(ctx, gateway, tx, receipt); err != nil { - return err - } - } else { - // check and vote on inbound tx - switch tracker.CoinType { - case coin.CoinType_Zeta: - _, err = ob.CheckAndVoteInboundTokenZeta(ctx, tx, receipt, true) - case coin.CoinType_ERC20: - _, err = ob.CheckAndVoteInboundTokenERC20(ctx, tx, receipt, true) - case coin.CoinType_Gas: - _, err = ob.CheckAndVoteInboundTokenGas(ctx, tx, receipt, true) - default: - return fmt.Errorf( - "unknown coin type %s for inbound %s chain %d", - tracker.CoinType, - tx.Hash, - ob.Chain().ChainId, - ) - } - if err != nil { - return errors.Wrapf(err, "error checking and voting for inbound %s chain %d", tx.Hash, ob.Chain().ChainId) - } + + // try processing the tracker for v1 inbound + switch tracker.CoinType { + case coin.CoinType_Zeta: + _, err = ob.CheckAndVoteInboundTokenZeta(ctx, tx, receipt, true) + case coin.CoinType_ERC20: + _, err = ob.CheckAndVoteInboundTokenERC20(ctx, tx, receipt, true) + case coin.CoinType_Gas: + _, err = ob.CheckAndVoteInboundTokenGas(ctx, tx, receipt, true) + default: + return fmt.Errorf( + "unknown coin type %s for inbound %s chain %d", + tracker.CoinType, + tx.Hash, + ob.Chain().ChainId, + ) + } + if err != nil { + return errors.Wrapf(err, "error checking and voting for inbound %s chain %d", tx.Hash, ob.Chain().ChainId) } } return nil diff --git a/zetaclient/chains/evm/observer/v2_inbound_tracker.go b/zetaclient/chains/evm/observer/v2_inbound_tracker.go index 11f39fe2a5..3b68b47ef7 100644 --- a/zetaclient/chains/evm/observer/v2_inbound_tracker.go +++ b/zetaclient/chains/evm/observer/v2_inbound_tracker.go @@ -6,18 +6,28 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/onrik/ethrpc" - "github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayevm.sol" + "github.com/pkg/errors" "github.com/zeta-chain/node/zetaclient/zetacore" ) +var ( + ErrEventNotFound = errors.New("event not found") + ErrGatewayNotSet = errors.New("gateway contract not set") +) + // ProcessInboundTrackerV2 processes inbound tracker events from the gateway func (ob *Observer) ProcessInboundTrackerV2( ctx context.Context, - gateway *gatewayevm.GatewayEVM, tx *ethrpc.Transaction, receipt *ethtypes.Receipt, ) error { + gatewayAddr, gateway, err := ob.GetGatewayContract() + if err != nil { + ob.Logger().Inbound.Debug().Err(err).Msg("error getting gateway contract for processing inbound tracker") + return ErrGatewayNotSet + } + // check confirmations if confirmed := ob.HasEnoughConfirmations(receipt, ob.LastBlock()); !confirmed { return fmt.Errorf( @@ -28,7 +38,7 @@ func (ob *Observer) ProcessInboundTrackerV2( } for _, log := range receipt.Logs { - if log == nil { + if log == nil || log.Address != gatewayAddr { continue } @@ -84,5 +94,5 @@ func (ob *Observer) ProcessInboundTrackerV2( } } - return fmt.Errorf("no gateway event found in inbound tracker %s", tx.Hash) + return errors.Wrapf(ErrEventNotFound, "inbound tracker %s", tx.Hash) }