Cosmos and Oraichain: the perfect match

Oraichain Labs
Oraichain
Published in
8 min readSep 30, 2020

--

Oraichain is a data oracle platform that aggregates and connects Artificial Intelligence APIs to smart contracts and regular applications. The world’s first oracle AI has arrived. The technologies underneath Oraichain are Cosmos — “a novel blockchain network architecture” which consists of many zones of standalone blockchains, and Tendermint — a Byzantine-Fault Tolerant consensus engine.

We have already written an article to describe briefly the Oraichain system’s overview. We recommend you read this article first if you want to get the gist of the Oraichain’s motivation and definition. In this article, we try to explain how Oraichain is built, what tools are used to develop Oraichain as well as the motivation behind using those tools.

The motivation of using Cosmos for the development of Oraichain

Underneath, Oraichain is fueled by Cosmos and Tendermint, where Cosmos makes use of Tendermint to build a complete public PoS blockchain. In this article, we only focus on Cosmos and Cosmos SDK only, there will be another article about the Tendermint layer, and how Oraichain makes use of it for the development. To sum up Tendermint in a sentence, it is a software that handles the consensus and network layer of a blockchain (lower layer), while Cosmos provides a tool to build the application layer (upper layer). The architecture of Cosmos integrated with Tendermint is shown below:

The overall architecture of a Cosmos blockchain. The image source: https://cosmos.network/intro

There are a total of three reasons for us to choose Cosmos as the main development technology:

  1. A Cosmos open-source framework — Cosmos SDK

The SDK comprises of different pre-built modules needed, and the developers can add more custom modules for their use cases. This increases flexibility when developing a custom blockchain, while still keeps the core untouched. Moreover, since it is an open-source project on Github, everyone can dig deep to understand more about how the SDK is built or how to use the provided modules.

There are other blockchain technologies such as Hyperledger Fabric and Ethereum that provides the source code publicly on Github. Nevertheless, these repository structures are quite difficult to follow and understand. Even when we fork them, it is not easy to continue developing the project in a new direction. With Cosmos SDK, we can easily integrate our custom modules, which is highly scalable.

Currently, Oraichain is using eight pre-built modules which are: auth, bank, supply, staking, slashing, mint, and distr. You can find the docs relating to the functionalities of these modules here. Oraichain also has a custom module called provider which contains all the functions and business logic of the system. The module is responsible for creating and editing oracle scripts, data sources, and test cases. It also handles all the Oraichain use cases from yAI to KYC.

2. Public and domain-specific blockchain

Currently, there are only two popular public blockchains that people believe in and use: Bitcoin and Ethereum. However, Bitcoin serves only as a place for digital money, whereas Ethereum provides dApps through smart contracts. Indeed, there are a lot of disadvantages relating to developing and using smart contracts such as high data sizes, strictness, and the environment. Since the motivation of Ethereum is to create a platform for any arbitrary application development, it can not optimize or provide services for specific-domain applications like AI models. A similar example can be seen in the Windows operating system, where it cannot fulfill the requirements of an automatic emergency brake for a car.

Ethereum logo from Wikipedia

Regarding private blockchains like Hyperledger Fabric, even though it only focuses on one specific application domain or business logic depending on the system, it is still a private blockchain. As a result, only a small group of people can participate in the network, and there will always be centralized entities above others.

Fortunately, Cosmos has many characteristics that satisfy the requirements of Oraichain: a public blockchain where the community directly governs the changes of the system, and an application-specific blockchain that works only with one domain — Oracle AI in the case of Oraichain. It also allows Oraichain to create a native token (ORAI token) to support the service, which overcomes the high fee charge of Ethereum. In addition, we also have a unique incentive method as well as a sampling algorithm for validators that take part in the request execution process. The details are described in our documents here.

3. Oraichain will be able to connect to other Cosmos blockchains

In our vision, Oraichain will connect to other blockchains not only in the Cosmos ecosystem but also external existing blockchains like Bitcoin or Ethereum to exchange data and information, which will elevate the values of Oraichain even more. This will be made possible thanks to the on-going development of IBC — “The interoperability protocol connecting the global economy to blockchain technology”. We are looking forward to the release of the IBC stable version so that blockchains can communicate with each other for the first time.

The development of Oraichain

  1. Oraichain’s development path and architecture

