コード例 #1
0
        public async Task ProcessConfirmedTransactionAsync(Transaction tx)
        {
            // This should not be needed until we would only accept unconfirmed CJ outputs an no other unconf outs. But it'll be more bulletproof for future extensions.
            // Turns out you shouldn't accept RBF at all never. (See below.)

            // https://github.com/zkSNACKs/WalletWasabi/issues/145
            // if it spends a banned output AND it's not CJ output
            // ban all the outputs of the transaction
            tx.PrecomputeHash(false, true);

            UnconfirmedCoinJoins.Remove(tx.GetHash());             // Locked outside.

            if (RoundConfig.DosSeverity <= 1)
            {
                return;
            }

            foreach (TxIn input in tx.Inputs)
            {
                OutPoint prevOut = input.PrevOut;

                // if coin is not banned
                var foundElem = await UtxoReferee.TryGetBannedAsync(prevOut, notedToo : true).ConfigureAwait(false);

                if (foundElem is { })
コード例 #2
0
        public async Task <bool> IsUnconfirmedCoinJoinLimitReachedAsync()
        {
            using (await CoinJoinsLock.LockAsync())
            {
                if (UnconfirmedCoinJoins.Count() < 24)
                {
                    return(false);
                }
                else
                {
                    foreach (var cjHash in UnconfirmedCoinJoins)
                    {
                        RPCResponse getRawTransactionResponse = await RpcClient.SendCommandAsync(RPCOperations.getrawtransaction, cjHash.ToString(), true);

                        // if failed remove from everywhere (should not happen normally)
                        if (string.IsNullOrWhiteSpace(getRawTransactionResponse?.ResultString))
                        {
                            UnconfirmedCoinJoins.Remove(cjHash);
                            CoinJoins.Remove(cjHash);
                            await File.WriteAllLinesAsync(CoinJoinsFilePath, CoinJoins.Select(x => x.ToString()));
                        }
                        // if confirmed remove only from unconfirmed
                        if (getRawTransactionResponse.Result.Value <int>("confirmations") > 0)
                        {
                            UnconfirmedCoinJoins.Remove(cjHash);
                        }
                    }
                }

                return(UnconfirmedCoinJoins.Count() >= 24);
            }
        }
コード例 #3
0
        public async Task <bool> IsUnconfirmedCoinJoinLimitReachedAsync()
        {
            using (await CoinJoinsLock.LockAsync())
            {
                if (UnconfirmedCoinJoins.Count < 24)
                {
                    return(false);
                }
                foreach (var cjHash in UnconfirmedCoinJoins.ToArray())
                {
                    try
                    {
                        var txInfo = await RpcClient.GetRawTransactionInfoAsync(cjHash);

                        // if confirmed remove only from unconfirmed
                        if (txInfo.Confirmations > 0)
                        {
                            UnconfirmedCoinJoins.Remove(cjHash);
                        }
                    }
                    catch (Exception ex)
                    {
                        // If aborted remove from everywhere (should not happen normally).
                        UnconfirmedCoinJoins.Remove(cjHash);
                        CoinJoins.Remove(cjHash);
                        await File.WriteAllLinesAsync(CoinJoinsFilePath, CoinJoins.Select(x => x.ToString()));

                        Logger.LogWarning <CcjCoordinator>(ex);
                    }
                }

                return(UnconfirmedCoinJoins.Count >= 24);
            }
        }
コード例 #4
0
        public async Task ProcessConfirmedTransactionAsync(Transaction tx)
        {
            // This should not be needed until we would only accept unconfirmed CJ outputs an no other unconf outs. But it'll be more bulletproof for future extensions.
            // Turns out you shouldn't accept RBF at all never. (See below.)

            // https://github.com/zkSNACKs/WalletWasabi/issues/145
            // if it spends a banned output AND it's not CJ output
            // ban all the outputs of the transaction
            tx.PrecomputeHash(false, true);

            UnconfirmedCoinJoins.Remove(tx.GetHash());             // Locked outside.

            if (RoundConfig.DosSeverity <= 1)
            {
                return;
            }

            foreach (TxIn input in tx.Inputs)
            {
                OutPoint prevOut = input.PrevOut;

                // if coin is not banned
                var foundElem = await UtxoReferee.TryGetBannedAsync(prevOut, notedToo : true).ConfigureAwait(false);

                if (foundElem != null)
                {
                    if (!AnyRunningRoundContainsInput(prevOut, out _))
                    {
                        int newSeverity = foundElem.Severity + 1;
                        await UtxoReferee.UnbanAsync(prevOut).ConfigureAwait(false);                         // since it's not an UTXO anymore

                        if (RoundConfig.DosSeverity >= newSeverity)
                        {
                            var txCoins = tx.Outputs.AsIndexedOutputs().Select(x => x.ToCoin().Outpoint);
                            await UtxoReferee.BanUtxosAsync(newSeverity, foundElem.TimeOfBan, forceNoted : foundElem.IsNoted, foundElem.BannedForRound, txCoins.ToArray()).ConfigureAwait(false);
                        }
                    }
                }
            }
        }