Giter Site home page Giter Site logo

ocular's Introduction

Ocular

Ocular seeks to be the preferred cosmos client library UX for Rust projects. It is strongly based on Lens, a go client library for blockchains built with the Cosmos SDK.

Features

Existing

let client = ChainClient::new("cosmoshub");

In Progress

  • Core module querys
  • Tendermint querys
  • Key management
  • TX signing with the familiar cosmos Accounts paradigm
  • Automatic IBC relayer path retrieval

Future

  • Arbitrary gRPC message sending (for custom modules)

ocular's People

Contributors

cbrit avatar philipjames44 avatar hannydevelop avatar zmanian avatar

Stargazers

Kun avatar dzmitry-lahoda avatar  avatar Tobias Leinss avatar Keefer Taylor | Tessellated avatar  avatar Sigrid Jin (ง'̀-'́)ง oO avatar Steven avatar Javier Aceña avatar Ethan Frey avatar Zack Kollar avatar Daniel Ribeiro avatar Etch avatar Etienne Napoleone avatar Mike Purvis avatar LeTurt avatar SIRIUS | PUPMØS avatar  avatar Sascha1337 avatar MSalopek avatar yoisha avatar Barton Rhodes avatar Runchao Han avatar scalalang2 avatar Evgeniy Abramov avatar Philipp avatar  avatar Romain Ruetschi avatar Stanislav Tkach avatar  avatar Nick Hagianis avatar Agost Biro avatar  avatar Kevin Ridgway avatar  avatar Adi Seredinschi avatar Jay Namsayin avatar Stephen Saunders avatar Larry avatar Jake Hartnell avatar

Watchers

 avatar Romain Ruetschi avatar Barton Rhodes avatar Gavin Doughtie avatar  avatar  avatar  avatar Tony Arcieri (iqlusion) avatar  avatar  avatar

ocular's Issues

Test coverage

We need unit test coverage on methods that do not require network calls and more comprehensive integration test flows for various code paths.

1.0.0 Release candidate criterea discussion

Before release?:

  • Reliable gRPC endpoint selection when using automatic client construction
  • Easy Account reference construction from key
  • Auth, Authz and Bank module txs and queries
  • Automatic and Manual client construction paths
  • Airdrop functionality
    • Rigorous testing
  • Unit and integration test coverage

Sketch of library requirements for Hermes operator user-story

This sketches part of the requirements on the ocular library.

The main persona here is the relayer operator. I'll assume the perspective of Hermes relayer, since ocular is a Rust library and Hermes will most likely be a representative user of ocular.

There are two stories that come to mind and & would be useful to have.

1. Generate the relayer's configuration file starting from a tag

This story starts with a CLI that handles initialization of the relayer's config.toml starting from one TAG. The operator would invoke a CLI as follows:

hermes config gen TAG

This would generate a config.toml for Hermes with all the chains and all the paths from the chain registry that match the given TAG. We can define "match" to mean either a substr/regex or exact string equality, not sure yet, depending on the tag type definition & content from the chain-registry.

Ocular requirement A

This use-case translates into an ocular requirement for an API roughly as follows:

fn get_paths_filtered(tag_filter: String) -> Vec<Path>

I imagine calling this method from the relayer (while executing hermes config x) to result into a vector of Paths which can be JsonValue or similar types, filtered by their tags.

Of course, transforming these Paths into their appropriate representation and generating the config.toml will be done on the Hermes side. To do so, we need one more API from ocular, documented below.

Ocular requirement B

To be able to fully generate the relayer's config.toml, we need additional pieces of information for each chain from the chain registry. The full set of details are as follows:

To summarize, in an ideal world ocular would provide an API as follows:

fn chain_info(chain_id: String) -> ChainInfo

Where ChainInfo would comprise the corresponding attributes to describe the necessary fields. To recap: rpc_addr, grpc_addr websocket_addr, account_prefix, denom, max_block_size, clock_drift, max_block_time, and optionally key_name if ocular supports key management. None of these are a hard requirement. However, the fewer of these fields are present, the less useful the API will be.

2. Append IBC paths to the relayer's config.toml

In this story, the config.toml is already pre-populated with most of the chain information (i.e., we don't need to call into chain_info). The relayer operator is only interested in appending path information to each section of the configuration file. Path information in Hermes consists of a simple list (example, example) of channel identifiers, but is subject to change. In the future it will comprise connection and client also. Suppose this information is missing from config.toml and we'd want to add it automatically from chain registry.

The top-level relayer's CLI would look as follows:

hermes config paths

Then Hermes would call into ocular to fetch path information for every pair of chains present in the config.toml. Suppose config.toml comprises three chains A, B, C, then Hermes would call into ocular to fetch three paths: A <> B, B <> C, A <> C. To do so, would be great if ocular exposed the following API:

Ocular requirement C

fn get_paths_pairwise(source_chain: ChainId, dest_chain: ChainId) -> Vec<Path>

The meaning is pretty straightforward. This should return a Path such as this one, which may be a vector, but not sure.

Simplify UX of creating a client

Users should be able to simply pass a name or enum to the ChainClient constructor. The ChainInfo and ChainClientConfig creation necessary should be abstracted away.

Ex:

let client = ChainClient::new("osmosis").unwrap();

I should have already implemented this but forgot 😮‍💨

Retrieve relayer paths pairwise

Covers the final API requirement of #8

Something like

fn get_paths_pairwise(source_chain: ChainId, dest_chain: ChainId) -> Vec<Path>

Batch tx support for toml input

Something in the format of

[sender]
source_account = “xyz”
...

[transaction]
  [transaction.details]
  name = “xyz”
  destination_account = “xyz”
  amount = 1
  ...

This issue should include toml parsing, tx sending support, unit testing, and integration testing.

REST API for cached chain registry

We need either a feature or separate ocular crate in the workspace for hosting a cache of the chain registry with a RESTful API for ocular to query chain and IBC path information. This should be optional as a user may opt to manually configure their chain client and/or read in IBC path data some other way.

Add in grpc caching mechanisms

1.) Should support ability to read and write from file based cache
2.) Option for in ephemeral in-memory caching
3.) Option to have no caching whatsoever

