public void CanReleaseAfterLongBan() { var p = new Prison(); var id1 = BitcoinFactory.CreateUint256(); var utxo = BitcoinFactory.CreateOutPoint(); var past = DateTimeOffset.UtcNow - TimeSpan.FromDays(40); p.Punish(new Inmate(utxo, Punishment.Banned, past, id1, IsLongBan: true)); Assert.Single(p.GetInmates()); p.ReleaseEligibleInmates(normalBanPeriod: TimeSpan.FromSeconds(1), longBanPeriod: TimeSpan.FromDays(31)); Assert.Empty(p.GetInmates()); }
protected override async Task ActionAsync(CancellationToken cancel) { var count = Prison.ReleaseEligibleInmates(Config.ReleaseUtxoFromPrisonAfter).Count(); if (count > 0) { Logger.LogInfo($"{count} UTXOs are released from prison."); } // If something changed, send prison to file. if (LastKnownChange != Prison.ChangeId) { await SerializePrisonAsync().ConfigureAwait(false); LastKnownChange = Prison.ChangeId; } }
public void PrisonChangeTracking() { var p = new Prison(); var currentChangeId = p.ChangeId; // Make sure we set them to the past so the release method that looks at the time evaluates to true. var past = DateTimeOffset.UtcNow - TimeSpan.FromMilliseconds(2); var id1 = BitcoinFactory.CreateUint256(); p.Punish(new Inmate(BitcoinFactory.CreateOutPoint(), Punishment.Banned, past, id1)); Assert.NotEqual(currentChangeId, p.ChangeId); currentChangeId = p.ChangeId; p.Punish(new Inmate(BitcoinFactory.CreateOutPoint(), Punishment.Noted, past, id1)); Assert.NotEqual(currentChangeId, p.ChangeId); currentChangeId = p.ChangeId; var op = BitcoinFactory.CreateOutPoint(); var id2 = BitcoinFactory.CreateUint256(); p.Punish(new Inmate(op, Punishment.Noted, past, id2)); Assert.NotEqual(currentChangeId, p.ChangeId); currentChangeId = p.ChangeId; p.Punish(new Inmate(op, Punishment.Noted, past, id1)); Assert.NotEqual(currentChangeId, p.ChangeId); currentChangeId = p.ChangeId; Assert.True(p.TryRelease(op, out _)); Assert.NotEqual(currentChangeId, p.ChangeId); currentChangeId = p.ChangeId; p.ReleaseEligibleInmates(TimeSpan.FromMilliseconds(1)); Assert.NotEqual(currentChangeId, p.ChangeId); }