Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select coins for round abstraction #9123

Conversation

onvej-sl
Copy link
Contributor

This PR allows for implementation of Wabisabi client library which will be used by Trezor.

Copy link
Collaborator

@lontivero lontivero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could extract all the coins selection code to some class (lets call it: CoinSelector) which implements and ICoinSelector and implement your own if you want, that would give you a lot more power and flexibility.


namespace WalletWasabi.Blockchain.TransactionOutputs;

public interface ISmartCoin
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an ICoin + AnonymitySet. I mean, a NBitcoin::ICoin already has and TxOut (Amount, ScriptPubKey) and an OutPoint (TransactionId, Index). The only think tit doesn't have is an "anonymityset" (that shoulc be called AnonymityScore because we are abandoming the concept)

Btw, ScriptType is not really necessary because it can be extracted from the scriptPubKey.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an ICoin + AnonymitySet. I mean, a NBitcoin::ICoin already has and TxOut (Amount, ScriptPubKey) and an OutPoint (TransactionId, Index).

It is not, because (as you already said yourself) ICoin + AnonymitySet contains ScriptPubKey instead of ScriptType. The ScriptPubKey itself is not needed in the coin selection algorithm.

@@ -472,11 +475,17 @@ public static FeeRate GetSanityFeeRate(this MemPoolInfo me)
output.Value + feeRate.GetFee(output.ScriptPubKey.EstimateOutputVsize());

public static Money EffectiveValue(this Coin coin, FeeRate feeRate, CoordinationFeeRate coordinationFeeRate)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we could receive an ICoin instead of a Coin because in that way nothing needs to be changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 95ebc9a.

@@ -66,6 +66,7 @@ public record RoundParameters
public TimeSpan TransactionSigningTimeout { get; init; }
public TimeSpan BlameInputRegistrationTimeout { get; init; }

public ImmutableSortedSet<ScriptType> AllowedInputScriptTypes => AllowedInputTypes;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in c49b791.

