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

Static ClientState API #683

Merged
merged 137 commits into from
Jul 5, 2023
Merged

Static ClientState API #683

merged 137 commits into from
Jul 5, 2023

Conversation

plafer
Copy link
Contributor

@plafer plafer commented May 17, 2023

Closes: #296
Closes: #534
Closes: #614

Description

  • Finish implementation
  • Mock: put context implementations in separate files
  • Implement derive macros to reduce boilerplate for users
    • ClientState
    • ConsensusState
  • Integrate with basecoin-rs
  • Document why we need ClientExecutionContext
  • Tendermint LC: Add CommonContext as a supertrait to Validation/ExecutionContext
    • with method consensus_state(). All other ValidationContext methods are not needed in execution.
  • Write ADR
  • Document all new types and methods

PR author checklist:

  • Added changelog entry, using unclog.
  • Added tests.
  • Linked to GitHub issue.
  • Updated code comments and documentation (e.g., docs/).
  • Tagged one reviewer who will be the one responsible for shepherding this PR.

Reviewer checklist:

  • Reviewed Files changed in the GitHub PR explorer.
  • Manually tested (in case integration/unit/mock tests are absent).

@codecov
Copy link

codecov bot commented May 17, 2023

Codecov Report

Patch coverage: 83.86% and project coverage change: +0.88 🎉

Comparison is base (5ceaef3) 72.32% compared to head (0cb3657) 73.21%.

❗ Current head 0cb3657 differs from pull request most recent head ee4e888. Consider uploading reports for the commit ee4e888 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #683      +/-   ##
==========================================
+ Coverage   72.32%   73.21%   +0.88%     
==========================================
  Files         116      124       +8     
  Lines       15527    16101     +574     
==========================================
+ Hits        11230    11788     +558     
- Misses       4297     4313      +16     
Impacted Files Coverage Δ
crates/ibc/src/core/handler.rs 88.60% <ø> (-1.54%) ⬇️
crates/ibc/src/core/ics02_client/client_state.rs 0.00% <0.00%> (-78.95%) ⬇️
crates/ibc/src/core/ics03_connection/error.rs 7.69% <ø> (ø)
...src/core/ics04_channel/events/packet_attributes.rs 10.82% <ø> (+0.13%) ⬆️
.../src/core/ics04_channel/handler/acknowledgement.rs 94.39% <ø> (ø)
...c/core/ics04_channel/handler/chan_close_confirm.rs 97.57% <ø> (ø)
.../src/core/ics04_channel/handler/chan_close_init.rs 97.19% <ø> (ø)
...bc/src/core/ics04_channel/handler/chan_open_ack.rs 97.50% <ø> (ø)
...rc/core/ics04_channel/handler/chan_open_confirm.rs 97.70% <ø> (ø)
...c/src/core/ics04_channel/handler/chan_open_init.rs 96.34% <ø> (ø)
... and 37 more

... and 10 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@plafer plafer marked this pull request as ready for review June 14, 2023 13:28
Copy link
Member

@Farhad-Shabani Farhad-Shabani left a comment

Choose a reason for hiding this comment

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

Further to our discussions on this PR, I went over the changes once again and left a few questions to ensure some other parts of the design.

crates/ibc/src/core/context.rs Show resolved Hide resolved
crates/ibc/src/core/context.rs Outdated Show resolved Hide resolved
///
/// Note that the `Protobuf` trait in `tendermint-proto` provides convenience methods
/// to do this automatically.
fn encode_vec(&self) -> Result<Vec<u8>, tendermint_proto::Error>;
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't we go with Protobuf trait from ibc-proto-rs instead? by which encode_vec can return Vec<u8> instead of Result<Vec<u8, tendermint_proto::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.

The Protobuf trait in ibc-proto-rs is trait object safe, which it trades off with being more complex, such as having Self: erased::TryFrom<Raw> instead of just Self: TryFrom<Raw>. Now that we no longer need trait object safety, we no longer need this additional complexity.

We can just bring the same changes and make tendermint_proto::Protobuf::encode_vec() return Vec<u8>?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm. We can do so but also was thinking of not being dependent on tendermint-specific things in the "core" module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed that would be desirable, but we should do this in another PR

@Farhad-Shabani
Copy link
Member

Reminder to add unclogs :)
Also, I think #614 is resolved through this PR.

Copy link
Member

@Farhad-Shabani Farhad-Shabani left a comment

