public CcjRound TryGetRound(string roundHash) { using (RoundsListLock.Lock()) { return(Rounds.SingleOrDefault(x => x.RoundHash == roundHash)); } }
public async Task MakeSureTwoRunningRoundsAsync(Money feePerInputs = null, Money feePerOutputs = null) { using (await RoundsListLock.LockAsync().ConfigureAwait(false)) { int runningRoundCount = Rounds.Count(x => x.Status == CoordinatorRoundStatus.Running); int confirmationTarget = await AdjustConfirmationTargetAsync(lockCoinJoins : true).ConfigureAwait(false); if (runningRoundCount == 0) { var round = new CoordinatorRound(RpcClient, UtxoReferee, RoundConfig, confirmationTarget, RoundConfig.ConfirmationTarget, RoundConfig.ConfirmationTargetReductionRate); round.CoinJoinBroadcasted += Round_CoinJoinBroadcasted; round.StatusChanged += Round_StatusChangedAsync; await round.ExecuteNextPhaseAsync(RoundPhase.InputRegistration, feePerInputs, feePerOutputs).ConfigureAwait(false); Rounds.Add(round); var round2 = new CoordinatorRound(RpcClient, UtxoReferee, RoundConfig, confirmationTarget, RoundConfig.ConfirmationTarget, RoundConfig.ConfirmationTargetReductionRate); round2.StatusChanged += Round_StatusChangedAsync; round2.CoinJoinBroadcasted += Round_CoinJoinBroadcasted; await round2.ExecuteNextPhaseAsync(RoundPhase.InputRegistration, feePerInputs, feePerOutputs).ConfigureAwait(false); Rounds.Add(round2); } else if (runningRoundCount == 1) { var round = new CoordinatorRound(RpcClient, UtxoReferee, RoundConfig, confirmationTarget, RoundConfig.ConfirmationTarget, RoundConfig.ConfirmationTargetReductionRate); round.StatusChanged += Round_StatusChangedAsync; round.CoinJoinBroadcasted += Round_CoinJoinBroadcasted; await round.ExecuteNextPhaseAsync(RoundPhase.InputRegistration, feePerInputs, feePerOutputs).ConfigureAwait(false); Rounds.Add(round); } } }
public CcjRound TryGetRound(long roundId) { using (RoundsListLock.Lock()) { return(Rounds.SingleOrDefault(x => x.RoundId == roundId)); } }
public IEnumerable <CcjRound> GetRunningRounds() { using (RoundsListLock.Lock()) { return(Rounds.Where(x => x.Status == CcjRoundStatus.Running).ToArray()); } }
public CcjRound GetCurrentInputRegisterableRound() { using (RoundsListLock.Lock()) { return(Rounds.First(x => x.Status == CcjRoundStatus.Running && x.Phase == CcjRoundPhase.InputRegistration)); // not FirstOrDefault, it must always exist } }
public async Task MakeSureTwoRunningRoundsAsync() { using (await RoundsListLock.LockAsync()) { int runningRoundCount = Rounds.Count(x => x.Status == CcjRoundStatus.Running); if (runningRoundCount == 0) { var round = new CcjRound(RpcClient, UtxoReferee, RoundConfig); round.StatusChanged += Round_StatusChangedAsync; await round.ExecuteNextPhaseAsync(CcjRoundPhase.InputRegistration); Rounds.Add(round); var round2 = new CcjRound(RpcClient, UtxoReferee, RoundConfig); round2.StatusChanged += Round_StatusChangedAsync; await round2.ExecuteNextPhaseAsync(CcjRoundPhase.InputRegistration); Rounds.Add(round2); } else if (runningRoundCount == 1) { var round = new CcjRound(RpcClient, UtxoReferee, RoundConfig); round.StatusChanged += Round_StatusChangedAsync; await round.ExecuteNextPhaseAsync(CcjRoundPhase.InputRegistration); Rounds.Add(round); } } }
private volatile bool _disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { using (RoundsListLock.Lock()) { foreach (CcjRound round in Rounds) { round.StatusChanged -= Round_StatusChangedAsync; round.CoinJoinBroadcasted -= Round_CoinJoinBroadcasted; } try { string roundCountFilePath = Path.Combine(FolderPath, "RoundCount.txt"); IoHelpers.EnsureContainingDirectoryExists(roundCountFilePath); File.WriteAllText(roundCountFilePath, CcjRound.RoundCount.ToString()); } catch (Exception ex) { Logger.LogDebug <CcjCoordinator>(ex); } } } _disposedValue = true; } }
public void AbortAllRoundsInInputRegistration(string reason, [CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = -1) { using (RoundsListLock.Lock()) { foreach (var r in Rounds.Where(x => x.Status == CoordinatorRoundStatus.Running && x.Phase == RoundPhase.InputRegistration)) { r.Abort(reason, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber); } } }
public void FailAllRoundsInInputRegistration() { using (RoundsListLock.Lock()) { foreach (var r in Rounds.Where(x => x.Status == CcjRoundStatus.Running && x.Phase == CcjRoundPhase.InputRegistration)) { r.Fail(); } } }
public void AbortAllRoundsInInputRegistration(string loggingCategory, string reason) { string category = string.IsNullOrWhiteSpace(loggingCategory) ? nameof(CcjCoordinator) : loggingCategory; using (RoundsListLock.Lock()) { foreach (var r in Rounds.Where(x => x.Status == CcjRoundStatus.Running && x.Phase == CcjRoundPhase.InputRegistration)) { r.Abort(category, reason); } } }
public CcjRound GetCurrentInputRegisterableRoundOrDefault(bool syncLock = true) { if (syncLock) { using (RoundsListLock.Lock()) { return(Rounds.FirstOrDefault(x => x.Status == CcjRoundStatus.Running && x.Phase == CcjRoundPhase.InputRegistration)); } } return(Rounds.FirstOrDefault(x => x.Status == CcjRoundStatus.Running && x.Phase == CcjRoundPhase.InputRegistration)); }
public bool AnyRunningRoundContainsInput(OutPoint input, out List <Alice> alices) { using (RoundsListLock.Lock()) { alices = new List <Alice>(); foreach (var round in Rounds.Where(x => x.Status == CcjRoundStatus.Running)) { if (round.ContainsInput(input, out List <Alice> roundAlices)) { foreach (var alice in roundAlices) { alices.Add(alice); } } } return(alices.Count > 0); } }
private volatile bool _disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { using (RoundsListLock.Lock()) { foreach (CcjRound round in Rounds) { round.StatusChanged -= Round_StatusChangedAsync; } } } _disposedValue = true; } }