-
Notifications
You must be signed in to change notification settings - Fork 146
Add default returns for eth_coinbase, eth_hashrate, eth_gasPrice JSON RPC calls #112
Add default returns for eth_coinbase, eth_hashrate, eth_gasPrice JSON RPC calls #112
Conversation
@pipermerriam review please. |
trinity/rpc/modules/eth.py
Outdated
block_overall_gas_price = 0 | ||
for transaction in canonical_block.transactions: | ||
block_overall_gas_price += transaction.gas_price | ||
block_average_gas_price = block_overall_gas_price // len(canonical_block.transactions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs special handling for the case where len(transactions) == 0
.
37c2ef7
to
16c3872
Compare
@pipermerriam please take a look now. I have modified the logic so that if the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Bhargavasomu sorry to ask you to toss the work you did, but I'm inclined to just drop all the intelligence from the gasPrice
for now since we know it's something that will ultimately be pluggable allowing different engines for computing gas prices.
trinity/rpc/modules/eth.py
Outdated
num_transactions_latest_block = len(latest_block_having_transactions.transactions) | ||
block_average_gas_price = block_overall_gas_price // num_transactions_latest_block | ||
|
||
return hex(block_average_gas_price) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that even this approach has edge cases (like the genesis block when there are no transactions) I'm now inclined to drop this whole implementation in favor of a dead simple approach.
def gasPrice(self):
return int(os.environ.get('TRINITY_GAS_PRICE', eth_utils.to_wei(1, 'gwei')))
This allows the user to set the price if they need via an environment variable and defaults to 1 gwei. In a subsequent PR we can make this pluggable.
7e02e6e
to
083c8db
Compare
083c8db
to
c41df03
Compare
@pipermerriam I understand the problem, and have made the code in a simple way. Please review. Thankyou. |
What was wrong?
Link to Old PR: ethereum/py-evm#1651
As part of Issue #20 .
Implements
eth_coinbase
andeth_hashrate
functions. The return values are the default values as mining isn't supported by trinity as of now.eth_gasPrice
currently returns the average of thegasprices
of all the transactions in a block.How was it fixed?
The functions were
modified/added
totrinity/rpc/eth.py
Cute Animal Picture