7.2 Oracle design pattern
All oracles provide three key functions
Collect data from off-chain sources
Transfer data On-chain with certified messages
Store data in Smart Contract memory
Once the data has been placed in the storage systems of a Smart Contract, it can be accessed by other Smart Contracts via calls that invoke "retrieval" functions, and it can also be read via nodes in a blockchain infrastructure with appropriate clients enabled to directly access the memory of an oracle.
There are three main architectures to which an oracle pu; conform, and they are:
immediate-read
publish-subscribe
request-response
Immediate-read oracles are those that provide data necessary for an immediate decision. The query method of these oracles is just-in-time: the query is performed when the information is needed, and potentially never again. Once the data has been stored in a contract's storage, it can be used by other Smart Contracts.
An example of immediate-read oracle applied to the MerlinProtocol project could be the oracle that responds to the getLastPrice query, which is useful for finding updated information on the market price of traded pairs.
The second pattern considered is that of the publish-subscribe oracle, in which the oracle offers a data broadcast service in case of data modification. This is received by a series of on-chain Smart Contracts, or by special off-chain "daemon" controllers.
The pattern has an architecture similar to RSS Feed, WebSub and MQTT, with a flag alerting subscribers to the presence of new updates available.
"Subscribed" Smart Contracts must either request updated data from the oracles or remain listening for broadcast updates generated periodically by the oracles.
Polling is very inefficient in the web server world, but not overly so in the peer-to-peer context of blockchain platforms.
The third category is request-response oracles. This architectural approach has disadvantages in terms of the storage space required by the data on the Smart Contract, which can potentially become very high.
In general, in this architecture, users are expected to require only a small portion of the total space concurrently, and never the entire available storage.
The request-response architecture involves a set of on-chain Smart Contracts and off-chain infrastructure used for the entire process of requesting and related forwarding of the query to the appropriate oracles, retrieving and returning the response to the requestor's query.
From the requester to the oracle there are a number of intermediate actors interacting asynchronously, part of which presumably controlled by a data provider: after an initial interaction with a (potentially decentralized) application, the requester's query is forwarded to a function of an oracle's Smart Contract.
The launched function initializes the query with the appropriate arguments and includes additional relevant information, and then transmits it to the oracle itself.
Once the transaction has been validated, the oracle's response can be observed in the form of an oracle-generated EVM event that allows the oracle to retrieve information from oracle-generated data stored in an off-chain location.
The oracle may require a payment in Ethereum for this process, and certainly an expense will be required in terms of gas consumed by transactions on the main net.
Last updated