At the early stage of the Oraichain development, we heavily relied on the basic nameservice tutorial of Cosmos SDK to build the system. We also make use of the scaffold tool to generate some core source code files. Thus, the basic structure of the project is similar to the nameservice tutorial. However, there are still some key changes in the design, but let’s not get ahead of ourselves here, as they will be discussed in another article.

Below is the overall architecture of Oraichain that is integrated with Cosmos SDK and Tendermint. We now consider Tendermint as a black box, and inside there are nodes that interact with each other directly (P2P) with a deterministic chain.

The simplified system architecture of Oraichain

The diagram illustrates all the components of Oraichain currently, as well as three validator servers for serving end-user requests.

2. Making uses of Cosmos for Oraichain's basic request flow

You can make a request to one of the three validator APIs. The request is parsed to collect the user inputs before the system forwards it to the Tendermint layer using an interface called ABCI. This interface has necessary functions for the application layer to interact with the lower layer. As a result, the request message is broadcast to all the nodes of the network, and the next node that commits a new block is the one executing the request. Finally, you receive a transaction hash, and you can use it to make a query for your request result. The fees are charged after you receive a transaction hash, regardless of the request failure or success. Simple, right?

  • Since Cosmos SDK is open-source, we are able to deep dive into the native module structures of Cosmos.

Luckily, the module structures are very similar to each other, so it is quite easy for developers like us to follow the same development path. In the application layer, we create a custom module provider that has basic elements of a Cosmos module: message for the end-users, a handler, a keeper, and data structures. Because these elements appear in every other module, once you understand the module’s process flow, you can easily work with the Cosmos SDK. A keeper is an entity that guards the states of a module secured in the module’s store. Whenever a user wants to fetch or change the states in the provider module, she must ask the provider keeper which holds the store key. A handler is also an entity that executes the business logic after Tendermint broadcasts the request message, where each handler maps with a specific message type. Last but not least, to communicate with other native modules, Oraichain also adds other native module keepers with basic module exported functions. For example, the distribution module allows allocating tokens to an arbitrary validator by using the distribution keeper interface with the AllocateTokensToValidator function.

  • Since Oraichain only has one custom module which is provider, it now focuses on only one domain only, which is Oracle AI

The provider module optimizes and utilizes the request flow for Oraichain with Oracle Scripts, Test Cases, and Data Sources. Indeed, we can create anything we want to satisfy the use case process. For instance, a Strategy structure is created for the yAI use case, and we make sure that we have all the tools we need for it. Below is the structure of a Strategy struct:

// Strategy stores the information of a strategy for a yAI flowtype Strategy struct {StratID        uint64   `json:"strategy_id"`StratName      string   `json:"strategy_name"`StratFlow      []string `json:"strategy_flow"`PerformanceFee uint64   `json:"performance_fee"`PerformanceMax uint64   `json:"performance_max"`WithdrawalFee  uint64   `json:"withdrawal_fee"`WithdrawalMax  uint64   `json:"withdrawal_max"`GovernanceAddr string   `json:"governance_address"`StrategistAddr string   `json:"strategist_address"`}
  • Native ORAI tokens, community and incentives

Because Oraichain is a public DPoS blockchain, it needs a native token to reward validators and providers that participate in the network. Cosmos SDK makes it simple for developers to handle events when a block is committed and before a new block is proposed. Thus, we can create a custom token allocation process for our module. The process should run during the beginning of the proposing new blocks phase. This is because at that moment we have obtained all the votes from the validators, as well as the total transaction fees in the previous block. Using these figures, we can allocate tokens to validators and providers accordingly. The allocation process is thoroughly described in our docs. When it comes to the community, we are creating a website to get feedback from the users along with FAQs. We will be using them to make Oraichain better, and all the future decisions of Oraichain will be decided by the community.

Now, Oraichain is in a very active state, so all the information given here may change in the future. We have not implemented the IBC protocol and governance DAO for Oraichain yet, but they are definitely in our future development plan. We hope that this article can help you understand more about Cosmos and Oraichain in general, and what we are trying to achieve. In other articles, we will go further in detail about Tendermint, its role in Oraichain, as well as a quick tutorial for those who are keen on trying out the network first hands!

Join the Oraichain community and Get the latest updates!!!

Website: https://orai.io

Twitter: https://twitter.com/oraichain

Group chat: https://t.me/oraichain

Channel: https://t.me/oraichain_official

Medium: https://medium.com/@oraichain

References:

--

--