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

decode query error #49

Merged
merged 2 commits into from
Jul 10, 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
21 changes: 14 additions & 7 deletions pkg/relay/ethereum/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ func (c *Chain) QueryClientConsensusState(ctx core.QueryContext, dstClientConsHe
defer logger.TimeTrack(time.Now(), "QueryClientConsensusState")
s, found, err := c.ibcHandler.GetConsensusState(c.callOptsFromQueryContext(ctx), c.pathEnd.ClientID, pbToHostHeight(dstClientConsHeight))
if err != nil {
logger.Error("failed to get consensus state", err)
revertReason, data := c.parseRpcError(err)
logger.Error("failed to get consensus state", err, logAttrRevertReason, revertReason, logAttrRawErrorData, data)
return nil, err
} else if !found {
logger.Error("client consensus not found", errors.New("client consensus not found"))
Expand All @@ -221,7 +222,8 @@ func (c *Chain) QueryClientState(ctx core.QueryContext) (*clienttypes.QueryClien
defer logger.TimeTrack(time.Now(), "QueryClientState")
s, found, err := c.ibcHandler.GetClientState(c.callOptsFromQueryContext(ctx), c.pathEnd.ClientID)
if err != nil {
logger.Error("failed to get client state", err)
revertReason, data := c.parseRpcError(err)
logger.Error("failed to get client state", err, logAttrRevertReason, revertReason, logAttrRawErrorData, data)
return nil, err
} else if !found {
logger.Error("client not found", errors.New("client not found"))
Expand Down Expand Up @@ -262,7 +264,8 @@ func (c *Chain) QueryConnection(ctx core.QueryContext) (*conntypes.QueryConnecti
defer logger.TimeTrack(time.Now(), "QueryConnection")
conn, found, err := c.ibcHandler.GetConnection(c.callOptsFromQueryContext(ctx), c.pathEnd.ConnectionID)
if err != nil {
logger.Error("failed to get connection", err)
revertReason, data := c.parseRpcError(err)
logger.Error("failed to get connection", err, logAttrRevertReason, revertReason, logAttrRawErrorData, data)
return nil, err
} else if !found {
return emptyConnRes, nil
Expand Down Expand Up @@ -291,7 +294,8 @@ func (c *Chain) QueryChannel(ctx core.QueryContext) (chanRes *chantypes.QueryCha
defer logger.TimeTrack(time.Now(), "QueryChannel")
chann, found, err := c.ibcHandler.GetChannel(c.callOptsFromQueryContext(ctx), c.pathEnd.PortID, c.pathEnd.ChannelID)
if err != nil {
logger.Error("failed to get channel", err)
revertReason, data := c.parseRpcError(err)
logger.Error("failed to get channel", err, logAttrRevertReason, revertReason, logAttrRawErrorData, data)
return nil, err
} else if !found {
return emptyChannelRes, nil
Expand All @@ -313,7 +317,8 @@ func (c *Chain) QueryUnreceivedPackets(ctx core.QueryContext, seqs []uint64) ([]
switch c.Path().GetOrder() {
case chantypes.UNORDERED:
if rc, err := c.ibcHandler.GetPacketReceipt(c.callOptsFromQueryContext(ctx), c.pathEnd.PortID, c.pathEnd.ChannelID, seq); err != nil {
logger.Error("failed to get packet receipt", err)
revertReason, data := c.parseRpcError(err)
logger.Error("failed to get packet receipt", err, logAttrRevertReason, revertReason, logAttrRawErrorData, data)
return nil, err
} else if rc == PACKET_RECEIPT_SUCCESSFUL {
received = true
Expand All @@ -327,7 +332,8 @@ func (c *Chain) QueryUnreceivedPackets(ctx core.QueryContext, seqs []uint64) ([]
// queried only once
nextSequenceRecv, err = c.ibcHandler.GetNextSequenceRecv(c.callOptsFromQueryContext(ctx), c.pathEnd.PortID, c.pathEnd.ChannelID)
if err != nil {
logger.Error("failed to get nextSequenceRecv", err)
revertReason, data := c.parseRpcError(err)
logger.Error("failed to get nextSequenceRecv", err, logAttrRevertReason, revertReason, logAttrRawErrorData, data)
return nil, err
}
}
Expand Down Expand Up @@ -397,7 +403,8 @@ func (c *Chain) QueryUnreceivedAcknowledgements(ctx core.QueryContext, seqs []ui
key := crypto.Keccak256Hash(host.PacketCommitmentKey(c.pathEnd.PortID, c.pathEnd.ChannelID, seq))
commitment, err := c.ibcHandler.GetCommitment(c.callOptsFromQueryContext(ctx), key)
if err != nil {
logger.Error("failed to get hashed packet commitment", err)
revertReason, data := c.parseRpcError(err)
logger.Error("failed to get hashed packet commitment", err, logAttrRevertReason, revertReason, logAttrRawErrorData, data)
return nil, err
} else if commitment != [32]byte{} {
ret = append(ret, seq)
Expand Down
5 changes: 4 additions & 1 deletion pkg/relay/ethereum/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ func (chain *Chain) findSentPackets(ctx core.QueryContext, fromHeight uint64) (c
chain.Path().PortID,
chain.Path().ChannelID,
); err != nil {
logger.Error("failed to get channel", err)
revertReason, data := chain.parseRpcError(err)
logger.Error("failed to get channel", err, "port_id", chain.Path().PortID, "channel_id", chain.Path().ChannelID,
logAttrRevertReason, revertReason,
logAttrRawErrorData, data)
return nil, err
} else if !found {
err := fmt.Errorf("channel not found")
Expand Down
31 changes: 15 additions & 16 deletions pkg/relay/ethereum/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,8 @@ func (c *Chain) SendMsgs(msgs []sdk.Msg) ([]core.MsgID, error) {

estimatedGas, err := c.client.EstimateGasFromTx(ctx, tx)
if err != nil {
if revertReason, rawErrorData, err := c.getRevertReasonFromEstimateGas(err); err != nil {
// Raw error data may be available even if revert reason isn't available.
logger.Logger = logger.With(logAttrRawErrorData, hex.EncodeToString(rawErrorData))
logger.Error("failed to get revert reason", err)
} else {
logger.Logger = logger.With(
logAttrRawErrorData, hex.EncodeToString(rawErrorData),
logAttrRevertReason, revertReason,
)
}

logger.Error("failed to estimate gas", err)
revertReason, data := c.parseRpcError(err)
logger.Error("failed to estimate gas", err, logAttrRevertReason, revertReason, logAttrRawErrorData, data)
return nil, err
}

Expand Down Expand Up @@ -445,13 +435,13 @@ func (c *Chain) getRevertReasonFromReceipt(ctx context.Context, receipt *client.
return revertReason, errorData, nil
}

func (c *Chain) getRevertReasonFromEstimateGas(err error) (string, []byte, error) {
func (c *Chain) getRevertReasonFromRpcError(err error) (string, []byte, error) {
if de, ok := err.(rpc.DataError); !ok {
return "", nil, fmt.Errorf("eth_estimateGas failed with unexpected error type: errorType=%T", err)
return "", nil, fmt.Errorf("failed with unexpected error type: errorType=%T", err)
} else if de.ErrorData() == nil {
return "", nil, fmt.Errorf("eth_estimateGas failed without error data")
return "", nil, fmt.Errorf("failed without error data")
} else if errorData, ok := de.ErrorData().(string); !ok {
return "", nil, fmt.Errorf("eth_estimateGas failed with unexpected error data type: errorDataType=%T", de.ErrorData())
return "", nil, fmt.Errorf("failed with unexpected error data type: errorDataType=%T", de.ErrorData())
} else {
errorData := common.FromHex(errorData)
revertReason, err := c.errorRepository.ParseError(errorData)
Expand All @@ -461,3 +451,12 @@ func (c *Chain) getRevertReasonFromEstimateGas(err error) (string, []byte, error
return revertReason, errorData, nil
}
}

func (c *Chain) parseRpcError(err error) (string, string) {
revertReason, rawErrorData, err := c.getRevertReasonFromRpcError(err)
if err != nil {
revertReason = fmt.Sprintf("failed to get revert reason: %s", err.Error())
}
// Note that Raw error data may be available even if revert reason isn't available.
return revertReason, hex.EncodeToString(rawErrorData)
}