diff --git a/pkg/relay/ethereum/log.go b/pkg/relay/ethereum/log.go index 506bfc2..8df6712 100644 --- a/pkg/relay/ethereum/log.go +++ b/pkg/relay/ethereum/log.go @@ -1,16 +1,21 @@ package ethereum const ( - logAttrMsgIndexFrom = "msg_index_from" - logAttrMsgCount = "msg_count" - logAttrMsgType = "msg_type" - logAttrRevertReason = "revert_reason" - logAttrRawErrorData = "raw_error_data" - logAttrRawTxData = "raw_tx_data" - logAttrTxHash = "tx_hash" - logAttrBlockHash = "block_hash" - logAttrBlockNumber = "block_number" - logAttrTxIndex = "tx_index" - logAttrEstimatedGas = "estimated_gas" - logAttrMaxGasLimit = "max_gas_limit" + logAttrMsgIndexFrom = "msg_index_from" + logAttrMsgCount = "msg_count" + logAttrMsgType = "msg_type" + logAttrRevertReason = "revert_reason" + logAttrRawErrorData = "raw_error_data" + logAttrRawTxData = "raw_tx_data" + logAttrTxHash = "tx_hash" + logAttrBlockHash = "block_hash" + logAttrBlockNumber = "block_number" + logAttrTxIndex = "tx_index" + logAttrEstimatedGas = "estimated_gas" + logAttrMaxGasLimit = "max_gas_limit" + logAttrPortID = "port_id" + logAttrChannelID = "channel_id" + logAttrUpgradeFields = "upgrade_fields" + logAttrTimeout = "timeout" + logAttrUpgradeSequence = "upgrade_sequence" ) diff --git a/pkg/relay/ethereum/upgrade.go b/pkg/relay/ethereum/upgrade.go index 767c8c4..19d7a6d 100644 --- a/pkg/relay/ethereum/upgrade.go +++ b/pkg/relay/ethereum/upgrade.go @@ -2,10 +2,12 @@ package ethereum import ( "context" + "encoding/hex" "fmt" "github.com/datachainlab/ethereum-ibc-relay-chain/pkg/contract/iibcchannelupgradablemodule" gethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/hyperledger-labs/yui-relayer/log" ) func (c *Chain) ProposeUpgrade( @@ -15,6 +17,14 @@ func (c *Chain) ProposeUpgrade( upgradeFields iibcchannelupgradablemodule.UpgradeFieldsData, timeout iibcchannelupgradablemodule.TimeoutData, ) error { + logger := c.GetChainLogger() + logger = &log.RelayLogger{Logger: logger.With( + logAttrPortID, portID, + logAttrChannelID, channelID, + logAttrUpgradeFields, upgradeFields, + logAttrTimeout, timeout, + )} + appAddr, err := c.ibcHandler.GetIBCModuleByChannel(c.CallOpts(ctx, 0), portID, channelID) if err != nil { return err @@ -40,17 +50,8 @@ func (c *Chain) ProposeUpgrade( upgradeFields, timeout, ) - if err != nil { - return err - } - - if receipt, err := c.client.WaitForReceiptAndGet(ctx, tx.Hash()); err != nil { - return err - } else if receipt.Status == gethtypes.ReceiptStatusFailed { - return fmt.Errorf("tx execution reverted") - } - return nil + return processSendTxResult(ctx, logger, c, tx, err) } func (c *Chain) AllowTransitionToFlushComplete( @@ -59,6 +60,13 @@ func (c *Chain) AllowTransitionToFlushComplete( channelID string, upgradeSequence uint64, ) error { + logger := c.GetChainLogger() + logger = &log.RelayLogger{Logger: logger.With( + logAttrPortID, portID, + logAttrChannelID, channelID, + logAttrUpgradeSequence, upgradeSequence, + )} + appAddr, err := c.ibcHandler.GetIBCModuleByChannel(c.CallOpts(ctx, 0), portID, channelID) if err != nil { return err @@ -87,9 +95,49 @@ func (c *Chain) AllowTransitionToFlushComplete( return err } + return processSendTxResult(ctx, logger, c, tx, err) +} + +func processSendTxResult(ctx context.Context, logger *log.RelayLogger, c *Chain, tx *gethtypes.Transaction, err error) error { + if err != nil { + if revertReason, returnData, err := c.getRevertReasonFromRpcError(err); err != nil { + logger = &log.RelayLogger{Logger: logger.With( + logAttrRawErrorData, hex.EncodeToString(returnData), + )} + logger.Error("failed to get revert reason from RPC error", err) + } else { + logger = &log.RelayLogger{Logger: logger.With( + logAttrRevertReason, revertReason, + logAttrRawErrorData, hex.EncodeToString(returnData), + )} + } + logger.Error("failed to send tx", err) + return err + } + + if rawTxData, err := tx.MarshalBinary(); err != nil { + logger.Error("failed to encode tx", err) + } else { + logger = &log.RelayLogger{Logger: logger.With( + logAttrRawTxData, hex.EncodeToString(rawTxData), + )} + } + if receipt, err := c.client.WaitForReceiptAndGet(ctx, tx.Hash()); err != nil { + logger.Error("failed to wait for tx receipt", err) return err } else if receipt.Status == gethtypes.ReceiptStatusFailed { + if revertReason, returnData, err := c.getRevertReasonFromReceipt(ctx, receipt); err != nil { + logger = &log.RelayLogger{Logger: logger.With( + logAttrRawErrorData, hex.EncodeToString(returnData), + )} + logger.Error("failed to get revert reason from receipt", err) + } else { + logger = &log.RelayLogger{Logger: logger.With( + logAttrRevertReason, revertReason, + logAttrRawErrorData, hex.EncodeToString(returnData), + )} + } return fmt.Errorf("tx execution reverted") }