10

As per the basic rules of blockchains believe it is mentioned that no service call from the smart contract should be made where the result is non deterministic.

What I understand is if the result is non deterministic in that case, when the transaction will be executed in different nodes it will not be possible to reach consensus as everyone may get different results.

When a new node is added it is expected to first sync to get the whole distributed ledger downloaded.

Believe every new node added on the blockchain network verifies all the previously generated transactions. So in this case it will invoke this external service as well to verify the result and based on the output will behave accordingly.

But found using Oraclize one can invoke external services from smart contract. So if the above assumption is correct then how come it is feasible to invoke external services or are they invoked for specific scenarios only

eth
  • 85,679
  • 53
  • 285
  • 406
Susmit
  • 1,804
  • 2
  • 14
  • 29

1 Answers1

8

Miners never make external calls on behalf of your contracts. Oracles are done by a user (or machine, of course) sending a tx into the Oracle contract putting the data there. Your contract then reads the data from the Oracle contract, not from the off-blockchain world. The data from the external source may be non-deterministic, but once it's on the blockchain, it's been determined.

natewelch_
  • 12,021
  • 1
  • 29
  • 43
  • Question is will this same transaction be invoked from every node to verify the result. If so then it makes me believe that it will invoke the service for each node. Or are you saying that the invocation of external service will be done only once? – Susmit Nov 11 '17 at 03:53
  • I'm saying that there is never an invocation of an external service on the blockchain or by a node. Contracts can not call outside of the blockchain. Oracles are services off-chain that send transactions to contracts in the blockchain to store the data on the blockchain. Only after the data is on the blockchain can you access the data. Aka I would query some service from my computer, get the result, then send a transaction to the blockchain to store the data. I am the oracle, and I'm putting the data in an oracle contract. You then access the data from the oracle contract. – natewelch_ Nov 12 '17 at 15:24
  • So lets say I need to check the state of status which is actually updated by an external service and based on that will be applying some logic in my contract. Now are you saying that I should invoke that service external to blockchain, fetch the status value and store the result in blockchain via a transaction. The contract used to store the value becomes the Oracle. Once done then the main contract will invoke this Oracle contract to check the the status value? But if you really mean that then what feature provided by Oracalize library. – Susmit Nov 12 '17 at 16:59
  • Like this contract invokes "oraclize_query" to check youtube video watch count. https://github.com/oraclize/ethereum-examples/blob/master/solidity/YoutubeViews.sol – Susmit Nov 12 '17 at 17:00
  • Oraclize works as this: 1. You send a query to Oraclize on-chain. 2. Oraclize has servers off-chain listening to these queries and does the HTTP request off-chain when you create an on-chain query 3. After getting the data, Oraclize sends an on-chain transaction calling the __callback function in the contract you linked to with the data from the query. – natewelch_ Nov 12 '17 at 20:25
  • So the first transaction is the one invoked on my contract to generate a oraclize query request. After that request gets queued at Oraclize contract. Now second transaction is introduced, as Oraclize external service picks up the request, fetches the data and then invokes the callback function of my contract. But even in this scenario when the consecutive nodes execute the first transaction won't the same flow be repeated. If yes the data provided the callback function may differ for rest of the nodes. So first transaction will be same for each node but second wont be. How is this avoided. – Susmit Nov 13 '17 at 04:39
  • 1
    Mostly correct, but you're still mixing up the ordering of the external query/2nd tx. After oracalize picks up your request for a query, it does the call to a URL to do your request. This only ever happens once per query. After the query, Oraclize creates a tx to call your __callback function. – natewelch_ Nov 13 '17 at 12:10
  • Great to have that insight. But not quite sure to understand how Oraclize is achieving only one call per query. So if you could share some insight as to how it is achieving that will be great. Otherwise the basic flow seems when rest of the nodes will be invoking it they will just get the data returned and not invoke the query again. – Susmit Nov 13 '17 at 13:15
  • What do you mean by "But not quite sure to understand how Oraclize is achieving only one call per query"? Correct, the basic flow is as I said above. You send a query request to the Oraclize contract, the Oraclize node listens to this requests and performs the query off-chain, and Oraclize then sends a tx calling your __callback function with the data. – natewelch_ Nov 13 '17 at 13:52
  • So this facility is only available on public blockchain and cannot be achieved on private one? To achieve it possibly have to create similar framework of watching a contract and serving the requests offline. – Susmit Nov 13 '17 at 14:14
  • 2
    Correct. Oraclize is a company completely separate from the Ethereum foundation that runs this service, and it won't exist on private blockchains. Yes, you would have to create a similar framework for a private blockchain to get the same functionality. – natewelch_ Nov 13 '17 at 14:32
  • To understand it more precisely, one tries to create that using a custom contract. Lets say custom oraclize contract accepts data source information, parameters and source contract address. Now off chain my service invokes the final server, fetches the data and then invokes the custom oracle to store result. On doing that the __callback method of registered contract address is invoked to pas the data. Did I miss anything? – Susmit Nov 13 '17 at 15:38
  • Didn't miss anything, that sounds exactly right! – natewelch_ Nov 13 '17 at 16:11