A Brief Introduction To The Decentralized Oracle Network
Blockchain technology supports the multibillion-dollar cryptocurrency industry and promises to revolutionize how we trade, interact, or exchange finances. As a decentralized digital ledger, Blockchain eradicates the requirement for third-party validation while guaranteeing best-in-class security standards, immutability, and transparency. The diverse participants in the channel are named network nodes, and they are the ones who manage everything.
In addition to its merits, Blockchain technology also has some loopholes. Using one Blockchain system to trade data is easy but exchanging data across multiple Blockchains is more challenging. This is where Blockchain Oracles come into space. Oracles function as a bridge for linking Blockchain ecosystems to exterior data inputs & outputs. Besides enhancing the working capacity of a Blockchain network, they also ensure the accuracy of the data statistics available to users.
This blog will help you understand what Blockchain Oracles are and how a Decentralized Oracle Network works. So, let’s get started!
What Is Blockchain Oracle Network?
Blockchain Oracles act like a bridge to connect the on-chain and off-chain worlds. They play a key role in letting deterministic Blockchain access non-deterministic values. But having a single oracle provide value to the Blockchain challenges the trustless principle of Blockchain. Being dependent on this single oracle might be risky; what if that oracle itself is compromised or is getting data that was compromised before reaching the Oracle?
To solve this problem, the Decentralized Network of Oracles is designed in such a way that oracles form the core of this network, forming an infrastructural layer. Here they work beside Blockchain, gathering, processing, and then supplying the verified aggregate result to the smart contract in Blockchain.
Blockchain Oracles Key Functionalities
Oracles provide several functionalities but here view the key functionalities of it:
- Collecting data from the off-chain world
- Send the data to a smart contract on Blockchain by using a signed message
- Store the data in the smart contract’s storage so that it remains accessible
Note: The stored data can be accessed via the smart contract’s “retrieve” function call.
Determine The Type Of Oracle
An oracle can be determined based on the type of data required by the Blockchain as described below-
It is used when a result is required on a just-in-time basis. For example, to verify someone’s identity.
This is used when the required data keeps changing. Whenever a change occurs, it is notified by polling a smart contract or by keeping a watch on the updates via off-chain triggers. For example, weather updates.
It is used when users need to use only a small part of a big data set at any given time. In this scenario, data is too large to be stored in a smart contract; therefore, a combination of on-chain smart contracts and off-chain infrastructure is used.
A request is sent from the Blockchain to off-chain infrastructure, which keeps monitoring for requests, processes them, and returns results. This being an asynchronous process, follows multiple steps. For example, geolocation data for tracking and tracing in the supply chain.
How Does The Decentralized Oracle Network (DONs) Work?
We can have a single or mixed type of oracles in the network. Understand how the decentralized oracle network works with Chainlink’s architecture for the data feeds. These data feeds enable Smart Contracts to quickly connect with the real world and include the following components –
An application that uses data feeds. It may be an on-chain or off-chain application, where its contracts called consumer contracts calls functions on the proxy contract and retrieve information from the aggregator contract.
They are proxies that are on-chain contracts pointing to the aggregator for data. With the use of proxies, the upgradation of the underlying aggregator becomes seamless due to zero service interruption to consuming contracts. They may vary for different data feeds as per the application requirements.
This contract receives data updates periodically from the decentralized oracle network. Then it stores the aggregated data on-chain for the consumers to retrieve and act upon it in the same transaction.
Connecting smart contracts to external data (off-chain) is done using a decentralized oracle network. Chainlink handles API requests by 1:1 by an oracle. It does this by using the following models –
Basic Request Model
This model is used when data is required from a single oracle source.
The following diagram shows the flow of its contract, the open-source code of which is available at the Chainlink Github repository.
Image Reference: Architecture Request Model
It is a parent contract of the basic request model that allows smart contracts to take data from oracles. It sends the required encoded information via transferAndCall function request to chainlink oracle via LINK token.
It is an ERC-677 compliant token that executes the transferAndCall request sent by ChainlinkClient. It lets token transfer and triggering of logic in a single transaction in the receiving contract via onTokenTransfer call.
These run beside off-chain oracle nodes and are owned by oracle node operators. They are responsible for handling on-chain requests received via onTokenTransfer through LINK Token.
It must be made by the client contract that initiated the process with the following must-haves:
- Oracle Address – which oracle to contact
- Job ID – which tasks to perform
- Callback function – through which the oracle shall send back the response
On completion, a fulfillOracleRequest function returns the result to ChainlinkClient via a defined callback function.
Oracle Node (Off-chain)
It listens to the events of its on-chain smart contract. On listening to the OracleRequest event, it uses the data emitted to execute the task.
For example, a GET request to an API retrieves data, parses the response, converts the result into Blockchain-compatible data, and then sends the result back via the fulfilllOracleRequest function to the oracle contract.
Decentralized Data Model
This model is used when data is aggregated from several independent oracles nodes in a decentralized oracle network.
Each data feed is updated by independent oracle nodes of the decentralized oracle network, and the AccessControlledOffchainAggregator is used to aggregate the data on-chain. The aggregation process is improved by Off-Chain Reporting (OCR).
Shared Data Resource
Every data feed has its own properties, and each data feed is created by a community of users. These users rely on accurate data in smart contracts. In order to enhance the quality of the data feed, more users are added that add their contribution to the data feed, thus, enhancing its quality.
Decentralized Oracle Network (DON)
It consists of a consumer contract, a proxy contract, and an aggregator contract. DON updates each data feed where the number of participating oracles in each data feed varies. Every oracle operator is awarded for publishing data. For any update to take place, the data feed aggregator contract must have a minimum number of oracles to respond in an aggregation round, or the update will not be published. This data is validated and aggregated by a smart contract which forms the latest response of the feed.
Updates are received by aggregators from DON only when a trigger happens on the Deviation Threshold (when off-chain values vary by more than the specified variation threshold from the on-chain value) or Heartbeat Threshold (after a specified amount of time) while in an aggregation round. The first met condition triggers an update to the data.
In Off-Chain Reporting (OCR), nodes communicate off-chain using a peer-to-peer network. A lightweight consensus algorithm is executed during the communication process. During this communication process, every node returns its observed price and signs it. The result is then aggregated and sent as a single value, thus saving a good amount of gas fees.
During the process, nodes regularly elect a new leader who is responsible for the execution of the whole process. The leader repeatedly asks their followers to send freshly signed observations & aggregates them into a report. The report is then sent back to followers for verification of its validity. If the required number of followers approves the report, then a signed copy is sent back to the leader, who then combines it into a final report along with the signature of the followers who approved it, and then the leader broadcasts that report to the whole network.
As per a randomized schedule, nodes in the DON try to transmit the final report to the aggregator contract. The aggregator contract then verifies that the required number of nodes have signed the report and reveals the median value as an answer to the consumers, along with a block timestamp and a round ID.
During transmission, the Blockchain is watched by all the nodes for the final report, and in it, if any single point of failure is discovered, then that is removed. A round-robin protocol is used when the desired node does not get the transmission confirmed within the given time period; in this case, other nodes keep transmitting the final report till the time one of them gets confirmation.
Blockchain technology can only be expanded globally if a secure infrastructure facilitates communication between smart contracts and external sources. Without oracles, smart contracts cannot attain their full potential, as they would only rely on on-chain data for work.
With decentralized oracles, Blockchain networks can ease different system risks & operational limitations. In addition, Blockchain oracles can provide businesses with an interface that is trustless, secure, and safe for them to develop and grow within a decentralized economic system; if you also want that, then connect with a reliable Blockchain development company (Infrablok).
Moreover, if you are seeking help to call APIs from Ethereum smart contracts using chainlink oracles, follow the steps present in our tutorial.
Note: To write informative information on this blog, we referred Chainlink Architecture doc!