From c2ad6a6e975e7e20e071f98042f504a2e99c5452 Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Mon, 6 May 2024 10:49:12 +0530 Subject: [PATCH] add: state sync txn in getBlockReceipts, testcase to check hashing of state sync txn in GetTransactonReceiptsByBlock --- internal/ethapi/api.go | 6 ++++++ tests/bor/bor_api_test.go | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 5a8eb6c961..8acc6a39b3 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1095,6 +1095,12 @@ func (s *BlockChainAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc. result[i] = marshalReceipt(receipt, block.Hash(), block.NumberU64(), signer, txs[i], i, false) } + stateSyncReceipt := rawdb.ReadBorReceipt(s.b.ChainDb(), block.Hash(), block.NumberU64(), s.b.ChainConfig()) + if stateSyncReceipt != nil { + tx, _, _, _ := rawdb.ReadBorTransaction(s.b.ChainDb(), stateSyncReceipt.TxHash) + result = append(result, marshalReceipt(stateSyncReceipt, block.Hash(), block.NumberU64(), signer, tx, len(result), true)) + } + return result, nil } diff --git a/tests/bor/bor_api_test.go b/tests/bor/bor_api_test.go index cd4119c0e9..8d314193a7 100644 --- a/tests/bor/bor_api_test.go +++ b/tests/bor/bor_api_test.go @@ -98,6 +98,15 @@ func testGetTransactionReceiptsByBlock(t *testing.T, publicBlockchainAPI *ethapi assert.Equal(t, 2, len(receiptsOut)) assert.True(t, areDifferentHashes(receiptsOut)) + // check 5: Tx hash for state sync txn + block, err := publicBlockchainAPI.GetBlockByNumber(context.Background(), rpc.BlockNumber(4), false) + assert.Nil(t, err) + blockHash := block["hash"].(common.Hash) + txHash := types.GetDerivedBorTxHash(types.BorReceiptKey(4, blockHash)) + // Compare tx hash from GetTransactionReceiptsByBlock with hash computed above + txReceipts, err := publicBlockchainAPI.GetTransactionReceiptsByBlock(context.Background(), rpc.BlockNumberOrHashWithNumber(4)) + assert.Nil(t, err) + assert.Equal(t, txHash, txReceipts[1]["transactionHash"].(common.Hash)) } // Test for GetTransactionByBlockNumberAndIndex @@ -122,7 +131,7 @@ func testGetTransactionByBlockNumberAndIndex(t *testing.T, publicTransactionPool tx = publicTransactionPoolAPI.GetTransactionByBlockNumberAndIndex(context.Background(), rpc.BlockNumber(4), 0) assert.Equal(t, common.HexToAddress("0x1000"), *tx.To) - // check 5 : Normal Transaction + // check 5 : State Sync Transaction tx = publicTransactionPoolAPI.GetTransactionByBlockNumberAndIndex(context.Background(), rpc.BlockNumber(4), 1) assert.Equal(t, common.HexToAddress("0x0"), *tx.To) }