Course Content

Chapter 0: Introduction




Chapter 3: How does BandChain work



Chapter 3

How does BandChain work

Estimated time: 20 mins


Yoda

Yoda is a program that BandChain's validator node use to fulfill data requests when they're selected to do so.

Yoda's main job is to listen for incoming oracle requests on BandChain and to execute the corresponding data sources listed within the oracle request. Once the data source is executed and it's results recieved and parsed, the end-results are then collated and packaged into a MsgReportData, stored in a local pending list then broadcasted onto BandChain.

Yoda

Data Sources

A data source is the most fundamental unit in BandChain’s oracle system. It describes a proceduce, like a Python script, to retrieve and process a raw data point from a external source.

Anyone is able to deploy and register a data source on BandChain through sending a MsgCreateDataSource message to BandChain and if an owner is specified, the owner is able to edit a data source through sending a MsgEditDataSource message to BandChain.

Oracle Scripts

An oracle script is a turing-complete executable program that is at the heart of BandChain. It encodes a set of raw data requests, which is then sent to the data sources, and aggregates the raw data returned from the data sources into a final report.

When an oracle script is called and executed, a data proof is also produced. This proof is a Merkle proof that shows the existence of the final result of the data request on BandChain. In addition to the actual result of the request, the proof also contains information on the request parameters such as the script hash, the time of execution and the number of validators that responded. This proof can then be used by any smart contract on other blockchains to verify that the existence of the data on BandChain and to retrieve the results stored.

Similarly to a data source, anyone is able to deploy or edit an oracle script on BandChain through sending a MsgCreateOracleScript or MsgEditDataSource message to BandChain.

Prepare Phase

During the preperation phase, an oracle script is used to request external data from validators through yoda.

Execution Phase

During the execution phase, an oracle script processes the reported data from the validators and returns the output. The processing an oracle script can be done in a variety of ways but a common approach is to medianize the results.

Data Request Flow

  1. When requesting an oracle script, a MsgRequestData needs to be broadcasted in a transaction to BandChain.
  2. Once the transaction has been discovered on-chain, the randomly selected validators will then run the oracle scripts prepare code.
  3. The prepare code sends a request to Yoda, which will execute the associated data sources and create a MsgReportData containing the data sources results.
  4. The MsgReportData is then broadcasted in a message signed by the validator and broadcasted.
  5. Once the transaction containing the MsgReportData is delivered, the reports are then checked to assure that the minimum number of validators have reported the data and once that is assured, the request is added to the PendingResolveList.
  6. At the end of the block, the oracle script execute code is then run and its results saved on-chain.

Data Request Flow

Quiz

In order to request data on BandChain, what type of message must be sent within a transaction?

Previous Chapter

Why the need for BandChain