I suspect that the question about the price discovery mechanism of gas/Ether was not studied very deeply by the Ethereum developers.
The mechanism that currently exists must work by miners adaptively changing the lower bound of Ether per gas (asking price), and creators of transactions - offering certain prices and watching if the transactions get mined.
Number 0.05e12 wei, or its order of magnitude, most probably came out these sort of calculations: we have 5 ether per block mining reward, or 5e18 wei. One transaction costs at least 21000 gas. If every miner, after receiving the reward, spent all the ether on sending transaction, how many should they be able to send per second? If we allow around 3000 per second, then we can arrive at the right order magnitude for the current gas price.
Let me now make a little diversion.
Since miners do not current have a way to advertise what their current asking prices are, the transaction creators are effectively making 'blind' bids in hope that they will be equal or higher than the asking price (but not much higher). Also, the miner do not have a way of explicitly rejecting the bids when they are too low. So the bidders have to assume rejections implicitly, seeing that their transaction did not make it into the next block. That, of course, does not mean that all miners would reject the bid, only the one that happened to mine that block.
From above it should be obvious, that the current state of the gas price discovery is very inconvenient and inefficient. Therefore, some explicit market mechanisms would need to be added either to the protocol, or in a form of contract. This is probably easier to do post Proof-Of-Stake, because offer prices can be signed and relayed as ordinary transactions. But even now it would be possible to create such a contract, 'gas market' :)
Starting with Solidity 0.5.0 all available gas will be forwarded by default with an external call (see changelog).
But it is important to note what "all available gas" means. EIP-150 defines the "all but one 64th" rule, which states that always at least 1/64 of the gas still not used for this transaction cannot be sent along.
How do wallets determine how much gas is needed for a transaction?
Most wallets use eth_estimateGas
to estimate the total gas usage of a transaction. Geth implements this by doing a binary search with a gas limit set until they find a value where the transaction does not fail (e.g. starting with the block gas limit, then trying half, etc).
If you require your internal call to be successful (e.g. require(success, "Internal call failed")
), then this process will estimate the correct gas amount to also make your internal call succeed (if possible).
If you don't enforce this then it might happen that the gas estimated is lower than what is needed, since the outer transaction will success even if the inner one fails. In this case it might make sense to use other was to enforce that enough gas is available (e.g. require(gasleft() > 1000000, "I need a lot of gas")
, but hardcoding this is discouraged, as gas costs change over time.
Last note: Just because you specific the gas that should be sent along with a call, doesn't mean that really that much gas will be sent along. Looking again at EIP-150 it is defined there that if more gas is requested to be sent, than what is available, then all but 1/64th are sent along.
Best Answer
A
specifies a gas price.M1
andM2
decide whether to mineA
's transaction if the gas price is high enough. IfA
's gas price was 1.5 GWei/gas, then onlyM1
would choose to mineA
's transaction (sinceM2
wants 2 GWei/gas).A
always pays 1000 (givenF
costs 1,000 gas) multiplied by the gas price it specified; miners cannot change the transaction feeA
pays and can only choose whether to includeA
's transaction in a block.Only the winning miner gets the transaction fee paid by
A
. Other miners and all other (full) nodes do have to verify the transaction and store its results: yes, it's unfair to them and part of the problem related to incentives and scalability.More information, https://blog.ethereum.org/2014/02/01/on-transaction-fees-and-the-fallacy-of-market-based-solutions