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); } }
/// <summary> /// /// </summary> /// <param name="db"></param> /// <param name="key"></param> /// <returns>Can return null or empty Span on missing key</returns> /// <exception cref="InvalidOperationException"></exception> public static Span <byte> GetSpan(this IDbWithSpan db, Keccak key) { #if DEBUG if (key == Keccak.OfAnEmptyString) { throw new InvalidOperationException(); } #endif return(db.GetSpan(key.Bytes)); }
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); } }
/// <summary> /// /// </summary> /// <param name="db"></param> /// <param name="key"></param> /// <returns>Can return null or empty Span on missing key</returns> public static Span <byte> GetSpan(this IDbWithSpan db, long key) => db.GetSpan(key.ToBigEndianByteArrayWithoutLeadingZeros());