How does "Gas Price Oracle" work?
"Gas Price Oracle" is explained here in go-ethereum wiki, but it doesn't explain how it works. Where does it get the data from? How does it do its calculations?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.Sign up to join this community
This blog post (old since default gas price is currently 0.02 szabos) from Stephan Tual has the hint:
The default gas price is set at 50 shannon (0.05 szabos, or 0.00000005 ether). Remember that the gas price is ultimately always defined by the users calling a contract, while the miners can set a parameter on their machines to accept or ignore transactions that have a gas price within a certain range.
On the user side of things, we also have a built-in oracle defining the optimal gas price, determined by the previous block gas usage. For example, if the previous block was less than 80% full, the gas price oracle will adjust to a lower gas price recommendation.
In essence, the gas price oracle is trying to predict the future gas price by looking at the past (previous block utilisation). There is the block gas limit (currently 4,712,388 gas) which sets the maximum gas which can be spent per block.
A lower than 100% utilisation indicates that there was spare capacity and therefore, if you are on the demand side of the deal, suggestive of an opportunity to reduce gas price. Miners are better off harvesting as many transactions in a block (up to the gas limit) so in periods of low demand, they should be willing to accept low gas prices.
Conversely, if the previous block was fully subscribed (indicative of high transaction demand), the gas price oracle will deduce that lowering gas price will incur a risk of its transaction not being selected by the miners (in favour of competing transactions offering higher gas prices), therefore opting for a higher gas price instead.
As long as all (or most) nodes are running the same oracle, then prices will tend to stablise and converge in-line with demand.
Much the same way that supply/demand works in traditional economies.