Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

More XML docs for memory pool classes. #355

Merged
merged 6 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Stratis.Bitcoin.IntegrationTests/FeeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void BlockPolicyEstimates()
{
Assert.True(mpool.EstimateSmartFee(i, out answerFound).FeePerK >= mpool.EstimateFee(i).FeePerK);
Assert.True(mpool.EstimateSmartFee(i, out answerFound).FeePerK >= mpool.GetMinFee(1).FeePerK);
Assert.True(mpool.EstimateSmartPriority(i, out answerFound) == BlockPolicyEstimator.INF_PRIORITY);
Assert.True(mpool.EstimateSmartPriority(i, out answerFound) == BlockPolicyEstimator.InfPriority);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Stratis.Bitcoin.Tests/MemoryPool/MempoolPersistenceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void SaveStreamTest()
}

Assert.True(actualStreamLength > 0);
Assert.Equal(MempoolPersistence.MEMPOOL_DUMP_VERSION, actualVersion);
Assert.Equal(MempoolPersistence.MempoolDumpVersion, actualVersion);
Assert.Equal(numTx, actualCount);
Assert.Equal(loaded, toSave.ToArray());
}
Expand Down
292 changes: 183 additions & 109 deletions Stratis.Bitcoin/Features/MemoryPool/Fee/BlockPolicyEstimator.cs

Large diffs are not rendered by default.

212 changes: 133 additions & 79 deletions Stratis.Bitcoin/Features/MemoryPool/Fee/TxConfirmStats.cs

Large diffs are not rendered by default.

50 changes: 11 additions & 39 deletions Stratis.Bitcoin/Features/MemoryPool/MempoolBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ namespace Stratis.Bitcoin.Features.MemoryPool
/// </summary>
public class MempoolBehavior : NodeBehavior
{
#region Fields

/// <summary>
/// Average delay between trickled inventory transmissions in seconds.
/// Blocks and whitelisted receivers bypass this, outbound peers get half this delay.
Expand Down Expand Up @@ -51,7 +49,7 @@ public class MempoolBehavior : NodeBehavior
/// <summary>Node notifications available to subscribe to.</summary>
private readonly Signals.Signals signals;

/// <summary>Logger for the memory pool component.</summary>
/// <summary>Instance logger for the memory pool component.</summary>
private readonly ILogger logger;

/// <summary>
Expand All @@ -66,10 +64,6 @@ public class MempoolBehavior : NodeBehavior
/// </summary>
private readonly Dictionary<uint256, uint256> filterInventoryKnown;

#endregion

#region Constructors

/// <summary>
/// Constructs an instance of memory pool behavior.
/// </summary>
Expand All @@ -79,7 +73,7 @@ public class MempoolBehavior : NodeBehavior
/// <param name="connectionManager">Connection manager for managing node connections.</param>
/// <param name="chainState">Current block chain state.</param>
/// <param name="signals">Node notifications available to subscribe to.</param>
/// <param name="logger">Memory pool behavior logger.</param>
/// <param name="logger">Instance logger for memory pool behavior.</param>
public MempoolBehavior(
IMempoolValidator validator,
MempoolManager manager,
Expand Down Expand Up @@ -124,10 +118,6 @@ public MempoolBehavior(
{
}

#endregion

#region Properties

/// <summary>Time of last memory pool request in unix time.</summary>
public long LastMempoolReq { get; private set; }

Expand Down Expand Up @@ -157,10 +147,6 @@ public bool CanSend
}
}

#endregion

#region NodeBehavior Overrides

/// <inheritdoc />
protected override void AttachCore()
{
Expand All @@ -179,10 +165,6 @@ public override object Clone()
return new MempoolBehavior(this.validator, this.manager, this.orphans, this.connectionManager, this.chainState, this.signals, this.logger);
}

#endregion

#region Message Handlers

/// <summary>
/// Handler for processing incoming message from node.
/// </summary>
Expand Down Expand Up @@ -247,10 +229,6 @@ private Task AttachedNode_MessageReceivedAsync(Node node, IncomingMessage messag
return Task.CompletedTask;
}

#endregion

#region Message Processing

/// <summary>
/// Send the memory pool payload to the attached node.
/// Gets the transaction info from the memory pool and sends to the attached node.
Expand All @@ -266,25 +244,25 @@ private async Task SendMempoolPayload(Node node, MempoolPayload message)

//if (!(pfrom->GetLocalServices() & NODE_BLOOM) && !pfrom->fWhitelisted)
//{
// LogPrint("net", "mempool request with bloom filters disabled, disconnect peer=%d\n", pfrom->GetId());
// pfrom->fDisconnect = true;
// return true;
// LogPrint("net", "mempool request with bloom filters disabled, disconnect peer=%d\n", pfrom->GetId());
// pfrom->fDisconnect = true;
// return true;
//}

//if (connman.OutboundTargetReached(false) && !pfrom->fWhitelisted)
//{
// LogPrint("net", "mempool request with bandwidth limit reached, disconnect peer=%d\n", pfrom->GetId());
// pfrom->fDisconnect = true;
// return true;
// LogPrint("net", "mempool request with bandwidth limit reached, disconnect peer=%d\n", pfrom->GetId());
// pfrom->fDisconnect = true;
// return true;
//}

List<TxMempoolInfo> vtxinfo = await this.manager.InfoAllAsync();
Money filterrate = Money.Zero;

// TODO: implement minFeeFilter
//{
// LOCK(pto->cs_feeFilter);
// filterrate = pto->minFeeFilter;
// LOCK(pto->cs_feeFilter);
// filterrate = pto->minFeeFilter;
//}

List<TxMempoolInfo> sends = await this.manager.MempoolLock.WriteAsync(() =>
Expand Down Expand Up @@ -445,10 +423,6 @@ private async Task SendAsTxInventory(Node node, IEnumerable<uint256> trxList)
}
}

