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

02-client refactor: add CheckForMisbehaviour & UpdateOnMisbehaviour fns #1116

Conversation

seantking
Copy link
Contributor

Description

Merging into #1115.

  • Adding CheckForMisbehaviour and UpdateOnMisbehaviour functions
  • Using helper functions in both CheckForMisbehaviourAndUpdateState and CheckHeaderAndUpdateState.

partially closes: #879


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

func (cs ClientState) CheckForMisbehaviour(
ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore,
msg exported.ClientMessage,
) (bool, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning an optional error here to allow for more fine-grained error handling (see Misbehaviour section). Not sure if this is golang best practice.

I think it would be good to sync on our function signatures for these new functions @damiannolan @colin-axner @AdityaSripal

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VerifyClientMessage should return the error. We can panic here (as that implies VerifyClientMessage wasn't called first)

@codecov-commenter
Copy link

Codecov Report

Merging #1116 (579e9f0) into sean/issue#879-rename-check-validity-verify-header (b76e338) will increase coverage by 0.02%.
The diff coverage is 90.16%.

Impacted file tree graph

@@                                  Coverage Diff                                   @@
##           sean/issue#879-rename-check-validity-verify-header    #1116      +/-   ##
======================================================================================
+ Coverage                                               79.72%   79.75%   +0.02%     
======================================================================================
  Files                                                     151      151              
  Lines                                                   10899    10914      +15     
======================================================================================
+ Hits                                                     8689     8704      +15     
  Misses                                                   1786     1786              
  Partials                                                  424      424              
Impacted Files Coverage Δ
...odules/light-clients/07-tendermint/types/update.go 84.16% <89.47%> (-0.58%) ⬇️
...clients/07-tendermint/types/misbehaviour_handle.go 86.66% <100.00%> (+6.33%) ⬆️

@seantking seantking mentioned this pull request Mar 13, 2022
3 tasks

// UpdateStateOnMisbehaviour updates state upon misbehaviour. This method should only be called on misbehaviour
// as it does not perform any misbehaviour checks.
func (cs ClientState) UpdateStateOnMisbehaviour(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized we should probably refactor the tests as well so there's a specific test for these new functions. (I noticed coverage actually went up somehow with the refactor though :-) )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there should be unit tests for each function we add

func (cs ClientState) CheckForMisbehaviour(
ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore,
msg exported.ClientMessage,
) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VerifyClientMessage should return the error. We can panic here (as that implies VerifyClientMessage wasn't called first)


// UpdateStateOnMisbehaviour updates state upon misbehaviour. This method should only be called on misbehaviour
// as it does not perform any misbehaviour checks.
func (cs ClientState) UpdateStateOnMisbehaviour(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there should be unit tests for each function we add

}
foundMisbehaviour, err := cs.CheckForMisbehaviour(ctx, cdc, clientStore, tmMisbehaviour)
if foundMisbehaviour {
return nil, err
}

if err := cs.ValidateClientMessage(ctx, clientStore, cdc, nil, misbehaviour, ctx.BlockTime()); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VerifyClientMessage will be occurring before CheckForMisbehaviour. It doesn't matter though since we will delete this function

if tmMisbehaviour.Header1.GetHeight().EQ(tmMisbehaviour.Header2.GetHeight()) {
blockID1, err := tmtypes.BlockIDFromProto(&tmMisbehaviour.Header1.SignedHeader.Commit.BlockID)
if err != nil {
return true, sdkerrors.Wrap(err, "invalid block ID from header 1 in misbehaviour")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the bool should be false here

@seantking seantking changed the base branch from sean/issue#879-rename-check-validity-verify-header to 02-client-refactor March 21, 2022 13:32
@seantking seantking requested a review from damiannolan as a code owner March 21, 2022 13:32
@seantking seantking changed the base branch from 02-client-refactor to sean/issue#879-rename-check-validity-verify-header March 21, 2022 13:33
@seantking seantking closed this Mar 22, 2022
@seantking seantking deleted the sean/issue#879-add-check-for-misbehaviour-fn branch August 3, 2022 13:59
CosmosCar pushed a commit to caelus-labs/ibc-go that referenced this pull request Nov 6, 2023
<!--
Please read and fill out this form before submitting your PR.

Please make sure you have reviewed our contributors guide before
submitting your
first PR.
-->

## Overview
There was a potential deadlock for a channel capacity of zero. This code
removes that deadlock and adds a comment explaining the code more.

Related to cosmos#1069 

<!-- 
Please provide an explanation of the PR, including the appropriate
context,
background, goal, and rationale. If there is an issue with this
information,
please provide a tl;dr and link the issue. 
-->

## Checklist

<!-- 
Please complete the checklist to ensure that the PR is ready to be
reviewed.

IMPORTANT:
PRs should be left in Draft until the below checklist is completed.
-->

- [ ] New and updated code has appropriate documentation
- [ ] New and updated code has new and/or updated testing
- [ ] Required CI checks are passing
- [ ] Visual proof for any user facing features like CLI or
documentation updates
- [ ] Linked issues closed with keywords
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants