diff --git a/src/Nethermind/Nethermind.Evm/IntrinsicGasCalculator.cs b/src/Nethermind/Nethermind.Evm/IntrinsicGasCalculator.cs index 08e46ad6ee01..631d182503be 100644 --- a/src/Nethermind/Nethermind.Evm/IntrinsicGasCalculator.cs +++ b/src/Nethermind/Nethermind.Evm/IntrinsicGasCalculator.cs @@ -96,11 +96,14 @@ private static long AccessListCost(Transaction transaction, IReleaseSpec release public static ulong CalculateDataGas(int blobCount) => (ulong)blobCount * Eip4844Constants.DataGasPerBlob; + public static ulong CalculateDataGas(Transaction transaction) => + CalculateDataGas(transaction.BlobVersionedHashes?.Length ?? 0); + public static UInt256 CalculateDataGasPrice(BlockHeader header, Transaction transaction) => - CalculateDataGas(transaction.BlobVersionedHashes?.Length ?? 0) * CalculateDataGasPricePerUnit(header); + CalculateDataGas(transaction) * CalculateDataGasPricePerUnit(header); public static UInt256 CalculateDataGasPrice(BlockHeader header) => - header.DataGasUsed.Value * CalculateDataGasPricePerUnit(header); + header.DataGasUsed!.Value * CalculateDataGasPricePerUnit(header); public static UInt256 CalculateDataGasPricePerUnit(BlockHeader header) { diff --git a/src/Nethermind/Nethermind.Evm/TransactionExtensions.cs b/src/Nethermind/Nethermind.Evm/TransactionExtensions.cs index a5f85fe7075e..e0bd18c18603 100644 --- a/src/Nethermind/Nethermind.Evm/TransactionExtensions.cs +++ b/src/Nethermind/Nethermind.Evm/TransactionExtensions.cs @@ -14,5 +14,40 @@ tx.To is not null : tx.IsSystem() ? tx.SenderAddress : ContractAddress.From(tx.SenderAddress, nonce > 0 ? nonce - 1 : nonce); + + public static TxGasInfo GetGasInfo(this Transaction tx, bool is1559Enabled, BlockHeader header) + { + UInt256 effectiveGasPrice = tx.CalculateEffectiveGasPrice(is1559Enabled, header.BaseFeePerGas); + ulong? dataGas = null; + UInt256? dataGasPrice = null; + if (tx.SupportsBlobs) + { + dataGas = IntrinsicGasCalculator.CalculateDataGas(tx); + dataGasPrice = IntrinsicGasCalculator.CalculateDataGasPrice(header, tx); + } + + return new(effectiveGasPrice, dataGasPrice, dataGas); + } + } + + public struct TxGasInfo + { + public TxGasInfo() { } + + public TxGasInfo(UInt256? effectiveGasPrice, UInt256? dataGasPrice, ulong? dataGasUsed) + { + EffectiveGasPrice = effectiveGasPrice; + DataGasPrice = dataGasPrice; + DataGasUsed = dataGasUsed; + } + + public TxGasInfo(UInt256? effectiveGasPrice) + { + EffectiveGasPrice = effectiveGasPrice; + } + + public UInt256? EffectiveGasPrice { get; private set; } + public UInt256? DataGasPrice { get; private set; } + public ulong? DataGasUsed { get; private set; } } } diff --git a/src/Nethermind/Nethermind.Facade.Test/BlockchainBridgeTests.cs b/src/Nethermind/Nethermind.Facade.Test/BlockchainBridgeTests.cs index 6ace9a200d09..4dba1905c19c 100644 --- a/src/Nethermind/Nethermind.Facade.Test/BlockchainBridgeTests.cs +++ b/src/Nethermind/Nethermind.Facade.Test/BlockchainBridgeTests.cs @@ -28,6 +28,7 @@ using NSubstitute; using NUnit.Framework; using Nethermind.Config; +using Nethermind.Evm; namespace Nethermind.Facade.Test { @@ -231,20 +232,34 @@ public void Bridge_head_is_correct(long headNumber) _blockchainBridge.HeadBlock.Should().Be(head); } - [TestCase(true)] - [TestCase(false)] - public void GetReceiptAndEffectiveGasPrice_returns_correct_results(bool isCanonical) + [TestCase(true, true)] + [TestCase(false, true)] + [TestCase(true, false)] + [TestCase(false, false)] + public void GetReceiptAndGasInfo_returns_correct_results(bool isCanonical, bool postEip4844) { Keccak txHash = TestItem.KeccakA; Keccak blockHash = TestItem.KeccakB; UInt256 effectiveGasPrice = 123; - Transaction tx = Build.A.Transaction - .WithGasPrice(effectiveGasPrice) - .TestObject; - Block block = Build.A.Block - .WithTransactions(tx) - .TestObject; + Transaction tx = postEip4844 + ? Build.A.Transaction + .WithGasPrice(effectiveGasPrice) + .WithType(TxType.Blob) + .WithMaxFeePerDataGas(2) + .WithBlobVersionedHashes(2) + .TestObject + : Build.A.Transaction + .WithGasPrice(effectiveGasPrice) + .TestObject; + Block block = postEip4844 + ? Build.A.Block + .WithTransactions(tx) + .WithExcessDataGas(2) + .TestObject + : Build.A.Block + .WithTransactions(tx) + .TestObject; TxReceipt receipt = Build.A.Receipt .WithBlockHash(blockHash) .WithTransactionHash(txHash) @@ -255,8 +270,16 @@ public void GetReceiptAndEffectiveGasPrice_returns_correct_results(bool isCanoni _receiptStorage.FindBlockHash(txHash).Returns(blockHash); _receiptStorage.Get(block).Returns(new[] { receipt }); - (TxReceipt Receipt, UInt256? EffectiveGasPrice, int LogIndexStart) result = isCanonical ? (receipt, effectiveGasPrice, 0) : (null, null, 0); - _blockchainBridge.GetReceiptAndEffectiveGasPrice(txHash).Should().BeEquivalentTo(result); + (TxReceipt? Receipt, TxGasInfo? GasInfo, int LogIndexStart) result = postEip4844 + ? (receipt, new(effectiveGasPrice, 262144, 262144), 0) + : (receipt, new(effectiveGasPrice), 0); + + if (!isCanonical) + { + result = (null, null, 0); + } + + _blockchainBridge.GetReceiptAndGasInfo(txHash).Should().BeEquivalentTo(result); } } } diff --git a/src/Nethermind/Nethermind.Facade.Test/Nethermind.Facade.Test.csproj b/src/Nethermind/Nethermind.Facade.Test/Nethermind.Facade.Test.csproj index 15608eea2e80..5feafc0ae107 100644 --- a/src/Nethermind/Nethermind.Facade.Test/Nethermind.Facade.Test.csproj +++ b/src/Nethermind/Nethermind.Facade.Test/Nethermind.Facade.Test.csproj @@ -3,6 +3,7 @@ net7.0 true + annotations diff --git a/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs b/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs index 0746848502a9..dbc10993fb9b 100644 --- a/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs +++ b/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs @@ -83,7 +83,7 @@ public Block? HeadBlock public bool IsMining { get; } - public (TxReceipt Receipt, UInt256? EffectiveGasPrice, int LogIndexStart) GetReceiptAndEffectiveGasPrice(Keccak txHash) + public (TxReceipt? Receipt, TxGasInfo? GasInfo, int LogIndexStart) GetReceiptAndGasInfo(Keccak txHash) { Keccak blockHash = _receiptFinder.FindBlockHash(txHash); if (blockHash is not null) @@ -96,15 +96,14 @@ public Block? HeadBlock int logIndexStart = txReceipts.GetBlockLogFirstIndex(txReceipt.Index); Transaction tx = block.Transactions[txReceipt.Index]; bool is1559Enabled = _specProvider.GetSpecFor1559(block.Number).IsEip1559Enabled; - UInt256 effectiveGasPrice = tx.CalculateEffectiveGasPrice(is1559Enabled, block.Header.BaseFeePerGas); - return (txReceipt, effectiveGasPrice, logIndexStart); + return (txReceipt, tx.GetGasInfo(is1559Enabled, block.Header), logIndexStart); } } return (null, null, 0); } - public (TxReceipt Receipt, Transaction Transaction, UInt256? baseFee) GetTransaction(Keccak txHash) + public (TxReceipt? Receipt, Transaction Transaction, UInt256? baseFee) GetTransaction(Keccak txHash) { Keccak blockHash = _receiptFinder.FindBlockHash(txHash); if (blockHash is not null) @@ -271,7 +270,7 @@ private void CallAndRestore( if (releaseSpec.IsEip4844Enabled) { - callHeader.DataGasUsed = IntrinsicGasCalculator.CalculateDataGas(transaction.BlobVersionedHashes?.Length ?? 0); + callHeader.DataGasUsed = IntrinsicGasCalculator.CalculateDataGas(transaction); callHeader.ExcessDataGas = treatBlockHeaderAsParentBlock ? IntrinsicGasCalculator.CalculateExcessDataGas(blockHeader, releaseSpec) : blockHeader.ExcessDataGas; diff --git a/src/Nethermind/Nethermind.Facade/IBlockchainBridge.cs b/src/Nethermind/Nethermind.Facade/IBlockchainBridge.cs index 0b39fac85b9f..cccff0b75ea8 100644 --- a/src/Nethermind/Nethermind.Facade/IBlockchainBridge.cs +++ b/src/Nethermind/Nethermind.Facade/IBlockchainBridge.cs @@ -7,6 +7,7 @@ using Nethermind.Blockchain.Find; using Nethermind.Core; using Nethermind.Core.Crypto; +using Nethermind.Evm; using Nethermind.Facade.Filters; using Nethermind.Int256; using Nethermind.Trie; @@ -21,8 +22,8 @@ public interface IBlockchainBridge : ILogFinder void RecoverTxSenders(Block block); Address? RecoverTxSender(Transaction tx); TxReceipt GetReceipt(Keccak txHash); - (TxReceipt Receipt, UInt256? EffectiveGasPrice, int LogIndexStart) GetReceiptAndEffectiveGasPrice(Keccak txHash); - (TxReceipt Receipt, Transaction Transaction, UInt256? baseFee) GetTransaction(Keccak txHash); + (TxReceipt? Receipt, TxGasInfo? GasInfo, int LogIndexStart) GetReceiptAndGasInfo(Keccak txHash); + (TxReceipt? Receipt, Transaction Transaction, UInt256? baseFee) GetTransaction(Keccak txHash); BlockchainBridge.CallOutput Call(BlockHeader header, Transaction tx, CancellationToken cancellationToken); BlockchainBridge.CallOutput EstimateGas(BlockHeader header, Transaction tx, CancellationToken cancellationToken); BlockchainBridge.CallOutput CreateAccessList(BlockHeader header, Transaction tx, CancellationToken cancellationToken, bool optimize); diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Data/ReceiptsForRpcTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Data/ReceiptsForRpcTests.cs index 06e71db2bf51..2ab81efce343 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Data/ReceiptsForRpcTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Data/ReceiptsForRpcTests.cs @@ -38,7 +38,7 @@ public void Are_log_indexes_unique() }; UInt256 effectiveGasPrice = new(5526); - ReceiptForRpc receiptForRpc = new(txHash, receipt1, effectiveGasPrice); + ReceiptForRpc receiptForRpc = new(txHash, receipt1, new(effectiveGasPrice)); long?[] indexes = receiptForRpc.Logs.Select(log => log.LogIndex).ToArray(); long?[] expected = { 0, 1, 2 }; diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs index 36a6105b6b8a..4f97badc6637 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs @@ -818,8 +818,9 @@ public async Task Eth_get_block_by_number_with_recovering_sender_from_receipts() Assert.That(serialized, Is.EqualTo("{\"jsonrpc\":\"2.0\",\"result\":{\"author\":\"0x0000000000000000000000000000000000000000\",\"difficulty\":\"0xf4240\",\"extraData\":\"0x010203\",\"gasLimit\":\"0x3d0900\",\"gasUsed\":\"0x0\",\"hash\":\"0xe3026a6708b90d5cb25557ac38ddc3f5ef550af10f31e1cf771524da8553fa1c\",\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"miner\":\"0x0000000000000000000000000000000000000000\",\"mixHash\":\"0x2ba5557a4c62a513c7e56d1bf13373e0da6bec016755483e91589fe1c6d212e2\",\"nonce\":\"0x00000000000003e8\",\"number\":\"0x1\",\"parentHash\":\"0xff483e972a04a9a62bb4b7d04ae403c615604e4090521ecc5bb7af67f71be09c\",\"receiptsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"sha3Uncles\":\"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347\",\"size\":\"0x221\",\"stateRoot\":\"0x1ef7300d8961797263939a3d29bbba4ccf1702fabf02d8ad7a20b454edb6fd2f\",\"totalDifficulty\":\"0x0\",\"timestamp\":\"0xf4240\",\"transactions\":[{\"nonce\":\"0x0\",\"blockHash\":\"0xe3026a6708b90d5cb25557ac38ddc3f5ef550af10f31e1cf771524da8553fa1c\",\"blockNumber\":\"0x1\",\"transactionIndex\":\"0x0\",\"from\":\"0x2d36e6c27c34ea22620e7b7c45de774599406cf3\",\"to\":\"0x0000000000000000000000000000000000000000\",\"value\":\"0x1\",\"gasPrice\":\"0x1\",\"gas\":\"0x5208\",\"data\":\"0x\",\"input\":\"0x\",\"type\":\"0x0\"}],\"transactionsRoot\":\"0x29cc403075ed3d1d6af940d577125cc378ee5a26f7746cbaf87f1cf4a38258b5\",\"uncles\":[]},\"id\":67}")); } - [Test] - public async Task Eth_get_transaction_receipt() + [TestCase(false)] + [TestCase(true)] + public async Task Eth_get_transaction_receipt(bool postEip4844) { using Context ctx = await Context.Create(); IBlockchainBridge blockchainBridge = Substitute.For(); @@ -840,7 +841,9 @@ public async Task Eth_get_transaction_receipt() .WithLogs(entries).TestObject; TxReceipt[] receiptsTab = { receipt }; - blockchainBridge.GetReceiptAndEffectiveGasPrice(Arg.Any()).Returns((receipt, UInt256.One, 0)); + + blockchainBridge.GetReceiptAndGasInfo(Arg.Any()) + .Returns((receipt, postEip4844 ? new(UInt256.One, 2, 3) : new(UInt256.One), 0)); blockFinder.FindBlock(Arg.Any()).Returns(block); receiptFinder.Get(Arg.Any()).Returns(receiptsTab); receiptFinder.Get(Arg.Any()).Returns(receiptsTab); @@ -848,7 +851,10 @@ public async Task Eth_get_transaction_receipt() ctx.Test = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).WithBlockFinder(blockFinder).WithReceiptFinder(receiptFinder).WithBlockchainBridge(blockchainBridge).Build(); string serialized = ctx.Test.TestEthRpc("eth_getTransactionReceipt", TestItem.KeccakA.ToString()); - Assert.That(serialized, Is.EqualTo("{\"jsonrpc\":\"2.0\",\"result\":{\"transactionHash\":\"0x03783fac2efed8fbc9ad443e592ee30e61d65f471140c10ca155e937b435b760\",\"transactionIndex\":\"0x2\",\"blockHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"blockNumber\":\"0x2\",\"cumulativeGasUsed\":\"0x3e8\",\"gasUsed\":\"0x64\",\"effectiveGasPrice\":\"0x1\",\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"to\":\"0x942921b14f1b1c385cd7e0cc2ef7abe5598c8358\",\"contractAddress\":\"0x76e68a8696537e4141926f3e528733af9e237d69\",\"logs\":[{\"removed\":false,\"logIndex\":\"0x0\",\"transactionIndex\":\"0x2\",\"transactionHash\":\"0x03783fac2efed8fbc9ad443e592ee30e61d65f471140c10ca155e937b435b760\",\"blockHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"blockNumber\":\"0x2\",\"address\":\"0x0000000000000000000000000000000000000000\",\"data\":\"0x\",\"topics\":[\"0x0000000000000000000000000000000000000000000000000000000000000000\"]},{\"removed\":false,\"logIndex\":\"0x1\",\"transactionIndex\":\"0x2\",\"transactionHash\":\"0x03783fac2efed8fbc9ad443e592ee30e61d65f471140c10ca155e937b435b760\",\"blockHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"blockNumber\":\"0x2\",\"address\":\"0x0000000000000000000000000000000000000000\",\"data\":\"0x\",\"topics\":[\"0x0000000000000000000000000000000000000000000000000000000000000000\"]}],\"logsBloom\":\"0x00000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000800000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000\",\"root\":\"0x1f675bff07515f5df96737194ea945c36c41e7b4fcef307b7cd4d0e602a69111\",\"status\":\"0x1\",\"error\":\"error\",\"type\":\"0x0\"},\"id\":67}")); + if (postEip4844) + Assert.That(serialized, Is.EqualTo("{\"jsonrpc\":\"2.0\",\"result\":{\"transactionHash\":\"0x03783fac2efed8fbc9ad443e592ee30e61d65f471140c10ca155e937b435b760\",\"transactionIndex\":\"0x2\",\"blockHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"blockNumber\":\"0x2\",\"cumulativeGasUsed\":\"0x3e8\",\"gasUsed\":\"0x64\",\"dataGasUsed\":\"0x3\",\"dataGasPrice\":\"0x2\",\"effectiveGasPrice\":\"0x1\",\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"to\":\"0x942921b14f1b1c385cd7e0cc2ef7abe5598c8358\",\"contractAddress\":\"0x76e68a8696537e4141926f3e528733af9e237d69\",\"logs\":[{\"removed\":false,\"logIndex\":\"0x0\",\"transactionIndex\":\"0x2\",\"transactionHash\":\"0x03783fac2efed8fbc9ad443e592ee30e61d65f471140c10ca155e937b435b760\",\"blockHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"blockNumber\":\"0x2\",\"address\":\"0x0000000000000000000000000000000000000000\",\"data\":\"0x\",\"topics\":[\"0x0000000000000000000000000000000000000000000000000000000000000000\"]},{\"removed\":false,\"logIndex\":\"0x1\",\"transactionIndex\":\"0x2\",\"transactionHash\":\"0x03783fac2efed8fbc9ad443e592ee30e61d65f471140c10ca155e937b435b760\",\"blockHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"blockNumber\":\"0x2\",\"address\":\"0x0000000000000000000000000000000000000000\",\"data\":\"0x\",\"topics\":[\"0x0000000000000000000000000000000000000000000000000000000000000000\"]}],\"logsBloom\":\"0x00000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000800000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000\",\"root\":\"0x1f675bff07515f5df96737194ea945c36c41e7b4fcef307b7cd4d0e602a69111\",\"status\":\"0x1\",\"error\":\"error\",\"type\":\"0x0\"},\"id\":67}")); + else + Assert.That(serialized, Is.EqualTo("{\"jsonrpc\":\"2.0\",\"result\":{\"transactionHash\":\"0x03783fac2efed8fbc9ad443e592ee30e61d65f471140c10ca155e937b435b760\",\"transactionIndex\":\"0x2\",\"blockHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"blockNumber\":\"0x2\",\"cumulativeGasUsed\":\"0x3e8\",\"gasUsed\":\"0x64\",\"effectiveGasPrice\":\"0x1\",\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"to\":\"0x942921b14f1b1c385cd7e0cc2ef7abe5598c8358\",\"contractAddress\":\"0x76e68a8696537e4141926f3e528733af9e237d69\",\"logs\":[{\"removed\":false,\"logIndex\":\"0x0\",\"transactionIndex\":\"0x2\",\"transactionHash\":\"0x03783fac2efed8fbc9ad443e592ee30e61d65f471140c10ca155e937b435b760\",\"blockHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"blockNumber\":\"0x2\",\"address\":\"0x0000000000000000000000000000000000000000\",\"data\":\"0x\",\"topics\":[\"0x0000000000000000000000000000000000000000000000000000000000000000\"]},{\"removed\":false,\"logIndex\":\"0x1\",\"transactionIndex\":\"0x2\",\"transactionHash\":\"0x03783fac2efed8fbc9ad443e592ee30e61d65f471140c10ca155e937b435b760\",\"blockHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"blockNumber\":\"0x2\",\"address\":\"0x0000000000000000000000000000000000000000\",\"data\":\"0x\",\"topics\":[\"0x0000000000000000000000000000000000000000000000000000000000000000\"]}],\"logsBloom\":\"0x00000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000800000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000\",\"root\":\"0x1f675bff07515f5df96737194ea945c36c41e7b4fcef307b7cd4d0e602a69111\",\"status\":\"0x1\",\"error\":\"error\",\"type\":\"0x0\"},\"id\":67}")); } @@ -903,7 +909,7 @@ public async Task Eth_get_transaction_receipt_when_block_has_few_receipts() Logs = logEntries }; - blockchainBridge.GetReceiptAndEffectiveGasPrice(Arg.Any()).Returns((receipt2, UInt256.One, 2)); + blockchainBridge.GetReceiptAndGasInfo(Arg.Any()).Returns((receipt2, new(UInt256.One), 2)); TxReceipt[] receipts = { receipt1, receipt2 }; @@ -959,7 +965,7 @@ public async Task Eth_getTransactionReceipt_return_info_about_mined_tx() blockFinder.FindBlock(Arg.Any()).Returns(block); receiptFinder.Get(Arg.Any()).Returns(receiptsTab); receiptFinder.Get(Arg.Any()).Returns(receiptsTab); - blockchainBridge.GetReceiptAndEffectiveGasPrice(Arg.Any()).Returns((receipt, UInt256.One, 0)); + blockchainBridge.GetReceiptAndGasInfo(Arg.Any()).Returns((receipt, new(UInt256.One), 0)); ctx.Test = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).WithBlockFinder(blockFinder).WithReceiptFinder(receiptFinder).WithBlockchainBridge(blockchainBridge).Build(); string serialized = ctx.Test.TestEthRpc("eth_getTransactionReceipt", tx.Hash!.ToString()); diff --git a/src/Nethermind/Nethermind.JsonRpc/Converters/TxReceiptConverter.cs b/src/Nethermind/Nethermind.JsonRpc/Converters/TxReceiptConverter.cs index 682247df55bf..34da8afada23 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Converters/TxReceiptConverter.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Converters/TxReceiptConverter.cs @@ -13,7 +13,7 @@ public class TxReceiptConverter : JsonConverter { public override void WriteJson(JsonWriter writer, TxReceipt value, JsonSerializer serializer) { - serializer.Serialize(writer, new ReceiptForRpc(value.TxHash!, value, UInt256.Zero)); + serializer.Serialize(writer, new ReceiptForRpc(value.TxHash!, value, new(UInt256.Zero))); } public override TxReceipt ReadJson(JsonReader reader, Type objectType, TxReceipt existingValue, bool hasExistingValue, JsonSerializer serializer) diff --git a/src/Nethermind/Nethermind.JsonRpc/Data/ReceiptForRpc.cs b/src/Nethermind/Nethermind.JsonRpc/Data/ReceiptForRpc.cs index 00de50c6f1b8..7ce43ff3411e 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Data/ReceiptForRpc.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Data/ReceiptForRpc.cs @@ -1,10 +1,10 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only -using System; using System.Linq; using Nethermind.Core; using Nethermind.Core.Crypto; +using Nethermind.Evm; using Nethermind.Int256; using Newtonsoft.Json; @@ -16,7 +16,7 @@ public ReceiptForRpc() { } - public ReceiptForRpc(Keccak txHash, TxReceipt receipt, UInt256? effectiveGasPrice, int logIndexStart = 0) + public ReceiptForRpc(Keccak txHash, TxReceipt receipt, TxGasInfo gasInfo, int logIndexStart = 0) { TransactionHash = txHash; TransactionIndex = receipt.Index; @@ -24,7 +24,9 @@ public ReceiptForRpc(Keccak txHash, TxReceipt receipt, UInt256? effectiveGasPric BlockNumber = receipt.BlockNumber; CumulativeGasUsed = receipt.GasUsedTotal; GasUsed = receipt.GasUsed; - EffectiveGasPrice = effectiveGasPrice; + EffectiveGasPrice = gasInfo.EffectiveGasPrice; + DataGasUsed = gasInfo.DataGasUsed; + DataGasPrice = gasInfo.DataGasPrice; From = receipt.Sender; To = receipt.Recipient; ContractAddress = receipt.ContractAddress; @@ -42,6 +44,10 @@ public ReceiptForRpc(Keccak txHash, TxReceipt receipt, UInt256? effectiveGasPric public long BlockNumber { get; set; } public long CumulativeGasUsed { get; set; } public long GasUsed { get; set; } + [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + public ulong? DataGasUsed { get; set; } + [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + public UInt256? DataGasPrice { get; set; } public UInt256? EffectiveGasPrice { get; set; } public Address From { get; set; } diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/EthRpcModule.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/EthRpcModule.cs index 743f656c121e..2fb9ce4c21a6 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/EthRpcModule.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/EthRpcModule.cs @@ -15,6 +15,7 @@ using Nethermind.Core.Crypto; using Nethermind.Core.Extensions; using Nethermind.Core.Specs; +using Nethermind.Evm; using Nethermind.Facade; using Nethermind.Facade.Eth; using Nethermind.Facade.Filters; @@ -494,14 +495,14 @@ public ResultWrapper eth_getTransactionByBlockNumberAndIndex( public Task> eth_getTransactionReceipt(Keccak txHash) { - (TxReceipt receipt, UInt256? effectiveGasPrice, int logIndexStart) = _blockchainBridge.GetReceiptAndEffectiveGasPrice(txHash); - if (receipt is null) + (TxReceipt? receipt, TxGasInfo? gasInfo, int logIndexStart) = _blockchainBridge.GetReceiptAndGasInfo(txHash); + if (receipt is null || gasInfo is null) { return Task.FromResult(ResultWrapper.Success(null)); } if (_logger.IsTrace) _logger.Trace($"eth_getTransactionReceipt request {txHash}, result: {txHash}"); - return Task.FromResult(ResultWrapper.Success(new(txHash, receipt, effectiveGasPrice, logIndexStart))); + return Task.FromResult(ResultWrapper.Success(new(txHash, receipt, gasInfo.Value, logIndexStart))); } public ResultWrapper eth_getUncleByBlockHashAndIndex(Keccak blockHash, UInt256 positionIndex) diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Parity/ParityRpcModule.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Parity/ParityRpcModule.cs index 07680e96e900..7e0b3a92a382 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Parity/ParityRpcModule.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Parity/ParityRpcModule.cs @@ -11,7 +11,7 @@ using Nethermind.Core; using Nethermind.Core.Specs; using Nethermind.Crypto; -using Nethermind.Int256; +using Nethermind.Evm; using Nethermind.JsonRpc.Data; using Nethermind.KeyStore; using Nethermind.Serialization.Rlp; @@ -77,7 +77,9 @@ public ResultWrapper parity_getBlockReceipts(BlockParameter blo bool isEip1559Enabled = _specProvider.GetSpec(block.Header).IsEip1559Enabled; IEnumerable result = receipts .Zip(block.Transactions, (r, t) => - new ReceiptForRpc(t.Hash, r, t.CalculateEffectiveGasPrice(isEip1559Enabled, block.BaseFeePerGas), receipts.GetBlockLogFirstIndex(r.Index))); + { + return new ReceiptForRpc(t.Hash, r, t.GetGasInfo(isEip1559Enabled, block.Header), receipts.GetBlockLogFirstIndex(r.Index)); + }); ReceiptForRpc[] resultAsArray = result.ToArray(); return ResultWrapper.Success(resultAsArray); } diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Proof/ProofRpcModule.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Proof/ProofRpcModule.cs index 05427d8a01b2..0ead70e46c11 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Proof/ProofRpcModule.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Proof/ProofRpcModule.cs @@ -4,18 +4,16 @@ using System; using System.Collections.Generic; using System.Linq; -using Nethermind.Blockchain; using Nethermind.Blockchain.Find; using Nethermind.Blockchain.Receipts; using Nethermind.Consensus.Tracing; using Nethermind.Core; using Nethermind.Core.Crypto; -using Nethermind.Core.Extensions; using Nethermind.Core.Specs; using Nethermind.Crypto; +using Nethermind.Evm; using Nethermind.Evm.Tracing; using Nethermind.Evm.Tracing.Proofs; -using Nethermind.Facade; using Nethermind.JsonRpc.Data; using Nethermind.Logging; using Nethermind.Serialization.Rlp; @@ -159,7 +157,8 @@ public ResultWrapper proof_getTransactionReceipt(Keccak txHash Transaction? tx = txs.FirstOrDefault(x => x.Hash == txHash); int logIndexStart = _receiptFinder.Get(block).GetBlockLogFirstIndex(receipt.Index); - receiptWithProof.Receipt = new ReceiptForRpc(txHash, receipt, tx?.CalculateEffectiveGasPrice(isEip1559Enabled, block.BaseFeePerGas), logIndexStart); + + receiptWithProof.Receipt = new ReceiptForRpc(txHash, receipt, tx?.GetGasInfo(isEip1559Enabled, block.Header) ?? new(), logIndexStart); receiptWithProof.ReceiptProof = BuildReceiptProofs(block.Header, receipts, receipt.Index); receiptWithProof.TxProof = BuildTxProofs(txs, _specProvider.GetSpec(block.Header), receipt.Index);