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 to guarantee ack & timeout to be sccuess #23

Merged
merged 1 commit into from
Jun 14, 2024
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
49 changes: 36 additions & 13 deletions app/ibc-hooks/ack.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,42 @@
if !isEVMRouted || hookData.AsyncCallback == nil {
return nil
} else if err != nil {
return err
h.evmKeeper.Logger(ctx).Error("failed to parse memo", "error", err)
return nil

Check warning on line 31 in app/ibc-hooks/ack.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/ack.go#L30-L31

Added lines #L30 - L31 were not covered by tests
}

// create a new cache context to ignore errors during
// the execution of the callback
cacheCtx, write := ctx.CacheContext()

callback := hookData.AsyncCallback
if allowed, err := h.checkACL(im, ctx, callback.ContractAddress); err != nil {
return err
if allowed, err := h.checkACL(im, cacheCtx, callback.ContractAddress); err != nil {
h.evmKeeper.Logger(cacheCtx).Error("failed to check ACL", "error", err)
return nil

Check warning on line 41 in app/ibc-hooks/ack.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/ack.go#L40-L41

Added lines #L40 - L41 were not covered by tests
} else if !allowed {
// just return nil here to avoid packet stuck due to hook acl.
h.evmKeeper.Logger(cacheCtx).Error("failed to check ACL", "not allowed")
return nil
}

inputBz, err := h.asyncCallbackABI.Pack(functionNameAck, callback.Id, !isAckError(h.codec, acknowledgement))
if err != nil {
return err
h.evmKeeper.Logger(cacheCtx).Error("failed to pack input", "error", err)
return nil

Check warning on line 50 in app/ibc-hooks/ack.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/ack.go#L49-L50

Added lines #L49 - L50 were not covered by tests
}

_, err = h.execMsg(ctx, &evmtypes.MsgCall{
_, err = h.execMsg(cacheCtx, &evmtypes.MsgCall{
Sender: data.Sender,
ContractAddr: callback.ContractAddress,
Input: hexutil.Encode(inputBz),
})
if err != nil {
return err
h.evmKeeper.Logger(cacheCtx).Error("failed to execute callback", "error", err)
return nil

Check warning on line 60 in app/ibc-hooks/ack.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/ack.go#L59-L60

Added lines #L59 - L60 were not covered by tests
}

// write the cache context only if the callback execution was successful
write()

return nil
}

Expand All @@ -71,29 +82,41 @@
if !isEVMRouted || hookData.AsyncCallback == nil {
return nil
} else if err != nil {
return err
h.evmKeeper.Logger(ctx).Error("failed to parse memo", "error", err)
return nil

Check warning on line 86 in app/ibc-hooks/ack.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/ack.go#L85-L86

Added lines #L85 - L86 were not covered by tests
}

// create a new cache context to ignore errors during
// the execution of the callback
cacheCtx, write := ctx.CacheContext()

callback := hookData.AsyncCallback
if allowed, err := h.checkACL(im, ctx, callback.ContractAddress); err != nil {
return err
if allowed, err := h.checkACL(im, cacheCtx, callback.ContractAddress); err != nil {
h.evmKeeper.Logger(cacheCtx).Error("failed to check ACL", "error", err)
return nil

Check warning on line 96 in app/ibc-hooks/ack.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/ack.go#L95-L96

Added lines #L95 - L96 were not covered by tests
} else if !allowed {
h.evmKeeper.Logger(cacheCtx).Error("failed to check ACL", "not allowed")
return nil
}

inputBz, err := h.asyncCallbackABI.Pack(functionNameAck, callback.Id, !isAckError(h.codec, acknowledgement))
if err != nil {
return err
h.evmKeeper.Logger(cacheCtx).Error("failed to pack input", "error", err)
return nil

Check warning on line 105 in app/ibc-hooks/ack.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/ack.go#L104-L105

Added lines #L104 - L105 were not covered by tests
}

_, err = h.execMsg(ctx, &evmtypes.MsgCall{
_, err = h.execMsg(cacheCtx, &evmtypes.MsgCall{
Sender: data.Sender,
ContractAddr: callback.ContractAddress,
Input: hexutil.Encode(inputBz),
})
if err != nil {
return err
h.evmKeeper.Logger(cacheCtx).Error("failed to execute callback", "error", err)
return nil

Check warning on line 115 in app/ibc-hooks/ack.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/ack.go#L114-L115

Added lines #L114 - L115 were not covered by tests
}

// write the cache context only if the callback execution was successful
write()

return nil
}
49 changes: 36 additions & 13 deletions app/ibc-hooks/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,42 @@
if !isEVMRouted || hookData.AsyncCallback == nil {
return nil
} else if err != nil {
return err
h.evmKeeper.Logger(ctx).Error("failed to parse memo", "error", err)
return nil

Check warning on line 31 in app/ibc-hooks/timeout.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/timeout.go#L30-L31

Added lines #L30 - L31 were not covered by tests
}

// create a new cache context to ignore errors during
// the execution of the callback
cacheCtx, write := ctx.CacheContext()

callback := hookData.AsyncCallback
if allowed, err := h.checkACL(im, ctx, callback.ContractAddress); err != nil {
return err
if allowed, err := h.checkACL(im, cacheCtx, callback.ContractAddress); err != nil {
h.evmKeeper.Logger(cacheCtx).Error("failed to check ACL", "error", err)
return nil

Check warning on line 41 in app/ibc-hooks/timeout.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/timeout.go#L40-L41

Added lines #L40 - L41 were not covered by tests
} else if !allowed {
// just return nil here to avoid packet stuck due to hook acl.
h.evmKeeper.Logger(cacheCtx).Error("failed to check ACL", "not allowed")
return nil
}

inputBz, err := h.asyncCallbackABI.Pack(functionNameTimeout, callback.Id)
if err != nil {
return err
h.evmKeeper.Logger(cacheCtx).Error("failed to pack input", "error", err)
return nil

Check warning on line 50 in app/ibc-hooks/timeout.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/timeout.go#L49-L50

Added lines #L49 - L50 were not covered by tests
}

_, err = h.execMsg(ctx, &evmtypes.MsgCall{
_, err = h.execMsg(cacheCtx, &evmtypes.MsgCall{
Sender: data.Sender,
ContractAddr: callback.ContractAddress,
Input: hexutil.Encode(inputBz),
})
if err != nil {
return err
h.evmKeeper.Logger(cacheCtx).Error("failed to execute callback", "error", err)
return nil

Check warning on line 60 in app/ibc-hooks/timeout.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/timeout.go#L59-L60

Added lines #L59 - L60 were not covered by tests
}

// write the cache context only if the callback execution was successful
write()

return nil
}

Expand All @@ -70,29 +81,41 @@
if !isEVMRouted || hookData.AsyncCallback == nil {
return nil
} else if err != nil {
return err
h.evmKeeper.Logger(ctx).Error("failed to parse memo", "error", err)
return nil

Check warning on line 85 in app/ibc-hooks/timeout.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/timeout.go#L84-L85

Added lines #L84 - L85 were not covered by tests
}

// create a new cache context to ignore errors during
// the execution of the callback
cacheCtx, write := ctx.CacheContext()

Check warning on line 91 in app/ibc-hooks/timeout.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/timeout.go#L90-L91

Added lines #L90 - L91 were not covered by tests
callback := hookData.AsyncCallback
if allowed, err := h.checkACL(im, ctx, callback.ContractAddress); err != nil {
return err
if allowed, err := h.checkACL(im, cacheCtx, callback.ContractAddress); err != nil {
h.evmKeeper.Logger(cacheCtx).Error("failed to check ACL", "error", err)
return nil

Check warning on line 95 in app/ibc-hooks/timeout.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/timeout.go#L93-L95

Added lines #L93 - L95 were not covered by tests
} else if !allowed {
h.evmKeeper.Logger(cacheCtx).Error("failed to check ACL", "not allowed")

Check warning on line 97 in app/ibc-hooks/timeout.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/timeout.go#L97

Added line #L97 was not covered by tests
return nil
}

inputBz, err := h.asyncCallbackABI.Pack(functionNameTimeout, callback.Id)
if err != nil {
return err
h.evmKeeper.Logger(cacheCtx).Error("failed to pack input", "error", err)
return nil

Check warning on line 104 in app/ibc-hooks/timeout.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/timeout.go#L103-L104

Added lines #L103 - L104 were not covered by tests
}

_, err = h.execMsg(ctx, &evmtypes.MsgCall{
_, err = h.execMsg(cacheCtx, &evmtypes.MsgCall{

Check warning on line 107 in app/ibc-hooks/timeout.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/timeout.go#L107

Added line #L107 was not covered by tests
Sender: data.Sender,
ContractAddr: callback.ContractAddress,
Input: hexutil.Encode(inputBz),
})
if err != nil {
return err
h.evmKeeper.Logger(cacheCtx).Error("failed to execute callback", "error", err)
return nil

Check warning on line 114 in app/ibc-hooks/timeout.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/timeout.go#L113-L114

Added lines #L113 - L114 were not covered by tests
}

// write the cache context only if the callback execution was successful
write()

Check warning on line 119 in app/ibc-hooks/timeout.go

View check run for this annotation

Codecov / codecov/patch

app/ibc-hooks/timeout.go#L118-L119

Added lines #L118 - L119 were not covered by tests
return nil
}
Loading