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: allow processing v2 inbound trackers for gateway calls initiated by smart contracts (v2 backport) #3241

Merged
merged 1 commit into from
Dec 4, 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
55 changes: 27 additions & 28 deletions zetaclient/chains/evm/observer/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions zetaclient/chains/evm/observer/v2_inbound_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -28,7 +38,7 @@ func (ob *Observer) ProcessInboundTrackerV2(
}

for _, log := range receipt.Logs {
if log == nil {
if log == nil || log.Address != gatewayAddr {
continue
}

Expand Down Expand Up @@ -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)
}
Loading