diff --git a/src/Nethermind/Nethermind.DataMarketplace.Core/Services/NdmBlockchainBridge.cs b/src/Nethermind/Nethermind.DataMarketplace.Core/Services/NdmBlockchainBridge.cs index f2cf798e54e..ec82d785674 100644 --- a/src/Nethermind/Nethermind.DataMarketplace.Core/Services/NdmBlockchainBridge.cs +++ b/src/Nethermind/Nethermind.DataMarketplace.Core/Services/NdmBlockchainBridge.cs @@ -82,7 +82,7 @@ public Task GetNonceAsync(Address address) public Task GetTransactionAsync(Keccak transactionHash) { - (TxReceipt receipt, Transaction transaction) = _blockchainBridge.GetTransaction(transactionHash); + (TxReceipt receipt, Transaction transaction, UInt256? baseFee) = _blockchainBridge.GetTransaction(transactionHash); if (transaction is null) { return Task.FromResult(null); diff --git a/src/Nethermind/Nethermind.DataMarketplace.Test/ContractInteractionTest.cs b/src/Nethermind/Nethermind.DataMarketplace.Test/ContractInteractionTest.cs index a2af57cf8af..c4deeb2041a 100644 --- a/src/Nethermind/Nethermind.DataMarketplace.Test/ContractInteractionTest.cs +++ b/src/Nethermind/Nethermind.DataMarketplace.Test/ContractInteractionTest.cs @@ -237,12 +237,12 @@ public BlockHeader FindBestSuggestedHeader() throw new NotImplementedException(); } - public (TxReceipt Receipt, Transaction Transaction) GetTransaction(Keccak txHash) + public (TxReceipt Receipt, Transaction Transaction, UInt256? baseFee) GetTransaction(Keccak txHash) { return (new TxReceipt(), new Transaction { Hash = txHash - }); + }, null); } private BlockReceiptsTracer _receiptsTracer; diff --git a/src/Nethermind/Nethermind.DataMarketplace.Test/Services/NdmBlockchainBridgeTests.cs b/src/Nethermind/Nethermind.DataMarketplace.Test/Services/NdmBlockchainBridgeTests.cs index ae61f423d91..0d096700907 100644 --- a/src/Nethermind/Nethermind.DataMarketplace.Test/Services/NdmBlockchainBridgeTests.cs +++ b/src/Nethermind/Nethermind.DataMarketplace.Test/Services/NdmBlockchainBridgeTests.cs @@ -21,6 +21,7 @@ using Nethermind.Core; using Nethermind.Core.Crypto; using Nethermind.Core.Test.Builders; +using Nethermind.DataMarketplace.Core.Domain; using Nethermind.DataMarketplace.Core.Services; using Nethermind.Int256; using Nethermind.Facade; @@ -55,16 +56,16 @@ public void Setup() [Test] public async Task get_latest_block_number_should_return_0_if_head_is_null() { - var result = await _ndmBridge.GetLatestBlockNumberAsync(); + long result = await _ndmBridge.GetLatestBlockNumberAsync(); result.Should().Be(0); } [Test] public async Task get_latest_block_number_should_return_head_number() { - var header = Build.A.Block.TestObject; + Block header = Build.A.Block.TestObject; _blockFinder.Head.Returns(header); - var result = await _ndmBridge.GetLatestBlockNumberAsync(); + long result = await _ndmBridge.GetLatestBlockNumberAsync(); result.Should().Be(_blockFinder.Head.Number); } @@ -73,11 +74,11 @@ public async Task get_latest_block_number_should_return_head_number() [Test] public async Task get_code_should_invoke_blockchain_bridge_get_code() { - var code = new byte[] {0, 1, 2}; - var address = TestItem.AddressA; + byte[] code = new byte[] {0, 1, 2}; + Address address = TestItem.AddressA; _stateReader.GetCode(Arg.Any(), address).Returns(code); _blockFinder.Head.Returns(_anyBlock); - var result = await _ndmBridge.GetCodeAsync(address); + byte[] result = await _ndmBridge.GetCodeAsync(address); _stateReader.Received().GetCode(_anyBlock.StateRoot, address); result.Should().BeSameAs(code); } @@ -85,9 +86,9 @@ public async Task get_code_should_invoke_blockchain_bridge_get_code() [Test] public async Task find_block_by_hash_should_invoke_blockchain_bridge_find_block_by_hash() { - var block = Build.A.Block.TestObject; + Block block = Build.A.Block.TestObject; _blockFinder.FindBlock(block.Hash).Returns(block); - var result = await _ndmBridge.FindBlockAsync(block.Hash); + Block? result = await _ndmBridge.FindBlockAsync(block.Hash); _blockFinder.Received().FindBlock(block.Hash); result.Should().Be(block); } @@ -95,9 +96,9 @@ public async Task find_block_by_hash_should_invoke_blockchain_bridge_find_block_ [Test] public async Task find_block_by_number_should_invoke_blockchain_bridge_find_block_by_number() { - var block = Build.A.Block.TestObject; + Block block = Build.A.Block.TestObject; _blockFinder.FindBlock(block.Number).Returns(block); - var result = await _ndmBridge.FindBlockAsync(block.Number); + Block? result = await _ndmBridge.FindBlockAsync(block.Number); _blockFinder.Received().FindBlock(block.Number); result.Should().Be(block); } @@ -105,17 +106,17 @@ public async Task find_block_by_number_should_invoke_blockchain_bridge_find_bloc [Test] public async Task get_latest_block_number_should_return_null_if_head_is_null() { - var result = await _ndmBridge.GetLatestBlockAsync(); + Block? result = await _ndmBridge.GetLatestBlockAsync(); result.Should().BeNull(); } [Test] public async Task get_latest_block_should_return_head_number() { - var block = Build.A.Block.TestObject; + Block block = Build.A.Block.TestObject; _blockchainBridge.BeamHead.Returns(block); _blockFinder.FindBlock(block.Hash).Returns(block); - var result = await _ndmBridge.GetLatestBlockAsync(); + Block? result = await _ndmBridge.GetLatestBlockAsync(); result.Should().Be(block); _blockFinder.Received().FindBlock(block.Hash); } @@ -124,10 +125,10 @@ public async Task get_latest_block_should_return_head_number() public async Task get_nonce_should_invoke_blockchain_bridge_get_nonce() { UInt256 nonce = 1; - var address = TestItem.AddressA; + Address address = TestItem.AddressA; _blockchainBridge.BeamHead.Returns(_anyBlock); _stateReader.GetAccount(_anyBlock.StateRoot, address).Returns(Account.TotallyEmpty.WithChangedNonce(nonce)); - var result = await _ndmBridge.GetNonceAsync(address); + UInt256 result = await _ndmBridge.GetNonceAsync(address); _stateReader.Received().GetNonce(_anyBlock.StateRoot, address); result.Should().Be(nonce); } @@ -135,8 +136,8 @@ public async Task get_nonce_should_invoke_blockchain_bridge_get_nonce() [Test] public async Task get_transaction_should_return_null_if_receipt_or_transaction_is_null() { - var hash = TestItem.KeccakA; - var result = await _ndmBridge.GetTransactionAsync(hash); + Keccak hash = TestItem.KeccakA; + NdmTransaction? result = await _ndmBridge.GetTransactionAsync(hash); result.Should().BeNull(); _blockchainBridge.Received().GetTransaction(hash); } @@ -144,12 +145,13 @@ public async Task get_transaction_should_return_null_if_receipt_or_transaction_i [Test] public async Task get_transaction_should_invoke_blockchain_bridge_get_transaction_and_return_ndm_transaction() { - var receipt = Build.A.Receipt.TestObject; - var transaction = Build.A.Transaction.TestObject; - var tuple = (receipt, transaction); - var hash = TestItem.KeccakA; + TxReceipt receipt = Build.A.Receipt.TestObject; + Transaction transaction = Build.A.Transaction.TestObject; + UInt256? baseFee = null; + (TxReceipt receipt, Transaction transaction, UInt256? baseFee) tuple = (receipt, transaction, baseFee); + Keccak hash = TestItem.KeccakA; _blockchainBridge.GetTransaction(hash).Returns(tuple); - var result = await _ndmBridge.GetTransactionAsync(hash); + NdmTransaction? result = await _ndmBridge.GetTransactionAsync(hash); result.Should().NotBeNull(); _blockchainBridge.Received().GetTransaction(hash); result.Transaction.Should().Be(transaction); @@ -163,7 +165,7 @@ public async Task get_network_id_should_invoke_blockchain_bridge_get_network_id( { const ulong networkId = 1; _blockchainBridge.GetChainId().Returns(networkId); - var result = await _ndmBridge.GetNetworkIdAsync(); + ulong result = await _ndmBridge.GetNetworkIdAsync(); _blockchainBridge.Received().GetChainId(); result.Should().Be(networkId); } @@ -171,13 +173,13 @@ public async Task get_network_id_should_invoke_blockchain_bridge_get_network_id( [Test] public async Task call_should_invoke_blockchain_bridge_call_and_return_data() { - var head = Build.A.Block.TestObject; - var transaction = Build.A.Transaction.TestObject; - var data = new byte[] {0, 1, 2}; + Block head = Build.A.Block.TestObject; + Transaction transaction = Build.A.Transaction.TestObject; + byte[] data = new byte[] {0, 1, 2}; _blockchainBridge.BeamHead.Returns(head); - var output = new BlockchainBridge.CallOutput(data, 0, null); + BlockchainBridge.CallOutput output = new BlockchainBridge.CallOutput(data, 0, null); _blockchainBridge.Call(head?.Header, transaction, default).Returns(output); - var result = await _ndmBridge.CallAsync(transaction); + byte[] result = await _ndmBridge.CallAsync(transaction); _blockchainBridge.Received().Call(head?.Header, transaction, default); result.Should().BeSameAs(data); } @@ -186,8 +188,8 @@ public async Task call_should_invoke_blockchain_bridge_call_and_return_data() public async Task call_with_transaction_number_for_invalid_block_should_invoke_blockchain_bridge_call_and_return_empty_data() { const int blockNumber = 1; - var transaction = Build.A.Transaction.TestObject; - var result = await _ndmBridge.CallAsync(transaction, blockNumber); + Transaction transaction = Build.A.Transaction.TestObject; + byte[] result = await _ndmBridge.CallAsync(transaction, blockNumber); _blockFinder.Received().FindBlock(blockNumber); _blockchainBridge.DidNotReceiveWithAnyArgs().Call(null, null, default); result.Should().BeSameAs(Array.Empty()); @@ -196,13 +198,13 @@ public async Task call_with_transaction_number_for_invalid_block_should_invoke_b [Test] public async Task call_with_transaction_number_should_invoke_blockchain_bridge_call_and_return_data() { - var block = Build.A.Block.TestObject; - var transaction = Build.A.Transaction.TestObject; - var data = new byte[] {0, 1, 2}; + Block block = Build.A.Block.TestObject; + Transaction transaction = Build.A.Transaction.TestObject; + byte[] data = new byte[] {0, 1, 2}; _blockFinder.FindBlock(block.Number).Returns(block); - var output = new BlockchainBridge.CallOutput(data, 0, null); + BlockchainBridge.CallOutput output = new BlockchainBridge.CallOutput(data, 0, null); _blockchainBridge.Call(block.Header, transaction, default).Returns(output); - var result = await _ndmBridge.CallAsync(transaction, block.Number); + byte[] result = await _ndmBridge.CallAsync(transaction, block.Number); _blockFinder.Received().FindBlock(block.Number); _blockchainBridge.Received().Call(block.Header, transaction, default); result.Should().BeSameAs(data); @@ -211,10 +213,10 @@ public async Task call_with_transaction_number_should_invoke_blockchain_bridge_c [Test] public async Task send_own_transaction_should_invoke_blockchain_bridge_send_transaction_and_return_hash() { - var transaction = Build.A.Transaction.TestObject; - var hash = TestItem.KeccakA; + Transaction transaction = Build.A.Transaction.TestObject; + Keccak hash = TestItem.KeccakA; _txSender.SendTransaction(transaction, TxHandlingOptions.PersistentBroadcast | TxHandlingOptions.ManagedNonce).Returns((hash, null)); - var result = await _ndmBridge.SendOwnTransactionAsync(transaction); + Keccak? result = await _ndmBridge.SendOwnTransactionAsync(transaction); await _txSender.Received().SendTransaction(transaction, TxHandlingOptions.PersistentBroadcast | TxHandlingOptions.ManagedNonce); result.Should().Be(hash); } diff --git a/src/Nethermind/Nethermind.Facade.Test/BlockChainBridgeTests.cs b/src/Nethermind/Nethermind.Facade.Test/BlockchainBridgeTests.cs similarity index 99% rename from src/Nethermind/Nethermind.Facade.Test/BlockChainBridgeTests.cs rename to src/Nethermind/Nethermind.Facade.Test/BlockchainBridgeTests.cs index d5a3fa3abe7..fdae3cba937 100644 --- a/src/Nethermind/Nethermind.Facade.Test/BlockChainBridgeTests.cs +++ b/src/Nethermind/Nethermind.Facade.Test/BlockchainBridgeTests.cs @@ -96,14 +96,14 @@ public async Task SetUp() [Test] public void get_transaction_returns_null_when_transaction_not_found() { - _blockchainBridge.GetTransaction(TestItem.KeccakA).Should().Be((null, null)); + _blockchainBridge.GetTransaction(TestItem.KeccakA).Should().Be((null, null, null)); } [Test] public void get_transaction_returns_null_when_block_not_found() { _receiptStorage.FindBlockHash(TestItem.KeccakA).Returns(TestItem.KeccakB); - _blockchainBridge.GetTransaction(TestItem.KeccakA).Should().Be((null, null)); + _blockchainBridge.GetTransaction(TestItem.KeccakA).Should().Be((null, null, null)); } [Test] diff --git a/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs b/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs index 192dfa69fdb..2df1744366b 100644 --- a/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs +++ b/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs @@ -134,22 +134,22 @@ public Block BeamHead return (null, null); } - public (TxReceipt Receipt, Transaction Transaction) GetTransaction(Keccak txHash) + public (TxReceipt Receipt, Transaction Transaction, UInt256? baseFee) GetTransaction(Keccak txHash) { Keccak blockHash = _receiptFinder.FindBlockHash(txHash); if (blockHash != null) { Block block = _blockTree.FindBlock(blockHash, BlockTreeLookupOptions.TotalDifficultyNotNeeded); TxReceipt txReceipt = _receiptFinder.Get(block).ForTransaction(txHash); - return (txReceipt, block?.Transactions[txReceipt.Index]); + return (txReceipt, block?.Transactions[txReceipt.Index], block?.BaseFeePerGas); } if (_txPool.TryGetPendingTransaction(txHash, out Transaction? transaction)) { - return (null, transaction); + return (null, transaction, null); } - return (null, null); + return (null, null, null); } public TxReceipt GetReceipt(Keccak txHash) diff --git a/src/Nethermind/Nethermind.Facade/IBlockchainBridge.cs b/src/Nethermind/Nethermind.Facade/IBlockchainBridge.cs index 45fcf5ebf9d..d6a37bdff9c 100644 --- a/src/Nethermind/Nethermind.Facade/IBlockchainBridge.cs +++ b/src/Nethermind/Nethermind.Facade/IBlockchainBridge.cs @@ -34,7 +34,7 @@ public interface IBlockchainBridge : ILogFinder void RecoverTxSender(Transaction tx); TxReceipt GetReceipt(Keccak txHash); (TxReceipt Receipt, UInt256? EffectiveGasPrice) GetReceiptAndEffectiveGasPrice(Keccak txHash); - (TxReceipt Receipt, Transaction Transaction) GetTransaction(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/Modules/Eth/EthRpcModuleTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs index cd5ca464cad..52b360d4c4a 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs @@ -97,6 +97,15 @@ public async Task Eth_pending_transactions() string serialized = ctx._test.TestEthRpc("eth_pendingTransactions"); Assert.AreEqual("{\"jsonrpc\":\"2.0\",\"result\":[{\"hash\":\"0x190d9a78dbc61b1856162ab909976a1b28ba4a41ee041341576ea69686cd3b29\",\"nonce\":\"0x0\",\"blockHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"blockNumber\":null,\"transactionIndex\":null,\"from\":\"0x475674cb523a0a2736b7f7534390288fce16982c\",\"to\":\"0x0000000000000000000000000000000000000000\",\"value\":\"0x1\",\"gasPrice\":\"0x1\",\"gas\":\"0x5208\",\"data\":\"0x\",\"input\":\"0x\",\"type\":\"0x0\",\"v\":\"0x26\",\"s\":\"0x2d04e55699fa32e6b65a22189f7571f5030d636d7d44a8b53fe016a2c3ecde24\",\"r\":\"0xda3978c3a1430bd902cf5bbca73c5a1eca019b3f003c95ee16657fd0bb89534c\"}],\"id\":67}", serialized, serialized.Replace("\"", "\\\"")); } + + [Test] + public async Task Eth_pending_transactions_1559_tx() + { + using Context ctx = await Context.CreateWithLondonEnabled(); + ctx._test.AddTransactions(Build.A.Transaction.WithMaxPriorityFeePerGas(6.GWei()).WithMaxFeePerGas(11.GWei()).WithType(TxType.EIP1559).SignedAndResolved(TestItem.PrivateKeyD).TestObject); + string serialized = ctx._test.TestEthRpc("eth_pendingTransactions"); + Assert.AreEqual("{\"jsonrpc\":\"2.0\",\"result\":[{\"hash\":\"0x629190363a5457ff385cb4770426d98590446c08783f2c96961156351657be67\",\"nonce\":\"0x0\",\"blockHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"blockNumber\":null,\"transactionIndex\":null,\"from\":\"0x475674cb523a0a2736b7f7534390288fce16982c\",\"to\":\"0x0000000000000000000000000000000000000000\",\"value\":\"0x1\",\"gasPrice\":\"0x28fa6ae00\",\"maxPriorityFeePerGas\":\"0x165a0bc00\",\"maxFeePerGas\":\"0x28fa6ae00\",\"gas\":\"0x5208\",\"data\":\"0x\",\"input\":\"0x\",\"chainId\":\"0x1\",\"type\":\"0x2\",\"v\":\"0x0\",\"s\":\"0x4d8e9a47d74a88cdc49d5b56cd0466e920c39f2d28a98be0f657c1884ad4b32d\",\"r\":\"0xcb08c119a76bdb58f29423ea7b084ea14be24cfbdc75300d3dab06b35a1a124b\"}],\"id\":67}", serialized, serialized.Replace("\"", "\\\"")); + } [Test] public async Task Eth_get_transaction_by_block_number_and_index() @@ -567,6 +576,19 @@ public async Task Eth_getTransactionReceipt_return_info_about_mined_1559tx() string serialized = ctx._test.TestEthRpc("eth_getTransactionReceipt", tx.Hash.ToString()); Assert.AreEqual("{\"jsonrpc\":\"2.0\",\"result\":{\"transactionHash\":\"0x31501f80bf2ec493c368a519cb8ed6f132f0be26202304bbf1e1728642affb7f\",\"transactionIndex\":\"0x0\",\"blockHash\":\"0x691ca9ebaa6f2839593bcc22284277ff6e5d89d8dec2e40f9813ea109669be92\",\"blockNumber\":\"0x5\",\"cumulativeGasUsed\":\"0x521c\",\"gasUsed\":\"0x521c\",\"effectiveGasPrice\":\"0x5e91eb5d\",\"from\":\"0x723847c97bc651c7e8c013dbbe65a70712f02ad3\",\"to\":\"0x0000000000000000000000000000000000000000\",\"contractAddress\":null,\"logs\":[],\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"status\":\"0x1\",\"type\":\"0x2\"},\"id\":67}", serialized); } + + [Test] + public async Task Eth_getTransactionByHash_return_info_about_mined_1559tx() + { + using Context ctx = await Context.CreateWithLondonEnabled(); + await ctx._test.AddFundsAfterLondon((new Address("0x723847c97bc651c7e8c013dbbe65a70712f02ad3"), 1.Ether())); + Transaction tx = Build.A.Transaction.WithData(new byte[]{0, 1}) + .SignedAndResolved().WithChainId(1).WithGasPrice(0).WithValue(0).WithGasLimit(210200) + .WithType(TxType.EIP1559).WithMaxFeePerGas(20.GWei()).WithMaxPriorityFeePerGas(1.GWei()).TestObject; + await ctx._test.AddBlock(tx); + string serialized = ctx._test.TestEthRpc("eth_getTransactionByHash", tx.Hash.ToString()); + Assert.AreEqual("{\"jsonrpc\":\"2.0\",\"result\":{\"hash\":\"0x31501f80bf2ec493c368a519cb8ed6f132f0be26202304bbf1e1728642affb7f\",\"nonce\":\"0x0\",\"blockHash\":\"0x691ca9ebaa6f2839593bcc22284277ff6e5d89d8dec2e40f9813ea109669be92\",\"blockNumber\":\"0x5\",\"transactionIndex\":\"0x0\",\"from\":\"0x723847c97bc651c7e8c013dbbe65a70712f02ad3\",\"to\":\"0x0000000000000000000000000000000000000000\",\"value\":\"0x0\",\"gasPrice\":\"0x5e91eb5d\",\"maxPriorityFeePerGas\":\"0x3b9aca00\",\"maxFeePerGas\":\"0x4a817c800\",\"gas\":\"0x33518\",\"data\":\"0x0001\",\"input\":\"0x0001\",\"chainId\":\"0x1\",\"type\":\"0x2\",\"v\":\"0x0\",\"s\":\"0x6b82095065a599e6b5e52bed0043702baf3411418af679ac483f9fc75a8f6aef\",\"r\":\"0x8654517f7822e7a4e10e79f3f5a4136703c7d1b51d98e47686e201c3c2845f92\"},\"id\":67}", serialized); + } [Test] public async Task Eth_syncing() diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Proof/ProofModuleTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Proof/ProofRpcModuleTests.cs similarity index 99% rename from src/Nethermind/Nethermind.JsonRpc.Test/Modules/Proof/ProofModuleTests.cs rename to src/Nethermind/Nethermind.JsonRpc.Test/Modules/Proof/ProofRpcModuleTests.cs index 1cfe5c01760..d593a36665c 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Proof/ProofModuleTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Proof/ProofRpcModuleTests.cs @@ -50,7 +50,7 @@ namespace Nethermind.JsonRpc.Test.Modules.Proof [TestFixture(true, true)] [TestFixture(true, false)] [TestFixture(false, false)] - public class ProofModuleTests + public class ProofRpcModuleTests { private readonly bool _createSystemAccount; private readonly bool _useNonZeroGasPrice; @@ -59,7 +59,7 @@ public class ProofModuleTests private IDbProvider _dbProvider; private TestSpecProvider _specProvider; - public ProofModuleTests(bool createSystemAccount, bool useNonZeroGasPrice) + public ProofRpcModuleTests(bool createSystemAccount, bool useNonZeroGasPrice) { _createSystemAccount = createSystemAccount; _useNonZeroGasPrice = useNonZeroGasPrice; diff --git a/src/Nethermind/Nethermind.JsonRpc/Data/TransactionForRpc.cs b/src/Nethermind/Nethermind.JsonRpc/Data/TransactionForRpc.cs index 816615381cf..979e1fdaf97 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Data/TransactionForRpc.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Data/TransactionForRpc.cs @@ -16,6 +16,7 @@ using System.Collections.Generic; using System.Linq; +using MathGmp.Native; using Nethermind.Core; using Nethermind.Core.Crypto; using Nethermind.Core.Eip2930; @@ -29,7 +30,7 @@ public class TransactionForRpc { public TransactionForRpc(Transaction transaction) : this(null, null, null, transaction) { } - public TransactionForRpc(Keccak? blockHash, long? blockNumber, int? txIndex, Transaction transaction) + public TransactionForRpc(Keccak? blockHash, long? blockNumber, int? txIndex, Transaction transaction, UInt256? baseFee = null) { Hash = transaction.Hash; Nonce = transaction.Nonce; @@ -44,6 +45,9 @@ public TransactionForRpc(Keccak? blockHash, long? blockNumber, int? txIndex, Tra Input = Data = transaction.Data; if (transaction.IsEip1559) { + GasPrice = baseFee != null + ? transaction.CalculateEffectiveGasPrice(true, baseFee.Value) + : transaction.MaxFeePerGas; MaxFeePerGas = transaction.MaxFeePerGas; MaxPriorityFeePerGas = transaction.MaxPriorityFeePerGas; } diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/BlockForRpc.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/BlockForRpc.cs index 5ed7a892502..273c318abeb 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/BlockForRpc.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/BlockForRpc.cs @@ -78,7 +78,7 @@ public BlockForRpc(Block block, bool includeFullTransactionData, ISpecProvider? StateRoot = block.StateRoot; Timestamp = block.Timestamp; TotalDifficulty = block.TotalDifficulty ?? 0; - Transactions = includeFullTransactionData ? block.Transactions.Select((t, idx) => new TransactionForRpc(block.Hash, block.Number, idx, t)).ToArray() : block.Transactions.Select(t => t.Hash).OfType().ToArray(); + Transactions = includeFullTransactionData ? block.Transactions.Select((t, idx) => new TransactionForRpc(block.Hash, block.Number, idx, t, block.BaseFeePerGas)).ToArray() : block.Transactions.Select(t => t.Hash).OfType().ToArray(); TransactionsRoot = block.TxRoot; Uncles = block.Ommers.Select(o => o.Hash); } diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/EthRpcModule.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/EthRpcModule.cs index ec305cf73e2..fed49d664a2 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/EthRpcModule.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/EthRpcModule.cs @@ -406,11 +406,12 @@ private ResultWrapper GetBlock(BlockParameter blockParameter, bool public Task> eth_getTransactionByHash(Keccak transactionHash) { + UInt256? baseFee = null; _txPoolBridge.TryGetPendingTransaction(transactionHash, out Transaction transaction); TxReceipt receipt = null; // note that if transaction is pending then for sure no receipt is known if (transaction == null) { - (receipt, transaction) = _blockchainBridge.GetTransaction(transactionHash); + (receipt, transaction, baseFee) = _blockchainBridge.GetTransaction(transactionHash); if (transaction == null) { return Task.FromResult(ResultWrapper.Success(null)); @@ -419,7 +420,7 @@ public Task> eth_getTransactionByHash(Keccak tr RecoverTxSenderIfNeeded(transaction); TransactionForRpc transactionModel = - new(receipt?.BlockHash, receipt?.BlockNumber, receipt?.Index, transaction); + new(receipt?.BlockHash, receipt?.BlockNumber, receipt?.Index, transaction, baseFee); if (_logger.IsTrace) _logger.Trace($"eth_getTransactionByHash request {transactionHash}, result: {transactionModel.Hash}"); return Task.FromResult(ResultWrapper.Success(transactionModel)); @@ -459,7 +460,7 @@ public ResultWrapper eth_getTransactionByBlockHashAndIndex(Ke Transaction transaction = block.Transactions[(int)positionIndex]; RecoverTxSenderIfNeeded(transaction); - TransactionForRpc transactionModel = new(block.Hash, block.Number, (int)positionIndex, transaction); + TransactionForRpc transactionModel = new(block.Hash, block.Number, (int)positionIndex, transaction, block.BaseFeePerGas); return ResultWrapper.Success(transactionModel); } @@ -482,7 +483,7 @@ public ResultWrapper eth_getTransactionByBlockNumberAndIndex( Transaction transaction = block.Transactions[(int)positionIndex]; RecoverTxSenderIfNeeded(transaction); - TransactionForRpc transactionModel = new(block.Hash, block.Number, (int)positionIndex, transaction); + TransactionForRpc transactionModel = new(block.Hash, block.Number, (int)positionIndex, transaction, block.BaseFeePerGas); if (_logger.IsDebug) _logger.Debug( diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Proof/ProofRpcModule.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Proof/ProofRpcModule.cs index 42d4062dea3..936b135b585 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Proof/ProofRpcModule.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Proof/ProofRpcModule.cs @@ -132,7 +132,7 @@ public ResultWrapper proof_getTransactionByHash(Keccak txH Transaction transaction = txs[receipt.Index]; TransactionWithProof txWithProof = new(); - txWithProof.Transaction = new TransactionForRpc(block.Hash, block.Number, receipt.Index, transaction); + txWithProof.Transaction = new TransactionForRpc(block.Hash, block.Number, receipt.Index, transaction, block.BaseFeePerGas); txWithProof.TxProof = BuildTxProofs(txs, _specProvider.GetSpec(block.Number), receipt.Index); if (includeHeader) {