Skip to content

Commit

Permalink
Change to time provider (neo-project#1943)
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored and Shawn committed Jan 8, 2021
1 parent 89d1fb9 commit 5bc6d71
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/neo/Ledger/MemoryPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ internal void InvalidateAllTransactions()
private int ReverifyTransactions(SortedSet<PoolItem> verifiedSortedTxPool,
SortedSet<PoolItem> unverifiedSortedTxPool, int count, double millisecondsTimeout, StoreView snapshot)
{
DateTime reverifyCutOffTimeStamp = DateTime.UtcNow.AddMilliseconds(millisecondsTimeout);
DateTime reverifyCutOffTimeStamp = TimeProvider.Current.UtcNow.AddMilliseconds(millisecondsTimeout);
List<PoolItem> reverifiedItems = new List<PoolItem>(count);
List<PoolItem> invalidItems = new List<PoolItem>();

Expand All @@ -433,15 +433,15 @@ private int ReverifyTransactions(SortedSet<PoolItem> verifiedSortedTxPool,
else // Transaction no longer valid -- it will be removed from unverifiedTxPool.
invalidItems.Add(item);

if (DateTime.UtcNow > reverifyCutOffTimeStamp) break;
if (TimeProvider.Current.UtcNow > reverifyCutOffTimeStamp) break;
}

int blocksTillRebroadcast = BlocksTillRebroadcast;
// Increases, proportionally, blocksTillRebroadcast if mempool has more items than threshold bigger RebroadcastMultiplierThreshold
if (Count > RebroadcastMultiplierThreshold)
blocksTillRebroadcast = blocksTillRebroadcast * Count / RebroadcastMultiplierThreshold;

var rebroadcastCutOffTime = DateTime.UtcNow.AddMilliseconds(
var rebroadcastCutOffTime = TimeProvider.Current.UtcNow.AddMilliseconds(
-Blockchain.MillisecondsPerBlock * blocksTillRebroadcast);
foreach (PoolItem item in reverifiedItems)
{
Expand All @@ -452,7 +452,7 @@ private int ReverifyTransactions(SortedSet<PoolItem> verifiedSortedTxPool,
if (item.LastBroadcastTimestamp < rebroadcastCutOffTime)
{
_system.LocalNode.Tell(new LocalNode.RelayDirectly { Inventory = item.Tx }, _system.Blockchain);
item.LastBroadcastTimestamp = DateTime.UtcNow;
item.LastBroadcastTimestamp = TimeProvider.Current.UtcNow;
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/neo/Network/P2P/Payloads/PingPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static PingPayload Create(uint height, uint nonce)
return new PingPayload
{
LastBlockIndex = height,
Timestamp = DateTime.UtcNow.ToTimestamp(),
Timestamp = TimeProvider.Current.UtcNow.ToTimestamp(),
Nonce = nonce
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/neo/Network/P2P/RemoteNode.ProtocolHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ private void OnInvMessageReceived(InvPayload payload)
}
if (hashes.Length == 0) return;
foreach (UInt256 hash in hashes)
pendingKnownHashes.Add((hash, DateTime.UtcNow));
pendingKnownHashes.Add((hash, TimeProvider.Current.UtcNow));
system.TaskManager.Tell(new TaskManager.NewTasks { Payload = InvPayload.Create(payload.Type, hashes) });
}

Expand Down Expand Up @@ -377,7 +377,7 @@ private void RefreshPendingKnownHashes()
while (pendingKnownHashes.Count > 0)
{
var (_, time) = pendingKnownHashes[0];
if (DateTime.UtcNow - time <= PendingTimeout)
if (TimeProvider.Current.UtcNow - time <= PendingTimeout)
break;
pendingKnownHashes.RemoveAt(0);
}
Expand Down
4 changes: 2 additions & 2 deletions src/neo/Network/P2P/TaskManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private void OnNewTasks(InvPayload payload)
foreach (UInt256 hash in hashes)
{
IncrementGlobalTask(hash);
session.InvTasks[hash] = DateTime.UtcNow;
session.InvTasks[hash] = TimeProvider.Current.UtcNow;
}

foreach (InvPayload group in InvPayload.CreateGroup(payload.Type, hashes.ToArray()))
Expand Down Expand Up @@ -251,7 +251,7 @@ private void OnTimer()

foreach (var task in session.InvTasks.ToArray())
{
if (DateTime.UtcNow - task.Value > TaskTimeout)
if (TimeProvider.Current.UtcNow - task.Value > TaskTimeout)
{
if (session.InvTasks.Remove(task.Key))
DecrementGlobalTask(task.Key);
Expand Down

0 comments on commit 5bc6d71

Please sign in to comment.