Skip to content

Commit

Permalink
remove redundant fields in log message; unified logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Aug 5, 2024
1 parent d659e5a commit 2a3366a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 80 deletions.
91 changes: 22 additions & 69 deletions zetaclient/chains/evm/observer/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/erc20custody.sol"
"github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zetaconnector.non-eth.sol"

Expand Down Expand Up @@ -414,36 +413,30 @@ func (ob *Observer) checkConfirmedTx(
ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
defer cancel()

// prepare logger
logger := ob.Logger().Outbound.With().
Str(logs.FieldMethod, "checkConfirmedTx").
Int64(logs.FieldChain, ob.Chain().ChainId).
Uint64(logs.FieldNonce, nonce).
Str(logs.FieldTx, txHash).
Logger()

Check warning on line 422 in zetaclient/chains/evm/observer/outbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/outbound.go#L417-L422

Added lines #L417 - L422 were not covered by tests

// query transaction
transaction, isPending, err := ob.evmClient.TransactionByHash(ctx, ethcommon.HexToHash(txHash))
if err != nil {
log.Error().
Err(err).
Str("function", "confirmTxByHash").
Str("outboundTxHash", txHash).
Int64("chainID", ob.Chain().ChainId).
Msg("error getting transaction for outbound")
logger.Error().Err(err).Msg("TransactionByHash error")

Check warning on line 427 in zetaclient/chains/evm/observer/outbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/outbound.go#L427

Added line #L427 was not covered by tests
return nil, nil, false
}
if transaction == nil { // should not happen
log.Error().
Str("function", "confirmTxByHash").
Str("outboundTxHash", txHash).
Uint64("nonce", nonce).
Msg("transaction is nil for txHash")
logger.Error().Msg("transaction is nil")

Check warning on line 431 in zetaclient/chains/evm/observer/outbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/outbound.go#L431

Added line #L431 was not covered by tests
return nil, nil, false
}

// check tx sender and nonce
signer := ethtypes.NewLondonSigner(big.NewInt(ob.Chain().ChainId))
from, err := signer.Sender(transaction)
if err != nil {
log.Error().
Err(err).
Str("function", "confirmTxByHash").
Str("outboundTxHash", transaction.Hash().Hex()).
Int64("chainID", ob.Chain().ChainId).
Msg("local recovery of sender address failed for outbound")
logger.Error().Err(err).Msg("local recovery of sender address failed")

Check warning on line 439 in zetaclient/chains/evm/observer/outbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/outbound.go#L439

Added line #L439 was not covered by tests
return nil, nil, false
}
if from != ob.TSS().EVMAddress() { // must be TSS address
Expand All @@ -453,13 +446,8 @@ func (ob *Observer) checkConfirmedTx(

// TODO : improve this logic to verify that the correct TSS address is the from address.
// https://github.com/zeta-chain/node/issues/2487
log.Info().
Str("function", "confirmTxByHash").
Str("sender", from.Hex()).
Str("outboundTxHash", transaction.Hash().Hex()).
Int64("chainID", ob.Chain().ChainId).
Str("currentTSSAddress", ob.TSS().EVMAddress().Hex()).
Msg("sender is not current TSS address")
logger.Warn().
Msgf("tx sender %s is not matching current TSS address %s", from.String(), ob.TSS().EVMAddress().String())

Check warning on line 450 in zetaclient/chains/evm/observer/outbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/outbound.go#L449-L450

Added lines #L449 - L450 were not covered by tests
addressList := ob.TSS().EVMAddressList()
isOldTssAddress := false
for _, addr := range addressList {
Expand All @@ -468,23 +456,12 @@ func (ob *Observer) checkConfirmedTx(
}
}
if !isOldTssAddress {
log.Error().
Str("function", "confirmTxByHash").
Str("sender", from.Hex()).
Str("outboundTxHash", transaction.Hash().Hex()).
Int64("chainID", ob.Chain().ChainId).
Str("currentTSSAddress", ob.TSS().EVMAddress().Hex()).
Msg("sender is not current or old TSS address")
logger.Error().Msgf("tx sender %s is not matching any of the TSS addresses", from.String())

Check warning on line 459 in zetaclient/chains/evm/observer/outbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/outbound.go#L459

Added line #L459 was not covered by tests
return nil, nil, false
}
}
if transaction.Nonce() != nonce { // must match cctx nonce
log.Error().
Str("function", "confirmTxByHash").
Str("outboundTxHash", txHash).
Uint64("wantedNonce", nonce).
Uint64("gotTxNonce", transaction.Nonce()).
Msg("outbound nonce mismatch")
if transaction.Nonce() != nonce { // must match tracker nonce
logger.Error().Msgf("tx nonce %d is not matching tracker nonce", nonce)

Check warning on line 464 in zetaclient/chains/evm/observer/outbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/outbound.go#L463-L464

Added lines #L463 - L464 were not covered by tests
return nil, nil, false
}

Expand All @@ -497,55 +474,31 @@ func (ob *Observer) checkConfirmedTx(
// query receipt
receipt, err := ob.evmClient.TransactionReceipt(ctx, ethcommon.HexToHash(txHash))
if err != nil {
log.Error().
Err(err).
Str("function", "confirmTxByHash").
Str("outboundTxHash", txHash).
Uint64("nonce", nonce).
Msg("transactionReceipt error")
logger.Error().Err(err).Msg("TransactionReceipt error")

Check warning on line 477 in zetaclient/chains/evm/observer/outbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/outbound.go#L477

Added line #L477 was not covered by tests
return nil, nil, false
}
if receipt == nil { // should not happen
log.Error().
Str("function", "confirmTxByHash").
Str("outboundTxHash", txHash).
Uint64("nonce", nonce).
Msg("receipt is nil")
logger.Error().Msg("receipt is nil")

Check warning on line 481 in zetaclient/chains/evm/observer/outbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/outbound.go#L481

Added line #L481 was not covered by tests
return nil, nil, false
}
ob.LastBlock()
// check confirmations
lastHeight, err := ob.evmClient.BlockNumber(ctx)
if err != nil {
log.Error().
Str("function", "confirmTxByHash").
Err(err).
Int64("chainID", ob.GetChainParams().ChainId).
Msg("error getting block number for chain")
logger.Error().Err(err).Msg("BlockNumber error")

Check warning on line 488 in zetaclient/chains/evm/observer/outbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/outbound.go#L488

Added line #L488 was not covered by tests
return nil, nil, false
}
if !ob.HasEnoughConfirmations(receipt, lastHeight) {
log.Debug().
Str("function", "confirmTxByHash").
Str("txHash", txHash).
Uint64("nonce", nonce).
Uint64("receiptBlock", receipt.BlockNumber.Uint64()).
Uint64("currentBlock", lastHeight).
Msg("txHash included but not confirmed")
logger.Debug().
Msgf("tx included but not confirmed, receipt block %d current block %d", receipt.BlockNumber.Uint64(), lastHeight)

Check warning on line 493 in zetaclient/chains/evm/observer/outbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/outbound.go#L492-L493

Added lines #L492 - L493 were not covered by tests
return nil, nil, false
}

// cross-check tx inclusion against the block
// Note: a guard for false BlockNumber in receipt. The blob-carrying tx won't come here
err = ob.CheckTxInclusion(transaction, receipt)
if err != nil {
log.Error().
Err(err).
Str("function", "confirmTxByHash").
Str("errorContext", "checkTxInclusion").
Str("txHash", txHash).
Uint64("nonce", nonce).
Msg("checkTxInclusion error")
logger.Error().Err(err).Msg("CheckTxInclusion error")

Check warning on line 501 in zetaclient/chains/evm/observer/outbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/outbound.go#L501

Added line #L501 was not covered by tests
return nil, nil, false
}

Expand Down
1 change: 1 addition & 0 deletions zetaclient/chains/evm/signer/outbound_tracker_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (signer *Signer) reportToOutboundTracker(
confirmed, err := rpc.IsTxConfirmed(ctx, signer.client, outboundHash, evm.ReorgProtectBlockCount)
if err != nil {
logger.Err(err).Msg("unable to check confirmation status of outbound")
continue

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

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/signer/outbound_tracker_reporter.go#L61-L64

Added lines #L61 - L64 were not covered by tests
}
if !confirmed {
continue

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

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/signer/outbound_tracker_reporter.go#L66-L67

Added lines #L66 - L67 were not covered by tests
Expand Down
23 changes: 12 additions & 11 deletions zetaclient/chains/solana/observer/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
"github.com/zeta-chain/zetacore/zetaclient/chains/interfaces"
zctx "github.com/zeta-chain/zetacore/zetaclient/context"
"github.com/zeta-chain/zetacore/zetaclient/logs"
clienttypes "github.com/zeta-chain/zetacore/zetaclient/types"
"github.com/zeta-chain/zetacore/zetaclient/zetacore"
)
Expand Down Expand Up @@ -254,15 +255,15 @@ func (ob *Observer) CheckFinalizedTx(
// prepare logger fields
chainID := ob.Chain().ChainId
logger := ob.Logger().Outbound.With().
Str("method", "checkFinalizedTx").
Int64("chain", chainID).
Uint64("nonce", nonce).
Str("tx", txHash).Logger()
Str(logs.FieldMethod, "CheckFinalizedTx").
Int64(logs.FieldChain, chainID).
Uint64(logs.FieldNonce, nonce).
Str(logs.FieldTx, txHash).Logger()

// convert txHash to signature
sig, err := solana.SignatureFromBase58(txHash)
if err != nil {
logger.Error().Err(err).Msgf("SignatureFromBase58 err for chain %d nonce %d", chainID, nonce)
logger.Error().Err(err).Msg("SignatureFromBase58 error")
return nil, false
}

Expand All @@ -271,40 +272,40 @@ func (ob *Observer) CheckFinalizedTx(
Commitment: rpc.CommitmentFinalized,
})
if err != nil {
logger.Error().Err(err).Msgf("GetTransaction err for chain %d nonce %d", chainID, nonce)
logger.Error().Err(err).Msg("GetTransaction error")
return nil, false
}

// the tx must be successful in order to effectively increment the nonce
if txResult.Meta.Err != nil {
logger.Error().Any("Err", txResult.Meta.Err).Msgf("tx is not successful for chain %d nonce %d", chainID, nonce)
logger.Error().Any("Err", txResult.Meta.Err).Msg("tx is not successful")
return nil, false
}

// parse gateway instruction from tx result
inst, err := ParseGatewayInstruction(txResult, ob.gatewayID, coinType)
if err != nil {
logger.Error().Err(err).Msgf("ParseGatewayInstruction err for chain %d nonce %d", chainID, nonce)
logger.Error().Err(err).Msg("ParseGatewayInstruction error")
return nil, false
}
txNonce := inst.GatewayNonce()

// recover ECDSA signer from instruction
signerECDSA, err := inst.Signer()
if err != nil {
logger.Error().Err(err).Msgf("cannot get instruction signer for chain %d nonce %d", chainID, nonce)
logger.Error().Err(err).Msg("cannot get instruction signer")

Check warning on line 296 in zetaclient/chains/solana/observer/outbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/observer/outbound.go#L296

Added line #L296 was not covered by tests
return nil, false
}

// check tx authorization
if signerECDSA != ob.TSS().EVMAddress() {
logger.Error().Msgf("tx signer %s is not matching TSS, chain %d nonce %d", signerECDSA, chainID, nonce)
logger.Error().Msgf("tx signer %s is not matching current TSS address %s", signerECDSA, ob.TSS().EVMAddress())
return nil, false
}

// check tx nonce
if txNonce != nonce {
logger.Error().Msgf("tx nonce %d is not matching cctx, chain %d nonce %d", txNonce, chainID, nonce)
logger.Error().Msgf("tx nonce %d is not matching tracker nonce", txNonce)
return nil, false
}

Expand Down

0 comments on commit 2a3366a

Please sign in to comment.