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

imp: remove timestamp from consensusState and query contract to retrieve it #4034

Conversation

crodriguezvega
Copy link
Contributor

@crodriguezvega crodriguezvega commented Jul 7, 2023

Description

Still work in progress, since we need new versions of the contracts supporting the query to get the timestamp at a certain height. Tests are expected to fail.

closes: #3957

Commit Message / Changelog Entry

type: commit message

see the guidelines for commit messages. (view raw markdown for examples)


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 and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

Comment on lines 42 to 55
type metadataQueryResponse struct {
contractResult
GenesisMetadata []clienttypes.GenesisMetadata `json:"genesis_metadata"`
}

type timestampAtHeightQueryResponse struct {
contractResult
Timestamp uint64 `json:"timestamp"`
}

type CheckForMisbehaviourExecuteResult struct {
contractResult
FoundMisbehaviour bool `json:"found_misbehaviour"`
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added these types for the different query results that we obtain.

}

// wasmQuery queries the contract with the given payload and writes the result to output.
func wasmQuery[T ContractResult](ctx sdk.Context, clientStore sdk.KVStore, cs *ClientState, payload any) (T, error) {
Copy link
Contributor Author

@crodriguezvega crodriguezvega Jul 9, 2023

Choose a reason for hiding this comment

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

I added this function (which is very similar to call above) to wrap the query call to the contract. Since the query (still to be added) to return the timestamp at a certain height (with payload of type timestampAtHeightQueryResponse) might return an error if there's no consensus at that given height, I thought that we can also check the result and wrap the error if there's any.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to named this function like this and not query, because query conflicted with another function defined in a package in the SDK that is also in scope. I will probably rename call above to wasmExecute, for consistency.

modules/light-clients/08-wasm/types/client_state.go Outdated Show resolved Hide resolved
@@ -24,15 +22,11 @@ func (cs ConsensusState) ClientType() string {

// GetTimestamp returns block time in nanoseconds of the header that created consensus state.
func (cs ConsensusState) GetTimestamp() uint64 {
return cs.Timestamp
return 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we query the contract in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, the idea is that we will mark this function as deprecated, since it is only used in the light clients, so it doesn't need to be part of the ConsensusState interface. In the meantime, until we remove it, we will just return 0.

crodriguezvega and others added 4 commits July 21, 2023 22:31
* Use hasConsensusState instead of GetConsensusState.
* Use wasmQuery for the rest of the query functions.

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
…om-consensusstate-and-query-contract-to-retrieve-it
Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

Leaving my approval, left some suggestions 👍

Comment on lines +90 to +97
type (
timestampAtHeightInnerPayload struct {
Height exported.Height `json:"height"`
}
timestampAtHeightPayload struct {
TimestampAtHeight timestampAtHeightInnerPayload `json:"timestamp_at_height"`
}
)
Copy link
Member

Choose a reason for hiding this comment

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

this is also superseded by #4133, right?

I'd like to not use type blocks, e.g.:

type (
    someType struct {}

    someOtherType struct {}
)

instead:

type someType struct {}

type someOtherType struct {}

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 for my own understanding: what's wrong with type blocks?

Copy link
Member

Choose a reason for hiding this comment

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

@chatton doesn't like them! 😆

I think I have similar feelings!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I don't want to get @chatton angry, so...

modules/light-clients/08-wasm/types/client_state.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/types/client_state.go Outdated Show resolved Hide resolved

// wasmQuery queries the contract with the given payload and writes the result to output.
func wasmQuery[T ContractResult](ctx sdk.Context, clientStore sdk.KVStore, cs *ClientState, payload any) (T, error) {
var output T
Copy link
Member

Choose a reason for hiding this comment

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

is this output, result, or response?

I see these three different terms being used interchangeably in a lot of places, we be good to standardise on one.
I'm happy enough with result / ContractResult, response or ContractResponse is also fine imo! :)

Copy link
Contributor Author

@crodriguezvega crodriguezvega Aug 1, 2023

Choose a reason for hiding this comment

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

Did some renaming.

Timestamp uint64 `json:"timestamp"`
}

type checkForMisbehaviourExecuteResult struct {
Copy link
Member

Choose a reason for hiding this comment

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

this should be checkForMisbehaviourReponse or? how come the different naming?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed as well.

Comment on lines +37 to +50
type statusQueryResponse struct {
contractResult
Status exported.Status `json:"status"`
}

type metadataQueryResponse struct {
contractResult
GenesisMetadata []clienttypes.GenesisMetadata `json:"genesis_metadata"`
}

type timestampAtHeightQueryResponse struct {
contractResult
Timestamp uint64 `json:"timestamp"`
}
Copy link
Member

Choose a reason for hiding this comment

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

In #4133 all the contract payload types are in msgs.go right? Should these be included alongside them?

Even tho they are unexported, would be nice to have basic godocs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add them in #4133.

modules/light-clients/08-wasm/types/store.go Outdated Show resolved Hide resolved
DimitrisJim and others added 6 commits August 1, 2023 13:25
* Add linting for 08-wasm.

* Go mod tidy.

* Please the linter.
* add 08-wasm global store key

* Update client_state.go

* Update modules/light-clients/08-wasm/types/vm.go

Co-authored-by: Jim Fasarakis-Hilliard <d.f.hilliard@gmail.com>

---------

Co-authored-by: Jim Fasarakis-Hilliard <d.f.hilliard@gmail.com>
…om-consensusstate-and-query-contract-to-retrieve-it
@crodriguezvega crodriguezvega merged commit 644367f into feat/wasm-clients Aug 1, 2023
20 of 21 checks passed
@crodriguezvega crodriguezvega deleted the carlos/3957-remove-timestamp-from-consensusstate-and-query-contract-to-retrieve-it branch August 1, 2023 12:28
@faddat faddat mentioned this pull request Sep 10, 2023
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants