Skip to content

Commit 3e1331a

Browse files
authored
[ots] Fix incorrect return type and overflow on total block fees calc (#10070)
For E2: fix incorrect type + overflow in certain blocks Corresponding otterscan issue: otterscan/otterscan#1658
1 parent d7cd1fa commit 3e1331a

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

turbo/jsonrpc/otterscan_api.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,11 @@ func delegateIssuance(tx kv.Tx, block *types.Block, chainConfig *chain.Config, e
537537
return ret, nil
538538
}
539539

540-
func delegateBlockFees(ctx context.Context, tx kv.Tx, block *types.Block, senders []common.Address, chainConfig *chain.Config, receipts types.Receipts) (uint64, error) {
541-
fees := uint64(0)
540+
func delegateBlockFees(ctx context.Context, tx kv.Tx, block *types.Block, senders []common.Address, chainConfig *chain.Config, receipts types.Receipts) (*big.Int, error) {
541+
fee := big.NewInt(0)
542+
gasUsed := big.NewInt(0)
543+
544+
totalFees := big.NewInt(0)
542545
for _, receipt := range receipts {
543546
txn := block.Transactions()[receipt.TransactionIndex]
544547
effectiveGasPrice := uint64(0)
@@ -549,10 +552,15 @@ func delegateBlockFees(ctx context.Context, tx kv.Tx, block *types.Block, sender
549552
gasPrice := new(big.Int).Add(block.BaseFee(), txn.GetEffectiveGasTip(baseFee).ToBig())
550553
effectiveGasPrice = gasPrice.Uint64()
551554
}
552-
fees += effectiveGasPrice * receipt.GasUsed
555+
556+
fee.SetUint64(effectiveGasPrice)
557+
gasUsed.SetUint64(receipt.GasUsed)
558+
fee.Mul(fee, gasUsed)
559+
560+
totalFees.Add(totalFees, fee)
553561
}
554562

555-
return fees, nil
563+
return totalFees, nil
556564
}
557565

558566
func (api *OtterscanAPIImpl) getBlockWithSenders(ctx context.Context, number rpc.BlockNumber, tx kv.Tx) (*types.Block, []common.Address, error) {

turbo/jsonrpc/otterscan_block_details.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ func (api *OtterscanAPIImpl) getBlockDetailsImpl(ctx context.Context, tx kv.Tx,
8282
response := map[string]interface{}{}
8383
response["block"] = getBlockRes
8484
response["issuance"] = getIssuanceRes
85-
response["totalFees"] = hexutil.Uint64(feesRes)
85+
response["totalFees"] = (*hexutil.Big)(feesRes)
8686
return response, nil
8787
}

0 commit comments

Comments
 (0)