diff --git a/src/neo/Network/P2P/TaskManager.cs b/src/neo/Network/P2P/TaskManager.cs index 5bea005a36..e4e526e63d 100644 --- a/src/neo/Network/P2P/TaskManager.cs +++ b/src/neo/Network/P2P/TaskManager.cs @@ -4,6 +4,7 @@ using Neo.IO.Caching; using Neo.Ledger; using Neo.Network.P2P.Payloads; +using Neo.Persistence; using System; using System.Collections; using System.Collections.Generic; @@ -299,14 +300,22 @@ private void RequestTasks() private void SendPingMessage() { + if (sessions.Count == 0) return; + + TrimmedBlock block; + using (SnapshotView snapshot = Blockchain.Singleton.GetSnapshot()) + { + block = snapshot.Blocks[snapshot.CurrentBlockHash]; + } + foreach (KeyValuePair item in sessions) { var node = item.Key; var session = item.Value; if (session.ExpireTime < TimeProvider.Current.UtcNow || - (Blockchain.Singleton.Height >= session.LastBlockIndex - && TimeProvider.Current.UtcNow.ToTimestampMS() - PingCoolingOffPeriod >= Blockchain.Singleton.GetBlock(Blockchain.Singleton.CurrentBlockHash)?.Timestamp)) + (block.Index >= session.LastBlockIndex && + TimeProvider.Current.UtcNow.ToTimestampMS() - PingCoolingOffPeriod >= block.Timestamp)) { if (session.InvTasks.Remove(MemPoolTaskHash)) {