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

Implement Height interface in core IBC #7211

Merged
merged 34 commits into from
Sep 3, 2020
Merged

Conversation

AdityaSripal
Copy link
Member

@AdityaSripal AdityaSripal commented Aug 31, 2020

Description

Part 2 of #6531


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

@AdityaSripal AdityaSripal marked this pull request as draft August 31, 2020 21:07
@AdityaSripal AdityaSripal changed the title Start implementing Height interface in core IBC Implement Height interface in core IBC Aug 31, 2020
@jackzampolin
Copy link
Member

jackzampolin commented Sep 1, 2020

This PR is blocking continued progress on the relayer

@jackzampolin jackzampolin marked this pull request as ready for review September 1, 2020 21:21
@AdityaSripal AdityaSripal marked this pull request as draft September 1, 2020 21:44
@@ -72,13 +77,16 @@ to the counterparty channel. Any timeout set to 0 is disabled.`),
// if the timeouts are not absolute, retrieve latest block height and block timestamp
// for the consensus state connected to the destination port/channel
if !absoluteTimeouts {
consensusState, _, err := channelutils.QueryCounterpartyConsensusState(clientCtx, srcPort, srcChannel, uint64(clientCtx.Height))
consensusState, _, err := channelutils.QueryLatestConsensusState(clientCtx, srcPort, srcChannel)
Copy link
Member Author

Choose a reason for hiding this comment

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

This was incorrect, we cannot query consensus state with a consensus height using our own block height

if err != nil {
return err
}

proofHeight := uint64(clientCtx.Height)
Copy link
Member Author

Choose a reason for hiding this comment

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

This was incorrect, cannot retrieve proofHeight/consensusHeight from our own context

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for fixing these, most of the cli code is broken and we can address anything else in a final refactor of it

if err != nil {
return err
}

proofHeight := uint64(clientCtx.Height)
Copy link
Member Author

Choose a reason for hiding this comment

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

ditto

x/ibc/04-channel/exported/exported.go Outdated Show resolved Hide resolved
@jackzampolin
Copy link
Member

Quick Q on the height interface... How do I get the height number out of it?

@colin-axner
Copy link
Contributor

Quick Q on the height interface... How do I get the height number out of it?

cast to the height concrete type and use height.EpochHeight. The interface is just there because we use exported.go files, we plan to enforce usage of the concrete type only by not using Any.

@AdityaSripal AdityaSripal marked this pull request as ready for review September 2, 2020 23:48
Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

Fantastic work !!! Glad to see this is finally ready to be merged! 🎉

left some small nits, but nothing needs to be addressed now. In a followup pr or at some point in the future is fine

proto/ibc/channel/query.proto Show resolved Hide resolved
x/ibc-transfer/client/cli/tx.go Show resolved Hide resolved
x/ibc/02-client/client/cli/query.go Outdated Show resolved Hide resolved
x/ibc/02-client/types/height_test.go Show resolved Hide resolved
x/ibc/02-client/types/height.go Show resolved Hide resolved
x/ibc/02-client/client/utils/utils.go Outdated Show resolved Hide resolved
version.AppName, host.ModuleName, types.SubModuleName,
),
Args: cobra.ExactArgs(10),
Args: cobra.ExactArgs(12),
Copy link
Contributor

Choose a reason for hiding this comment

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

lmao the usability of entering 12 arguments by command line 👀 My hot take is IBC should drop support for doing handshakes by CLI. I'd rather just leave this to relayers

Copy link
Contributor

Choose a reason for hiding this comment

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

hehe, this is probably reasonable, although it has been convenient for testing

x/ibc/04-channel/types/packet.go Show resolved Hide resolved
Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

Still have 40+ files left to review

proto/ibc/connection/query.proto Show resolved Hide resolved
x/ibc/02-client/client/utils/utils.go Outdated Show resolved Hide resolved
x/ibc/02-client/keeper/client.go Outdated Show resolved Hide resolved
testConnectionID = "connectionid"
testChannelID = "testchannelid"
testPortID = "testportid"
)

var (
prefix = commitmenttypes.NewMerklePrefix([]byte("ibc"))
prefix = commitmenttypes.NewMerklePrefix([]byte("ibc"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we define this in ibctesting?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can just use chain.GetPrefix()

x/ibc/spec/01_concepts.md Outdated Show resolved Hide resolved
x/ibc/24-host/keys.go Show resolved Hide resolved
x/ibc/09-localhost/types/client_state.go Outdated Show resolved Hide resolved
@@ -152,7 +151,7 @@ func checkValidity(

// update the consensus state from a new header
func update(clientState *ClientState, header *Header) (*ClientState, *ConsensusState) {
height := clienttypes.NewHeight(0, header.GetHeight())
height := header.GetHeight().(clienttypes.Height)
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this validated somewhere? otherwise, it will panic

Copy link
Collaborator

Choose a reason for hiding this comment

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

if this is a Tendermint HeaderI would prefer to return the concrete type instead from the fields

Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

final review comments. Great work!

x/ibc/04-channel/client/utils/utils.go Show resolved Hide resolved
x/ibc/04-channel/keeper/grpc_query_test.go Show resolved Hide resolved
x/ibc/04-channel/client/utils/utils.go Outdated Show resolved Hide resolved
@@ -731,3 +732,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() {
})
}
}

func malleateHeight(height exported.Height, diff uint64) exported.Height {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we move this to ibctesting since it's reused on the handshakes?

x/ibc/04-channel/types/msgs.go Outdated Show resolved Hide resolved
x/ibc/07-tendermint/types/misbehaviour.go Show resolved Hide resolved
@colin-axner
Copy link
Contributor

it might be worthwhile to add a ZeroHeight() func to clientypes similar to sdk.ZeroInt()

@AdityaSripal
Copy link
Member Author

All the RPC request types must have the EpochNumber and EpochHeight split. This is because you cannot put a message type into the rpc get url. Thus, they need to be split up so that the rpc url can be constructed like this example:

https://github.com/cosmos/cosmos-sdk/blob/aditya/height-interface/proto/ibc/client/query.proto#L26

Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

ACK 👍

@fedekunze fedekunze merged commit 4f9e31e into master Sep 3, 2020
@fedekunze fedekunze deleted the aditya/height-interface branch September 3, 2020 20:23
Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

I think we need to think a bit about the misbehaviour handling logic (may also require minor spec updates). Otherwise great work.

version.AppName, host.ModuleName, types.SubModuleName,
),
Args: cobra.ExactArgs(10),
Args: cobra.ExactArgs(12),
Copy link
Contributor

Choose a reason for hiding this comment

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

hehe, this is probably reasonable, although it has been convenient for testing

}

// calculate the age of the misbehaviour
infractionHeight := tmMisbehaviour.GetHeight()
infractionHeight := tmMisbehaviour.GetHeight().(clienttypes.Height).EpochHeight
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I'm a little worried about this. Is it possible we could treat previously invalid evidence as valid again after an upgrade? I think we need to parse the epoch from the chain ID of the misbehaviour and check using the height comparator.

}

// calculate the age of the misbehaviour
infractionHeight := tmMisbehaviour.GetHeight()
infractionHeight := tmMisbehaviour.GetHeight().(clienttypes.Height).EpochHeight
infractionTime := tmMisbehaviour.GetTime()
ageDuration := ctx.BlockTime().Sub(infractionTime)
ageBlocks := int64(cs.LatestHeight.EpochHeight - infractionHeight)
Copy link
Contributor

Choose a reason for hiding this comment

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

ageBlocks can still be calculated by summing the differences across epochs

Copy link
Member Author

Choose a reason for hiding this comment

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

This would require knowing the last epoch height of each epoch, and having them easily retrievable from state

Copy link
Contributor

Choose a reason for hiding this comment

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

Aye, yes, never mind

@AdityaSripal
Copy link
Member Author

Good point @cwgoes . We want to have the ability to submit misbehaviour from a previous epoch without storing the last epoch height of each epoch and summing them up to find out an absolute difference in block heights.

Note that in the expiration check we have both a time check and a block check. We can retain both checks in the case where the misbehaviour epoch number and the client's current epoch are the same.

In cases where the misbehaviour epoch is less than the client epoch, we can rely solely on the time check which will still work across epochs even as the epoch heights reset.

This allows us to submit previous epoch misbehaviour without adding any more state in the client store to track last epoch-heights for each epoch

@AdityaSripal AdityaSripal mentioned this pull request Sep 3, 2020
9 tasks
@AdityaSripal AdityaSripal mentioned this pull request Sep 15, 2020
9 tasks
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.

5 participants