Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ots] Fix incorrect return type and overflow on total block fees calc #10070

Merged
merged 1 commit into from
Apr 26, 2024
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
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
}
Loading