From 3318a24a887b002f53f36b72f4197602e49b39d3 Mon Sep 17 00:00:00 2001 From: David Hill Date: Wed, 18 Feb 2015 15:09:54 -0500 Subject: [PATCH] Simplify chain configuration. --- blockchain/accept.go | 6 +-- blockchain/chain.go | 7 +++- chaincfg/params.go | 93 ++++++++++++++++++++------------------------ 3 files changed, 49 insertions(+), 57 deletions(-) diff --git a/blockchain/accept.go b/blockchain/accept.go index cb8403958..083d2fe12 100644 --- a/blockchain/accept.go +++ b/blockchain/accept.go @@ -111,8 +111,7 @@ func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block, flags BehaviorFlags) // upgraded. This is part of BIP0034. if blockHeader.Version < 2 { if b.isMajorityVersion(2, prevNode, - b.chainParams.BlockV1RejectNumRequired, - b.chainParams.BlockV1RejectNumToCheck) { + b.chainParams.BlockRejectNumRequired) { str := "new blocks with version %d are no " + "longer valid" @@ -128,8 +127,7 @@ func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block, flags BehaviorFlags) if blockHeader.Version >= serializedHeightVersion { if b.isMajorityVersion(serializedHeightVersion, prevNode, - b.chainParams.CoinbaseBlockHeightNumRequired, - b.chainParams.CoinbaseBlockHeightNumToCheck) { + b.chainParams.BlockEnforceNumRequired) { expectedHeight := int64(0) if prevNode != nil { diff --git a/blockchain/chain.go b/blockchain/chain.go index b467a8bc8..6d1111c42 100644 --- a/blockchain/chain.go +++ b/blockchain/chain.go @@ -610,10 +610,13 @@ func (b *BlockChain) pruneBlockNodes() error { // isMajorityVersion determines if a previous number of blocks in the chain // starting with startNode are at least the minimum passed version. -func (b *BlockChain) isMajorityVersion(minVer int32, startNode *blockNode, numRequired, numToCheck uint64) bool { +func (b *BlockChain) isMajorityVersion(minVer int32, startNode *blockNode, + numRequired uint64) bool { + numFound := uint64(0) iterNode := startNode - for i := uint64(0); i < numToCheck && iterNode != nil; i++ { + for i := uint64(0); i < b.chainParams.BlockUpgradeNumToCheck && + numFound < numRequired && iterNode != nil; i++ { // This node has a version that is at least the minimum version. if iterNode.version >= minVer { numFound++ diff --git a/chaincfg/params.go b/chaincfg/params.go index b0225615a..bde39c18b 100644 --- a/chaincfg/params.go +++ b/chaincfg/params.go @@ -67,15 +67,16 @@ type Params struct { // Checkpoints ordered from oldest to newest. Checkpoints []Checkpoint - // Reject version 1 blocks once a majority of the network has upgraded. - // This is part of BIP0034. - BlockV1RejectNumRequired uint64 - BlockV1RejectNumToCheck uint64 + // Enforce current block version once network has + // upgraded. This is part of BIP0034. + BlockEnforceNumRequired uint64 - // Ensure coinbase starts with serialized block heights for version 2 - // blocks or newer once a majority of the network has upgraded. - CoinbaseBlockHeightNumRequired uint64 - CoinbaseBlockHeightNumToCheck uint64 + // Reject previous block versions once network has + // upgraded. This is part of BIP0034. + BlockRejectNumRequired uint64 + + // The number of nodes to check. This is part of BIP0034. + BlockUpgradeNumToCheck uint64 // Mempool parameters RelayNonStdTxs bool @@ -127,18 +128,15 @@ var MainNetParams = Params{ {319400, newShaHashFromStr("000000000000000021c6052e9becade189495d1c539aa37c58917305fd15f13b")}, }, - // Reject version 1 blocks once a majority of the network has upgraded. - // 95% (950 / 1000) - // This is part of BIP0034. - BlockV1RejectNumRequired: 950, - BlockV1RejectNumToCheck: 1000, - - // Ensure coinbase starts with serialized block heights for version 2 - // blocks or newer once a majority of the network has upgraded. + // Enforce current block version once majority of the network has + // upgraded. // 75% (750 / 1000) - // This is part of BIP0034. - CoinbaseBlockHeightNumRequired: 750, - CoinbaseBlockHeightNumToCheck: 1000, + // Reject previous block versions once a majority of the network has + // upgraded. + // 95% (950 / 1000) + BlockEnforceNumRequired: 750, + BlockRejectNumRequired: 950, + BlockUpgradeNumToCheck: 1000, // Mempool parameters RelayNonStdTxs: false, @@ -176,18 +174,15 @@ var RegressionNetParams = Params{ // Checkpoints ordered from oldest to newest. Checkpoints: nil, - // Reject version 1 blocks once a majority of the network has upgraded. - // 75% (75 / 100) - // This is part of BIP0034. - BlockV1RejectNumRequired: 75, - BlockV1RejectNumToCheck: 100, - - // Ensure coinbase starts with serialized block heights for version 2 - // blocks or newer once a majority of the network has upgraded. - // 51% (51 / 100) - // This is part of BIP0034. - CoinbaseBlockHeightNumRequired: 51, - CoinbaseBlockHeightNumToCheck: 100, + // Enforce current block version once majority of the network has + // upgraded. + // 75% (750 / 1000) + // Reject previous block versions once a majority of the network has + // upgraded. + // 95% (950 / 1000) + BlockEnforceNumRequired: 750, + BlockRejectNumRequired: 950, + BlockUpgradeNumToCheck: 1000, // Mempool parameters RelayNonStdTxs: true, @@ -227,18 +222,15 @@ var TestNet3Params = Params{ {546, newShaHashFromStr("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70")}, }, - // Reject version 1 blocks once a majority of the network has upgraded. - // 75% (75 / 100) - // This is part of BIP0034. - BlockV1RejectNumRequired: 75, - BlockV1RejectNumToCheck: 100, - - // Ensure coinbase starts with serialized block heights for version 2 - // blocks or newer once a majority of the network has upgraded. + // Enforce current block version once majority of the network has + // upgraded. // 51% (51 / 100) - // This is part of BIP0034. - CoinbaseBlockHeightNumRequired: 51, - CoinbaseBlockHeightNumToCheck: 100, + // Reject previous block versions once a majority of the network has + // upgraded. + // 75% (75 / 100) + BlockEnforceNumRequired: 51, + BlockRejectNumRequired: 75, + BlockUpgradeNumToCheck: 100, // Mempool parameters RelayNonStdTxs: true, @@ -280,16 +272,15 @@ var SimNetParams = Params{ // Checkpoints ordered from oldest to newest. Checkpoints: nil, - // Reject version 1 blocks once a majority of the network has upgraded. - // 75% (75 / 100) - BlockV1RejectNumRequired: 75, - BlockV1RejectNumToCheck: 100, - - // Ensure coinbase starts with serialized block heights for version 2 - // blocks or newer once a majority of the network has upgraded. + // Enforce current block version once majority of the network has + // upgraded. // 51% (51 / 100) - CoinbaseBlockHeightNumRequired: 51, - CoinbaseBlockHeightNumToCheck: 100, + // Reject previous block versions once a majority of the network has + // upgraded. + // 75% (75 / 100) + BlockEnforceNumRequired: 51, + BlockRejectNumRequired: 75, + BlockUpgradeNumToCheck: 100, // Mempool parameters RelayNonStdTxs: true,