-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Conversation
* Updated tracker is not enabled by default because it needs noticeable resources | ||
* and is excessive for most users. | ||
*/ | ||
@Deprecated |
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.
Let's mark it deprecated in the docs too
public static int getPercentileShare() { | ||
return PERCENTILE_SHARE; | ||
} | ||
} |
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.
New line, please :)
* (if {@link #getPercentileShare()} is not overridden) of the latest transactions were | ||
* executed at this or lower price. | ||
*/ | ||
public class RecommendedGasPriceTracker extends EthereumListenerAdapter { |
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.
I'd rather use composition here, cause price tracker is no a kind of ethereum listener. Anyway, it's not essential to be changed
private Long recommendedGasPrice = getDefaultPrice(); | ||
|
||
public RecommendedGasPriceTracker() { | ||
blockGasPrices = new CircularFifoQueue<>(Math.max(getMinTransactions(), getMinBlocks())); |
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.
Since gasPrices
collection became not responsible for purging old Txes CircularFifoQueue
starts to be redundant. Maybe it's better to use LinkedList
here?
private void onBlock(Block block) { | ||
if (onTransactions(block.getTransactionsList())) { | ||
++idx; | ||
if (idx == getBlocksRecount()) { |
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.
I'd rather use less strict >=
condition here, just in case. Or another way is to keep using modulo operand if idx
param would never reset
gasPrices[i] = ByteUtil.byteArrayToLong(txs.get(i).getGasPrice()); | ||
} | ||
|
||
while (blockGasPrices.size() >= getMinBlocks() && |
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.
If gasPrices
would be added before the loop then we got rid of extra + gasPrices.length
argument in the loop condition. But this would only work if intrusive CircularFifoQueue
was replaced
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.
If above changes are applied >=
can be replaced with >
which should be more precise condition
if (size < getMinTransactions() || | ||
blockGasPrices.size() < getMinBlocks()) return null; | ||
|
||
long[] difficulties = new long[size > getMinTransactions() ? size : getMinTransactions()]; |
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.
Ternary operator used in array size definition can be omitted here
@mkalinin sounds reasonable. updated. |
This is an updated version that returns more accurate data
in networks with large number of transactions like Ethereum MainNet.
However it needs more CPU and memory resources for processing so it's not enabled by default.