Skip to content

Commit

Permalink
[ots] Fix incorrect return type and overflow on total block fees calc (
Browse files Browse the repository at this point in the history
…#10070)

For E2: fix incorrect type + overflow in certain blocks

Corresponding otterscan issue:
otterscan/otterscan#1658
  • Loading branch information
wmitsuda authored Apr 26, 2024
1 parent d7cd1fa commit 3e1331a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions turbo/jsonrpc/otterscan_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,11 @@ func delegateIssuance(tx kv.Tx, block *types.Block, chainConfig *chain.Config, e
return ret, nil
}

func delegateBlockFees(ctx context.Context, tx kv.Tx, block *types.Block, senders []common.Address, chainConfig *chain.Config, receipts types.Receipts) (uint64, error) {
fees := uint64(0)
func delegateBlockFees(ctx context.Context, tx kv.Tx, block *types.Block, senders []common.Address, chainConfig *chain.Config, receipts types.Receipts) (*big.Int, error) {
fee := big.NewInt(0)
gasUsed := big.NewInt(0)

totalFees := big.NewInt(0)
for _, receipt := range receipts {
txn := block.Transactions()[receipt.TransactionIndex]
effectiveGasPrice := uint64(0)
Expand All @@ -549,10 +552,15 @@ func delegateBlockFees(ctx context.Context, tx kv.Tx, block *types.Block, sender
gasPrice := new(big.Int).Add(block.BaseFee(), txn.GetEffectiveGasTip(baseFee).ToBig())
effectiveGasPrice = gasPrice.Uint64()
}
fees += effectiveGasPrice * receipt.GasUsed

fee.SetUint64(effectiveGasPrice)
gasUsed.SetUint64(receipt.GasUsed)
fee.Mul(fee, gasUsed)

totalFees.Add(totalFees, fee)
}

return fees, nil
return totalFees, nil
}

func (api *OtterscanAPIImpl) getBlockWithSenders(ctx context.Context, number rpc.BlockNumber, tx kv.Tx) (*types.Block, []common.Address, error) {
Expand Down
2 changes: 1 addition & 1 deletion turbo/jsonrpc/otterscan_block_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ func (api *OtterscanAPIImpl) getBlockDetailsImpl(ctx context.Context, tx kv.Tx,
response := map[string]interface{}{}
response["block"] = getBlockRes
response["issuance"] = getIssuanceRes
response["totalFees"] = hexutil.Uint64(feesRes)
response["totalFees"] = (*hexutil.Big)(feesRes)
return response, nil
}

0 comments on commit 3e1331a

Please sign in to comment.