예제 #1
0
 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);
                }
            }
        }
예제 #3
0
 public CcjRound TryGetRound(long roundId)
 {
     using (RoundsListLock.Lock())
     {
         return(Rounds.SingleOrDefault(x => x.RoundId == roundId));
     }
 }
예제 #4
0
 public IEnumerable <CcjRound> GetRunningRounds()
 {
     using (RoundsListLock.Lock())
     {
         return(Rounds.Where(x => x.Status == CcjRoundStatus.Running).ToArray());
     }
 }
예제 #5
0
 public CcjRound GetCurrentInputRegisterableRound()
 {
     using (RoundsListLock.Lock())
     {
         return(Rounds.First(x => x.Status == CcjRoundStatus.Running && x.Phase == CcjRoundPhase.InputRegistration));                // not FirstOrDefault, it must always exist
     }
 }
예제 #6
0
        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);
                }
            }
        }
예제 #7
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;
                            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;
            }
        }
예제 #8
0
 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);
         }
     }
 }
예제 #9
0
 public void FailAllRoundsInInputRegistration()
 {
     using (RoundsListLock.Lock())
     {
         foreach (var r in Rounds.Where(x => x.Status == CcjRoundStatus.Running && x.Phase == CcjRoundPhase.InputRegistration))
         {
             r.Fail();
         }
     }
 }
예제 #10
0
		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);
				}
			}
		}
예제 #11
0
        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));
        }
예제 #12
0
 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);
     }
 }
예제 #13
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;
            }
        }