public TxReceipt[] Get(Block block) { if (block.ReceiptsRoot == Keccak.EmptyTreeHash) { return(Array.Empty <TxReceipt>()); } var receiptsData = _blocksDb.GetSpan(block.Hash); try { if (receiptsData != null) { return(DecodeArray(receiptsData)); } else { // didn't bring performance uplift that was expected // var data = _database.MultiGet(block.Transactions.Select(t => t.Hash)); // return data.Select(kvp => DeserializeObsolete(new Keccak(kvp.Key), kvp.Value)).ToArray(); TxReceipt[] result = new TxReceipt[block.Transactions.Length]; for (int i = 0; i < block.Transactions.Length; i++) { result[i] = FindReceiptObsolete(block.Transactions[i].Hash); } return(result); } } finally { _blocksDb.DangerousReleaseMemory(receiptsData); } }
public TxReceipt[] Get(Block block) { if (block.ReceiptsRoot == Keccak.EmptyTreeHash) { return(Array.Empty <TxReceipt>()); } if (_receiptsCache.TryGet(block.Hash, out var receipts)) { return(receipts); } var receiptsData = _blocksDb.GetSpan(block.Hash); try { bool shouldCache = true; if (!receiptsData.IsNullOrEmpty()) { receipts = DecodeArray(receiptsData); } else { // didn't bring performance uplift that was expected // var data = _database.MultiGet(block.Transactions.Select(t => t.Hash)); // return data.Select(kvp => DeserializeObsolete(new Keccak(kvp.Key), kvp.Value)).ToArray(); receipts = new TxReceipt[block.Transactions.Length]; for (int i = 0; i < block.Transactions.Length; i++) { receipts[i] = FindReceiptObsolete(block.Transactions[i].Hash); shouldCache &= receipts[i] != null; } } shouldCache &= receipts.Length > 0; if (shouldCache) { _receiptsCache.Set(block.Hash, receipts); } return(receipts); } finally { _blocksDb.DangerousReleaseMemory(receiptsData); } }