Skip to content

Commit

Permalink
add: state sync txn in getBlockReceipts, testcase to check hashing of…
Browse files Browse the repository at this point in the history
… state sync txn in GetTransactonReceiptsByBlock
  • Loading branch information
anshalshukla committed May 6, 2024
1 parent 53db521 commit c2ad6a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
11 changes: 10 additions & 1 deletion tests/bor/bor_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit c2ad6a6

Please sign in to comment.