Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release
- Cache last n blocks by using a new Besu flag --cache-last-blocks=n
- Optimize performances of RPC method Eth_feeHistory

### Breaking Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,33 +149,30 @@ public JsonRpcResponse response(final JsonRpcRequestContext request) {

final Optional<List<List<Wei>>> maybeRewards =
maybeRewardPercentiles.map(
rewardPercentiles ->
blockHeaders.stream()
.parallel()
.map(
blockHeader -> {
final RewardCacheKey key =
new RewardCacheKey(blockHeader.getBlockHash(), rewardPercentiles);
return Optional.ofNullable(cache.getIfPresent(key))
.or(
() -> {
Optional<Block> block =
blockchain.getBlockByHash(blockHeader.getBlockHash());
return block.map(
b -> {
List<Wei> rewards =
computeRewards(
rewardPercentiles.stream()
.sorted()
.collect(toUnmodifiableList()),
b);
cache.put(key, rewards);
return rewards;
});
});
})
.flatMap(Optional::stream)
.collect(toUnmodifiableList()));
rewardPercentiles -> {
var sortedPercentiles = rewardPercentiles.stream().sorted().toList();
return blockHeaders.stream()
.parallel()
.map(
blockHeader -> {
final RewardCacheKey key =
new RewardCacheKey(blockHeader.getBlockHash(), rewardPercentiles);
return Optional.ofNullable(cache.getIfPresent(key))
.or(
() -> {
Optional<Block> block =
blockchain.getBlockByHash(blockHeader.getBlockHash());
return block.map(
b -> {
List<Wei> rewards = computeRewards(sortedPercentiles, b);
cache.put(key, rewards);
return rewards;
});
});
})
.flatMap(Optional::stream)
.toList();
});

return new JsonRpcSuccessResponse(
requestId,
Expand Down