From 5caa80a6e7bd7b77f177b91f7bf24e85da89447a Mon Sep 17 00:00:00 2001 From: pcw109550 Date: Wed, 19 Apr 2023 20:01:19 +0900 Subject: [PATCH] Handle depositTx fee and gasUsed logic --- cmd/rpcdaemon/commands/otterscan_api.go | 12 +++++++++--- cmd/rpcdaemon/commands/otterscan_block_details.go | 10 ++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cmd/rpcdaemon/commands/otterscan_api.go b/cmd/rpcdaemon/commands/otterscan_api.go index 4405463d48a..669d3c73332 100644 --- a/cmd/rpcdaemon/commands/otterscan_api.go +++ b/cmd/rpcdaemon/commands/otterscan_api.go @@ -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] @@ -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) { diff --git a/cmd/rpcdaemon/commands/otterscan_block_details.go b/cmd/rpcdaemon/commands/otterscan_block_details.go index 0be91f3b632..40356f408c2 100644 --- a/cmd/rpcdaemon/commands/otterscan_block_details.go +++ b/cmd/rpcdaemon/commands/otterscan_block_details.go @@ -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 } @@ -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 } @@ -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 } @@ -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 }