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

fix: Observed Packet Metric #1345

Merged
merged 9 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
5 changes: 3 additions & 2 deletions interchaintest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ require (
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b // indirect
github.com/minio/highwayhash v1.0.2 // indirect
Expand Down Expand Up @@ -213,13 +212,15 @@ require (
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/rs/cors v1.8.3 // indirect
github.com/rs/zerolog v1.31.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.17.0 // indirect
github.com/strangelove-ventures/cometbft v0.37.3-0.20231004194858-c01e8d5bcac3 // indirect
Expand Down
209 changes: 37 additions & 172 deletions interchaintest/go.sum

Large diffs are not rendered by default.

24 changes: 0 additions & 24 deletions relayer/processor/path_end.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,3 @@ func (pe PathEnd) shouldRelayChannelSingle(channelKey ChainChannelKey, listChann
}
return !allowList
}

// if port ID is empty on allowlist channel, allow all ports
// if port ID is non-empty on allowlist channel, allow only that specific port
// if port ID is empty on blocklist channel, block all ports
// if port ID is non-empty on blocklist channel, block only that specific port
func (pe PathEnd) ShouldRelayChannel(channelKey ChainChannelKey) bool {
if pe.Rule == RuleAllowList {
for _, allowedChannel := range pe.FilterList {
if pe.shouldRelayChannelSingle(channelKey, allowedChannel, true) {
return true
}
}
return false
} else if pe.Rule == RuleDenyList {
for _, blockedChannel := range pe.FilterList {
if !pe.shouldRelayChannelSingle(channelKey, blockedChannel, false) {
return false
}
}
return true
}
// if neither allow list or block list are provided, all channels are okay
return true
}
46 changes: 44 additions & 2 deletions relayer/processor/path_end_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type pathEndRuntime struct {
clientTrustedState provider.ClientTrustedState
connectionStateCache ConnectionStateCache
channelStateCache ChannelStateCache
channelStateCacheMu sync.RWMutex
channelOrderCache map[string]chantypes.Order
latestHeader provider.IBCHeader
ibcHeaderCache IBCHeaderCache
Expand Down Expand Up @@ -107,7 +108,7 @@ func (pathEnd *pathEndRuntime) mergeMessageCache(messageCache IBCMessagesCache,
clientICQMessages := make(ClientICQMessagesCache)

for ch, pmc := range messageCache.PacketFlow {
if pathEnd.info.ShouldRelayChannel(ChainChannelKey{ChainID: pathEnd.info.ChainID, CounterpartyChainID: counterpartyChainID, ChannelKey: ch}) {
if pathEnd.ShouldRelayChannel(ChainChannelKey{ChainID: pathEnd.info.ChainID, CounterpartyChainID: counterpartyChainID, ChannelKey: ch}) {
if inSync && pathEnd.metrics != nil {
for eventType, pCache := range pmc {
pathEnd.metrics.AddPacketsObserved(pathEnd.info.PathName, pathEnd.info.ChainID, ch.ChannelID, ch.PortID, eventType, len(pCache))
Expand Down Expand Up @@ -403,7 +404,10 @@ func (pathEnd *pathEndRuntime) mergeCacheData(ctx context.Context, cancel func()
}

pathEnd.connectionStateCache = d.ConnectionStateCache // Update latest connection open state for chain
pathEnd.channelStateCache = d.ChannelStateCache // Update latest channel open state for chain

pathEnd.channelStateCacheMu.Lock()
pathEnd.channelStateCache = d.ChannelStateCache // Update latest channel open state for chain
pathEnd.channelStateCacheMu.Unlock()

pathEnd.mergeMessageCache(d.IBCMessagesCache, counterpartyChainID, pathEnd.inSync && counterpartyInSync) // Merge incoming packet IBC messages into the backlog

Expand Down Expand Up @@ -874,3 +878,41 @@ func (pathEnd *pathEndRuntime) localhostSentinelProofChannel(
Version: info.Version,
}, nil
}

boojamya marked this conversation as resolved.
Show resolved Hide resolved
// if channel ID is non-empty on allowlist, allow only specified channel(s)
// if channel ID is non-empty on denylist, deny specified channel(s)

// if port ID is empty on allowlist channel, allow all ports
// if port ID is non-empty on allowlist channel, allow only that specific port
// if port ID is empty on denylist channel, block all ports
// if port ID is non-empty on denylist channel, block only that specific port

// if no filter rule, allow all channels but ensure channels are relevant to the pathEndRuntime,
// ie, the channel is relevant to a src<->dest chain in the path section of the relayer config
func (pathEnd *pathEndRuntime) ShouldRelayChannel(chainChannelKey ChainChannelKey) bool {
pe := pathEnd.info
if pe.Rule == RuleAllowList {
for _, allowedChannel := range pe.FilterList {
if pe.shouldRelayChannelSingle(chainChannelKey, allowedChannel, true) {
return true
}
}
return false
} else if pe.Rule == RuleDenyList {
for _, blockedChannel := range pe.FilterList {
if !pe.shouldRelayChannelSingle(chainChannelKey, blockedChannel, false) {
return false
}
}
return true
}

pathEnd.channelStateCacheMu.RLock()
defer pathEnd.channelStateCacheMu.RUnlock()

// if no filter rule, check if the channel or counterparty channel is in the channelStateCache.
// Because channelStateCache only holds channels relevant to the client, we can ensure that the
// channel is built on top of a client for this pathEnd
_, exists := pathEnd.channelStateCache[chainChannelKey.ChannelKey]
return exists
}
Loading
Loading