#endregion

#region Operations

/// <summary>
/// Relays a transaction to the connected nodes.
/// </summary>
Expand Down Expand Up @@ -506,7 +480,7 @@ public async Task SendTrickle()
continue;
//if (filterrate && txinfo.feeRate.GetFeePerK() < filterrate) // TODO:filterrate
//{
// continue;
// continue;
//}
ret.Add(hash);
}
Expand All @@ -516,7 +490,5 @@ public async Task SendTrickle()
if (sends.Any())
await this.SendAsTxInventory(this.AttachedNode, sends);
}

#endregion
}
}
1 change: 0 additions & 1 deletion Stratis.Bitcoin/Features/MemoryPool/MempoolErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public static class MempoolErrors

#endregion


/// <summary>'coinbase' error returns a <see cref="RejectInvalid"/> reject code.</summary>
public static MempoolError Coinbase = new MempoolError(RejectInvalid, "coinbase");

Expand Down
17 changes: 2 additions & 15 deletions Stratis.Bitcoin/Features/MemoryPool/MempoolFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Stratis.Bitcoin.Connection;
using Stratis.Bitcoin.Features.MemoryPool.Fee;
using Stratis.Bitcoin.Interfaces;
using System.Threading.Tasks;
using System.Text;

namespace Stratis.Bitcoin.Features.MemoryPool
Expand All @@ -17,8 +16,6 @@ namespace Stratis.Bitcoin.Features.MemoryPool
/// <seealso cref="https://github.com/bitcoin/bitcoin/blob/6dbcc74a0e0a7d45d20b03bb4eb41a027397a21d/src/txmempool.cpp"/>
public class MempoolFeature : FullNodeFeature, IFeatureStats
{
#region Fields

/// <summary>Node notifications available to subscribe to.</summary>
private readonly Signals.Signals signals;

Expand All @@ -34,13 +31,9 @@ public class MempoolFeature : FullNodeFeature, IFeatureStats
/// <summary>Memory pool manager for managing external access to memory pool.</summary>
private readonly MempoolManager mempoolManager;

/// <summary>Logger for the memory pool component.</summary>
/// <summary>Instance logger for the memory pool component.</summary>
private readonly ILogger mempoolLogger;

#endregion

#region Constructors

/// <summary>
/// Constructs a memory pool feature.
/// </summary>
Expand All @@ -49,7 +42,7 @@ public class MempoolFeature : FullNodeFeature, IFeatureStats
/// <param name="mempoolSignaled">Observes block signal notifications from signals.</param>
/// <param name="mempoolBehavior">Memory pool node behavior for managing attached node messages.</param>
/// <param name="mempoolManager">Memory pool manager for managing external access to memory pool.</param>
/// <param name="loggerFactory">Logger factory for creating loggers.</param>
/// <param name="loggerFactory">Logger factory for creating instance logger.</param>
public MempoolFeature(
IConnectionManager connectionManager,
Signals.Signals signals,
Expand All @@ -76,10 +69,6 @@ public void AddFeatureStats(StringBuilder benchLogs)
}
}

