Skip to content

Commit

Permalink
put error handling higher level ObserverGateway
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Aug 5, 2024
1 parent ed4bc88 commit 63c4698
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
7 changes: 6 additions & 1 deletion zetaclient/chains/evm/observer/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,12 @@ func (ob *Observer) ObserveInbound(ctx context.Context, sampledLogger zerolog.Lo
// query the gateway logs
// TODO: refactor in a more declarative design. Example: storing the list of contract and events to listen in an array
// https://github.com/zeta-chain/node/issues/2493
lastScannedGateway := ob.ObserveGateway(ctx, startBlock, toBlock)
lastScannedGateway, err := ob.ObserveGateway(ctx, startBlock, toBlock)
if err != nil {
ob.Logger().Inbound.Error().
Err(err).
Msgf("ObserveInbound: error observing events from Gateway contract")

Check warning on line 227 in zetaclient/chains/evm/observer/inbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/inbound.go#L223-L227

Added lines #L223 - L227 were not covered by tests
}

// note: using lowest height for all 3 events is not perfect, but it's simple and good enough
lastScannedLowest := lastScannedZetaSent
Expand Down
21 changes: 13 additions & 8 deletions zetaclient/chains/evm/observer/v2_inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"sort"

"cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
ethcommon "github.com/ethereum/go-ethereum/common"
Expand All @@ -23,12 +24,12 @@ import (

// ObserveGateway queries the gateway contract for deposit/call events
// returns the last block successfully scanned
func (ob *Observer) ObserveGateway(ctx context.Context, startBlock, toBlock uint64) uint64 {
func (ob *Observer) ObserveGateway(ctx context.Context, startBlock, toBlock uint64) (uint64, error) {

Check warning on line 27 in zetaclient/chains/evm/observer/v2_inbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/v2_inbound.go#L27

Added line #L27 was not covered by tests
// filter ERC20CustodyDeposited logs
gatewayAddr, gatewayContract, err := ob.GetGatewayContract()
if err != nil {

Check warning on line 30 in zetaclient/chains/evm/observer/v2_inbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/v2_inbound.go#L29-L30

Added lines #L29 - L30 were not covered by tests
ob.Logger().Inbound.Warn().Err(err).Msgf("ObserveGateway: can't get gateway contract")
return startBlock - 1 // lastScanned
// lastScanned is startBlock - 1
return startBlock - 1, errors.Wrap(err, "can't get gateway contract")

Check warning on line 32 in zetaclient/chains/evm/observer/v2_inbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/v2_inbound.go#L32

Added line #L32 was not covered by tests
}

// get iterator for the events for the block range
Expand All @@ -38,9 +39,13 @@ func (ob *Observer) ObserveGateway(ctx context.Context, startBlock, toBlock uint
Context: ctx,
}, []ethcommon.Address{}, []ethcommon.Address{})
if err != nil {
ob.Logger().Inbound.Warn().Err(err).Msgf(
"ObserveGateway: FilterDeposit error from block %d to %d for chain %d", startBlock, toBlock, ob.Chain().ChainId)
return startBlock - 1 // lastScanned
return startBlock - 1, errors.Wrapf(
err,
"error filtering deposits from block %d to %d for chain %d",
startBlock,
toBlock,
ob.Chain().ChainId,
)

Check warning on line 48 in zetaclient/chains/evm/observer/v2_inbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/v2_inbound.go#L36-L48

Added lines #L36 - L48 were not covered by tests
}

// parse and validate events
Expand Down Expand Up @@ -72,12 +77,12 @@ func (ob *Observer) ObserveGateway(ctx context.Context, startBlock, toBlock uint
_, err = ob.PostVoteInbound(ctx, &msg, zetacore.PostVoteInboundExecutionGasLimit)
if err != nil {

Check warning on line 78 in zetaclient/chains/evm/observer/v2_inbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/v2_inbound.go#L77-L78

Added lines #L77 - L78 were not covered by tests
// decrement the last scanned block so we have to re-scan from this block next time
return lastScanned - 1
return lastScanned - 1, errors.Wrap(err, "error posting vote inbound")

Check warning on line 80 in zetaclient/chains/evm/observer/v2_inbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/v2_inbound.go#L80

Added line #L80 was not covered by tests
}
}

// successfully processed all events in [startBlock, toBlock]
return toBlock
return toBlock, nil

Check warning on line 85 in zetaclient/chains/evm/observer/v2_inbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/v2_inbound.go#L85

Added line #L85 was not covered by tests
}

// parseAndValidateEvents collects and sorts events by block number, tx index, and log index
Expand Down

0 comments on commit 63c4698

Please sign in to comment.