mirror of
https://github.com/btcsuite/btcd.git
synced 2025-01-18 21:32:30 +01:00
Implement BIP0066 changeover logic for v3 blocks.
This commit implements the changeover logic for version 3 blocks as described by BIP0066.
This commit is contained in:
parent
4c53599b67
commit
3ed8f363e7
@ -107,6 +107,16 @@ func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block, flags BehaviorFlags)
|
||||
}
|
||||
|
||||
if !fastAdd {
|
||||
// Reject version 2 blocks once a majority of the network has
|
||||
// upgraded. This is part of BIP0066.
|
||||
if blockHeader.Version < 3 && b.isMajorityVersion(3, prevNode,
|
||||
b.chainParams.BlockRejectNumRequired) {
|
||||
|
||||
str := "new blocks with version %d are no longer valid"
|
||||
str = fmt.Sprintf(str, blockHeader.Version)
|
||||
return ruleError(ErrBlockVersionTooOld, str)
|
||||
}
|
||||
|
||||
// Reject version 1 blocks once a majority of the network has
|
||||
// upgraded. This is part of BIP0034.
|
||||
if blockHeader.Version < 2 && b.isMajorityVersion(2, prevNode,
|
||||
|
@ -915,6 +915,16 @@ func (b *BlockChain) checkConnectBlock(node *blockNode, block *btcutil.Block) er
|
||||
runScripts = false
|
||||
}
|
||||
|
||||
// Get the previous block node. This function is used over simply
|
||||
// accessing node.parent directly as it will dynamically create previous
|
||||
// block nodes as needed. This helps allow only the pieces of the chain
|
||||
// that are needed to remain in memory.
|
||||
prevNode, err := b.getPrevNodeFromNode(node)
|
||||
if err != nil {
|
||||
log.Errorf("getPrevNodeFromNode: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Blocks created after the BIP0016 activation time need to have the
|
||||
// pay-to-script-hash checks enabled.
|
||||
var scriptFlags txscript.ScriptFlags
|
||||
@ -922,6 +932,16 @@ func (b *BlockChain) checkConnectBlock(node *blockNode, block *btcutil.Block) er
|
||||
scriptFlags |= txscript.ScriptBip16
|
||||
}
|
||||
|
||||
// Enforce DER signatures for block versions 3+ once the majority of the
|
||||
// network has upgraded to the enforcement threshold. This is part of
|
||||
// BIP0066.
|
||||
blockHeader := &block.MsgBlock().Header
|
||||
if blockHeader.Version >= 3 && b.isMajorityVersion(3, prevNode,
|
||||
b.chainParams.BlockEnforceNumRequired) {
|
||||
|
||||
scriptFlags |= txscript.ScriptVerifyDERSignatures
|
||||
}
|
||||
|
||||
// Now that the inexpensive checks are done and have passed, verify the
|
||||
// transactions are actually allowed to spend the coins by running the
|
||||
// expensive ECDSA signature check scripts. Doing this last helps
|
||||
|
@ -24,7 +24,7 @@ const (
|
||||
// will require changes to the generated block. Using the wire constant
|
||||
// for generated block version could allow creation of invalid blocks
|
||||
// for the updated version.
|
||||
generatedBlockVersion = 2
|
||||
generatedBlockVersion = 3
|
||||
|
||||
// minHighPriority is the minimum priority value that allows a
|
||||
// transaction to be considered high priority.
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
// BlockVersion is the current latest supported block version.
|
||||
const BlockVersion = 2
|
||||
const BlockVersion = 3
|
||||
|
||||
// Version 4 bytes + Timestamp 4 bytes + Bits 4 bytes + Nonce 4 bytes +
|
||||
// PrevBlock and MerkleRoot hashes.
|
||||
|
Loading…
Reference in New Issue
Block a user