Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Updated gas price tracker added #1056

Merged
merged 7 commits into from
Apr 18, 2018
Merged

Updated gas price tracker added #1056

merged 7 commits into from
Apr 18, 2018

Conversation

zilm13
Copy link
Collaborator

@zilm13 zilm13 commented Apr 16, 2018

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.

@coveralls
Copy link

coveralls commented Apr 16, 2018

Coverage Status

Coverage increased (+0.02%) to 56.271% when pulling 738f265 on fix/gasprice-tracker into 91d0127 on develop.

* Updated tracker is not enabled by default because it needs noticeable resources
* and is excessive for most users.
*/
@Deprecated
Copy link
Contributor

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;
}
}
Copy link
Contributor

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 {
Copy link
Contributor

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()));
Copy link
Contributor

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()) {
Copy link
Contributor

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() &&
Copy link
Contributor

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

Copy link
Contributor

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()];
Copy link
Contributor

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

@zilm13
Copy link
Collaborator Author

zilm13 commented Apr 18, 2018

@mkalinin sounds reasonable. updated.

@mkalinin mkalinin merged commit 605e8ac into develop Apr 18, 2018
@zilm13 zilm13 deleted the fix/gasprice-tracker branch June 4, 2018 15:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants