Skip to content

Commit

Permalink
added InboundCategoryUnknown; logs fields cleaning; renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Nov 25, 2024
1 parent c933432 commit 97ce52a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
37 changes: 16 additions & 21 deletions zetaclient/chains/bitcoin/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/zeta-chain/node/zetaclient/chains/interfaces"
"github.com/zeta-chain/node/zetaclient/compliance"
"github.com/zeta-chain/node/zetaclient/config"
"github.com/zeta-chain/node/zetaclient/logs"
"github.com/zeta-chain/node/zetaclient/metrics"
"github.com/zeta-chain/node/zetaclient/outboundprocessor"
)
Expand Down Expand Up @@ -355,12 +356,13 @@ func (signer *Signer) TryProcessOutbound(

// prepare logger
params := cctx.GetCurrentOutboundParam()
logger := signer.Logger().Std.With().
Str("method", "TryProcessOutbound").
Int64("chain", signer.Chain().ChainId).
Uint64("nonce", params.TssNonce).
Str("cctx", cctx.Index).
Logger()
// prepare logger fields
lf := map[string]any{
logs.FieldMethod: "TryProcessOutbound",
logs.FieldCctx: cctx.Index,
logs.FieldNonce: params.TssNonce,
}
logger := signer.Logger().Std.With().Fields(lf).Logger()

// support gas token only for Bitcoin outbound
coinType := cctx.InboundParams.CoinType
Expand Down Expand Up @@ -431,7 +433,7 @@ func (signer *Signer) TryProcessOutbound(
if cancelTx {
amount = 0.0
} else {
logger.Info().Msgf("SignGasWithdraw: to %s, value %d sats", to.EncodeAddress(), params.Amount.Uint64())
logger.Info().Msgf("withdraw BTC to %s, value %d sats", to.EncodeAddress(), params.Amount.Uint64())
}

// sign withdraw tx
Expand All @@ -448,40 +450,33 @@ func (signer *Signer) TryProcessOutbound(
cancelTx,
)
if err != nil {
logger.Warn().
Err(err).
Msgf("SignWithdrawTx error: nonce %d chain %d", outboundTssNonce, params.ReceiverChainId)
logger.Warn().Err(err).Msg("SignWithdrawTx failed")
return
}
logger.Info().
Msgf("Key-sign success: %d => %s, nonce %d", cctx.InboundParams.SenderChainId, chain.Name, outboundTssNonce)
logger.Info().Msg("Key-sign success")

// FIXME: add prometheus metrics
_, err = zetacoreClient.GetObserverList(ctx)
if err != nil {
logger.Warn().
Err(err).
Msgf("unable to get observer list: chain %d observation %s", outboundTssNonce, observertypes.ObservationType_OutboundTx.String())
Msgf("unable to get observer list, observation %s", observertypes.ObservationType_OutboundTx.String())
}
if tx != nil {
outboundHash := tx.TxHash().String()
logger.Info().
Msgf("on chain %s nonce %d, outboundHash %s signer %s", chain.Name, outboundTssNonce, outboundHash, signerAddress)
logger.Info().Msgf("signed outboundHash %s signer %s", outboundHash, signerAddress)

// try broacasting tx with increasing backoff (1s, 2s, 4s, 8s, 16s) in case of RPC error
backOff := broadcastBackoff
for i := 0; i < broadcastRetries; i++ {
time.Sleep(backOff)
err := signer.Broadcast(tx)
if err != nil {
logger.Warn().
Err(err).
Msgf("broadcasting tx %s to chain %s: nonce %d, retry %d", outboundHash, chain.Name, outboundTssNonce, i)
logger.Warn().Err(err).Msgf("broadcasting tx %s to chain %s, retry %d", outboundHash, chain.Name, i)
backOff *= 2
continue
}
logger.Info().
Msgf("Broadcast success: nonce %d to chain %s outboundHash %s", outboundTssNonce, chain.String(), outboundHash)
logger.Info().Msgf("Broadcast success: chain %s outboundHash %s", chain.String(), outboundHash)
zetaHash, err := zetacoreClient.PostOutboundTracker(
ctx,
chain.ChainId,
Expand All @@ -490,7 +485,7 @@ func (signer *Signer) TryProcessOutbound(
)
if err != nil {
logger.Err(err).
Msgf("Unable to add to tracker on zetacore: nonce %d chain %s outboundHash %s", outboundTssNonce, chain.Name, outboundHash)
Msgf("Unable to add to tracker on zetacore: chain %s outboundHash %s", chain.Name, outboundHash)
}
logger.Info().Msgf("Broadcast to core successful %s", zetaHash)

Expand Down
10 changes: 5 additions & 5 deletions zetaclient/chains/evm/observer/v2_inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"github.com/zeta-chain/node/zetaclient/zetacore"
)

// IsEventProcessable checks if the event is processable
func (ob *Observer) IsEventProcessable(
// isEventProcessable checks if the event is processable
func (ob *Observer) isEventProcessable(
sender, receiver ethcommon.Address,
txHash ethcommon.Hash,
payload []byte,
Expand Down Expand Up @@ -99,7 +99,7 @@ func (ob *Observer) ObserveGatewayDeposit(ctx context.Context, startBlock, toBlo
}

// check if the event is processable
if !ob.IsEventProcessable(event.Sender, event.Receiver, event.Raw.TxHash, event.Payload) {
if !ob.isEventProcessable(event.Sender, event.Receiver, event.Raw.TxHash, event.Payload) {
continue
}

Expand Down Expand Up @@ -247,7 +247,7 @@ func (ob *Observer) ObserveGatewayCall(ctx context.Context, startBlock, toBlock
}

// check if the event is processable
if !ob.IsEventProcessable(event.Sender, event.Receiver, event.Raw.TxHash, event.Payload) {
if !ob.isEventProcessable(event.Sender, event.Receiver, event.Raw.TxHash, event.Payload) {
continue
}

Expand Down Expand Up @@ -378,7 +378,7 @@ func (ob *Observer) ObserveGatewayDepositAndCall(ctx context.Context, startBlock
}

// check if the event is processable
if !ob.IsEventProcessable(event.Sender, event.Receiver, event.Raw.TxHash, event.Payload) {
if !ob.isEventProcessable(event.Sender, event.Receiver, event.Raw.TxHash, event.Payload) {
continue
}

Expand Down
6 changes: 3 additions & 3 deletions zetaclient/chains/evm/observer/v2_inbound_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (ob *Observer) ProcessInboundTrackerV2(
eventDeposit, err := gateway.ParseDeposited(*log)
if err == nil {
// check if the event is processable
if !ob.IsEventProcessable(
if !ob.isEventProcessable(
eventDeposit.Sender,
eventDeposit.Receiver,
eventDeposit.Raw.TxHash,
Expand All @@ -53,7 +53,7 @@ func (ob *Observer) ProcessInboundTrackerV2(
eventDepositAndCall, err := gateway.ParseDepositedAndCalled(*log)
if err == nil {
// check if the event is processable
if !ob.IsEventProcessable(
if !ob.isEventProcessable(
eventDepositAndCall.Sender,
eventDepositAndCall.Receiver,
eventDepositAndCall.Raw.TxHash,
Expand All @@ -70,7 +70,7 @@ func (ob *Observer) ProcessInboundTrackerV2(
eventCall, err := gateway.ParseCalled(*log)
if err == nil {
// check if the event is processable
if !ob.IsEventProcessable(
if !ob.isEventProcessable(
eventCall.Sender,
eventCall.Receiver,
eventCall.Raw.TxHash,
Expand Down
5 changes: 4 additions & 1 deletion zetaclient/types/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ import (
type InboundCategory int

const (
// InboundCategoryUnknown represents an unknown inbound
InboundCategoryUnknown InboundCategory = iota

// InboundCategoryGood represents a processable inbound
InboundCategoryGood InboundCategory = iota
InboundCategoryGood

// InboundCategoryDonation represents a donation inbound
InboundCategoryDonation
Expand Down

0 comments on commit 97ce52a

Please sign in to comment.