From 2b1ef70ee2deeb464fdd5206291cc08811da03a6 Mon Sep 17 00:00:00 2001 From: quantumagi Date: Wed, 16 Nov 2022 17:35:08 +1100 Subject: [PATCH 1/9] Clean-up activation heights --- .../PoATestsBase.cs | 2 +- .../PoAHeaderSignatureRule.cs | 2 +- .../FederationHistory.cs | 2 +- .../PoAConsensusOptions.cs | 116 ++++++++++-------- .../SlotsManager.cs | 2 +- .../Voting/PollsRepository.cs | 2 +- .../Voting/VotingManager.cs | 4 +- .../CheckCollateralCommitmentHeightRule.cs | 5 +- .../CollateralChecker.cs | 7 +- .../VotingRequestFullValidationRule.cs | 2 +- .../JoinFederationRequestMonitor.cs | 2 +- .../MaturedBlocksProviderTests.cs | 2 +- .../Distribution/RewardDistributionManager.cs | 2 +- .../SourceChain/RetrievalTypeConfirmations.cs | 2 +- .../TargetChain/MaturedBlocksSyncManager.cs | 3 +- src/Stratis.Sidechains.Networks/CirrusDev.cs | 4 +- src/Stratis.Sidechains.Networks/CirrusMain.cs | 24 ++-- .../CirrusRegTest.cs | 10 +- src/Stratis.Sidechains.Networks/CirrusTest.cs | 25 ++-- .../Deployments/CirrusBIP9Deployments.cs | 10 +- .../ContractPrimitiveSerializer.cs | 2 +- 21 files changed, 127 insertions(+), 103 deletions(-) diff --git a/src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs b/src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs index 6eae3eb7f5..6ff7f2a286 100644 --- a/src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs +++ b/src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs @@ -193,7 +193,7 @@ public TestPoANetwork(List pubKeysOverride = null) ) { PollExpiryBlocks = 10, - Release1100ActivationHeight = 10 + ActivationHeights = { [(int)PoAActivationHeights.Release1100] = 10 } }; this.Consensus.SetPrivatePropertyValue(nameof(this.Consensus.MaxReorgLength), (uint)5); diff --git a/src/Stratis.Bitcoin.Features.PoA/BasePoAFeatureConsensusRules/PoAHeaderSignatureRule.cs b/src/Stratis.Bitcoin.Features.PoA/BasePoAFeatureConsensusRules/PoAHeaderSignatureRule.cs index 0b631843fc..5a4c871a33 100644 --- a/src/Stratis.Bitcoin.Features.PoA/BasePoAFeatureConsensusRules/PoAHeaderSignatureRule.cs +++ b/src/Stratis.Bitcoin.Features.PoA/BasePoAFeatureConsensusRules/PoAHeaderSignatureRule.cs @@ -75,7 +75,7 @@ public override Task RunAsync(RuleContext context) PoAConsensusErrors.InvalidHeaderSignature.Throw(); } - if (chainedHeader.Height >= this.poAConsensusOptions.GetMiningTimestampV2ActivationStrictHeight) + if (chainedHeader.Height >= this.poAConsensusOptions.ActivationHeights[(int)PoAActivationHeights.GetMiningTimestampV2]) { uint expectedSlot = this.slotsManager.GetMiningTimestamp(chainedHeader.Previous, chainedHeader.Header.Time, pubKey); diff --git a/src/Stratis.Bitcoin.Features.PoA/FederationHistory.cs b/src/Stratis.Bitcoin.Features.PoA/FederationHistory.cs index bdd3a3d18a..469d6956e5 100644 --- a/src/Stratis.Bitcoin.Features.PoA/FederationHistory.cs +++ b/src/Stratis.Bitcoin.Features.PoA/FederationHistory.cs @@ -173,7 +173,7 @@ private IFederationMember[] GetFederationMembersForBlocks(ChainedHeader lastHead IFederationMember[] miners = new IFederationMember[headers.Length]; // Reading chainedHeader's "Header" does not play well with asynchronocity so we will load the block times here. - int votingManagerV2ActivationHeight = (this.network.Consensus.Options as PoAConsensusOptions).VotingManagerV2ActivationHeight; + int votingManagerV2ActivationHeight = (this.network.Consensus.Options as PoAConsensusOptions).ActivationHeights[(int)PoAActivationHeights.VotingManagerV2]; int startHeight = lastHeader.Height + 1 - count; diff --git a/src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs b/src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs index 2d93d0d1d6..1355cfd634 100644 --- a/src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs +++ b/src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs @@ -1,39 +1,16 @@ using System; using System.Collections.Generic; +using System.Linq; using NBitcoin; namespace Stratis.Bitcoin.Features.PoA { - public class PoAConsensusOptions : ConsensusOptions + public enum PoAActivationHeights { - /// Public keys and other federation members related information at the start of the chain. - /// - /// Do not use this list anywhere except for at the initialization of the chain. - /// Actual collection of the federation members can be changed with time. - /// Use as a source of - /// up to date federation keys. - /// - public List GenesisFederationMembers { get; protected set; } - /// - /// The number of elapsed seconds required between mined block. - /// - public uint TargetSpacingSeconds { get; protected set; } - - /// Adds capability of voting for adding\kicking federation members and other things. - public bool VotingEnabled { get; protected set; } - - /// Makes federation members kick idle members. - /// Requires voting to be enabled to be set true. - public bool AutoKickIdleMembers { get; set; } - - /// Time that federation member has to be idle to be kicked by others in case is enabled. - public uint FederationMemberMaxIdleTimeSeconds { get; protected set; } - - /// - /// This currently only applies to Cirrus Main Net. + /// This is the height on the main chain at which the dynamic fees paid to the multsig for interop conversion requests will activate. /// - public uint? FederationMemberActivationTime { get; set; } + InterFluxV2MainChain, /// /// The height at which a federation members will be resolved via the class. @@ -46,17 +23,46 @@ public class PoAConsensusOptions : ConsensusOptions /// method which resolves the pubkey from the signature directly. /// /// - public int VotingManagerV2ActivationHeight { get; set; } + VotingManagerV2, /// - /// This is the height on the main chain at which the dynamic fees paid to the multsig for interop conversion requests will activate. + /// Defines when V2 of the contract serializer will be used. + /// I.e if tip <= ContractSerializerV2ActivationHeight, V1 will be used. + /// + ContractSerializerV2, + + /// + /// Logic related to release 1.1.0.0 will activate at this height, this includes Poll Expiry and the Join Federation Voting Request consensus rule. + /// + Release1100, + + /// + /// The height at which inituitive mining slots become active. + /// Legacy mining slots are determined by mining_slot = block_height % number_of_federation_members. + /// Once the specified height is reached there should no longer be a shift in mining slots when new federation members are added/removed. + /// + GetMiningTimestampV2, + + /// + /// The height at which inituitive mining slots are enfored without any lenience. + /// Currently errors are sometimes suppressed if a federation change occurred. /// - public int InterFluxV2MainChainActivationHeight { get; set; } + GetMiningTimestampV2Strict, /// /// The height at which Release 1.3.0.0 became BIP activated. /// - public int Release1300ActivationHeight { get; set; } + Release1300, + + /// + /// The height at which Release 1.3.2.0 became BIP activated. + /// + Release1320, + + /// + /// The height at which Release 1.3.2.4 became BIP activated. + /// + Release1324, /// /// The height at which Release 1.4.0.0 became active. @@ -64,25 +70,39 @@ public class PoAConsensusOptions : ConsensusOptions /// This was primarily used for activating ScriptPubkey sorting for paying multisig recipients. /// /// - public int Release1400ActivationHeight { get; set; } + Release1400 + } - /// - /// The height at which inituitive mining slots become active. - /// Legacy mining slots are determined by mining_slot = block_height % number_of_federation_members. - /// Once the specified height is reached there should no longer be a shift in mining slots when new federation members are added/removed. - /// - public int GetMiningTimestampV2ActivationHeight { get; set; } + public class PoAConsensusOptions : ConsensusOptions + { + /// Public keys and other federation members related information at the start of the chain. + /// + /// Do not use this list anywhere except for at the initialization of the chain. + /// Actual collection of the federation members can be changed with time. + /// Use as a source of + /// up to date federation keys. + /// + public List GenesisFederationMembers { get; protected set; } /// - /// The height at which inituitive mining slots are enfored without any lenience. - /// Currently errors are sometimes suppressed if a federation change occurred. + /// The number of elapsed seconds required between mined block. /// - public int GetMiningTimestampV2ActivationStrictHeight { get; set; } + public uint TargetSpacingSeconds { get; protected set; } + + /// Adds capability of voting for adding\kicking federation members and other things. + public bool VotingEnabled { get; protected set; } + + /// Makes federation members kick idle members. + /// Requires voting to be enabled to be set true. + public bool AutoKickIdleMembers { get; set; } + + /// Time that federation member has to be idle to be kicked by others in case is enabled. + public uint FederationMemberMaxIdleTimeSeconds { get; protected set; } /// - /// Logic related to release 1.1.0.0 will activate at this height, this includes Poll Expiry and the Join Federation Voting Request consensus rule. + /// This currently only applies to Cirrus Main Net. /// - public int Release1100ActivationHeight { get; set; } + public uint? FederationMemberActivationTime { get; set; } /// /// Polls are expired once the tip reaches a block this far beyond the poll start block. @@ -90,11 +110,8 @@ public class PoAConsensusOptions : ConsensusOptions /// public int PollExpiryBlocks { get; set; } - /// - /// Defines when V2 of the contract serializer will be used. - /// I.e if tip <= ContractSerializerV2ActivationHeight, V1 will be used. - /// - public int ContractSerializerV2ActivationHeight { get; set; } + + public int[] ActivationHeights { get; set; } /// Initializes values for networks that use block size rules. /// See . @@ -125,7 +142,8 @@ public PoAConsensusOptions( this.VotingEnabled = votingEnabled; this.AutoKickIdleMembers = autoKickIdleMembers; this.FederationMemberMaxIdleTimeSeconds = federationMemberMaxIdleTimeSeconds; - this.InterFluxV2MainChainActivationHeight = 0; + this.ActivationHeights = new int[((int[])typeof(PoAActivationHeights).GetEnumValues()).Max() + 1]; + this.ActivationHeights[(int)PoAActivationHeights.InterFluxV2MainChain] = 0; if (this.AutoKickIdleMembers && !this.VotingEnabled) throw new ArgumentException("Voting should be enabled for automatic kicking to work."); diff --git a/src/Stratis.Bitcoin.Features.PoA/SlotsManager.cs b/src/Stratis.Bitcoin.Features.PoA/SlotsManager.cs index e74ab4b347..7b08e2752e 100644 --- a/src/Stratis.Bitcoin.Features.PoA/SlotsManager.cs +++ b/src/Stratis.Bitcoin.Features.PoA/SlotsManager.cs @@ -73,7 +73,7 @@ The fact that the federation can change at any time adds extra complexity to thi The miner that mined the last block may no longer exist when the next block is about to be mined. As such we may need to look a bit further back to find a "reference miner" that still occurs in the latest federation. */ - if (tip.Height < this.consensusOptions.GetMiningTimestampV2ActivationHeight) + if (tip.Height < this.consensusOptions.ActivationHeights[(int)PoAActivationHeights.GetMiningTimestampV2]) return GetMiningTimestampLegacy(tip, currentTime, currentMiner); List federationMembers = this.federationHistory.GetFederationForBlock(tip, 1); diff --git a/src/Stratis.Bitcoin.Features.PoA/Voting/PollsRepository.cs b/src/Stratis.Bitcoin.Features.PoA/Voting/PollsRepository.cs index 129896e406..7336fb6a4c 100644 --- a/src/Stratis.Bitcoin.Features.PoA/Voting/PollsRepository.cs +++ b/src/Stratis.Bitcoin.Features.PoA/Voting/PollsRepository.cs @@ -378,7 +378,7 @@ public List GetAllPolls(DBreeze.Transactions.Transaction transaction) private static int GetPollExpiryHeight(Poll poll, PoANetwork network) { - return Math.Max(poll.PollStartBlockData.Height + network.ConsensusOptions.PollExpiryBlocks, network.ConsensusOptions.Release1100ActivationHeight); + return Math.Max(poll.PollStartBlockData.Height + network.ConsensusOptions.PollExpiryBlocks, network.ConsensusOptions.ActivationHeights[(int)PoAActivationHeights.Release1100]); } public static int GetPollExpiryOrExecutionHeight(Poll poll, PoANetwork network) diff --git a/src/Stratis.Bitcoin.Features.PoA/Voting/VotingManager.cs b/src/Stratis.Bitcoin.Features.PoA/Voting/VotingManager.cs index d0e1b9105b..7fc5e7613a 100644 --- a/src/Stratis.Bitcoin.Features.PoA/Voting/VotingManager.cs +++ b/src/Stratis.Bitcoin.Features.PoA/Voting/VotingManager.cs @@ -606,7 +606,7 @@ private void ProcessBlock(DBreeze.Transactions.Transaction transaction, ChainedH // Hence, if the poll does not exist then this is not a valid vote. if (data.Key == VoteKey.AddFederationMember) { - if (chBlock.ChainedHeader.Height >= this.poaConsensusOptions.Release1300ActivationHeight) + if (chBlock.ChainedHeader.Height >= this.poaConsensusOptions.ActivationHeights[(int)PoAActivationHeights.Release1300]) continue; } @@ -990,7 +990,7 @@ private void AddComponentStats(StringBuilder log) foreach (Poll poll in pendingPolls.Where(p => !p.IsExecuted && (p.VotingData.Key == VoteKey.AddFederationMember || p.VotingData.Key == VoteKey.KickFederationMember))) { IFederationMember federationMember = ((PoAConsensusFactory)(this.network.Consensus.ConsensusFactory)).DeserializeFederationMember(poll.VotingData.Data); - string expiresIn = $", Expires In = {(Math.Max(this.poaConsensusOptions.Release1100ActivationHeight, poll.PollStartBlockData.Height + this.poaConsensusOptions.PollExpiryBlocks) - tipHeight)}"; + string expiresIn = $", Expires In = {(Math.Max(this.poaConsensusOptions.ActivationHeights[(int)PoAActivationHeights.Release1100], poll.PollStartBlockData.Height + this.poaConsensusOptions.PollExpiryBlocks) - tipHeight)}"; log.Append($"{poll.VotingData.Key.ToString().PadLeft(22)}, PubKey = { federationMember.PubKey.ToHex() }, In Favor = {poll.PubKeysHexVotedInFavor.Count}{expiresIn}"); bool exists = this.federationManager.GetFederationMembers().Any(m => m.PubKey == federationMember.PubKey); if (poll.VotingData.Key == VoteKey.AddFederationMember && exists) diff --git a/src/Stratis.Features.Collateral/CheckCollateralCommitmentHeightRule.cs b/src/Stratis.Features.Collateral/CheckCollateralCommitmentHeightRule.cs index 6a385bbbd9..28e95c6910 100644 --- a/src/Stratis.Features.Collateral/CheckCollateralCommitmentHeightRule.cs +++ b/src/Stratis.Features.Collateral/CheckCollateralCommitmentHeightRule.cs @@ -39,10 +39,7 @@ public override Task RunAsync(RuleContext context) } // Check that the commitment height is not less that of the prior block. - int release1324ActivationHeight = 0; - NodeDeployments nodeDeployments = this.Parent.NodeDeployments; - if (nodeDeployments.BIP9.ArraySize > 0 /* Not NoBIP9Deployments */) - release1324ActivationHeight = nodeDeployments.BIP9.ActivationHeightProviders[1 /* Release1324 */].ActivationHeight; + int release1324ActivationHeight = ((PoAConsensusOptions)this.Parent.Network.Consensus.Options).ActivationHeights[(int)PoAActivationHeights.Release1324]; if (context.ValidationContext.ChainedHeaderToValidate.Height >= release1324ActivationHeight) { diff --git a/src/Stratis.Features.Collateral/CollateralChecker.cs b/src/Stratis.Features.Collateral/CollateralChecker.cs index 11e36d56e7..0c065bbbc3 100644 --- a/src/Stratis.Features.Collateral/CollateralChecker.cs +++ b/src/Stratis.Features.Collateral/CollateralChecker.cs @@ -79,6 +79,8 @@ public class CollateralChecker : ICollateralChecker private readonly NodeDeployments nodeDeployments; + private readonly PoAConsensusOptions poAConsensusOptions; + private Task updateCollateralContinuouslyTask; private bool collateralUpdated; @@ -97,6 +99,7 @@ public CollateralChecker(IHttpClientFactory httpClientFactory, ICounterChainSett this.logger = LogManager.GetCurrentClassLogger(); this.blockStoreClient = new BlockStoreClient(httpClientFactory, $"http://{settings.CounterChainApiHost}", settings.CounterChainApiPort); this.nodeDeployments = nodeDeployments; + this.poAConsensusOptions = (PoAConsensusOptions)network.Consensus.Options; } public async Task InitializeAsync() @@ -271,9 +274,7 @@ public bool CheckCollateral(IFederationMember federationMember, int heightToChec return false; } - int release1320ActivationHeight = 0; - if (this.nodeDeployments?.BIP9.ArraySize > 0 /* Not NoBIP9Deployments */) - release1320ActivationHeight = this.nodeDeployments.BIP9.ActivationHeightProviders[0 /* Release1320 */].ActivationHeight; + int release1320ActivationHeight = this.poAConsensusOptions.ActivationHeights[(int)PoAActivationHeights.Release1320]; // Legacy behavior before activation. if (localChainHeight < release1320ActivationHeight) diff --git a/src/Stratis.Features.Collateral/ConsensusRules/VotingRequestFullValidationRule.cs b/src/Stratis.Features.Collateral/ConsensusRules/VotingRequestFullValidationRule.cs index 424734fad0..461d8ff642 100644 --- a/src/Stratis.Features.Collateral/ConsensusRules/VotingRequestFullValidationRule.cs +++ b/src/Stratis.Features.Collateral/ConsensusRules/VotingRequestFullValidationRule.cs @@ -75,7 +75,7 @@ public void CheckTransaction(Transaction transaction, int height) } // Prohibit re-use of collateral addresses. - if (height >= ((PoAConsensusOptions)(this.network.Consensus.Options)).Release1100ActivationHeight) + if (height >= ((PoAConsensusOptions)(this.network.Consensus.Options)).ActivationHeights[(int)PoAActivationHeights.Release1100]) { Script script = PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey(request.CollateralMainchainAddress); string collateralAddress = script.GetDestinationAddress(this.counterChainNetwork).ToString(); diff --git a/src/Stratis.Features.Collateral/JoinFederationRequestMonitor.cs b/src/Stratis.Features.Collateral/JoinFederationRequestMonitor.cs index 9842542602..869b92504a 100644 --- a/src/Stratis.Features.Collateral/JoinFederationRequestMonitor.cs +++ b/src/Stratis.Features.Collateral/JoinFederationRequestMonitor.cs @@ -113,7 +113,7 @@ public void OnBlockConnected(VotingManagerProcessBlock blockConnectedData) Data = federationMemberBytes }; - if (blockConnectedData.ConnectedBlock.ChainedHeader.Height >= ((PoAConsensusOptions)this.network.Consensus.Options).Release1300ActivationHeight) + if (blockConnectedData.ConnectedBlock.ChainedHeader.Height >= ((PoAConsensusOptions)this.network.Consensus.Options).ActivationHeights[(int)PoAActivationHeights.Release1300]) { // If we are executing this from the miner, there will be no transaction present. if (blockConnectedData.PollsRepositoryTransaction == null) diff --git a/src/Stratis.Features.FederatedPeg.Tests/MaturedBlocksProviderTests.cs b/src/Stratis.Features.FederatedPeg.Tests/MaturedBlocksProviderTests.cs index 8a7e47b598..1b5e21d825 100644 --- a/src/Stratis.Features.FederatedPeg.Tests/MaturedBlocksProviderTests.cs +++ b/src/Stratis.Features.FederatedPeg.Tests/MaturedBlocksProviderTests.cs @@ -56,7 +56,7 @@ public MaturedBlocksProviderTests() this.mainChainNetwork = new StraxRegTest(); // TODO: Upgrade these tests to conform with release 1.3.0.0 activation. - ((PoAConsensusOptions)this.network.Consensus.Options).Release1300ActivationHeight = int.MaxValue; + ((PoAConsensusOptions)this.network.Consensus.Options).ActivationHeights[(int)PoAActivationHeights.Release1300] = int.MaxValue; this.opReturnDataReader = Substitute.For(); this.opReturnDataReader.TryGetTargetAddress(null, out string address).Returns(callInfo => { callInfo[1] = null; return false; }); diff --git a/src/Stratis.Features.FederatedPeg/Distribution/RewardDistributionManager.cs b/src/Stratis.Features.FederatedPeg/Distribution/RewardDistributionManager.cs index 0758c37040..5835974f7c 100644 --- a/src/Stratis.Features.FederatedPeg/Distribution/RewardDistributionManager.cs +++ b/src/Stratis.Features.FederatedPeg/Distribution/RewardDistributionManager.cs @@ -144,7 +144,7 @@ public List DistributeToMultisigNodes(uint256 depositId, Money fee) } } - if (this.chainIndexer.Tip.Height >= (this.network.Consensus.Options as PoAConsensusOptions).Release1400ActivationHeight) + if (this.chainIndexer.Tip.Height >= (this.network.Consensus.Options as PoAConsensusOptions).ActivationHeights[(int)PoAActivationHeights.Release1400]) return multiSigRecipients.OrderBy(m => m.ScriptPubKey.ToHex()).ToList(); return multiSigRecipients; diff --git a/src/Stratis.Features.FederatedPeg/SourceChain/RetrievalTypeConfirmations.cs b/src/Stratis.Features.FederatedPeg/SourceChain/RetrievalTypeConfirmations.cs index 775d0e8a2f..e1f144f2e1 100644 --- a/src/Stratis.Features.FederatedPeg/SourceChain/RetrievalTypeConfirmations.cs +++ b/src/Stratis.Features.FederatedPeg/SourceChain/RetrievalTypeConfirmations.cs @@ -115,7 +115,7 @@ private int Release1300ActivationHeight if (this.federatedPegSettings.IsMainChain) return ((PosConsensusOptions)this.network.Consensus.Options).Release1300ActivationHeight; - return ((PoAConsensusOptions)this.network.Consensus.Options).Release1300ActivationHeight; + return ((PoAConsensusOptions)this.network.Consensus.Options).ActivationHeights[(int)PoAActivationHeights.Release1300]; } } } diff --git a/src/Stratis.Features.FederatedPeg/TargetChain/MaturedBlocksSyncManager.cs b/src/Stratis.Features.FederatedPeg/TargetChain/MaturedBlocksSyncManager.cs index 076ecbfd34..ab3d407ded 100644 --- a/src/Stratis.Features.FederatedPeg/TargetChain/MaturedBlocksSyncManager.cs +++ b/src/Stratis.Features.FederatedPeg/TargetChain/MaturedBlocksSyncManager.cs @@ -45,7 +45,6 @@ public interface IMaturedBlocksSyncManager : IDisposable /// public class MaturedBlocksSyncManager : IMaturedBlocksSyncManager { - private const string Release1320DeploymentNameLower = "release1320"; private readonly IAsyncProvider asyncProvider; private readonly ICrossChainTransferStore crossChainTransferStore; private readonly IFederationGatewayClient federationGatewayClient; @@ -239,7 +238,7 @@ private async Task ProcessMatureBlockDepositsAsync(SerializableResult /// Constructs the BIP9 deployments array. diff --git a/src/Stratis.SmartContracts.CLR/Serialization/ContractPrimitiveSerializer.cs b/src/Stratis.SmartContracts.CLR/Serialization/ContractPrimitiveSerializer.cs index b407e1fa8a..203178eec3 100644 --- a/src/Stratis.SmartContracts.CLR/Serialization/ContractPrimitiveSerializer.cs +++ b/src/Stratis.SmartContracts.CLR/Serialization/ContractPrimitiveSerializer.cs @@ -26,7 +26,7 @@ public ContractPrimitiveSerializer(Network network, ChainIndexer chainIndexer) public override object Deserialize(Type type, byte[] stream) { - if (this.network.Consensus.Options is PoAConsensusOptions poaConsensusOptions && this.chainIndexer.Tip.Height <= poaConsensusOptions.ContractSerializerV2ActivationHeight) + if (this.network.Consensus.Options is PoAConsensusOptions poaConsensusOptions && this.chainIndexer.Tip.Height <= poaConsensusOptions.ActivationHeights[(int)PoAActivationHeights.ContractSerializerV2]) return this.serializerV1.Deserialize(type, stream); return base.Deserialize(type, stream); From 495a42239636d65a0972ced36a9ccd97b90d85f0 Mon Sep 17 00:00:00 2001 From: quantumagi Date: Wed, 16 Nov 2022 17:47:08 +1100 Subject: [PATCH 2/9] Update CirrusTest --- src/Stratis.Sidechains.Networks/CirrusTest.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Stratis.Sidechains.Networks/CirrusTest.cs b/src/Stratis.Sidechains.Networks/CirrusTest.cs index 80c49261ae..4d812c3d28 100644 --- a/src/Stratis.Sidechains.Networks/CirrusTest.cs +++ b/src/Stratis.Sidechains.Networks/CirrusTest.cs @@ -141,6 +141,8 @@ public CirrusTest() activationHeights[(int)PoAActivationHeights.GetMiningTimestampV2] = 3_000_000; // 15 January 2022 activationHeights[(int)PoAActivationHeights.GetMiningTimestampV2Strict] = 3_121_500; // 17 January 2022 activationHeights[(int)PoAActivationHeights.Release1300] = 3_280_032; + activationHeights[(int)PoAActivationHeights.Release1320] = 3_588_480; + activationHeights[(int)PoAActivationHeights.Release1324] = 3_951_360; activationHeights[(int)PoAActivationHeights.Release1400] = 4_074_250; var buriedDeployments = new BuriedDeploymentsArray From 25fd80441e64d984b1ed9aadb72d889bcaa10ef4 Mon Sep 17 00:00:00 2001 From: quantumagi Date: Wed, 16 Nov 2022 17:54:49 +1100 Subject: [PATCH 3/9] Fix PoATestsBase --- src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs b/src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs index 6ff7f2a286..2621c10552 100644 --- a/src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs +++ b/src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs @@ -192,10 +192,12 @@ public TestPoANetwork(List pubKeysOverride = null) federationMemberMaxIdleTimeSeconds: baseOptions.FederationMemberMaxIdleTimeSeconds ) { - PollExpiryBlocks = 10, - ActivationHeights = { [(int)PoAActivationHeights.Release1100] = 10 } + PollExpiryBlocks = 10 }; + var activationHeights = ((PoAConsensusOptions)this.Consensus.Options).ActivationHeights; + activationHeights[(int)PoAActivationHeights.Release1100] = 10; + this.Consensus.SetPrivatePropertyValue(nameof(this.Consensus.MaxReorgLength), (uint)5); } } From eeae9e691af8e271d26387f246519f968cdfdaeb Mon Sep 17 00:00:00 2001 From: quantumagi Date: Wed, 16 Nov 2022 17:56:31 +1100 Subject: [PATCH 4/9] Fix PoAHeaderSignatureRule --- .../BasePoAFeatureConsensusRules/PoAHeaderSignatureRule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stratis.Bitcoin.Features.PoA/BasePoAFeatureConsensusRules/PoAHeaderSignatureRule.cs b/src/Stratis.Bitcoin.Features.PoA/BasePoAFeatureConsensusRules/PoAHeaderSignatureRule.cs index 5a4c871a33..3bd573a50b 100644 --- a/src/Stratis.Bitcoin.Features.PoA/BasePoAFeatureConsensusRules/PoAHeaderSignatureRule.cs +++ b/src/Stratis.Bitcoin.Features.PoA/BasePoAFeatureConsensusRules/PoAHeaderSignatureRule.cs @@ -75,7 +75,7 @@ public override Task RunAsync(RuleContext context) PoAConsensusErrors.InvalidHeaderSignature.Throw(); } - if (chainedHeader.Height >= this.poAConsensusOptions.ActivationHeights[(int)PoAActivationHeights.GetMiningTimestampV2]) + if (chainedHeader.Height >= this.poAConsensusOptions.ActivationHeights[(int)PoAActivationHeights.GetMiningTimestampV2Strict]) { uint expectedSlot = this.slotsManager.GetMiningTimestamp(chainedHeader.Previous, chainedHeader.Header.Time, pubKey); From 688f15a7776277fe8745ee53ee3a07f2dbb6f065 Mon Sep 17 00:00:00 2001 From: quantumagi Date: Fri, 18 Nov 2022 19:47:48 +1100 Subject: [PATCH 5/9] Revert ContractSerializerV2ActivationHeight --- src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs b/src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs index 1355cfd634..b2c7e43ace 100644 --- a/src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs +++ b/src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs @@ -110,6 +110,10 @@ public class PoAConsensusOptions : ConsensusOptions /// public int PollExpiryBlocks { get; set; } + /// + /// Leaving this for now for use by Stratis.SmartContracts.CLR. + /// + public int ContractSerializerV2ActivationHeight => this.ActivationHeights[(int)PoAActivationHeights.ContractSerializerV2]; public int[] ActivationHeights { get; set; } From 1a4e4c2781af96715314a0f0ad042c615301b4f2 Mon Sep 17 00:00:00 2001 From: quantumagi Date: Wed, 23 Nov 2022 16:11:29 +1100 Subject: [PATCH 6/9] Use existing BuriedDeployments --- src/NBitcoin/BuriedDeploymentsArray.cs | 16 ++++++--- .../PoAHeaderSignatureRule.cs | 6 ++-- .../FederationHistory.cs | 2 +- .../PoAConsensusOptions.cs | 11 +++--- .../PoANetwork.cs | 27 ++++++++++----- .../SlotsManager.cs | 5 ++- .../CheckCollateralCommitmentHeightRule.cs | 2 +- .../CollateralChecker.cs | 6 ++-- src/Stratis.Sidechains.Networks/CirrusDev.cs | 3 +- src/Stratis.Sidechains.Networks/CirrusMain.cs | 34 ++++++++----------- .../CirrusRegTest.cs | 18 ++++------ src/Stratis.Sidechains.Networks/CirrusTest.cs | 34 ++++++++----------- 12 files changed, 87 insertions(+), 77 deletions(-) diff --git a/src/NBitcoin/BuriedDeploymentsArray.cs b/src/NBitcoin/BuriedDeploymentsArray.cs index 5143e24703..45b4d7f818 100644 --- a/src/NBitcoin/BuriedDeploymentsArray.cs +++ b/src/NBitcoin/BuriedDeploymentsArray.cs @@ -4,17 +4,25 @@ namespace NBitcoin { public class BuriedDeploymentsArray { - private readonly int[] heights; + protected int[] heights; public BuriedDeploymentsArray() { - this.heights = new int[Enum.GetValues(typeof(BuriedDeployments)).Length]; + this.heights = new int[0]; + } + + protected int EnsureIndex(int index) + { + if (index >= this.heights.Length) + Array.Resize(ref this.heights, index + 1); + + return index; } public int this[BuriedDeployments index] { - get => this.heights[(int)index]; - set => this.heights[(int)index] = value; + get => this.heights[EnsureIndex((int)index)]; + set => this.heights[EnsureIndex((int)index)] = value; } } diff --git a/src/Stratis.Bitcoin.Features.PoA/BasePoAFeatureConsensusRules/PoAHeaderSignatureRule.cs b/src/Stratis.Bitcoin.Features.PoA/BasePoAFeatureConsensusRules/PoAHeaderSignatureRule.cs index 3bd573a50b..d912cca6a4 100644 --- a/src/Stratis.Bitcoin.Features.PoA/BasePoAFeatureConsensusRules/PoAHeaderSignatureRule.cs +++ b/src/Stratis.Bitcoin.Features.PoA/BasePoAFeatureConsensusRules/PoAHeaderSignatureRule.cs @@ -24,7 +24,7 @@ public class PoAHeaderSignatureRule : FullValidationConsensusRule private HashHeightPair lastCheckPoint; - private PoAConsensusOptions poAConsensusOptions; + private IConsensus consensus; /// public override void Initialize() @@ -37,7 +37,7 @@ public override void Initialize() this.slotsManager = engine.SlotsManager; this.federationHistory = engine.FederationHistory; this.validator = engine.PoaHeaderValidator; - this.poAConsensusOptions = engine.Network.Consensus.Options as PoAConsensusOptions; + this.consensus = engine.Network.Consensus; KeyValuePair lastCheckPoint = engine.Network.Checkpoints.LastOrDefault(); this.lastCheckPoint = (lastCheckPoint.Value != null) ? new HashHeightPair(lastCheckPoint.Value.Hash, lastCheckPoint.Key) : null; @@ -75,7 +75,7 @@ public override Task RunAsync(RuleContext context) PoAConsensusErrors.InvalidHeaderSignature.Throw(); } - if (chainedHeader.Height >= this.poAConsensusOptions.ActivationHeights[(int)PoAActivationHeights.GetMiningTimestampV2Strict]) + if (chainedHeader.Height >= this.consensus.CirrusBuriedDeployments(CirrusBuriedDeployments.GetMiningTimestampV2Strict)) { uint expectedSlot = this.slotsManager.GetMiningTimestamp(chainedHeader.Previous, chainedHeader.Header.Time, pubKey); diff --git a/src/Stratis.Bitcoin.Features.PoA/FederationHistory.cs b/src/Stratis.Bitcoin.Features.PoA/FederationHistory.cs index 469d6956e5..cfab1898fa 100644 --- a/src/Stratis.Bitcoin.Features.PoA/FederationHistory.cs +++ b/src/Stratis.Bitcoin.Features.PoA/FederationHistory.cs @@ -173,7 +173,7 @@ private IFederationMember[] GetFederationMembersForBlocks(ChainedHeader lastHead IFederationMember[] miners = new IFederationMember[headers.Length]; // Reading chainedHeader's "Header" does not play well with asynchronocity so we will load the block times here. - int votingManagerV2ActivationHeight = (this.network.Consensus.Options as PoAConsensusOptions).ActivationHeights[(int)PoAActivationHeights.VotingManagerV2]; + int votingManagerV2ActivationHeight = this.network.Consensus.CirrusBuriedDeployments(CirrusBuriedDeployments.VotingManagerV2); int startHeight = lastHeader.Height + 1 - count; diff --git a/src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs b/src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs index b2c7e43ace..ff808d592b 100644 --- a/src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs +++ b/src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs @@ -5,7 +5,7 @@ namespace Stratis.Bitcoin.Features.PoA { - public enum PoAActivationHeights + public enum CirrusBuriedDeployments { /// /// This is the height on the main chain at which the dynamic fees paid to the multsig for interop conversion requests will activate. @@ -113,9 +113,7 @@ public class PoAConsensusOptions : ConsensusOptions /// /// Leaving this for now for use by Stratis.SmartContracts.CLR. /// - public int ContractSerializerV2ActivationHeight => this.ActivationHeights[(int)PoAActivationHeights.ContractSerializerV2]; - - public int[] ActivationHeights { get; set; } + public int ContractSerializerV2ActivationHeight { get; set; } /// Initializes values for networks that use block size rules. /// See . @@ -128,6 +126,7 @@ public class PoAConsensusOptions : ConsensusOptions /// See . /// See . /// See . + /// See . public PoAConsensusOptions( uint maxBlockBaseSize, int maxStandardVersion, @@ -138,6 +137,7 @@ public PoAConsensusOptions( uint targetSpacingSeconds, bool votingEnabled, bool autoKickIdleMembers, + int contractSerializerV2ActivationHeight, uint federationMemberMaxIdleTimeSeconds = 60 * 60 * 24 * 7) : base(maxBlockBaseSize, maxStandardVersion, maxStandardTxWeight, maxBlockSigopsCost, maxStandardTxSigopsCost, witnessScaleFactor: 1) { @@ -146,8 +146,7 @@ public PoAConsensusOptions( this.VotingEnabled = votingEnabled; this.AutoKickIdleMembers = autoKickIdleMembers; this.FederationMemberMaxIdleTimeSeconds = federationMemberMaxIdleTimeSeconds; - this.ActivationHeights = new int[((int[])typeof(PoAActivationHeights).GetEnumValues()).Max() + 1]; - this.ActivationHeights[(int)PoAActivationHeights.InterFluxV2MainChain] = 0; + this.ContractSerializerV2ActivationHeight = contractSerializerV2ActivationHeight; if (this.AutoKickIdleMembers && !this.VotingEnabled) throw new ArgumentException("Voting should be enabled for automatic kicking to work."); diff --git a/src/Stratis.Bitcoin.Features.PoA/PoANetwork.cs b/src/Stratis.Bitcoin.Features.PoA/PoANetwork.cs index 0680392469..126a97a63a 100644 --- a/src/Stratis.Bitcoin.Features.PoA/PoANetwork.cs +++ b/src/Stratis.Bitcoin.Features.PoA/PoANetwork.cs @@ -11,6 +11,23 @@ namespace Stratis.Bitcoin.Features.PoA { + public class CirrusBuriedDeploymentsArray : BuriedDeploymentsArray + { + public int this[CirrusBuriedDeployments index] + { + get => this.heights[EnsureIndex((int)index)]; + set => this.heights[EnsureIndex((int)index)] = value; + } + } + + public static class ConsensusExt + { + public static int CirrusBuriedDeployments(this IConsensus consensus, CirrusBuriedDeployments index) + { + return ((CirrusBuriedDeploymentsArray)consensus.BuriedDeployments)[index]; + } + } + /// /// Example network for PoA consensus. /// @@ -106,19 +123,13 @@ public PoANetwork() genesisFederationMembers: genesisFederationMembers, targetSpacingSeconds: 16, votingEnabled: true, + contractSerializerV2ActivationHeight: 0, autoKickIdleMembers: true ) { PollExpiryBlocks = 450 }; - var buriedDeployments = new BuriedDeploymentsArray - { - [BuriedDeployments.BIP34] = 0, - [BuriedDeployments.BIP65] = 0, - [BuriedDeployments.BIP66] = 0 - }; - var bip9Deployments = new NoBIP9Deployments(); this.Consensus = new NBitcoin.Consensus( @@ -130,7 +141,7 @@ public PoANetwork() majorityEnforceBlockUpgrade: 750, majorityRejectBlockOutdated: 950, majorityWindow: 1000, - buriedDeployments: buriedDeployments, + buriedDeployments: new CirrusBuriedDeploymentsArray(), bip9Deployments: bip9Deployments, bip34Hash: new uint256("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8"), minerConfirmationWindow: 2016, // nPowTargetTimespan / nPowTargetSpacing diff --git a/src/Stratis.Bitcoin.Features.PoA/SlotsManager.cs b/src/Stratis.Bitcoin.Features.PoA/SlotsManager.cs index 7b08e2752e..e67676bcca 100644 --- a/src/Stratis.Bitcoin.Features.PoA/SlotsManager.cs +++ b/src/Stratis.Bitcoin.Features.PoA/SlotsManager.cs @@ -35,6 +35,8 @@ public interface ISlotsManager public class SlotsManager : ISlotsManager { + private readonly IConsensus consensus; + private readonly PoAConsensusOptions consensusOptions; private readonly IFederationManager federationManager; @@ -50,6 +52,7 @@ public SlotsManager(Network network, IFederationManager federationManager, IFede this.federationManager = Guard.NotNull(federationManager, nameof(federationManager)); this.federationHistory = federationHistory; this.chainIndexer = chainIndexer; + this.consensus = (network as PoANetwork).Consensus; this.consensusOptions = (network as PoANetwork).ConsensusOptions; } @@ -73,7 +76,7 @@ The fact that the federation can change at any time adds extra complexity to thi The miner that mined the last block may no longer exist when the next block is about to be mined. As such we may need to look a bit further back to find a "reference miner" that still occurs in the latest federation. */ - if (tip.Height < this.consensusOptions.ActivationHeights[(int)PoAActivationHeights.GetMiningTimestampV2]) + if (tip.Height < this.consensus.CirrusBuriedDeployments(CirrusBuriedDeployments.GetMiningTimestampV2)) return GetMiningTimestampLegacy(tip, currentTime, currentMiner); List federationMembers = this.federationHistory.GetFederationForBlock(tip, 1); diff --git a/src/Stratis.Features.Collateral/CheckCollateralCommitmentHeightRule.cs b/src/Stratis.Features.Collateral/CheckCollateralCommitmentHeightRule.cs index 28e95c6910..8334269df8 100644 --- a/src/Stratis.Features.Collateral/CheckCollateralCommitmentHeightRule.cs +++ b/src/Stratis.Features.Collateral/CheckCollateralCommitmentHeightRule.cs @@ -39,7 +39,7 @@ public override Task RunAsync(RuleContext context) } // Check that the commitment height is not less that of the prior block. - int release1324ActivationHeight = ((PoAConsensusOptions)this.Parent.Network.Consensus.Options).ActivationHeights[(int)PoAActivationHeights.Release1324]; + int release1324ActivationHeight = this.Parent.Network.Consensus.CirrusBuriedDeployments(CirrusBuriedDeployments.Release1324); if (context.ValidationContext.ChainedHeaderToValidate.Height >= release1324ActivationHeight) { diff --git a/src/Stratis.Features.Collateral/CollateralChecker.cs b/src/Stratis.Features.Collateral/CollateralChecker.cs index 0c065bbbc3..50c03245fb 100644 --- a/src/Stratis.Features.Collateral/CollateralChecker.cs +++ b/src/Stratis.Features.Collateral/CollateralChecker.cs @@ -79,7 +79,7 @@ public class CollateralChecker : ICollateralChecker private readonly NodeDeployments nodeDeployments; - private readonly PoAConsensusOptions poAConsensusOptions; + private readonly IConsensus consensus; private Task updateCollateralContinuouslyTask; @@ -99,7 +99,7 @@ public CollateralChecker(IHttpClientFactory httpClientFactory, ICounterChainSett this.logger = LogManager.GetCurrentClassLogger(); this.blockStoreClient = new BlockStoreClient(httpClientFactory, $"http://{settings.CounterChainApiHost}", settings.CounterChainApiPort); this.nodeDeployments = nodeDeployments; - this.poAConsensusOptions = (PoAConsensusOptions)network.Consensus.Options; + this.consensus = network.Consensus; } public async Task InitializeAsync() @@ -274,7 +274,7 @@ public bool CheckCollateral(IFederationMember federationMember, int heightToChec return false; } - int release1320ActivationHeight = this.poAConsensusOptions.ActivationHeights[(int)PoAActivationHeights.Release1320]; + int release1320ActivationHeight = this.consensus.CirrusBuriedDeployments(CirrusBuriedDeployments.Release1320); // Legacy behavior before activation. if (localChainHeight < release1320ActivationHeight) diff --git a/src/Stratis.Sidechains.Networks/CirrusDev.cs b/src/Stratis.Sidechains.Networks/CirrusDev.cs index 6d5de949fd..88938adaf6 100644 --- a/src/Stratis.Sidechains.Networks/CirrusDev.cs +++ b/src/Stratis.Sidechains.Networks/CirrusDev.cs @@ -91,7 +91,8 @@ public CirrusDev() genesisFederationMembers: genesisFederationMembers, targetSpacingSeconds: 16, votingEnabled: true, - autoKickIdleMembers: true + autoKickIdleMembers: true, + contractSerializerV2ActivationHeight: 0 ) { PollExpiryBlocks = 10 diff --git a/src/Stratis.Sidechains.Networks/CirrusMain.cs b/src/Stratis.Sidechains.Networks/CirrusMain.cs index e276436b61..c5e1355f62 100644 --- a/src/Stratis.Sidechains.Networks/CirrusMain.cs +++ b/src/Stratis.Sidechains.Networks/CirrusMain.cs @@ -162,6 +162,20 @@ public CirrusMain() new PubKey("03f5de5176e29e1e7d518ae76c1e020b1da18b57a3713ac81b16015026e232748e"), }; + var buriedDeployments = new CirrusBuriedDeploymentsArray + { + [CirrusBuriedDeployments.InterFluxV2MainChain] = 460_000, + [CirrusBuriedDeployments.VotingManagerV2] = 1_683_000, // Tuesday, 12 January 2021 9:00:00 AM (Estimated) + [CirrusBuriedDeployments.ContractSerializerV2] = 3_386_335, // Monday 13 December 16:00:00 (Estimated) + [CirrusBuriedDeployments.Release1100] = 3_426_950, // Monday, 20 December 2021 10:00:00 AM (Estimated) + [CirrusBuriedDeployments.GetMiningTimestampV2] = 3_709_000, // Monday 14 February 00:00:00 (Estimated) + [CirrusBuriedDeployments.GetMiningTimestampV2Strict] = 3_783_000, // Monday 28 February 07:00:00 (London Time) (Estimated) + [CirrusBuriedDeployments.Release1300] = 4_334_400, + [CirrusBuriedDeployments.Release1320] = 4_665_600, + [CirrusBuriedDeployments.Release1324] = 5_086_800, + [CirrusBuriedDeployments.Release1400] = 5_345_325 // 7 December 2022 (Estimated) + }; + var consensusOptions = new PoAConsensusOptions( maxBlockBaseSize: 1_000_000, maxStandardVersion: 2, @@ -172,6 +186,7 @@ public CirrusMain() targetSpacingSeconds: 16, votingEnabled: true, autoKickIdleMembers: true, + contractSerializerV2ActivationHeight: buriedDeployments[CirrusBuriedDeployments.ContractSerializerV2], federationMemberMaxIdleTimeSeconds: 60 * 60 * 24 * 2 // 2 days ) { @@ -181,25 +196,6 @@ public CirrusMain() PollExpiryBlocks = 50_000, // Roughly 9 days }; - var activationHeights = consensusOptions.ActivationHeights; - activationHeights[(int)PoAActivationHeights.InterFluxV2MainChain] = 460_000; - activationHeights[(int)PoAActivationHeights.VotingManagerV2] = 1_683_000; // Tuesday, 12 January 2021 9:00:00 AM (Estimated) - activationHeights[(int)PoAActivationHeights.ContractSerializerV2] = 3_386_335; // Monday 13 December 16:00:00 (Estimated) - activationHeights[(int)PoAActivationHeights.Release1100] = 3_426_950; // Monday, 20 December 2021 10:00:00 AM (Estimated) - activationHeights[(int)PoAActivationHeights.GetMiningTimestampV2] = 3_709_000; // Monday 14 February 00:00:00 (Estimated) - activationHeights[(int)PoAActivationHeights.GetMiningTimestampV2Strict] = 3_783_000; // Monday 28 February 07:00:00 (London Time) (Estimated) - activationHeights[(int)PoAActivationHeights.Release1300] = 4_334_400; - activationHeights[(int)PoAActivationHeights.Release1320] = 4_665_600; - activationHeights[(int)PoAActivationHeights.Release1324] = 5_086_800; - activationHeights[(int)PoAActivationHeights.Release1400] = 5_345_325; // 7 December 2022 (Estimated) - - var buriedDeployments = new BuriedDeploymentsArray - { - [BuriedDeployments.BIP34] = 0, - [BuriedDeployments.BIP65] = 0, - [BuriedDeployments.BIP66] = 0 - }; - var bip9Deployments = new CirrusBIP9Deployments() { // Deployment will go active once 75% of nodes are on 1.3.0.0 or later. diff --git a/src/Stratis.Sidechains.Networks/CirrusRegTest.cs b/src/Stratis.Sidechains.Networks/CirrusRegTest.cs index 0de4330c81..7d36526bef 100644 --- a/src/Stratis.Sidechains.Networks/CirrusRegTest.cs +++ b/src/Stratis.Sidechains.Networks/CirrusRegTest.cs @@ -100,6 +100,12 @@ public CirrusRegTest() // Use the new keys as the old keys should never be used by the new opcode. this.Federations.RegisterFederation(new Federation(newFederationPubKeys.ToArray())); + var buriedDeployments = new CirrusBuriedDeploymentsArray + { + [CirrusBuriedDeployments.GetMiningTimestampV2] = 100, + [CirrusBuriedDeployments.GetMiningTimestampV2Strict] = 100 + }; + var consensusOptions = new PoAConsensusOptions( maxBlockBaseSize: 1_000_000, maxStandardVersion: 2, @@ -109,22 +115,12 @@ public CirrusRegTest() genesisFederationMembers: genesisFederationMembers, targetSpacingSeconds: 16, votingEnabled: true, + contractSerializerV2ActivationHeight: buriedDeployments[CirrusBuriedDeployments.ContractSerializerV2], autoKickIdleMembers: true) { PollExpiryBlocks = 450 // 2 hours }; - var activationHeights = consensusOptions.ActivationHeights; - activationHeights[(int)PoAActivationHeights.GetMiningTimestampV2] = 100; - activationHeights[(int)PoAActivationHeights.GetMiningTimestampV2Strict] = 100; - - var buriedDeployments = new BuriedDeploymentsArray - { - [BuriedDeployments.BIP34] = 0, - [BuriedDeployments.BIP65] = 0, - [BuriedDeployments.BIP66] = 0 - }; - var bip9Deployments = new CirrusBIP9Deployments() { // Deployment will go active once 75% of nodes are on 1.3.0.0 or later. diff --git a/src/Stratis.Sidechains.Networks/CirrusTest.cs b/src/Stratis.Sidechains.Networks/CirrusTest.cs index 4d812c3d28..cc84cf4c30 100644 --- a/src/Stratis.Sidechains.Networks/CirrusTest.cs +++ b/src/Stratis.Sidechains.Networks/CirrusTest.cs @@ -115,6 +115,20 @@ public CirrusTest() new PubKey("03382ceb0a59b9b922aca6be9959ae51dabda159e79465393a308ee267ecebcaa5"),//Node8 }; + var buriedDeployments = new CirrusBuriedDeploymentsArray + { + [CirrusBuriedDeployments.InterFluxV2MainChain] = 500_000, + [CirrusBuriedDeployments.VotingManagerV2] = 1_999_500, + [CirrusBuriedDeployments.ContractSerializerV2] = 2_842_681, + [CirrusBuriedDeployments.Release1100] = 2_796_000, + [CirrusBuriedDeployments.GetMiningTimestampV2] = 3_000_000, // 15 January 2022 + [CirrusBuriedDeployments.GetMiningTimestampV2Strict] = 3_121_500, // 17 January 2022 + [CirrusBuriedDeployments.Release1300] = 3_280_032, + [CirrusBuriedDeployments.Release1320] = 3_588_480, + [CirrusBuriedDeployments.Release1324] = 3_951_360, + [CirrusBuriedDeployments.Release1400] = 4_074_250 + }; + var consensusOptions = new PoAConsensusOptions( maxBlockBaseSize: 1_000_000, maxStandardVersion: 2, @@ -125,6 +139,7 @@ public CirrusTest() targetSpacingSeconds: 16, votingEnabled: true, autoKickIdleMembers: true, + contractSerializerV2ActivationHeight: buriedDeployments[CirrusBuriedDeployments.ContractSerializerV2], federationMemberMaxIdleTimeSeconds: 60 * 30 // 30 minutes ) { @@ -133,25 +148,6 @@ public CirrusTest() PollExpiryBlocks = 450 }; - var activationHeights = consensusOptions.ActivationHeights; - activationHeights[(int)PoAActivationHeights.InterFluxV2MainChain] = 500_000; - activationHeights[(int)PoAActivationHeights.VotingManagerV2] = 1_999_500; - activationHeights[(int)PoAActivationHeights.ContractSerializerV2] = 2_842_681; - activationHeights[(int)PoAActivationHeights.Release1100] = 2_796_000; - activationHeights[(int)PoAActivationHeights.GetMiningTimestampV2] = 3_000_000; // 15 January 2022 - activationHeights[(int)PoAActivationHeights.GetMiningTimestampV2Strict] = 3_121_500; // 17 January 2022 - activationHeights[(int)PoAActivationHeights.Release1300] = 3_280_032; - activationHeights[(int)PoAActivationHeights.Release1320] = 3_588_480; - activationHeights[(int)PoAActivationHeights.Release1324] = 3_951_360; - activationHeights[(int)PoAActivationHeights.Release1400] = 4_074_250; - - var buriedDeployments = new BuriedDeploymentsArray - { - [BuriedDeployments.BIP34] = 0, - [BuriedDeployments.BIP65] = 0, - [BuriedDeployments.BIP66] = 0 - }; - var bip9Deployments = new CirrusBIP9Deployments() { // Deployment will go active once 75% of nodes are on 1.3.0.0 or later. From adea614887d940992da0eed131895cfe87764b59 Mon Sep 17 00:00:00 2001 From: quantumagi Date: Wed, 23 Nov 2022 16:19:50 +1100 Subject: [PATCH 7/9] Refactor --- .../PoAHeaderSignatureRule.cs | 2 +- .../FederationHistory.cs | 2 +- .../PoAConsensusOptions.cs | 2 +- .../PoANetwork.cs | 10 ++++---- .../SlotsManager.cs | 2 +- .../Voting/PollsRepository.cs | 2 +- .../Voting/VotingManager.cs | 4 ++-- .../CheckCollateralCommitmentHeightRule.cs | 2 +- .../CollateralChecker.cs | 2 +- .../VotingRequestFullValidationRule.cs | 2 +- .../JoinFederationRequestMonitor.cs | 2 +- src/Stratis.Sidechains.Networks/CirrusMain.cs | 24 +++++++++---------- .../CirrusRegTest.cs | 8 +++---- src/Stratis.Sidechains.Networks/CirrusTest.cs | 24 +++++++++---------- .../ContractPrimitiveSerializer.cs | 2 +- 15 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/Stratis.Bitcoin.Features.PoA/BasePoAFeatureConsensusRules/PoAHeaderSignatureRule.cs b/src/Stratis.Bitcoin.Features.PoA/BasePoAFeatureConsensusRules/PoAHeaderSignatureRule.cs index d912cca6a4..cce1951749 100644 --- a/src/Stratis.Bitcoin.Features.PoA/BasePoAFeatureConsensusRules/PoAHeaderSignatureRule.cs +++ b/src/Stratis.Bitcoin.Features.PoA/BasePoAFeatureConsensusRules/PoAHeaderSignatureRule.cs @@ -75,7 +75,7 @@ public override Task RunAsync(RuleContext context) PoAConsensusErrors.InvalidHeaderSignature.Throw(); } - if (chainedHeader.Height >= this.consensus.CirrusBuriedDeployments(CirrusBuriedDeployments.GetMiningTimestampV2Strict)) + if (chainedHeader.Height >= this.consensus.PoABuriedDeployments(PoABuriedDeployments.GetMiningTimestampV2Strict)) { uint expectedSlot = this.slotsManager.GetMiningTimestamp(chainedHeader.Previous, chainedHeader.Header.Time, pubKey); diff --git a/src/Stratis.Bitcoin.Features.PoA/FederationHistory.cs b/src/Stratis.Bitcoin.Features.PoA/FederationHistory.cs index cfab1898fa..33e71833af 100644 --- a/src/Stratis.Bitcoin.Features.PoA/FederationHistory.cs +++ b/src/Stratis.Bitcoin.Features.PoA/FederationHistory.cs @@ -173,7 +173,7 @@ private IFederationMember[] GetFederationMembersForBlocks(ChainedHeader lastHead IFederationMember[] miners = new IFederationMember[headers.Length]; // Reading chainedHeader's "Header" does not play well with asynchronocity so we will load the block times here. - int votingManagerV2ActivationHeight = this.network.Consensus.CirrusBuriedDeployments(CirrusBuriedDeployments.VotingManagerV2); + int votingManagerV2ActivationHeight = this.network.Consensus.PoABuriedDeployments(PoABuriedDeployments.VotingManagerV2); int startHeight = lastHeader.Height + 1 - count; diff --git a/src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs b/src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs index ff808d592b..ea25f42df5 100644 --- a/src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs +++ b/src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs @@ -5,7 +5,7 @@ namespace Stratis.Bitcoin.Features.PoA { - public enum CirrusBuriedDeployments + public enum PoABuriedDeployments { /// /// This is the height on the main chain at which the dynamic fees paid to the multsig for interop conversion requests will activate. diff --git a/src/Stratis.Bitcoin.Features.PoA/PoANetwork.cs b/src/Stratis.Bitcoin.Features.PoA/PoANetwork.cs index 126a97a63a..45cecf6ade 100644 --- a/src/Stratis.Bitcoin.Features.PoA/PoANetwork.cs +++ b/src/Stratis.Bitcoin.Features.PoA/PoANetwork.cs @@ -11,9 +11,9 @@ namespace Stratis.Bitcoin.Features.PoA { - public class CirrusBuriedDeploymentsArray : BuriedDeploymentsArray + public class PoABuriedDeploymentsArray : BuriedDeploymentsArray { - public int this[CirrusBuriedDeployments index] + public int this[PoABuriedDeployments index] { get => this.heights[EnsureIndex((int)index)]; set => this.heights[EnsureIndex((int)index)] = value; @@ -22,9 +22,9 @@ public int this[CirrusBuriedDeployments index] public static class ConsensusExt { - public static int CirrusBuriedDeployments(this IConsensus consensus, CirrusBuriedDeployments index) + public static int PoABuriedDeployments(this IConsensus consensus, PoABuriedDeployments index) { - return ((CirrusBuriedDeploymentsArray)consensus.BuriedDeployments)[index]; + return ((PoABuriedDeploymentsArray)consensus.BuriedDeployments)[index]; } } @@ -141,7 +141,7 @@ public PoANetwork() majorityEnforceBlockUpgrade: 750, majorityRejectBlockOutdated: 950, majorityWindow: 1000, - buriedDeployments: new CirrusBuriedDeploymentsArray(), + buriedDeployments: new PoABuriedDeploymentsArray(), bip9Deployments: bip9Deployments, bip34Hash: new uint256("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8"), minerConfirmationWindow: 2016, // nPowTargetTimespan / nPowTargetSpacing diff --git a/src/Stratis.Bitcoin.Features.PoA/SlotsManager.cs b/src/Stratis.Bitcoin.Features.PoA/SlotsManager.cs index e67676bcca..048560dae4 100644 --- a/src/Stratis.Bitcoin.Features.PoA/SlotsManager.cs +++ b/src/Stratis.Bitcoin.Features.PoA/SlotsManager.cs @@ -76,7 +76,7 @@ The fact that the federation can change at any time adds extra complexity to thi The miner that mined the last block may no longer exist when the next block is about to be mined. As such we may need to look a bit further back to find a "reference miner" that still occurs in the latest federation. */ - if (tip.Height < this.consensus.CirrusBuriedDeployments(CirrusBuriedDeployments.GetMiningTimestampV2)) + if (tip.Height < this.consensus.PoABuriedDeployments(PoABuriedDeployments.GetMiningTimestampV2)) return GetMiningTimestampLegacy(tip, currentTime, currentMiner); List federationMembers = this.federationHistory.GetFederationForBlock(tip, 1); diff --git a/src/Stratis.Bitcoin.Features.PoA/Voting/PollsRepository.cs b/src/Stratis.Bitcoin.Features.PoA/Voting/PollsRepository.cs index 7336fb6a4c..f756cd7131 100644 --- a/src/Stratis.Bitcoin.Features.PoA/Voting/PollsRepository.cs +++ b/src/Stratis.Bitcoin.Features.PoA/Voting/PollsRepository.cs @@ -378,7 +378,7 @@ public List GetAllPolls(DBreeze.Transactions.Transaction transaction) private static int GetPollExpiryHeight(Poll poll, PoANetwork network) { - return Math.Max(poll.PollStartBlockData.Height + network.ConsensusOptions.PollExpiryBlocks, network.ConsensusOptions.ActivationHeights[(int)PoAActivationHeights.Release1100]); + return Math.Max(poll.PollStartBlockData.Height + network.ConsensusOptions.PollExpiryBlocks, network.Consensus.PoABuriedDeployments(PoABuriedDeployments.Release1100)); } public static int GetPollExpiryOrExecutionHeight(Poll poll, PoANetwork network) diff --git a/src/Stratis.Bitcoin.Features.PoA/Voting/VotingManager.cs b/src/Stratis.Bitcoin.Features.PoA/Voting/VotingManager.cs index 7fc5e7613a..2ea68f1f6d 100644 --- a/src/Stratis.Bitcoin.Features.PoA/Voting/VotingManager.cs +++ b/src/Stratis.Bitcoin.Features.PoA/Voting/VotingManager.cs @@ -606,7 +606,7 @@ private void ProcessBlock(DBreeze.Transactions.Transaction transaction, ChainedH // Hence, if the poll does not exist then this is not a valid vote. if (data.Key == VoteKey.AddFederationMember) { - if (chBlock.ChainedHeader.Height >= this.poaConsensusOptions.ActivationHeights[(int)PoAActivationHeights.Release1300]) + if (chBlock.ChainedHeader.Height >= this.network.Consensus.PoABuriedDeployments(PoABuriedDeployments.Release1300)) continue; } @@ -990,7 +990,7 @@ private void AddComponentStats(StringBuilder log) foreach (Poll poll in pendingPolls.Where(p => !p.IsExecuted && (p.VotingData.Key == VoteKey.AddFederationMember || p.VotingData.Key == VoteKey.KickFederationMember))) { IFederationMember federationMember = ((PoAConsensusFactory)(this.network.Consensus.ConsensusFactory)).DeserializeFederationMember(poll.VotingData.Data); - string expiresIn = $", Expires In = {(Math.Max(this.poaConsensusOptions.ActivationHeights[(int)PoAActivationHeights.Release1100], poll.PollStartBlockData.Height + this.poaConsensusOptions.PollExpiryBlocks) - tipHeight)}"; + string expiresIn = $", Expires In = {(Math.Max(this.network.Consensus.PoABuriedDeployments(PoABuriedDeployments.Release1100), poll.PollStartBlockData.Height + this.poaConsensusOptions.PollExpiryBlocks) - tipHeight)}"; log.Append($"{poll.VotingData.Key.ToString().PadLeft(22)}, PubKey = { federationMember.PubKey.ToHex() }, In Favor = {poll.PubKeysHexVotedInFavor.Count}{expiresIn}"); bool exists = this.federationManager.GetFederationMembers().Any(m => m.PubKey == federationMember.PubKey); if (poll.VotingData.Key == VoteKey.AddFederationMember && exists) diff --git a/src/Stratis.Features.Collateral/CheckCollateralCommitmentHeightRule.cs b/src/Stratis.Features.Collateral/CheckCollateralCommitmentHeightRule.cs index 8334269df8..16a575866e 100644 --- a/src/Stratis.Features.Collateral/CheckCollateralCommitmentHeightRule.cs +++ b/src/Stratis.Features.Collateral/CheckCollateralCommitmentHeightRule.cs @@ -39,7 +39,7 @@ public override Task RunAsync(RuleContext context) } // Check that the commitment height is not less that of the prior block. - int release1324ActivationHeight = this.Parent.Network.Consensus.CirrusBuriedDeployments(CirrusBuriedDeployments.Release1324); + int release1324ActivationHeight = this.Parent.Network.Consensus.PoABuriedDeployments(PoABuriedDeployments.Release1324); if (context.ValidationContext.ChainedHeaderToValidate.Height >= release1324ActivationHeight) { diff --git a/src/Stratis.Features.Collateral/CollateralChecker.cs b/src/Stratis.Features.Collateral/CollateralChecker.cs index 50c03245fb..efc1eeab92 100644 --- a/src/Stratis.Features.Collateral/CollateralChecker.cs +++ b/src/Stratis.Features.Collateral/CollateralChecker.cs @@ -274,7 +274,7 @@ public bool CheckCollateral(IFederationMember federationMember, int heightToChec return false; } - int release1320ActivationHeight = this.consensus.CirrusBuriedDeployments(CirrusBuriedDeployments.Release1320); + int release1320ActivationHeight = this.consensus.PoABuriedDeployments(PoABuriedDeployments.Release1320); // Legacy behavior before activation. if (localChainHeight < release1320ActivationHeight) diff --git a/src/Stratis.Features.Collateral/ConsensusRules/VotingRequestFullValidationRule.cs b/src/Stratis.Features.Collateral/ConsensusRules/VotingRequestFullValidationRule.cs index 461d8ff642..b569917d81 100644 --- a/src/Stratis.Features.Collateral/ConsensusRules/VotingRequestFullValidationRule.cs +++ b/src/Stratis.Features.Collateral/ConsensusRules/VotingRequestFullValidationRule.cs @@ -75,7 +75,7 @@ public void CheckTransaction(Transaction transaction, int height) } // Prohibit re-use of collateral addresses. - if (height >= ((PoAConsensusOptions)(this.network.Consensus.Options)).ActivationHeights[(int)PoAActivationHeights.Release1100]) + if (height >= this.network.Consensus.PoABuriedDeployments(PoABuriedDeployments.Release1100)) { Script script = PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey(request.CollateralMainchainAddress); string collateralAddress = script.GetDestinationAddress(this.counterChainNetwork).ToString(); diff --git a/src/Stratis.Features.Collateral/JoinFederationRequestMonitor.cs b/src/Stratis.Features.Collateral/JoinFederationRequestMonitor.cs index 869b92504a..7b41b34447 100644 --- a/src/Stratis.Features.Collateral/JoinFederationRequestMonitor.cs +++ b/src/Stratis.Features.Collateral/JoinFederationRequestMonitor.cs @@ -113,7 +113,7 @@ public void OnBlockConnected(VotingManagerProcessBlock blockConnectedData) Data = federationMemberBytes }; - if (blockConnectedData.ConnectedBlock.ChainedHeader.Height >= ((PoAConsensusOptions)this.network.Consensus.Options).ActivationHeights[(int)PoAActivationHeights.Release1300]) + if (blockConnectedData.ConnectedBlock.ChainedHeader.Height >= this.network.Consensus.PoABuriedDeployments(PoABuriedDeployments.Release1300)) { // If we are executing this from the miner, there will be no transaction present. if (blockConnectedData.PollsRepositoryTransaction == null) diff --git a/src/Stratis.Sidechains.Networks/CirrusMain.cs b/src/Stratis.Sidechains.Networks/CirrusMain.cs index c5e1355f62..8c65f3e2e6 100644 --- a/src/Stratis.Sidechains.Networks/CirrusMain.cs +++ b/src/Stratis.Sidechains.Networks/CirrusMain.cs @@ -162,18 +162,18 @@ public CirrusMain() new PubKey("03f5de5176e29e1e7d518ae76c1e020b1da18b57a3713ac81b16015026e232748e"), }; - var buriedDeployments = new CirrusBuriedDeploymentsArray + var buriedDeployments = new PoABuriedDeploymentsArray { - [CirrusBuriedDeployments.InterFluxV2MainChain] = 460_000, - [CirrusBuriedDeployments.VotingManagerV2] = 1_683_000, // Tuesday, 12 January 2021 9:00:00 AM (Estimated) - [CirrusBuriedDeployments.ContractSerializerV2] = 3_386_335, // Monday 13 December 16:00:00 (Estimated) - [CirrusBuriedDeployments.Release1100] = 3_426_950, // Monday, 20 December 2021 10:00:00 AM (Estimated) - [CirrusBuriedDeployments.GetMiningTimestampV2] = 3_709_000, // Monday 14 February 00:00:00 (Estimated) - [CirrusBuriedDeployments.GetMiningTimestampV2Strict] = 3_783_000, // Monday 28 February 07:00:00 (London Time) (Estimated) - [CirrusBuriedDeployments.Release1300] = 4_334_400, - [CirrusBuriedDeployments.Release1320] = 4_665_600, - [CirrusBuriedDeployments.Release1324] = 5_086_800, - [CirrusBuriedDeployments.Release1400] = 5_345_325 // 7 December 2022 (Estimated) + [PoABuriedDeployments.InterFluxV2MainChain] = 460_000, + [PoABuriedDeployments.VotingManagerV2] = 1_683_000, // Tuesday, 12 January 2021 9:00:00 AM (Estimated) + [PoABuriedDeployments.ContractSerializerV2] = 3_386_335, // Monday 13 December 16:00:00 (Estimated) + [PoABuriedDeployments.Release1100] = 3_426_950, // Monday, 20 December 2021 10:00:00 AM (Estimated) + [PoABuriedDeployments.GetMiningTimestampV2] = 3_709_000, // Monday 14 February 00:00:00 (Estimated) + [PoABuriedDeployments.GetMiningTimestampV2Strict] = 3_783_000, // Monday 28 February 07:00:00 (London Time) (Estimated) + [PoABuriedDeployments.Release1300] = 4_334_400, + [PoABuriedDeployments.Release1320] = 4_665_600, + [PoABuriedDeployments.Release1324] = 5_086_800, + [PoABuriedDeployments.Release1400] = 5_345_325 // 7 December 2022 (Estimated) }; var consensusOptions = new PoAConsensusOptions( @@ -186,7 +186,7 @@ public CirrusMain() targetSpacingSeconds: 16, votingEnabled: true, autoKickIdleMembers: true, - contractSerializerV2ActivationHeight: buriedDeployments[CirrusBuriedDeployments.ContractSerializerV2], + contractSerializerV2ActivationHeight: buriedDeployments[PoABuriedDeployments.ContractSerializerV2], federationMemberMaxIdleTimeSeconds: 60 * 60 * 24 * 2 // 2 days ) { diff --git a/src/Stratis.Sidechains.Networks/CirrusRegTest.cs b/src/Stratis.Sidechains.Networks/CirrusRegTest.cs index 7d36526bef..efaaf24db6 100644 --- a/src/Stratis.Sidechains.Networks/CirrusRegTest.cs +++ b/src/Stratis.Sidechains.Networks/CirrusRegTest.cs @@ -100,10 +100,10 @@ public CirrusRegTest() // Use the new keys as the old keys should never be used by the new opcode. this.Federations.RegisterFederation(new Federation(newFederationPubKeys.ToArray())); - var buriedDeployments = new CirrusBuriedDeploymentsArray + var buriedDeployments = new PoABuriedDeploymentsArray { - [CirrusBuriedDeployments.GetMiningTimestampV2] = 100, - [CirrusBuriedDeployments.GetMiningTimestampV2Strict] = 100 + [PoABuriedDeployments.GetMiningTimestampV2] = 100, + [PoABuriedDeployments.GetMiningTimestampV2Strict] = 100 }; var consensusOptions = new PoAConsensusOptions( @@ -115,7 +115,7 @@ public CirrusRegTest() genesisFederationMembers: genesisFederationMembers, targetSpacingSeconds: 16, votingEnabled: true, - contractSerializerV2ActivationHeight: buriedDeployments[CirrusBuriedDeployments.ContractSerializerV2], + contractSerializerV2ActivationHeight: buriedDeployments[PoABuriedDeployments.ContractSerializerV2], autoKickIdleMembers: true) { PollExpiryBlocks = 450 // 2 hours diff --git a/src/Stratis.Sidechains.Networks/CirrusTest.cs b/src/Stratis.Sidechains.Networks/CirrusTest.cs index cc84cf4c30..426cbc52d4 100644 --- a/src/Stratis.Sidechains.Networks/CirrusTest.cs +++ b/src/Stratis.Sidechains.Networks/CirrusTest.cs @@ -115,18 +115,18 @@ public CirrusTest() new PubKey("03382ceb0a59b9b922aca6be9959ae51dabda159e79465393a308ee267ecebcaa5"),//Node8 }; - var buriedDeployments = new CirrusBuriedDeploymentsArray + var buriedDeployments = new PoABuriedDeploymentsArray { - [CirrusBuriedDeployments.InterFluxV2MainChain] = 500_000, - [CirrusBuriedDeployments.VotingManagerV2] = 1_999_500, - [CirrusBuriedDeployments.ContractSerializerV2] = 2_842_681, - [CirrusBuriedDeployments.Release1100] = 2_796_000, - [CirrusBuriedDeployments.GetMiningTimestampV2] = 3_000_000, // 15 January 2022 - [CirrusBuriedDeployments.GetMiningTimestampV2Strict] = 3_121_500, // 17 January 2022 - [CirrusBuriedDeployments.Release1300] = 3_280_032, - [CirrusBuriedDeployments.Release1320] = 3_588_480, - [CirrusBuriedDeployments.Release1324] = 3_951_360, - [CirrusBuriedDeployments.Release1400] = 4_074_250 + [PoABuriedDeployments.InterFluxV2MainChain] = 500_000, + [PoABuriedDeployments.VotingManagerV2] = 1_999_500, + [PoABuriedDeployments.ContractSerializerV2] = 2_842_681, + [PoABuriedDeployments.Release1100] = 2_796_000, + [PoABuriedDeployments.GetMiningTimestampV2] = 3_000_000, // 15 January 2022 + [PoABuriedDeployments.GetMiningTimestampV2Strict] = 3_121_500, // 17 January 2022 + [PoABuriedDeployments.Release1300] = 3_280_032, + [PoABuriedDeployments.Release1320] = 3_588_480, + [PoABuriedDeployments.Release1324] = 3_951_360, + [PoABuriedDeployments.Release1400] = 4_074_250 }; var consensusOptions = new PoAConsensusOptions( @@ -139,7 +139,7 @@ public CirrusTest() targetSpacingSeconds: 16, votingEnabled: true, autoKickIdleMembers: true, - contractSerializerV2ActivationHeight: buriedDeployments[CirrusBuriedDeployments.ContractSerializerV2], + contractSerializerV2ActivationHeight: buriedDeployments[PoABuriedDeployments.ContractSerializerV2], federationMemberMaxIdleTimeSeconds: 60 * 30 // 30 minutes ) { diff --git a/src/Stratis.SmartContracts.CLR/Serialization/ContractPrimitiveSerializer.cs b/src/Stratis.SmartContracts.CLR/Serialization/ContractPrimitiveSerializer.cs index 203178eec3..17391cff93 100644 --- a/src/Stratis.SmartContracts.CLR/Serialization/ContractPrimitiveSerializer.cs +++ b/src/Stratis.SmartContracts.CLR/Serialization/ContractPrimitiveSerializer.cs @@ -26,7 +26,7 @@ public ContractPrimitiveSerializer(Network network, ChainIndexer chainIndexer) public override object Deserialize(Type type, byte[] stream) { - if (this.network.Consensus.Options is PoAConsensusOptions poaConsensusOptions && this.chainIndexer.Tip.Height <= poaConsensusOptions.ActivationHeights[(int)PoAActivationHeights.ContractSerializerV2]) + if (this.network.Consensus.Options is PoAConsensusOptions poaConsensusOptions && this.chainIndexer.Tip.Height <= this.network.Consensus.PoABuriedDeployments(PoABuriedDeployments.ContractSerializerV2)) return this.serializerV1.Deserialize(type, stream); return base.Deserialize(type, stream); From 4cf7c23e5c28f83bb0d07b56a07a70670106cf82 Mon Sep 17 00:00:00 2001 From: quantumagi Date: Wed, 23 Nov 2022 16:28:27 +1100 Subject: [PATCH 8/9] Refactor --- src/NBitcoin/BuriedDeploymentsArray.cs | 8 +++----- src/Stratis.Bitcoin.Features.PoA/PoANetwork.cs | 4 ++-- src/Stratis.Sidechains.Networks/CirrusDev.cs | 9 +-------- .../SmartContractsPoARegTest.cs | 12 +++--------- 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/NBitcoin/BuriedDeploymentsArray.cs b/src/NBitcoin/BuriedDeploymentsArray.cs index 45b4d7f818..f9a8dd0c4f 100644 --- a/src/NBitcoin/BuriedDeploymentsArray.cs +++ b/src/NBitcoin/BuriedDeploymentsArray.cs @@ -11,18 +11,16 @@ public BuriedDeploymentsArray() this.heights = new int[0]; } - protected int EnsureIndex(int index) + protected void EnsureIndex(int index) { if (index >= this.heights.Length) Array.Resize(ref this.heights, index + 1); - - return index; } public int this[BuriedDeployments index] { - get => this.heights[EnsureIndex((int)index)]; - set => this.heights[EnsureIndex((int)index)] = value; + get { EnsureIndex((int)index); return this.heights[(int)index]; } + set { EnsureIndex((int)index); this.heights[(int)index] = value; } } } diff --git a/src/Stratis.Bitcoin.Features.PoA/PoANetwork.cs b/src/Stratis.Bitcoin.Features.PoA/PoANetwork.cs index 45cecf6ade..c97c899e92 100644 --- a/src/Stratis.Bitcoin.Features.PoA/PoANetwork.cs +++ b/src/Stratis.Bitcoin.Features.PoA/PoANetwork.cs @@ -15,8 +15,8 @@ public class PoABuriedDeploymentsArray : BuriedDeploymentsArray { public int this[PoABuriedDeployments index] { - get => this.heights[EnsureIndex((int)index)]; - set => this.heights[EnsureIndex((int)index)] = value; + get { EnsureIndex((int)index); return this.heights[(int)index]; } + set { EnsureIndex((int)index); this.heights[(int)index] = value; } } } diff --git a/src/Stratis.Sidechains.Networks/CirrusDev.cs b/src/Stratis.Sidechains.Networks/CirrusDev.cs index 88938adaf6..a74a2fafe7 100644 --- a/src/Stratis.Sidechains.Networks/CirrusDev.cs +++ b/src/Stratis.Sidechains.Networks/CirrusDev.cs @@ -98,13 +98,6 @@ public CirrusDev() PollExpiryBlocks = 10 }; - var buriedDeployments = new BuriedDeploymentsArray - { - [BuriedDeployments.BIP34] = 0, - [BuriedDeployments.BIP65] = 0, - [BuriedDeployments.BIP66] = 0 - }; - var bip9Deployments = new CirrusBIP9Deployments() { // Deployment will go active once 75% of nodes are on 1.3.0.0 or later. @@ -121,7 +114,7 @@ public CirrusDev() majorityEnforceBlockUpgrade: 750, majorityRejectBlockOutdated: 950, majorityWindow: 1000, - buriedDeployments: buriedDeployments, + buriedDeployments: new PoABuriedDeploymentsArray(), bip9Deployments: bip9Deployments, bip34Hash: new uint256("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8"), minerConfirmationWindow: 2016, // nPowTargetTimespan / nPowTargetSpacing diff --git a/src/Stratis.SmartContracts.Networks/SmartContractsPoARegTest.cs b/src/Stratis.SmartContracts.Networks/SmartContractsPoARegTest.cs index 5d32a93ac9..ed452578f1 100644 --- a/src/Stratis.SmartContracts.Networks/SmartContractsPoARegTest.cs +++ b/src/Stratis.SmartContracts.Networks/SmartContractsPoARegTest.cs @@ -65,19 +65,13 @@ public SmartContractsPoARegTest() genesisFederationMembers: genesisFederationMembers, targetSpacingSeconds: 60, votingEnabled: true, - autoKickIdleMembers: false + autoKickIdleMembers: false, + contractSerializerV2ActivationHeight: 0 ) { PollExpiryBlocks = 450 }; - var buriedDeployments = new BuriedDeploymentsArray - { - [BuriedDeployments.BIP34] = 0, - [BuriedDeployments.BIP65] = 0, - [BuriedDeployments.BIP66] = 0 - }; - var bip9Deployments = new NoBIP9Deployments(); this.Consensus = new Consensus( @@ -89,7 +83,7 @@ public SmartContractsPoARegTest() majorityEnforceBlockUpgrade: 750, majorityRejectBlockOutdated: 950, majorityWindow: 1000, - buriedDeployments: buriedDeployments, + buriedDeployments: new PoABuriedDeploymentsArray(), bip9Deployments: bip9Deployments, bip34Hash: new uint256("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8"), minerConfirmationWindow: 2016, // nPowTargetTimespan / nPowTargetSpacing From 812a8a9c41e874181ae15b8f601b6d6a5083db14 Mon Sep 17 00:00:00 2001 From: quantumagi Date: Wed, 23 Nov 2022 16:37:46 +1100 Subject: [PATCH 9/9] Update tests --- .../TestPoANetwork.cs | 1 + .../EnableVoteKickingTests.cs | 2 ++ src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs | 4 ++-- .../MaturedBlocksProviderTests.cs | 2 +- .../Distribution/RewardDistributionManager.cs | 2 +- .../SourceChain/RetrievalTypeConfirmations.cs | 2 +- .../TargetChain/MaturedBlocksSyncManager.cs | 2 +- 7 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Stratis.Bitcoin.Features.PoA.IntegrationTests.Common/TestPoANetwork.cs b/src/Stratis.Bitcoin.Features.PoA.IntegrationTests.Common/TestPoANetwork.cs index 104e020f0d..bc74a9ae23 100644 --- a/src/Stratis.Bitcoin.Features.PoA.IntegrationTests.Common/TestPoANetwork.cs +++ b/src/Stratis.Bitcoin.Features.PoA.IntegrationTests.Common/TestPoANetwork.cs @@ -48,6 +48,7 @@ public TestPoANetwork(string networkName = "") targetSpacingSeconds: 60, votingEnabled: baseOptions.VotingEnabled, autoKickIdleMembers: false, + contractSerializerV2ActivationHeight: 0, federationMemberMaxIdleTimeSeconds: baseOptions.FederationMemberMaxIdleTimeSeconds ) { diff --git a/src/Stratis.Bitcoin.Features.PoA.IntegrationTests/EnableVoteKickingTests.cs b/src/Stratis.Bitcoin.Features.PoA.IntegrationTests/EnableVoteKickingTests.cs index 97f8074144..7568f4e1fc 100644 --- a/src/Stratis.Bitcoin.Features.PoA.IntegrationTests/EnableVoteKickingTests.cs +++ b/src/Stratis.Bitcoin.Features.PoA.IntegrationTests/EnableVoteKickingTests.cs @@ -32,6 +32,7 @@ public async Task EnableAutoKickAsync() targetSpacingSeconds: 60, votingEnabled: true, autoKickIdleMembers: false, + contractSerializerV2ActivationHeight: 0, federationMemberMaxIdleTimeSeconds: oldOptions.FederationMemberMaxIdleTimeSeconds); CoreNode node1 = builder.CreatePoANode(votingNetwork1, votingNetwork1.FederationKey1).Start(); @@ -54,6 +55,7 @@ public async Task EnableAutoKickAsync() targetSpacingSeconds: 60, votingEnabled: true, autoKickIdleMembers: true, + contractSerializerV2ActivationHeight: 0, federationMemberMaxIdleTimeSeconds: idleTimeSeconds); // Restart node 1 to ensure that we have the new network consensus options which reflects diff --git a/src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs b/src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs index 2621c10552..88644c2e4b 100644 --- a/src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs +++ b/src/Stratis.Bitcoin.Features.PoA.Tests/PoATestsBase.cs @@ -189,14 +189,14 @@ public TestPoANetwork(List pubKeysOverride = null) targetSpacingSeconds: 60, votingEnabled: baseOptions.VotingEnabled, autoKickIdleMembers: baseOptions.AutoKickIdleMembers, + contractSerializerV2ActivationHeight: 0, federationMemberMaxIdleTimeSeconds: baseOptions.FederationMemberMaxIdleTimeSeconds ) { PollExpiryBlocks = 10 }; - var activationHeights = ((PoAConsensusOptions)this.Consensus.Options).ActivationHeights; - activationHeights[(int)PoAActivationHeights.Release1100] = 10; + ((PoABuriedDeploymentsArray)this.Consensus)[PoABuriedDeployments.Release1100] = 10; this.Consensus.SetPrivatePropertyValue(nameof(this.Consensus.MaxReorgLength), (uint)5); } diff --git a/src/Stratis.Features.FederatedPeg.Tests/MaturedBlocksProviderTests.cs b/src/Stratis.Features.FederatedPeg.Tests/MaturedBlocksProviderTests.cs index 1b5e21d825..719d5d9b66 100644 --- a/src/Stratis.Features.FederatedPeg.Tests/MaturedBlocksProviderTests.cs +++ b/src/Stratis.Features.FederatedPeg.Tests/MaturedBlocksProviderTests.cs @@ -56,7 +56,7 @@ public MaturedBlocksProviderTests() this.mainChainNetwork = new StraxRegTest(); // TODO: Upgrade these tests to conform with release 1.3.0.0 activation. - ((PoAConsensusOptions)this.network.Consensus.Options).ActivationHeights[(int)PoAActivationHeights.Release1300] = int.MaxValue; + ((PoABuriedDeploymentsArray)this.network.Consensus.BuriedDeployments)[PoABuriedDeployments.Release1300] = int.MaxValue; this.opReturnDataReader = Substitute.For(); this.opReturnDataReader.TryGetTargetAddress(null, out string address).Returns(callInfo => { callInfo[1] = null; return false; }); diff --git a/src/Stratis.Features.FederatedPeg/Distribution/RewardDistributionManager.cs b/src/Stratis.Features.FederatedPeg/Distribution/RewardDistributionManager.cs index 5835974f7c..d3d5bcbea5 100644 --- a/src/Stratis.Features.FederatedPeg/Distribution/RewardDistributionManager.cs +++ b/src/Stratis.Features.FederatedPeg/Distribution/RewardDistributionManager.cs @@ -144,7 +144,7 @@ public List DistributeToMultisigNodes(uint256 depositId, Money fee) } } - if (this.chainIndexer.Tip.Height >= (this.network.Consensus.Options as PoAConsensusOptions).ActivationHeights[(int)PoAActivationHeights.Release1400]) + if (this.chainIndexer.Tip.Height >= this.network.Consensus.PoABuriedDeployments(PoABuriedDeployments.Release1400)) return multiSigRecipients.OrderBy(m => m.ScriptPubKey.ToHex()).ToList(); return multiSigRecipients; diff --git a/src/Stratis.Features.FederatedPeg/SourceChain/RetrievalTypeConfirmations.cs b/src/Stratis.Features.FederatedPeg/SourceChain/RetrievalTypeConfirmations.cs index e1f144f2e1..840dc3ee06 100644 --- a/src/Stratis.Features.FederatedPeg/SourceChain/RetrievalTypeConfirmations.cs +++ b/src/Stratis.Features.FederatedPeg/SourceChain/RetrievalTypeConfirmations.cs @@ -115,7 +115,7 @@ private int Release1300ActivationHeight if (this.federatedPegSettings.IsMainChain) return ((PosConsensusOptions)this.network.Consensus.Options).Release1300ActivationHeight; - return ((PoAConsensusOptions)this.network.Consensus.Options).ActivationHeights[(int)PoAActivationHeights.Release1300]; + return this.network.Consensus.PoABuriedDeployments(PoABuriedDeployments.Release1300); } } } diff --git a/src/Stratis.Features.FederatedPeg/TargetChain/MaturedBlocksSyncManager.cs b/src/Stratis.Features.FederatedPeg/TargetChain/MaturedBlocksSyncManager.cs index ab3d407ded..ea3da2caf8 100644 --- a/src/Stratis.Features.FederatedPeg/TargetChain/MaturedBlocksSyncManager.cs +++ b/src/Stratis.Features.FederatedPeg/TargetChain/MaturedBlocksSyncManager.cs @@ -238,7 +238,7 @@ private async Task ProcessMatureBlockDepositsAsync(SerializableResult