Choose a reason for hiding this comment

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

From my end, nothing else remains. Looks solid. Excellent work on this PR 👌🏻

@plafer plafer merged commit cd3a266 into main Jul 5, 2023
@plafer plafer deleted the plafer/296-static-client-interface branch July 5, 2023 14:49
Farhad-Shabani added a commit that referenced this pull request Sep 9, 2024
* StaticClientState

* Static{Validation,Execution}Context

* improve static clientstate & contexts

* StaticTmClientState scaffold

* tentative separation of `ClientState`

* remove chain_id

* move `zero_custom_fields()`

* adjust comment

* changelog

* Remove methods from staticclientstate

* static client state for tendermint WIP

* `ClientStateValidation` for tendermint `ClientState`

* `StaticClientStateExecution` tendermint

* use static contexts in handlers

* `StaticConsensusState` trait for tm `ConsensusState`

* Move `MockClientRecord` to context file

* mock: make records use enums instead of dyn

* mock context works

* bunch of errors fixed

* fix tm consensus state

* clippy

* fix todos

* use derive_more

* Remove old types

* Remove old `ClientState`

* move things around

* Rename tendermint's ClientState

* Rename ValidationContext

* Rename ExecutionContext

* rename ClientState traits

* fix doc

* Rename ConsensusState

* ClientState derive macro scaffold

* macro improvements + test setup

* fmt

* remove ibc dev-dependency

* implement validate_proof_height

* fix previous merge from main

* crate-level `allow(non_snake_case)`

* `Imports` struct

* move ClientStateBase impl to a module

* extern crate trick

* outdated comments

* latest_height

* implement more `ClientStateBase` methods

* finish `ClientStateBase` impl

* rustdoc ignore

* comment line

* introduce darling

* ClientStateInitializer impl

* export attribute

* ClientStateInitializer done

* fmt

* add mock mode

* use `ClientState` macro in tests

* no long path

* clippy rust 1.70

* remove useless cruft

* comment

* impl ClientStateValidation

* use core::result::Result

* ClientStateExecution impl in macro

* Supported -> Any

* host -> generics

* rename derive macro attrs

* Remove `PartialEq` from `ClientState` traits

* Remove `Debug` supertrait from `ClientState`

* Remove `Clone` requirement on `ClientState` traits

* Remove `Send + Sync` from `ClientStateBase`

* Remove `Debug + Clone` from `ConsensusState`

* Remove `EncodeError` associated type (ConsensusState)

* client-state-derive: move to submodule client_state

* client-state-derive -> ibc-derive

* `ConsensusState` macro

* move `ClientState` re-export

* Fix `ConsensusState` macro

* add `ConsensuState` to ibc-derive-test

* remove ibc-derive-test

* Remove `ClientStateInitializer`

* Finish removing `ClientStateInitializer`

* docs

* Remove `store_update_{height,time}` from `ExecutionContext`

* Revert "Remove `store_update_{height,time}` from `ExecutionContext`"

This reverts commit 282424f.

* update client: store update time/height in core

* create client: store update height/time in core

* Remove store_update_time/height from Tm Client Execution context

* remove `store_{client,consensus}_state` from `ExecutionContext`

* docs

* tm client: `context` module

* Rename tm client types

* Rename TmConsensusState

* Remove `dyn-clone` dependency

* Remove erased-serde dependency

* Remove `ErasedPartialEq` from `Header`

* ClientStateCommon

* `ClientExecutionContext` trait

* Complete ClientExecutionContext

* Rename Host{Consensus,Client}State

* Move `ClientExecutionContext`

* Use `ContextError` in `ClientExecutionContext` methods

* mock: remove stale time/height update

* mock: clients submodule

* mock: application impls submodule

* mock context: file reorg

* ClientExecutionContext docs

* `ClientState` derive macro docs

* `ConsensusState` docs

* `ClientState` docstring

* docs

* Remove unused method

* tm docs

* core context traits docs

* refine tm client's contexts

* move `get_client_execution_context`

* Move `verify_consensus_state`

* Remove useless match in recv_packet

* fix typo in `UpgradeValidationContext`

* blanket impl for TmExecutionContext

* ClientState derive macro: document generic limitation

* Upgrade Contexts associated types

* fix

* add ClientType test

* chore: organize import calls

* changelog

* Add `CommonContext::ConversionError`

---------

Co-authored-by: Farhad Shabani <farhad.shabani@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
2 participants