33using NBitcoin ;
44using Stratis . Bitcoin . Base . Deployments ;
55using Stratis . Features . FederatedPeg . Interfaces ;
6+ using Stratis . Features . FederatedPeg . TargetChain ;
7+ using Stratis . Features . PoA . Collateral . CounterChain ;
68
79namespace Stratis . Features . FederatedPeg . SourceChain
810{
@@ -28,69 +30,53 @@ public class RetrievalTypeConfirmations : IRetrievalTypeConfirmations
2830 private const int MediumConfirmations = 25 ; // 1125 seconds - 18m45s
2931 private const int HighConfirmations = 50 ; // 2250 seconds - 37m30s
3032 private const int CirrusLowConfirmations = 30 ; // 480 seconds - 8m0s
31- private const int CirrusMediumConfirmation = 70 ; // 1120 seconds - 18m40s
33+ private const int CirrusMediumConfirmations = 70 ; // 1120 seconds - 18m40s
3234 private const int CirrusHighConfirmations = 140 ; // 2240 seconds - 37m20s
3335
3436 private readonly NodeDeployments nodeDeployments ;
3537 private readonly Dictionary < DepositRetrievalType , int > legacyRetrievalTypeConfirmations ;
3638 private readonly Dictionary < DepositRetrievalType , int > retrievalTypeConfirmations ;
3739 private readonly Network network ;
40+ private readonly IMaturedBlocksSyncManager maturedBlocksSyncManager ;
41+ private readonly ICounterChainSettings counterChainSettings ;
42+ private readonly IFederatedPegSettings federatedPegSettings ;
3843
39- public RetrievalTypeConfirmations ( Network network , NodeDeployments nodeDeployments , IFederatedPegSettings federatedPegSettings )
44+ public RetrievalTypeConfirmations ( Network network , NodeDeployments nodeDeployments , IFederatedPegSettings federatedPegSettings , IMaturedBlocksSyncManager maturedBlocksSyncManager , ICounterChainSettings counterChainSettings )
4045 {
4146 this . nodeDeployments = nodeDeployments ;
4247 this . network = network ;
48+ this . maturedBlocksSyncManager = maturedBlocksSyncManager ;
49+ this . counterChainSettings = counterChainSettings ;
50+ this . federatedPegSettings = federatedPegSettings ;
4351 this . legacyRetrievalTypeConfirmations = new Dictionary < DepositRetrievalType , int >
4452 {
4553 [ DepositRetrievalType . Small ] = federatedPegSettings . MinimumConfirmationsSmallDeposits ,
4654 [ DepositRetrievalType . Normal ] = federatedPegSettings . MinimumConfirmationsNormalDeposits ,
4755 [ DepositRetrievalType . Large ] = federatedPegSettings . MinimumConfirmationsLargeDeposits
4856 } ;
4957
58+ this . retrievalTypeConfirmations = new Dictionary < DepositRetrievalType , int > ( )
59+ {
60+ [ DepositRetrievalType . Small ] = federatedPegSettings . IsMainChain ? LowConfirmations : CirrusLowConfirmations ,
61+ [ DepositRetrievalType . Normal ] = federatedPegSettings . IsMainChain ? MediumConfirmations : CirrusMediumConfirmations ,
62+ [ DepositRetrievalType . Large ] = federatedPegSettings . IsMainChain ? HighConfirmations : CirrusHighConfirmations
63+ } ;
64+
5065 if ( federatedPegSettings . IsMainChain )
5166 {
5267 this . legacyRetrievalTypeConfirmations [ DepositRetrievalType . Distribution ] = federatedPegSettings . MinimumConfirmationsDistributionDeposits ;
5368 this . legacyRetrievalTypeConfirmations [ DepositRetrievalType . ConversionSmall ] = federatedPegSettings . MinimumConfirmationsSmallDeposits ;
5469 this . legacyRetrievalTypeConfirmations [ DepositRetrievalType . ConversionNormal ] = federatedPegSettings . MinimumConfirmationsNormalDeposits ;
5570 this . legacyRetrievalTypeConfirmations [ DepositRetrievalType . ConversionLarge ] = federatedPegSettings . MinimumConfirmationsLargeDeposits ;
56- }
5771
58- if ( this . network . Name . StartsWith ( "Cirrus" ) )
59- {
60- this . retrievalTypeConfirmations = new Dictionary < DepositRetrievalType , int >
61- {
62- [ DepositRetrievalType . Small ] = CirrusLowConfirmations ,
63- [ DepositRetrievalType . Normal ] = CirrusMediumConfirmation ,
64- [ DepositRetrievalType . Large ] = CirrusHighConfirmations
65- } ;
66-
67- if ( federatedPegSettings . IsMainChain )
68- {
69- this . retrievalTypeConfirmations [ DepositRetrievalType . Distribution ] = CirrusHighConfirmations ;
70- this . retrievalTypeConfirmations [ DepositRetrievalType . ConversionSmall ] = CirrusLowConfirmations ;
71- this . retrievalTypeConfirmations [ DepositRetrievalType . ConversionNormal ] = CirrusMediumConfirmation ;
72- this . retrievalTypeConfirmations [ DepositRetrievalType . ConversionLarge ] = CirrusHighConfirmations ;
73- }
74- }
75- else
76- {
77- this . retrievalTypeConfirmations = new Dictionary < DepositRetrievalType , int > ( )
78- {
79- [ DepositRetrievalType . Small ] = LowConfirmations ,
80- [ DepositRetrievalType . Normal ] = MediumConfirmations ,
81- [ DepositRetrievalType . Large ] = HighConfirmations
82- } ;
83-
84- if ( federatedPegSettings . IsMainChain )
85- {
86- this . retrievalTypeConfirmations [ DepositRetrievalType . Distribution ] = HighConfirmations ;
87- this . retrievalTypeConfirmations [ DepositRetrievalType . ConversionSmall ] = LowConfirmations ;
88- this . retrievalTypeConfirmations [ DepositRetrievalType . ConversionNormal ] = MediumConfirmations ;
89- this . retrievalTypeConfirmations [ DepositRetrievalType . ConversionLarge ] = HighConfirmations ;
90- }
72+ this . retrievalTypeConfirmations [ DepositRetrievalType . Distribution ] = HighConfirmations ;
73+ this . retrievalTypeConfirmations [ DepositRetrievalType . ConversionSmall ] = LowConfirmations ;
74+ this . retrievalTypeConfirmations [ DepositRetrievalType . ConversionNormal ] = MediumConfirmations ;
75+ this . retrievalTypeConfirmations [ DepositRetrievalType . ConversionLarge ] = HighConfirmations ;
9176 }
9277 }
9378
79+ /// <inheritdoc/>
9480 public int MaximumConfirmationsAtMaturityHeight ( int maturityHeight )
9581 {
9682 if ( maturityHeight < this . Release1300ActivationHeight )
@@ -99,8 +85,7 @@ public int MaximumConfirmationsAtMaturityHeight(int maturityHeight)
9985 return this . retrievalTypeConfirmations . Values . Max ( ) ;
10086 }
10187
102- private int Release1300ActivationHeight => ( this . nodeDeployments ? . BIP9 . ArraySize > 0 ) ? this . nodeDeployments . BIP9 . ActivationHeightProviders [ 0 /* Release 1300 */ ] . ActivationHeight : 0 ;
103-
88+ /// <inheritdoc/>
10489 public int GetDepositConfirmations ( int depositHeight , DepositRetrievalType retrievalType )
10590 {
10691 // Keep everything maturity-height-centric. Otherwise the way we use MaximumConfirmationsAtMaturityHeight will have to change as well.
@@ -110,14 +95,31 @@ public int GetDepositConfirmations(int depositHeight, DepositRetrievalType retri
11095 return this . retrievalTypeConfirmations [ retrievalType ] ;
11196 }
11297
98+ /// <inheritdoc/>
11399 public int GetDepositMaturityHeight ( int depositHeight , DepositRetrievalType retrievalType )
114100 {
115101 return depositHeight + GetDepositConfirmations ( depositHeight , retrievalType ) ;
116102 }
117103
104+ /// <inheritdoc/>
118105 public DepositRetrievalType [ ] GetRetrievalTypes ( )
119106 {
120107 return this . retrievalTypeConfirmations . Keys . ToArray ( ) ;
121108 }
109+
110+ private int Release1300ActivationHeight
111+ {
112+ get
113+ {
114+ if ( ! this . federatedPegSettings . IsMainChain )
115+ return ( this . nodeDeployments ? . BIP9 . ArraySize > 0 ) ? this . nodeDeployments . BIP9 . ActivationHeightProviders [ 0 /* Release 1300 */ ] . ActivationHeight : 0 ;
116+
117+ // This code is running on the main chain.
118+ if ( this . counterChainSettings . CounterChainNetwork . Consensus . BIP9Deployments . Length == 0 )
119+ return 0 ;
120+
121+ return this . maturedBlocksSyncManager . GetMainChainActivationHeight ( ) ;
122+ }
123+ }
122124 }
123125}
0 commit comments