#endregion

#region FullNodeFeature Overrides

/// <inheritdoc />
public override void Start()
{
Expand Down Expand Up @@ -107,8 +96,6 @@ public override void Stop()
}
}
}

#endregion
}

/// <summary>
Expand Down
41 changes: 13 additions & 28 deletions Stratis.Bitcoin/Features/MemoryPool/MempoolManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,15 @@ public class MempoolAsyncLock : AsyncLock
/// </summary>
public class MempoolManager: IPooledTransaction
{
#region Fields

/// <summary>Memory pool persistence methods for loading and saving from storage.</summary>
private IMempoolPersistence mempoolPersistence;

/// <summary>Memory pool manager logger.</summary>
/// <summary>Instance logger for memory pool manager.</summary>
private readonly ILogger mempoolLogger;

/// <summary>Transaction memory pool for managing transactions in the memory pool.</summary>
private readonly TxMempool memPool;

#endregion

#region Constructors

/// <summary>
/// Constructs an instance of a memory pool manager object.
/// </summary>
Expand All @@ -48,7 +42,7 @@ public class MempoolManager: IPooledTransaction
/// <param name="dateTimeProvider">Date and time information provider.</param>
/// <param name="nodeArgs">Settings from the node.</param>
/// <param name="mempoolPersistence">Memory pool persistence methods for loading and saving from storage.</param>
/// <param name="loggerFactory">Logger factory for creating logger.</param>
/// <param name="loggerFactory">Logger factory for creating instance logger.</param>
public MempoolManager(
MempoolAsyncLock mempoolLock,
TxMempool memPool,
Expand All @@ -69,20 +63,8 @@ public MempoolManager(
this.mempoolLogger = loggerFactory.CreateLogger(this.GetType().FullName);
}

public Task<Transaction> GetTransaction(uint256 trxid)
{
return Task.Run(() =>
{
return this.InfoAsync(trxid)?.GetAwaiter().GetResult()?.Trx;
});
}

#endregion

#region Properties

/// <summary>Lock for memory pool access.</summary>
public MempoolAsyncLock MempoolLock { get; }
/// <summary>Lock for memory pool access.</summary>
public MempoolAsyncLock MempoolLock { get; }

/// <summary>Memory pool validator for validating transactions.</summary>
public IMempoolValidator Validator { get; } // public for testing
Expand All @@ -99,9 +81,14 @@ public Task<Transaction> GetTransaction(uint256 trxid)
/// <summary>Access to memory pool validator performance counter.</summary>
public MempoolPerformanceCounter PerformanceCounter => this.Validator.PerformanceCounter;

#endregion

#region Operations
/// <inheritdoc />
public Task<Transaction> GetTransaction(uint256 trxid)
{
return Task.Run(() =>
{
return this.InfoAsync(trxid)?.GetAwaiter().GetResult()?.Trx;
});
}

/// <summary>
/// Gets the memory pool transactions.
Expand Down Expand Up @@ -248,7 +235,7 @@ public Task<long> MempoolDynamicMemoryUsage()
public Task RemoveForBlock(Block block, int blockHeight)
{
//if (this.IsInitialBlockDownload)
// return Task.CompletedTask;
// return Task.CompletedTask;

return this.MempoolLock.WriteAsync(() =>
{
Expand All @@ -258,7 +245,5 @@ public Task RemoveForBlock(Block block, int blockHeight)
this.Validator.PerformanceCounter.SetMempoolDynamicSize(this.memPool.DynamicMemoryUsage());
});
}

#endregion
}
}
22 changes: 3 additions & 19 deletions Stratis.Bitcoin/Features/MemoryPool/MempoolOrphans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ namespace Stratis.Bitcoin.Features.MemoryPool
/// </summary>
public class MempoolOrphans
{
#region Fields

/// <summary>Expiration time for orphan transactions in seconds.</summary>
private const long OrphanTxExpireTime = 20 * 60;

Expand Down Expand Up @@ -49,7 +47,7 @@ public class MempoolOrphans
/// <summary>Settings from the node.</summary>
private readonly NodeSettings nodeArgs;

/// <summary>Logger for the memory pool.</summary>
/// <summary>Instance logger for the memory pool.</summary>
private readonly ILogger mempoolLogger;

/// <summary>Dictionary of orphan transactions keyed by transaction hash.</summary>
Expand All @@ -70,10 +68,6 @@ public class MempoolOrphans
/// <summary>Location on chain when rejects are validated.</summary>
private uint256 hashRecentRejectsChainTip;

#endregion

#region Constructors

/// <summary>
/// Constructs a memory pool orphan manager object.
/// </summary>
Expand All @@ -86,7 +80,7 @@ public class MempoolOrphans
/// <param name="coinView">Coin view of the memory pool.</param>
/// <param name="dateTimeProvider">Date and time information provider.</param>
/// <param name="nodeArgs">Settings from the node.</param>
/// <param name="loggerFactory">Factory for creating logger for this object.</param>
/// <param name="loggerFactory">Factory for creating instance logger for this object.</param>
public MempoolOrphans(
MempoolAsyncLock mempoolLock,
TxMempool memPool,
Expand Down Expand Up @@ -116,20 +110,12 @@ public MempoolOrphans(
this.mempoolLogger = loggerFactory.CreateLogger(this.GetType().FullName);
}

#endregion

#region Properties

/// <summary>A lock for managing asynchronous access to memory pool.</summary>
public MempoolAsyncLock MempoolLock { get; }

/// <summary>Memory pool validator for validating transactions.</summary>
public IMempoolValidator Validator { get; } // public for testing

#endregion

#region Operations

/// <summary>
/// Object representing an orphan transaction information.
/// When modifying, adapt the copy of this definition in tests/DoS_tests.
Expand Down Expand Up @@ -288,7 +274,7 @@ public async Task<bool> ProcessesOrphansMissingInputs(Node from, Transaction tx)
//CInv _inv(MSG_TX | nFetchFlags, txin.prevout.hash);
//behavior.AttachedNode.Behaviors.Find<RelayBehaviour>() pfrom->AddInventoryKnown(_inv);
//if (!await this.AlreadyHave(txin.PrevOut.Hash))
// from. pfrom->AskFor(_inv);
// from. pfrom->AskFor(_inv);
}
var ret = await this.AddOrphanTx(from.PeerVersion.Nonce, tx);

Expand Down Expand Up @@ -450,7 +436,5 @@ public Task EraseOrphansFor(ulong peer)
//return true;
}).Unwrap();
}

#endregion
}
}
Loading