Skip to content

Commit

Permalink
Handle depositTx fee and gasUsed logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pcw109550 committed Apr 19, 2023
1 parent 965331c commit 5caa80a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 9 additions & 3 deletions cmd/rpcdaemon/commands/otterscan_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,12 +724,13 @@ func (api *OtterscanAPIImpl) delegateIssuance(tx kv.Tx, block *types.Block, chai
return ret, nil
}

func (api *OtterscanAPIImpl) delegateBlockFees(ctx context.Context, tx kv.Tx, block *types.Block, senders []common.Address, chainConfig *chain.Config) (uint64, error) {
func (api *OtterscanAPIImpl) delegateBlockFees(ctx context.Context, tx kv.Tx, block *types.Block, senders []common.Address, chainConfig *chain.Config) (uint64, uint64, error) {
receipts, err := api.getReceipts(ctx, tx, chainConfig, block, senders)
if err != nil {
return 0, fmt.Errorf("getReceipts error: %v", err)
return 0, 0, fmt.Errorf("getReceipts error: %v", err)
}

gasUsedDepositTx := uint64(0)
fees := uint64(0)
for _, receipt := range receipts {
txn := block.Transactions()[receipt.TransactionIndex]
Expand All @@ -738,13 +739,18 @@ func (api *OtterscanAPIImpl) delegateBlockFees(ctx context.Context, tx kv.Tx, bl
effectiveGasPrice = txn.GetPrice().Uint64()
} else {
baseFee, _ := uint256.FromBig(block.BaseFee())
if chainConfig.IsOptimism() && receipt.IsDepositTxReceipt() {
// if depositTx, no fee consumption
gasUsedDepositTx += receipt.GasUsed
continue
}
gasPrice := new(big.Int).Add(block.BaseFee(), txn.GetEffectiveGasTip(baseFee).ToBig())
effectiveGasPrice = gasPrice.Uint64()
}
fees += effectiveGasPrice * receipt.GasUsed
}

return fees, nil
return fees, gasUsedDepositTx, nil
}

func (api *OtterscanAPIImpl) getBlockWithSenders(ctx context.Context, number rpc.BlockNumber, tx kv.Tx) (*types.Block, []common.Address, error) {
Expand Down
10 changes: 8 additions & 2 deletions cmd/rpcdaemon/commands/otterscan_block_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (api *OtterscanAPIImpl) GetBlockDetails(ctx context.Context, number rpc.Blo
if err != nil {
return nil, err
}
feesRes, err := api.delegateBlockFees(ctx, tx, b, senders, chainConfig)
feesRes, gasUsedDepositTxRes, err := api.delegateBlockFees(ctx, tx, b, senders, chainConfig)
if err != nil {
return nil, err
}
Expand All @@ -52,6 +52,9 @@ func (api *OtterscanAPIImpl) GetBlockDetails(ctx context.Context, number rpc.Blo
response["block"] = getBlockRes
response["issuance"] = getIssuanceRes
response["totalFees"] = hexutil.Uint64(feesRes)
if chainConfig.IsOptimism() {
response["gasUsedDepositTx"] = hexutil.Uint64(gasUsedDepositTxRes)
}
return response, nil
}

Expand Down Expand Up @@ -89,7 +92,7 @@ func (api *OtterscanAPIImpl) GetBlockDetailsByHash(ctx context.Context, hash com
if err != nil {
return nil, err
}
feesRes, err := api.delegateBlockFees(ctx, tx, b, senders, chainConfig)
feesRes, gasUsedDepositTxRes, err := api.delegateBlockFees(ctx, tx, b, senders, chainConfig)
if err != nil {
return nil, err
}
Expand All @@ -98,5 +101,8 @@ func (api *OtterscanAPIImpl) GetBlockDetailsByHash(ctx context.Context, hash com
response["block"] = getBlockRes
response["issuance"] = getIssuanceRes
response["totalFees"] = hexutil.Uint64(feesRes)
if chainConfig.IsOptimism() {
response["gasUsedDepositTx"] = hexutil.Uint64(gasUsedDepositTxRes)
}
return response, nil
}

0 comments on commit 5caa80a

Please sign in to comment.