From 3f36c3b67d6fe93d9369461de90052b0f40e0fa1 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Fri, 5 Jan 2024 13:10:47 +0000 Subject: [PATCH] Write out IByteBuffer before it is released (#6459) --- src/Nethermind/Nethermind.TxPool/BlobTxStorage.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Nethermind/Nethermind.TxPool/BlobTxStorage.cs b/src/Nethermind/Nethermind.TxPool/BlobTxStorage.cs index 4ba704d7c54..e05f726d6e1 100644 --- a/src/Nethermind/Nethermind.TxPool/BlobTxStorage.cs +++ b/src/Nethermind/Nethermind.TxPool/BlobTxStorage.cs @@ -65,7 +65,7 @@ public void Add(Transaction transaction) Span txHashPrefixed = stackalloc byte[64]; GetHashPrefixedByTimestamp(transaction.Timestamp, transaction.Hash, txHashPrefixed); - _fullBlobTxsDb.PutSpan(txHashPrefixed, EncodeTx(transaction)); + EncodeAndSaveTx(transaction, _fullBlobTxsDb, txHashPrefixed); _lightBlobTxsDb.Set(transaction.Hash, LightTxDecoder.Encode(transaction)); } @@ -85,7 +85,7 @@ public void AddBlobTransactionsFromBlock(long blockNumber, IList bl return; } - _processedBlobTxsDb.Set(blockNumber, EncodeTxs(blockBlobTransactions)); + EncodeAndSaveTxs(blockBlobTransactions, _processedBlobTxsDb, blockNumber); } public bool TryGetBlobTransactionsFromBlock(long blockNumber, out Transaction[]? blockBlobTransactions) @@ -138,17 +138,17 @@ private static void GetHashPrefixedByTimestamp(UInt256 timestamp, ValueHash256 h hash.Bytes.CopyTo(txHashPrefixed[32..]); } - private Span EncodeTx(Transaction transaction) + private void EncodeAndSaveTx(Transaction transaction, IDb db, Span txHashPrefixed) { int length = _txDecoder.GetLength(transaction, RlpBehaviors.InMempoolForm); IByteBuffer byteBuffer = PooledByteBufferAllocator.Default.Buffer(length); using NettyRlpStream rlpStream = new(byteBuffer); rlpStream.Encode(transaction, RlpBehaviors.InMempoolForm); - return byteBuffer.AsSpan(); + db.PutSpan(txHashPrefixed, byteBuffer.AsSpan()); } - private byte[] EncodeTxs(IList blockBlobTransactions) + private void EncodeAndSaveTxs(IList blockBlobTransactions, IDb db, long blockNumber) { int contentLength = GetLength(blockBlobTransactions); @@ -160,7 +160,7 @@ private byte[] EncodeTxs(IList blockBlobTransactions) _txDecoder.Encode(rlpStream, transaction, RlpBehaviors.InMempoolForm); } - return byteBuffer.Array; + db.Set(blockNumber, byteBuffer.Array); } private int GetLength(IList blockBlobTransactions)