@@ -739,7 +740,7 @@ private void LogCoinJoinSummary(ImmutableArray<AliceClient> registeredAliceClien

var sw2 = Stopwatch.StartNew();
foreach (var group in orderedAllowedCoins
.Except(new[] { coin })
.Except(new TCoin[] { coin })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes TCoin is Equatable when it is not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in fc098d6.

@@ -6,7 +6,7 @@

namespace WalletWasabi.WabiSabi.Backend.Rounds;

public record RoundParameters
public record RoundParameters : IUtxoSelectionParameters
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try hard to avoid adding interfaces (we almost never use them). If you want you can add a new UtxoSelectionParameters containing the required properties and that can be build from a round parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 64f4744.

@onvej-sl
Copy link
Contributor Author

You could extract all the coins selection code to some class

This is definitely a good idea. I will probably do it in a following pull request.

@lontivero
Copy link
Collaborator

It was not possible for me to re-take the work on this so, I think the best would be to go with this version as it is and then I will go back to it when I find the time. Please fix the conflict and I will merge it.

@onvej-sl onvej-sl force-pushed the onvej-sl/select-coins-for-round-abstraction branch from 307aa54 to 2bf98f4 Compare November 3, 2022 14:43
@onvej-sl
Copy link
Contributor Author

@lontivero Is there anything I can to get this PR merged?

@lontivero
Copy link
Collaborator

@lontivero Is there anything I can to get this PR merged?

Yes, please answer my questions about the nullability. Is there any problem changing that? Where the is a null there is always a chance to get a NRE

@onvej-sl
Copy link
Contributor Author

@lontivero Is there anything I can to get this PR merged?

Yes, please answer my questions about the nullability. Is there any problem changing that? Where the is a null there is always a chance to get a NRE

What questions do you mean? I cannot see any questions.

{
var netFee = feeRate.GetFee(coin.ScriptPubKey.EstimateInputVsize());
var coordFee = coordinationFeeRate.GetFee(coin.Amount);
var netFee = feeRate.GetFee(scriptType.EstimateInputVsize());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if scriptType is null? Why is it nullable?

scriptPubKey.TryGetScriptType() switch
scriptPubKey.TryGetScriptType().EstimateInputVsize();

public static int EstimateInputVsize(this ScriptType? scriptType) =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be nullable.

@lontivero
Copy link
Collaborator

Sorry, they were "pending".

@onvej-sl
Copy link
Contributor Author

Yes, please answer my questions about the nullability. Is there any problem changing that? Where the is a null there is always a chance to get a NRE

Please see 9db433e. Do you think it solves the issue?

lontivero
lontivero previously approved these changes Nov 22, 2022
@@ -522,6 +534,6 @@ public static byte[] ExtractKeyId(this Script scriptPubKey)
}
}

return null;
throw new NotImplementedException($"Unsupported script type.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be NotSupportedException but I can see this is not the only place this exception is used so, it's okay, we have to change it everywhere.

@lontivero
Copy link
Collaborator

The content is mergeable as it is, just fix solve the conflict and we are ready.

@onvej-sl
Copy link
Contributor Author

just fix solve the conflict and we are ready.

Done.

git range-diff 4f0307374dfe03b11bef40f36d57b551d30264a0..9db433ee78494219ebe89919c258b6ae75de77de 37746b43167cc4b52b9705349daf4b0a87521591..729efd1a7a63865be941dac87b8debb4c07bf36d

1:  f6b429c98 ! 1:  51a728032 Add abstraction to allow working with the selection algorithm
    @@ WalletWasabi/Blockchain/TransactionOutputs/SmartCoin.cs: public class SmartCoin
      	public Coin Coin => _coin.Value;
      
      	public Script ScriptPubKey => TxOut.ScriptPubKey;
    -+	public ScriptType ScriptType => ScriptPubKey.TryGetScriptType() ?? throw new NotSupportedException("Unknown script type.");
    ++	public ScriptType ScriptType => ScriptPubKey.GetScriptType();
      	public Money Amount => TxOut.Value;
     +	public double AnonymitySet => HdPubKey.AnonymitySet;
      
      	public Height Height
      	{
     
    + ## WalletWasabi/Crypto/Bip322Signature.cs ##
    +@@ WalletWasabi/Crypto/Bip322Signature.cs: public record Bip322Signature : IBitcoinSerializable
    + 		NBitcoinExtensions.FromBytes<Bip322Signature>(bip322SignatureBytes);
    + 
    + 	public bool Verify(uint256 hash, Script scriptPubKey) =>
    +-		scriptPubKey.TryGetScriptType() switch
    ++		scriptPubKey.GetScriptType() switch
    + 		{
    + 			ScriptType.P2WPKH => VerifyP2wpkh(hash, scriptPubKey),
    + 			ScriptType.Taproot => VerifyP2tr(hash, scriptPubKey),
    +
    + ## WalletWasabi/Crypto/OwnershipProof.cs ##
    +@@ WalletWasabi/Crypto/OwnershipProof.cs: public record OwnershipProof : IBitcoinSerializable
    + 			Bip322Signature.Generate(key, proofBody.SignatureHash(key.PubKey.GetScriptPubKey(scriptPubKeyType), commitmentData), scriptPubKeyType));
    + 
    + 	public bool VerifyOwnership(Script scriptPubKey, byte[] commitmentData, bool requireUserConfirmation) =>
    +-		scriptPubKey.TryGetScriptType() switch
    ++		scriptPubKey.GetScriptType() switch
    + 		{
    + 			ScriptType.P2WPKH or ScriptType.Taproot => VerifyOwnershipProof(scriptPubKey, commitmentData, requireUserConfirmation),
    + 			_ => throw new NotImplementedException("Only P2WPKH and P2TR scripts are supported."),
    +
      ## WalletWasabi/Extensions/NBitcoinExtensions.cs ##
     @@ WalletWasabi/Extensions/NBitcoinExtensions.cs: public static class NBitcoinExtensions
      		new TxOut(Money.Zero, scriptPubKey).GetSerializedSize();
      
      	public static int EstimateInputVsize(this Script scriptPubKey) =>
     -		scriptPubKey.TryGetScriptType() switch
    -+		scriptPubKey.TryGetScriptType().EstimateInputVsize();
    ++		scriptPubKey.GetScriptType().EstimateInputVsize();
     +
    -+	public static int EstimateInputVsize(this ScriptType? scriptType) =>
    ++	public static int EstimateInputVsize(this ScriptType scriptType) =>
     +		scriptType switch
      		{
      			ScriptType.P2WPKH => Constants.P2wpkhInputVirtualSize,
      			ScriptType.Taproot => Constants.P2trInputVirtualSize,
     @@ WalletWasabi/Extensions/NBitcoinExtensions.cs: public static class NBitcoinExtensions
    + 	public static Money EffectiveCost(this TxOut output, FeeRate feeRate) =>
      		output.Value + feeRate.GetFee(output.ScriptPubKey.EstimateOutputVsize());
      
    - 	public static Money EffectiveValue(this Coin coin, FeeRate feeRate, CoordinationFeeRate coordinationFeeRate)
    -+		=> EffectiveValue(coin.Amount, coin.ScriptPubKey.TryGetScriptType(), feeRate, coordinationFeeRate);
    +-	public static Money EffectiveValue(this Coin coin, FeeRate feeRate, CoordinationFeeRate coordinationFeeRate)
    ++	public static Money EffectiveValue(this ICoin coin, FeeRate feeRate, CoordinationFeeRate coordinationFeeRate)
    ++		=> EffectiveValue(coin.TxOut.Value, coin.TxOut.ScriptPubKey.GetScriptType(), feeRate, coordinationFeeRate);
     +
     +	public static Money EffectiveValue(this ISmartCoin coin, FeeRate feeRate, CoordinationFeeRate coordinationFeeRate)
     +		=> EffectiveValue(coin.Amount, coin.ScriptType, feeRate, coordinationFeeRate);
     +
    -+	private static Money EffectiveValue(Money amount, ScriptType? scriptType, FeeRate feeRate, CoordinationFeeRate coordinationFeeRate)
    ++	private static Money EffectiveValue(Money amount, ScriptType scriptType, FeeRate feeRate, CoordinationFeeRate coordinationFeeRate)
      	{
     -		var netFee = feeRate.GetFee(coin.ScriptPubKey.EstimateInputVsize());
     -		var coordFee = coordinationFeeRate.GetFee(coin.Amount);
    @@ WalletWasabi/Extensions/NBitcoinExtensions.cs: public static class NBitcoinExten
      	public static T FromBytes<T>(byte[] input) where T : IBitcoinSerializable, new()
      	{
      		BitcoinStream inputStream = new(input);
    +@@ WalletWasabi/Extensions/NBitcoinExtensions.cs: public static class NBitcoinExtensions
    + 	/// </summary>
    + 	public static byte[] ExtractKeyId(this Script scriptPubKey)
    + 	{
    +-		return scriptPubKey.TryGetScriptType() switch
    ++		return scriptPubKey.GetScriptType() switch
    + 		{
    + 			ScriptType.P2WPKH => PayToWitPubKeyHashTemplate.Instance.ExtractScriptPubKeyParameters(scriptPubKey)!.ToBytes(),
    + 			ScriptType.P2PKH => PayToPubkeyHashTemplate.Instance.ExtractScriptPubKeyParameters(scriptPubKey)!.ToBytes(),
    +@@ WalletWasabi/Extensions/NBitcoinExtensions.cs: public static class NBitcoinExtensions
    + 		};
    + 	}
    + 
    +-	public static ScriptType? TryGetScriptType(this Script script)
    ++	public static ScriptType GetScriptType(this Script script)
    + 	{
    + 		foreach (ScriptType scriptType in new ScriptType[] { ScriptType.P2WPKH, ScriptType.P2PKH, ScriptType.P2PK, ScriptType.Taproot })
    + 		{
    +@@ WalletWasabi/Extensions/NBitcoinExtensions.cs: public static class NBitcoinExtensions
    + 			}
    + 		}
    + 
    +-		return null;
    ++		throw new NotImplementedException($"Unsupported script type.");
    + 	}
    + }
     
      ## WalletWasabi/WabiSabi/Client/CoinJoinClient.cs ##
     @@ WalletWasabi/WabiSabi/Client/CoinJoinClient.cs: public class CoinJoinClient
    @@ WalletWasabi/WabiSabi/Client/CoinJoinClient.cs: public class CoinJoinClient
      
      		int sameTxAllowance = GetRandomBiasedSameTxAllowance(rnd, percent);
      
    --		var winner = new List<SmartCoin>();
    -+		var winner = new List<TCoin>();
    +-		List<SmartCoin> winner = new()
    ++		List<TCoin> winner = new()
    + 		{
    + 			selectedNonPrivateCoin
    + 		};
    + 
      		foreach (var coin in finalCandidate
    + 			.Except(new[] { selectedNonPrivateCoin })
     -			.OrderBy(x => x.HdPubKey.AnonymitySet)
     +			.OrderBy(x => x.AnonymitySet)
      			.ThenByDescending(x => x.Amount))
      		{
      			// If the coin is coming from same tx, then check our allowance.
     @@ WalletWasabi/WabiSabi/Client/CoinJoinClient.cs: public class CoinJoinClient
    - 			Logger.LogDebug($"{nameof(winner)}: {winner.Count} coins, {string.Join(", ", winner.Select(x => x.Amount.ToString(false, true)).ToArray())} BTC.");
    - 		}
    + 		// Only stay in the while if we are above the liquidityClue (we are a whale) AND the weightedAnonLoss is not tolerable.
    + 		while ((winner.Sum(x => x.Amount) > liquidityClue) && (winnerAnonLoss > MaxWeightedAnonLoss))
    + 		{
    +-			List<SmartCoin> bestReducedWinner = winner;
    ++			List<TCoin> bestReducedWinner = winner;
    + 			var bestAnonLoss = winnerAnonLoss;
    + 			bool winnerchanged = false;
      
    --		return winner.ToShuffled()?.ToImmutableList() ?? ImmutableList<SmartCoin>.Empty;
    -+		return winner.ToShuffled()?.ToImmutableList() ?? ImmutableList<TCoin>.Empty;
    + 			// We always want to keep the non-private coins.
    +-			foreach (SmartCoin coin in winner.Except(new[] { selectedNonPrivateCoin }))
    ++			foreach (TCoin coin in winner.Except(new[] { selectedNonPrivateCoin }))
    + 			{
    + 				var reducedWinner = winner.Except(new[] { coin });
    + 				var anonLoss = GetAnonLoss(reducedWinner);
    +@@ WalletWasabi/WabiSabi/Client/CoinJoinClient.cs: public class CoinJoinClient
    + 		return winner.ToShuffled().ToImmutableList();
    + 	}
    + 
    +-	private static double GetAnonLoss(IEnumerable<SmartCoin> coins)
    ++	private static double GetAnonLoss<TCoin>(IEnumerable<TCoin> coins)
    ++		where TCoin : ISmartCoin
    + 	{
    +-		double minimumAnonScore = coins.Min(x => x.HdPubKey.AnonymitySet);
    +-		return coins.Sum(x => (x.HdPubKey.AnonymitySet - minimumAnonScore) * x.Amount.Satoshi) / coins.Sum(x => x.Amount.Satoshi);
    ++		double minimumAnonScore = coins.Min(x => x.AnonymitySet);
    ++		return coins.Sum(x => (x.AnonymitySet - minimumAnonScore) * x.Amount.Satoshi) / coins.Sum(x => x.Amount.Satoshi);
      	}
      
      	private static int GetRandomBiasedSameTxAllowance(WasabiRandom rnd, int percent)
2:  c867469b9 = 2:  ba2a4cf40 Use round parameters
3:  5a9613d65 < -:  --------- Use ICoin instead of Coin in EffectiveValue()
4:  14795de1e = 3:  db997058e Use record instead of interface
5:  9de684a07 = 4:  daf5b75a0 Remove unnecessary field
6:  0f1429d83 = 5:  2eba8c70d Make TCoin IEquatable
7:  2bf98f449 = 6:  729efd1a7 Do not touch existing classes
8:  9db433ee7 < -:  --------- fixup! Add abstraction to allow working with the selection algorithm

@lontivero lontivero merged commit 367ef7c into WalletWasabi:master Nov 23, 2022
@nopara73
Copy link
Contributor

This PR broke wallet load.

Kimi
  [9:36 AM](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669278985902999)
2022-11-24 09:35:29.746 [38] ERROR      WalletManagerViewModel.LoadWalletAsync (143)    System.NotImplementedException: Unsupported script type.
   at WalletWasabi.Extensions.NBitcoinExtensions.GetScriptType(Script script) in WalletWasabi\Extensions\NBitcoinExtensions.cs:line 537
   at WalletWasabi.Extensions.NBitcoinExtensions.ExtractKeyId(Script scriptPubKey) in WalletWasabi\Extensions\NBitcoinExtensions.cs:line 518
   at WalletWasabi.Blockchain.Transactions.SmartTransaction.<>c.<get_ForeignVirtualOutputs>b__46_0(IndexedTxOut o) in WalletWasabi\Blockchain\Transactions\SmartTransaction.cs:line 142
   at System.Linq.Lookup`2.Create(IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer)
   at System.Linq.GroupedEnumerable`2.GetEnumerator()
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.HashSet`1.UnionWith(IEnumerable`1 other)
   at System.Collections.Generic.HashSet`1..ctor(IEnumerable`1 collection, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToHashSet[TSource](IEnumerable`1 source, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToHashSet[TSource](IEnumerable`1 source)
   at WalletWasabi.Blockchain.Transactions.SmartTransaction.get_ForeignVirtualOutputs() in WalletWasabi\Blockchain\Transactions\SmartTransaction.cs:line 141
   at WalletWasabi.Blockchain.Analysis.CoinjoinAnalyzer.ComputeAnonymityContribution(SmartCoin transactionOutput, HashSet`1 relevantOutpoints) in WalletWasabi\Blockchain\Analysis\CoinjoinAnalyzer.cs:line 74
   at WalletWasabi.Blockchain.Analysis.CoinjoinAnalyzer.<>c__DisplayClass15_0.<ComputeInputSanction>g__ComputeInputSanctionHelper|0(SmartCoin transactionOutput, Int32 recursionDepth) in WalletWasabi\Blockchain\Analysis\CoinjoinAnalyzer.cs:line 51
   at WalletWasabi.Blockchain.Analysis.CoinjoinAnalyzer.ComputeInputSanction(SmartCoin transactionInput, AggregationFunction aggregationFunction) in WalletWasabi\Blockchain\Analysis\CoinjoinAnalyzer.cs:line 62
   at WalletWasabi.Blockchain.Analysis.CoinjoinAnalyzer.<>c__DisplayClass14_0.<ComputeInputSanction>b__0(SmartCoin x) in WalletWasabi\Blockchain\Analysis\CoinjoinAnalyzer.cs:line 30
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.Max(IEnumerable`1 source)
   at WalletWasabi.Blockchain.Analysis.CoinjoinAnalyzer.ComputeInputSanction(WalletVirtualInput virtualInput, AggregationFunction aggregationFunction) in WalletWasabi\Blockchain\Analysis\CoinjoinAnalyzer.cs:line 30
   at WalletWasabi.Blockchain.Analysis.BlockchainAnalyzer.<>c__DisplayClass2_0.<AnalyzeCoinjoinWalletInputs>b__1(WalletVirtualInput x) in WalletWasabi\Blockchain\Analysis\BlockchainAnalyzer.cs:line 73
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
   at WalletWasabi.Blockchain.Analysis.CoinjoinAnalyzer.<>c.<.cctor>b__18_1(IEnumerable`1 x) in WalletWasabi\Blockchain\Analysis\CoinjoinAnalyzer.cs:line 14
   at WalletWasabi.Blockchain.Analysis.BlockchainAnalyzer.AnalyzeCoinjoinWalletInputs(SmartTransaction tx, Double& mixedAnonScore, Double& mixedAnonScoreSanctioned, Double& nonMixedAnonScore, Double& nonMixedAnonScoreSanctioned) in WalletWasabi\Blockchain\Analysis\BlockchainAnalyzer.cs:line 73
   at WalletWasabi.Blockchain.Analysis.BlockchainAnalyzer.Analyze(SmartTransaction tx) in WalletWasabi\Blockchain\Analysis\BlockchainAnalyzer.cs:line 54
   at WalletWasabi.Blockchain.TransactionProcessing.TransactionProcessor.ProcessNoLock(SmartTransaction tx) in WalletWasabi\Blockchain\TransactionProcessing\TransactionProcessor.cs:line 279
   at WalletWasabi.Blockchain.TransactionProcessing.TransactionProcessor.Process(IEnumerable`1 txs) in WalletWasabi\Blockchain\TransactionProcessing\TransactionProcessor.cs:line 60
   at WalletWasabi.Wallets.Wallet.LoadWalletStateAsync(CancellationToken cancel) in WalletWasabi\Wallets\Wallet.cs:line 417
   at WalletWasabi.Wallets.Wallet.StartAsync(CancellationToken cancel) in WalletWasabi\Wallets\Wallet.cs:line 232
   at WalletWasabi.Wallets.WalletManager.StartWalletAsync(Wallet wallet) in WalletWasabi\Wallets\WalletManager.cs:line 162
   at WalletWasabi.Wallets.WalletManager.StartWalletAsync(Wallet wallet) in WalletWasabi\Wallets\WalletManager.cs:line 171
   at WalletWasabi.Fluent.ViewModels.WalletManagerViewModel.<>c__DisplayClass9_0.<<LoadWalletAsync>b__0>d.MoveNext() in WalletWasabi.Fluent\ViewModels\WalletManagerViewModel.cs:line 135
--- End of stack trace from previous location ---
   at WalletWasabi.Fluent.ViewModels.WalletManagerViewModel.LoadWalletAsync(Wallet wallet) in WalletWasabi.Fluent\ViewModels\WalletManagerViewModel.cs:line 135
[9:36](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669278996552109)
Anyone seeing this when starting the wallet?


nopara73
  [10:07 AM](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669280873261179)
Yes, the master is broken
:fire:
1



Kimi
  [10:11 AM](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669281106456259)
I can start my wallet with this change: https://github.com/zkSNACKs/WalletWasabi/pull/9615


nopara73
  [10:16 AM](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669281380781589)
I'm trying to figure out which commit ruined it, but cannot find it easily
[10:16](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669281389748749)
That change
[10:16](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669281394499669)
How the heck does that help?
[10:16](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669281411869709)
We shouldn't have such script types that you added.


Kimi
  [10:20 AM](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669281610235999)
Well, I don't really know. I'm just sharing what helped me.


nopara73
  [10:20 AM](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669281643301789)
Tested and it does work indeed.
[10:20](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669281652842509)
Well, we should figure it out then.


Kimi
  [10:21 AM](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669281690103969)
So could it be something like CoinjoinAnalyzer analyzing foreing transactions?


nopara73
  [10:22 AM](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669281761674259)
https://github.com/zkSNACKs/WalletWasabi/pull/9123
[10:22](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669281765113829)
This
[10:23](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669281787810309)
Something smart happened here that broke wallet load 
[@Lucas Ontivero](https://tumblebit.slack.com/team/U94F4TFD4)


Kimi
  [10:25 AM](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669281916820129)
ah, I see https://github.com/zkSNACKs/WalletWasabi/pull/9123/files#diff-7ba3d1ab86c96ca4f6105ed4f669a985cfe62294fdc1fe982d55de3b1bf8c1b9R537


nopara73
  [10:26 AM](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669281993786889)
Yup
[10:27](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669282051626139)
So, they throw this exception instead of returning null.
[10:28](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669282096924779)
That feels problematic, because that means if the wallet finds any transaction that does not conform to the specified script types (eg Bitcoin Core adds a new one in the future) then wallet load is killed.


Kimi
  [10:30 AM](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669282227960179)
Yeah, also NBitcoin might be lagging and then we would have to patch NBitcoin.


nopara73
  [10:31 AM](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669282274747489)
public static byte[] ExtractKeyId(this Script scriptPubKey)
	{
		return scriptPubKey.GetScriptType() switch
		{
			ScriptType.P2WPKH => PayToWitPubKeyHashTemplate.Instance.ExtractScriptPubKeyParameters(scriptPubKey)!.ToBytes(),
			ScriptType.P2PKH => PayToPubkeyHashTemplate.Instance.ExtractScriptPubKeyParameters(scriptPubKey)!.ToBytes(),
			ScriptType.P2PK => PayToPubkeyTemplate.Instance.ExtractScriptPubKeyParameters(scriptPubKey)!.ToBytes(),
			_ => scriptPubKey.ToBytes()
		};
	}
[10:31](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669282276614919)
This
[10:31](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669282294484789)
It was expecting a not exception from GetScriptType
[10:31](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669282304441519)
To return default.
New


Kimi
  [10:32 AM](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669282329170399)
return scriptPubKey.TryGetScriptType() switch
[10:32](https://tumblebit.slack.com/archives/CFBJX6MN0/p1669282332545209)
would work nice

@kiminuo is working on to fix, if he fails to do it quickly, then this PR gets reverted and need to be sorted out later.

@nopara73
Copy link
Contributor

No need to revert. #9615 fixes it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants