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

Misbehaviour Monitoring #457

Merged
merged 5 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
SDKCOMMIT := $(shell go list -m -u -f '{{.Version}}' github.com/cosmos/cosmos-sdk)
GAIA_VERSION := v4.0.0
GAIA_VERSION := v4.1.0
AKASH_VERSION := jack/update-sdk
WASMD_VERSION := v0.14.1

Expand Down
58 changes: 47 additions & 11 deletions relayer/naive-strategy.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package relayer

import (
"encoding/hex"
"fmt"
"reflect"
"strconv"
"strings"

retry "github.com/avast/retry-go"
sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
chantypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types"
tmclient "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"golang.org/x/sync/errgroup"
)
Expand All @@ -18,17 +21,20 @@ var (
_ Strategy = &NaiveStrategy{}

// Strings for parsing events
spTag = "send_packet"
waTag = "write_acknowledgement"
srcChanTag = "packet_src_channel"
dstChanTag = "packet_dst_channel"
srcPortTag = "packet_src_port"
dstPortTag = "packet_dst_port"
dataTag = "packet_data"
ackTag = "packet_ack"
toHeightTag = "packet_timeout_height"
toTSTag = "packet_timeout_timestamp"
seqTag = "packet_sequence"
spTag = "send_packet"
waTag = "write_acknowledgement"
srcChanTag = "packet_src_channel"
dstChanTag = "packet_dst_channel"
srcPortTag = "packet_src_port"
dstPortTag = "packet_dst_port"
dataTag = "packet_data"
ackTag = "packet_ack"
toHeightTag = "packet_timeout_height"
toTSTag = "packet_timeout_timestamp"
seqTag = "packet_sequence"
updateCliTag = "update_client"
headerTag = "header"
clientIDTag = "client_id"
)

// NewNaiveStrategy returns the proper config for the NaiveStrategy
Expand Down Expand Up @@ -232,6 +238,36 @@ func (nrs *NaiveStrategy) UnrelayedAcknowledgements(src, dst *Chain) (*RelaySequ

// HandleEvents defines how the relayer will handle block and transaction events as they are emitted
func (nrs *NaiveStrategy) HandleEvents(src, dst *Chain, events map[string][]string) {
// check for misbehaviour
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
if hdrs, ok := events[fmt.Sprintf("%s.%s", updateCliTag, headerTag)]; ok {
for i, hdr := range hdrs {
clientIDs := events[fmt.Sprintf("%s.%s", updateCliTag, clientIDTag)]

if src.PathEnd.ClientID == clientIDs[i] && dst.PathEnd.ClientID == clientIDs[i] {
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
hdrBytes, err := hex.DecodeString(hdr)
if err == nil {
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
exportedHeader, err := clienttypes.UnmarshalHeader(src.Encoding.Marshaler, hdrBytes)
if err == nil {
gotHeader, ok := exportedHeader.(*tmclient.Header)
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
if ok {
trustedHeader, err := src.GetLatestLightHeader()
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
if err == nil && !reflect.DeepEqual(gotHeader, trustedHeader) {
misbehaviour := tmclient.NewMisbehaviour(clientIDs[i], gotHeader, trustedHeader)
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
msg, err := clienttypes.NewMsgSubmitMisbehaviour(clientIDs[i], misbehaviour, src.MustGetAddress())
if err == nil {
_, _, _ = src.SendMsg(msg)
}
}
}
}

} else {
src.Error(err)
}
}
}
}

colin-axner marked this conversation as resolved.
Show resolved Hide resolved
rlyPackets, err := relayPacketsFromEventListener(src.PathEnd, dst.PathEnd, events)
if len(rlyPackets) > 0 && err == nil {
nrs.sendTxFromEventPackets(src, dst, rlyPackets)
Expand Down