/// <summary> /// Gets the deployment flags to set when the deployment activates. /// </summary> /// <param name="deployment">The deployment number.</param> /// <returns>The deployment flags.</returns> public override BIP9DeploymentFlags GetFlags(int deployment) { // The flags get combined in the caller, so it is ok to make a fresh object here. var flags = new BIP9DeploymentFlags(); switch (deployment) { case ColdStaking: flags.ScriptFlags = ScriptVerify.CheckColdStakeVerify; break; case CSV: // Start enforcing BIP68 (sequence locks), BIP112 (CHECKSEQUENCEVERIFY) and BIP113 (Median Time Past) using versionbits logic. flags.ScriptFlags = ScriptVerify.CheckSequenceVerify; flags.LockTimeFlags = Transaction.LockTimeFlags.VerifySequence | Transaction.LockTimeFlags.MedianTimePast; break; case Segwit: // Start enforcing WITNESS rules using versionbits logic. flags.ScriptFlags = ScriptVerify.Witness; break; } return(flags); }
public DeploymentFlags(ChainedHeader nextBlock, ThresholdState[] prevBlockStates, IConsensus chainparams, ConcurrentChain chain) { this.EnforceBIP30 = EnforceBIP30ForBlock(nextBlock); // Once BIP34 activated it was not possible to create new duplicate coinbases and thus other than starting // with the 2 existing duplicate coinbase pairs, not possible to create overwriting txs. But by the // time BIP34 activated, in each of the existing pairs the duplicate coinbase had overwritten the first // before the first had been spent. Since those coinbases are sufficiently buried its no longer possible to create further // duplicate transactions descending from the known pairs either. // If we're on the known chain at height greater than where BIP34 activated, we can save the db accesses needed for the BIP30 check. ChainedHeader bip34HeightChainedHeader = chain.GetBlock(chainparams.BuriedDeployments[BuriedDeployments.BIP34]); // Only continue to enforce if we're below BIP34 activation height or the block hash at that height doesn't correspond. this.EnforceBIP30 = this.EnforceBIP30 && ((bip34HeightChainedHeader == null) || !(bip34HeightChainedHeader.HashBlock == chainparams.BIP34Hash)); // BIP16 didn't become active until Apr 1 2012. DateTimeOffset nBIP16SwitchTime = Utils.UnixTimeToDateTime(1333238400); bool fStrictPayToScriptHash = (nextBlock.Header.BlockTime >= nBIP16SwitchTime); this.ScriptFlags = fStrictPayToScriptHash ? ScriptVerify.P2SH : ScriptVerify.None; // Start enforcing the DERSIG (BIP66) rule. if (nextBlock.Height >= chainparams.BuriedDeployments[BuriedDeployments.BIP66]) { this.ScriptFlags |= ScriptVerify.DerSig; } // Start enforcing CHECKLOCKTIMEVERIFY, (BIP65) for block.nVersion=4 // blocks, when 75% of the network has upgraded. if (nextBlock.Height >= chainparams.BuriedDeployments[BuriedDeployments.BIP65]) { this.ScriptFlags |= ScriptVerify.CheckLockTimeVerify; } // Set the relevant flags for active BIP9 deployments. for (int deployment = 0; deployment < prevBlockStates.Length; deployment++) { if (prevBlockStates[deployment] == ThresholdState.Active) { BIP9DeploymentFlags flags = chain.Network.Consensus.BIP9Deployments.GetFlags(deployment); this.ScriptFlags |= flags.ScriptFlags; this.LockTimeFlags |= flags.LockTimeFlags; } } // Enforce block.nVersion=2 rule that the coinbase starts with serialized block height if (nextBlock.Height >= chainparams.BuriedDeployments[BuriedDeployments.BIP34]) { this.EnforceBIP34 = true; } }
/// <summary> /// Gets the deployment flags to set when the deployment activates. /// </summary> /// <param name="deployment">The deployment number.</param> /// <returns>The deployment flags.</returns> public override BIP9DeploymentFlags GetFlags(int deployment) { var flags = new BIP9DeploymentFlags(); switch (deployment) { case ColdStaking: flags.ScriptFlags |= ScriptVerify.CheckColdStakeVerify; break; } return(flags); }
/// <summary> /// Gets the deployment flags to set when the deployment activates. /// </summary> /// <param name="deployment">The deployment number.</param> /// <returns>The deployment flags.</returns> public override BIP9DeploymentFlags GetFlags(int deployment) { BIP9DeploymentFlags flags = new BIP9DeploymentFlags(); switch (deployment) { case CSV: // Start enforcing BIP68 (sequence locks), BIP112 (CHECKSEQUENCEVERIFY) and BIP113 (Median Time Past) using versionbits logic. flags.ScriptFlags = ScriptVerify.CheckSequenceVerify; flags.LockTimeFlags = Transaction.LockTimeFlags.VerifySequence | Transaction.LockTimeFlags.MedianTimePast; break; case Segwit: // Start enforcing WITNESS rules using versionbits logic. flags.ScriptFlags = ScriptVerify.Witness; break; } return(flags); }
public DeploymentFlags(ChainedHeader nextBlock, ThresholdState[] prevBlockStates, IConsensus chainparams, ChainIndexer chainIndexer) { this.EnforceBIP30 = EnforceBIP30ForBlock(nextBlock, chainparams, chainIndexer); // BIP16 didn't become active until Apr 1 2012. DateTimeOffset nBIP16SwitchTime = Utils.UnixTimeToDateTime(1333238400); bool fStrictPayToScriptHash = (nextBlock.Header.BlockTime >= nBIP16SwitchTime); this.ScriptFlags = fStrictPayToScriptHash ? ScriptVerify.P2SH : ScriptVerify.None; // Start enforcing the DERSIG (BIP66) rule. if (nextBlock.Height >= chainparams.BuriedDeployments[BuriedDeployments.BIP66]) { this.ScriptFlags |= ScriptVerify.DerSig; } // Start enforcing CHECKLOCKTIMEVERIFY, (BIP65) for block.nVersion=4 // blocks, when 75% of the network has upgraded. if (nextBlock.Height >= chainparams.BuriedDeployments[BuriedDeployments.BIP65]) { this.ScriptFlags |= ScriptVerify.CheckLockTimeVerify; } // Set the relevant flags for active BIP9 deployments. for (int deployment = 0; deployment < prevBlockStates.Length; deployment++) { if (prevBlockStates[deployment] == ThresholdState.Active) { BIP9DeploymentFlags flags = chainIndexer.Network.Consensus.BIP9Deployments.GetFlags(deployment); this.ScriptFlags |= flags.ScriptFlags; this.LockTimeFlags |= flags.LockTimeFlags; } } // Enforce block.nVersion=2 rule that the coinbase starts with serialized block height if (nextBlock.Height >= chainparams.BuriedDeployments[BuriedDeployments.BIP34]) { this.EnforceBIP34 = true; } }