Skip to content

Commit

Permalink
fix: query packet height based on fixed duration
Browse files Browse the repository at this point in the history
  • Loading branch information
viveksharmapoudel committed Sep 12, 2023
1 parent fc991ed commit 2cf0a6c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
3 changes: 3 additions & 0 deletions relayer/processor/path_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ const (
// made to retrieve the client consensus state in order to assemble a
// MsgUpdateClient message.
clientConsensusHeightUpdateThresholdBlocks = 2

// Needed for finding trusting block one week
defaultTrustingPeriod = 7 * 24 * time.Hour
)

// PathProcessor is a process that handles incoming IBC messages from a pair of chains.
Expand Down
16 changes: 12 additions & 4 deletions relayer/processor/path_processor_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"sort"
"sync"
"time"

clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
conntypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
Expand Down Expand Up @@ -1708,11 +1709,18 @@ func QueryPacketHeights(
}

Check warning on line 1709 in relayer/processor/path_processor_internal.go

View check run for this annotation

Codecov / codecov/patch

relayer/processor/path_processor_internal.go#L1702-L1709

Added lines #L1702 - L1709 were not covered by tests

startSeq := uint64(0)
if dst.clientState.TrustingPeriodBlock > 0 {
startSeq, err = src.chainProvider.QueryNextSeqSend(ctx, int64(src.latestBlock.Height)-dst.clientState.TrustingPeriodBlock, k.ChannelID, k.PortID)
if err != nil {
return err
if src.chainProvider.ProviderConfig().GetBlockInterval() > 0 {
// blockInterval from provider config will be in milliseconds
blockInterval := int64(src.chainProvider.ProviderConfig().GetBlockInterval()) * int64(time.Millisecond)
startBlock := int64(src.latestBlock.Height) - defaultTrustingPeriod.Nanoseconds()/blockInterval
if startBlock > 0 {
startSeq, err = src.chainProvider.QueryNextSeqSend(ctx, startBlock, k.ChannelID, k.PortID)
if err != nil {
// don't care about error here,
// if error start from startSeq 0
}

Check warning on line 1721 in relayer/processor/path_processor_internal.go

View check run for this annotation

Codecov / codecov/patch

relayer/processor/path_processor_internal.go#L1711-L1721

Added lines #L1711 - L1721 were not covered by tests
}

}

c, err := src.chainProvider.QueryPacketHeights(ctx, int64(src.latestBlock.Height), k.ChannelID, k.PortID, startSeq, endSeq)
Expand Down
11 changes: 5 additions & 6 deletions relayer/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ type IBCHeader interface {

// ClientState holds the current state of a client from a single chain's perspective
type ClientState struct {
ClientID string
ConsensusHeight clienttypes.Height
TrustingPeriod time.Duration // trustring period wont be there in ICON client state
ConsensusTime time.Time // consensus time wont be there in ICON light client State
Header []byte //
TrustingPeriodBlock int64
ClientID string
ConsensusHeight clienttypes.Height
TrustingPeriod time.Duration // trustring period wont be there in ICON client state
ConsensusTime time.Time // consensus time wont be there in ICON light client State
Header []byte //
}

// ClientTrustedState holds the current state of a client from the perspective of both involved chains,
Expand Down

0 comments on commit 2cf0a6c

Please sign in to comment.