Skip to content

Commit

Permalink
fix: nil pointer expection issue for wasm header (#195)
Browse files Browse the repository at this point in the history
* fix: memory leak issue

* fix: latest header cannot be nil

---------

Co-authored-by: viveksharmapoudel <[email protected]>
  • Loading branch information
izyak and viveksharmapoudel authored Nov 24, 2023
1 parent bb0a2e4 commit 7c51b1c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
3 changes: 1 addition & 2 deletions relayer/chains/icon/icon_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,6 @@ func (icp *IconChainProcessor) monitoring(ctx context.Context, persistence *quer
ctxMonitorBlock, cancelMonitorBlock := context.WithCancel(ctx)
reconnect()

ibcHeaderCache := make(processor.IBCHeaderCache)

icp.firstTime = true

blockReq := &types.BlockRequest{
Expand Down Expand Up @@ -368,6 +366,7 @@ loop:
icp.handleMessage(ctx, *m, ibcMessageCache)
}

ibcHeaderCache := make(processor.IBCHeaderCache)
ibcHeaderCache[uint64(br.Height)] = br.Header
icp.log.Debug("Queried block ",
zap.Int64("height", br.Height))
Expand Down
14 changes: 12 additions & 2 deletions relayer/chains/wasm/wasm_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ func (ccp *WasmChainProcessor) queryCycle(ctx context.Context, persistence *quer
var eg errgroup.Group
var blockRes *ctypes.ResultBlockResults
var lightBlock *types.LightBlock
var h provider.IBCHeader
i := i
eg.Go(func() (err error) {
queryCtx, cancelQueryCtx := context.WithTimeout(ctx, blockResultsQueryTimeout)
Expand All @@ -426,7 +427,7 @@ func (ccp *WasmChainProcessor) queryCycle(ctx context.Context, persistence *quer
eg.Go(func() (err error) {
queryCtx, cancelQueryCtx := context.WithTimeout(ctx, queryTimeout)
defer cancelQueryCtx()
latestHeader, lightBlock, err = ccp.chainProvider.QueryLightBlock(queryCtx, i)
h, lightBlock, err = ccp.chainProvider.QueryLightBlock(queryCtx, i)
return err
})

Expand All @@ -435,6 +436,15 @@ func (ccp *WasmChainProcessor) queryCycle(ctx context.Context, persistence *quer
break
}

ccp.log.Debug(
"Queried block",
zap.Int64("height", i),
zap.Int64("latest", persistence.latestHeight),
zap.Int64("delta", persistence.latestHeight-i),
)

latestHeader = h

if err := ccp.Verify(ctx, lightBlock); err != nil {
ccp.log.Warn("Failed to verify block", zap.Int64("height", blockRes.Height), zap.Error(err))
return err
Expand Down Expand Up @@ -550,7 +560,7 @@ func (ccp *WasmChainProcessor) Verify(ctx context.Context, untrusted *types.Ligh
untrusted.ValidatorSet,
ccp.verifier.Header.SignedHeader,
time.Now(), 0); err != nil {
return fmt.Errorf("Failed to verify Header: %v", err)
return fmt.Errorf("failed to verify Header: %v", err)
}

if !bytes.Equal(untrusted.Header.ValidatorsHash, ccp.verifier.Header.NextValidatorsHash) {
Expand Down
10 changes: 7 additions & 3 deletions relayer/processor/message_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,12 @@ func (mp *messageProcessor) sendClientUpdate(
msgs := []provider.RelayerMessage{mp.msgUpdateClient}

callback := func(rtr *provider.RelayerTxResponse, err error) {
mp.log.Debug("Executing callback of sendClientUpdate",
zap.Any("response", rtr),
zap.Uint64("last_client_update_height", dst.lastClientUpdateHeight))
if rtr != nil {
mp.log.Debug("Executing callback of sendClientUpdate",
zap.Any("response", rtr),
zap.Uint64("last_client_update_height", dst.lastClientUpdateHeight),
zap.Error(err))
}
if IsBTPLightClient(dst.clientState) {
if src.BTPHeightQueue.Size() == 0 {
return
Expand Down Expand Up @@ -484,6 +487,7 @@ func (mp *messageProcessor) sendClientUpdate(
zap.String("dst_client_id", dst.info.ClientID),
zap.Error(err),
)
callback(nil, err)
return
}
dst.log.Debug("Client update broadcast completed")
Expand Down

0 comments on commit 7c51b1c

Please sign in to comment.