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

feat: update respective wasm client based on message sent from icon #193

Merged
merged 7 commits into from
Nov 24, 2023
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
5 changes: 3 additions & 2 deletions relayer/chains/icon/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ func (h IconIBCHeader) ConsensusState() ibcexported.ConsensusState {
}
return &icon.ConsensusState{}
}
func (h IconIBCHeader) ShouldUpdateWithZeroMessage() bool {
if h.Header != nil && h.Header.MessageCount == 0 {

func (h IconIBCHeader) ShouldUpdateForProofContextChange() bool {
if h.Header != nil && h.Header.NextProofContext != nil {
return true
}
return false
Expand Down
2 changes: 1 addition & 1 deletion relayer/chains/penumbra/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (h PenumbraIBCHeader) IsCompleteBlock() bool {
return true
}

func (h PenumbraIBCHeader) ShouldUpdateWithZeroMessage() bool {
func (h PenumbraIBCHeader) ShouldUpdateForProofContextChange() bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion relayer/chains/wasm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (a WasmIBCHeader) NextValidatorsHash() []byte {
return a.SignedHeader.Header.NextValidatorsHash
}

func (a WasmIBCHeader) ShouldUpdateWithZeroMessage() bool {
func (a WasmIBCHeader) ShouldUpdateForProofContextChange() bool {
return false
}

Expand Down
74 changes: 70 additions & 4 deletions relayer/processor/path_end_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,6 @@ func (pathEnd *pathEndRuntime) mergeCacheData(ctx context.Context, cancel func()
pathEnd.latestHeader = d.LatestHeader
pathEnd.clientState = d.ClientState

if pathEnd.chainProvider.Type() == common.IconModule && d.LatestHeader.IsCompleteBlock() {
pathEnd.BTPHeightQueue.Enqueue(BlockInfoHeight{Height: int64(d.LatestHeader.Height()), IsProcessing: false})
}

terminate, err := pathEnd.checkForMisbehaviour(ctx, pathEnd.clientState, counterParty)
if err != nil {
pathEnd.log.Error(
Expand Down Expand Up @@ -424,10 +420,80 @@ func (pathEnd *pathEndRuntime) mergeCacheData(ctx context.Context, cancel func()

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

pathEnd.updateBTPQueue(d, counterpartyChainID)

pathEnd.ibcHeaderCache.Merge(d.IBCHeaderCache) // Update latest IBC header state
pathEnd.ibcHeaderCache.Prune(ibcHeadersToCache) // Only keep most recent IBC headers
}

// handle update for icon btp blocks.
// When btp blocks are produced, forward them only to chain which the message is directed for.
// However, when proof context changes, update has to be sent
func (pathEnd *pathEndRuntime) updateBTPQueue(d ChainProcessorCacheData, counterpartyChainID string) {
if pathEnd.chainProvider.Type() != common.IconModule {
return
}

btpHeightKey := BlockInfoHeight{Height: int64(d.LatestHeader.Height()), IsProcessing: false}
if d.LatestHeader.ShouldUpdateForProofContextChange() {
pathEnd.BTPHeightQueue.Enqueue(btpHeightKey)
return
}

for k := range d.IBCMessagesCache.PacketFlow {
ck := ChannelKey{
ChannelID: k.ChannelID,
PortID: k.PortID,
CounterpartyChannelID: k.CounterpartyChannelID,
CounterpartyPortID: k.CounterpartyPortID,
}

if pathEnd.channelStateCache[ck] && d.LatestHeader.IsCompleteBlock() {

pathEnd.log.Info("This packet message is directed",
zap.String("to", counterpartyChainID),
zap.Uint64("height", d.LatestHeader.Height()),
)
if !pathEnd.BTPHeightQueue.ItemExist(btpHeightKey) {
pathEnd.BTPHeightQueue.Enqueue(btpHeightKey)
return
}
}
}

// handle for connection handshake
for _, v := range d.IBCMessagesCache.ConnectionHandshake {
for k := range v {
if k.ClientID == pathEnd.info.ClientID {
pathEnd.log.Info("This connection handshake message is directed",
zap.String("to", counterpartyChainID),
zap.Uint64("height", d.LatestHeader.Height()),
)
if !pathEnd.BTPHeightQueue.ItemExist(btpHeightKey) {
pathEnd.BTPHeightQueue.Enqueue(btpHeightKey)
return
}
}
}
}

// handle for channel handshake
for _, v := range d.IBCMessagesCache.ChannelHandshake {
for _, x := range v {
if pathEnd.isRelevantConnection(x.ConnID) {
pathEnd.log.Info("This channel handshake message is directed",
zap.String("to", counterpartyChainID),
zap.Uint64("height", d.LatestHeader.Height()),
)
if !pathEnd.BTPHeightQueue.ItemExist(btpHeightKey) {
pathEnd.BTPHeightQueue.Enqueue(btpHeightKey)
return
}
}
}
}
}

// shouldSendPacketMessage determines if the packet flow message should be sent now.
// It will also determine if the message needs to be given up on entirely and remove retention if so.
func (pathEnd *pathEndRuntime) shouldSendPacketMessage(message packetIBCMessage, counterparty *pathEndRuntime) bool {
Expand Down
2 changes: 1 addition & 1 deletion relayer/processor/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (h mockIBCHeader) Height() uint64 { return 0 }
func (h mockIBCHeader) ConsensusState() ibcexported.ConsensusState { return nil }
func (h mockIBCHeader) NextValidatorsHash() []byte { return nil }
func (h mockIBCHeader) IsCompleteBlock() bool { return true }
func (h mockIBCHeader) ShouldUpdateWithZeroMessage() bool { return false }
func (h mockIBCHeader) ShouldUpdateForProofContextChange() bool { return false }

func TestIBCHeaderCachePrune(t *testing.T) {
cache := make(processor.IBCHeaderCache)
Expand Down
6 changes: 3 additions & 3 deletions relayer/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ type IBCHeader interface {
Height() uint64
ConsensusState() ibcexported.ConsensusState
NextValidatorsHash() []byte
IsCompleteBlock() bool //defined for IconIBCHeader
ShouldUpdateWithZeroMessage() bool //defined for IconIBCHeader
IsCompleteBlock() bool //defined for IconIBCHeader
ShouldUpdateForProofContextChange() bool //defined for IconIBCHeader
}

// ClientState holds the current state of a client from a single chain's perspective
Expand Down Expand Up @@ -553,7 +553,7 @@ func (h TendermintIBCHeader) ConsensusState() ibcexported.ConsensusState {
func (h TendermintIBCHeader) IsCompleteBlock() bool {
return true
}
func (h TendermintIBCHeader) ShouldUpdateWithZeroMessage() bool {
func (h TendermintIBCHeader) ShouldUpdateForProofContextChange() bool {
return false
}

Expand Down
Loading