This PR should be followed by #23 to actually utilize the cache. This is split into 2 issues to separate actual cache implementation and utilization bc the latter will require a bit of a refractor.

Msg type URL public constants

Provide Msg type URLs as public constants for the core SDK modules in the ocular::tx::<module> modules respectively

Airdrop Testing

  • Integration tests for full airdropping flow, delegated and undelegated
  • Integration tests for individual methods where relevant
  • Unit tests of relevant methods
  • Mainnet test with real funds

Include additional chain info for relayers

Covers 1B of #8

Fields not included in the chain registry chain.json:

  • websocket_addr
  • account_prefix
  • key_name (covered by key management PR)
  • max_block_size
  • clock_drift
  • max_block_time

Append these to the current ChainInfo struct or create a superstruct?

Ocular_CLI (Set_default Chain)

Users can change the default chain that comes with Ocular. To do this, they'll use the set_default command. This way, they can change the default to the chain of their choice.

Basic module query clients and queries

Implement the query logic that exists in lens and also expose the different modules' query clients in case users want more fine-tuned queries (with pagination for example)

  • Bank query client and queries
  • Other module query clients
  • Test coverage

Add a more flexible grpc call wrapper

Per #22 (comment), we should add in a wrapper around gRPC connections/calls that:

1.) Adds in an ability to do optional backoff retries
2.) Keeps track of healthy gRPC endpoints on the fly and update cache

This PR should be done after #31. This is split into 2 issues to separate actual cache implementation and utilization bc the latter will require a bit of a refractor.

This PR should also extend the cache hashset into a hashmap with values indicating how many times in a row connection attempts have failed and remove endpoints that have failed more than some threshold value

Account management

There should be some sensible harmony of key/account management. Accounts will be used for transactions and the lower-level key management for just that.

Accounts are just abstractions on top of keys; therefore "creating" an account is just an abstraction of generating and saving a new private key, or deriving a new address from an existing public key.
Account should be able to yield addresses with any prefix provided, with a go-to method defaulting to "cosmos".

Need to look into supporting module accounts as well.

Think through caching config

It's been unofficially decided ocular doesn't really need a cli because it's redundant with lens. However, one really useful thing about the lens cli is that it caches chain registry config data locally. Ocular should probably have this capability in case the registry becomes inaccessible such as during a Github outage.

Ocular could cache config in a local file when a chain client is first constructed so that future construction of clients for that chain wouldn't need to make calls to the registry. We may need to think about some kind of policy around making sure the config doesn't get stale like if endpoints are updated in the registry. Alternatively we could leave this to the user. Perhaps some kind of way to configure the behavior at client construction time (a method like ChainClient::new_with_options()?). This issue for starting a discussion.

Ocular_CLI (Show_default Chain)

Command to show details of the default chain in ocular. Ocular comes with some default chains, you can check the default chain with the show-default command

Batch tx support from toml input

Process delegated tx's from a toml file contingent upon a valid grant existing for a grantee account from a specified granter.

Toml should look something like

[sender]
grantee_account = “xyz”...
granter_account = “xyz”...
...

[transaction]
  [transaction.details]
  name = “xyz”
  destination_account = “xyz”
  amount = 1
  ...

This issue should include toml parsing, tx sending support, unit testing, and integration testing.

Control cosmos/chain-registry version pulls

While running cargo tests I saw results such as:

---- chain::client::query::tests::gets_bank_client stdout ----
thread 'chain::client::query::tests::gets_bank_client' panicked at 'Assay test failed', ocular/src/chain/client/query.rs:158:5

running 1 test
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ChainRegistry(InvalidChainInfo(Error("expected `,` or `}`", line: 196, column: 17)))', ocular/src/chain/client/query.rs:160:57
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

On a deeper dive we can see this is caused by a missing comma at cosmos/chain-registry@4d03592

We should consider pinning commit versions in our chain registry pull at https://github.com/PeggyJV/ocular/blob/main/ocular/src/chain/registry.rs#L68-L74 to prevent main branch regressions in cosmos/chain-registry from affecting ocular.

Per conversing with Collin, we should additionally add in tests that try every chain and asset chain json in cosmos/chain-registry so that each version of ocular that is deployed is guaranteed to function correctly when released.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.