From 58cee31a69a6884de6b0fe2ed59976124b55e3a6 Mon Sep 17 00:00:00 2001 From: Max Revitt Date: Thu, 1 Feb 2024 13:18:12 +0000 Subject: [PATCH 1/2] fix(rpc): fix effectiveGasPrice eth_getTransactionReceipt --- cmd/rpcdaemon/commands/eth_receipts.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/rpcdaemon/commands/eth_receipts.go b/cmd/rpcdaemon/commands/eth_receipts.go index 24ea874bd9a..bcfa64b3750 100644 --- a/cmd/rpcdaemon/commands/eth_receipts.go +++ b/cmd/rpcdaemon/commands/eth_receipts.go @@ -676,7 +676,17 @@ func (api *APIImpl) GetTransactionReceipt(ctx context.Context, txnHash common.Ha return nil, fmt.Errorf("block has less receipts than expected: %d <= %d, block: %d", len(receipts), int(txnIndex), blockNum) } - return marshalReceipt(receipts[txnIndex], block.Transactions()[txnIndex], cc, block.HeaderNoCopy(), txnHash, true), nil + effectiveGasPricePercentage, err := api.getEffectiveGasPricePercentage(tx, txn.Hash()) + if err != nil { + return nil, err + } + + fields := marshalReceipt(receipts[txnIndex], block.Transactions()[txnIndex], cc, block.HeaderNoCopy(), txnHash, true) + + // zkevm - override effectiveGasPrice to consider effectiveGasPricePercentage + fields["effectiveGasPrice"] = core.CalculateEffectiveGas(txn.GetPrice(), effectiveGasPricePercentage) + + return fields, nil } // GetBlockReceipts - receipts for individual block @@ -770,6 +780,7 @@ func marshalReceipt(receipt *types.Receipt, txn types.Transaction, chainConfig * gasPrice := new(big.Int).Add(header.BaseFee, txn.GetEffectiveGasTip(baseFee).ToBig()) fields["effectiveGasPrice"] = hexutil.Uint64(gasPrice.Uint64()) } + // Assign receipt status. fields["status"] = hexutil.Uint64(receipt.Status) if receipt.Logs == nil { From 0789ec94781f7c0ac3528089dd9a0f9e3b0db2ee Mon Sep 17 00:00:00 2001 From: Max Revitt Date: Thu, 1 Feb 2024 13:18:12 +0000 Subject: [PATCH 2/2] fix(rpc): fix effectiveGasPrice eth_getTransactionReceipt --- cmd/rpcdaemon/commands/eth_receipts.go | 13 +------------ cmd/rpcdaemon/commands/eth_receipts_zkevm.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 cmd/rpcdaemon/commands/eth_receipts_zkevm.go diff --git a/cmd/rpcdaemon/commands/eth_receipts.go b/cmd/rpcdaemon/commands/eth_receipts.go index bcfa64b3750..d313564ce05 100644 --- a/cmd/rpcdaemon/commands/eth_receipts.go +++ b/cmd/rpcdaemon/commands/eth_receipts.go @@ -676,17 +676,7 @@ func (api *APIImpl) GetTransactionReceipt(ctx context.Context, txnHash common.Ha return nil, fmt.Errorf("block has less receipts than expected: %d <= %d, block: %d", len(receipts), int(txnIndex), blockNum) } - effectiveGasPricePercentage, err := api.getEffectiveGasPricePercentage(tx, txn.Hash()) - if err != nil { - return nil, err - } - - fields := marshalReceipt(receipts[txnIndex], block.Transactions()[txnIndex], cc, block.HeaderNoCopy(), txnHash, true) - - // zkevm - override effectiveGasPrice to consider effectiveGasPricePercentage - fields["effectiveGasPrice"] = core.CalculateEffectiveGas(txn.GetPrice(), effectiveGasPricePercentage) - - return fields, nil + return api.addEffectiveGasPercentage(marshalReceipt(receipts[txnIndex], txn, cc, block.HeaderNoCopy(), txnHash, true), tx, txn) } // GetBlockReceipts - receipts for individual block @@ -780,7 +770,6 @@ func marshalReceipt(receipt *types.Receipt, txn types.Transaction, chainConfig * gasPrice := new(big.Int).Add(header.BaseFee, txn.GetEffectiveGasTip(baseFee).ToBig()) fields["effectiveGasPrice"] = hexutil.Uint64(gasPrice.Uint64()) } - // Assign receipt status. fields["status"] = hexutil.Uint64(receipt.Status) if receipt.Logs == nil { diff --git a/cmd/rpcdaemon/commands/eth_receipts_zkevm.go b/cmd/rpcdaemon/commands/eth_receipts_zkevm.go new file mode 100644 index 00000000000..d79a5919907 --- /dev/null +++ b/cmd/rpcdaemon/commands/eth_receipts_zkevm.go @@ -0,0 +1,16 @@ +package commands + +import ( + "github.com/ledgerwatch/erigon-lib/kv" + "github.com/ledgerwatch/erigon/core" + "github.com/ledgerwatch/erigon/core/types" +) + +func (api *APIImpl) addEffectiveGasPercentage(fields map[string]interface{}, tx kv.Tx, txn types.Transaction) (map[string]interface{}, error) { + effectiveGasPricePercentage, err := api.getEffectiveGasPricePercentage(tx, txn.Hash()) + if err != nil { + return nil, err + } + fields["effectiveGasPrice"] = core.CalculateEffectiveGas(txn.GetPrice(), effectiveGasPricePercentage) + return fields, nil +}