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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ public Wei calculateBlockValue(final BlockWithReceipts blockWithReceipts) {
Wei totalFee = Wei.ZERO;
for (int i = 0; i < txs.size(); i++) {
final Wei minerFee = txs.get(i).getEffectivePriorityFeePerGas(block.getHeader().getBaseFee());
totalFee = totalFee.add(minerFee.multiply(receipts.get(i).getCumulativeGasUsed()));
// we don't store gasUsed and need to calculate that on the fly
// receipts are fetched in ascending sorted by cumulativeGasUsed
long gasUsed = receipts.get(i).getCumulativeGasUsed();
if (i > 0) {
gasUsed = gasUsed - receipts.get(i - 1).getCumulativeGasUsed();
}
totalFee = totalFee.add(minerFee.multiply(gasUsed));
}
return totalFee;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public void shouldCalculateCorrectBlockValue() {
new BlockValueCalculator()
.calculateBlockValue(
new BlockWithReceipts(block, List.of(receipt1, receipt2, receipt3)));
// Block value = 71 * 1 + 143 * 2 + 214 * 5 = 1427
assertThat(blockValue).isEqualTo(Wei.of(1427L));
// Block value = 71 * 1 + (143-71) * 2 + (214-143) * 5 = 1427
assertThat(blockValue).isEqualTo(Wei.of(570L));
}

@Test
Expand Down