Skip to content

Commit

Permalink
Recount only when we have new data
Browse files Browse the repository at this point in the history
  • Loading branch information
zilm13 committed Apr 17, 2018
1 parent aa9d55e commit 738f265
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,20 @@ public void onBlock(BlockSummary blockSummary) {
}

private void onBlock(Block block) {
onTransactions(block.getTransactionsList());
++idx;
if (idx == getBlocksRecount()) {
Long newGasPrice = getGasPrice();
if (newGasPrice != null) {
this.recommendedGasPrice = newGasPrice;
if (onTransactions(block.getTransactionsList())) {
++idx;
if (idx == getBlocksRecount()) {
Long newGasPrice = getGasPrice();
if (newGasPrice != null) {
this.recommendedGasPrice = newGasPrice;
}
idx = 0;
}
idx = 0;
}
}

private synchronized void onTransactions(List<Transaction> txs) {
if (txs.isEmpty()) return;
private synchronized boolean onTransactions(List<Transaction> txs) {
if (txs.isEmpty()) return false;

long[] gasPrices = new long[txs.size()];
for (int i = 0; i < txs.size(); ++i) {
Expand All @@ -85,6 +86,7 @@ private synchronized void onTransactions(List<Transaction> txs) {
blockGasPrices.remove(blockGasPrices.get(0));
}
blockGasPrices.add(gasPrices);
return true;
}

private int calcGasPricesSize() {
Expand Down

0 comments on commit 738f265

Please sign in to comment.