Make regtest subsidy halving interval 150.

This commit moves the subsidy halving interval to the chain params so it
can be configured per network.  With that change it sets the regression
test halving interval to 150 to match the regression test params of the
reference implementation.

This was pointed out by @flammit.
This commit is contained in:
Dave Collins 2014-02-23 14:25:15 -06:00
parent b25bf566b0
commit bfef4e4a31
2 changed files with 26 additions and 23 deletions

View file

@ -26,6 +26,11 @@ type Params struct {
// have represented in compact form. See CompactToBig for more details
// on compact form.
PowLimitBits uint32
// SubsidyHalvingInterval is the interval of blocks at which the
// baseSubsidy is continually halved. Mathematically this is:
// baseSubsidy / 2^(height/SubsidyHalvingInterval)
SubsidyHalvingInterval int64
}
// mainPowLimit is the highest proof of work value a bitcoin block can have for
@ -35,10 +40,11 @@ var mainPowLimit = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 224), bigOne)
// mainNetParams contains parameters specific to the main network
// (btcwire.MainNet).
var mainNetParams = Params{
GenesisBlock: &btcwire.GenesisBlock,
GenesisHash: &btcwire.GenesisHash,
PowLimit: mainPowLimit,
PowLimitBits: BigToCompact(mainPowLimit),
GenesisBlock: &btcwire.GenesisBlock,
GenesisHash: &btcwire.GenesisHash,
PowLimit: mainPowLimit,
PowLimitBits: BigToCompact(mainPowLimit),
SubsidyHalvingInterval: 210000,
}
// regressionPowLimit is the highest proof of work value a bitcoin block can
@ -48,10 +54,11 @@ var regressionPowLimit = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 255), bigOne)
// regressionParams contains parameters specific to the regression test network
// (btcwire.TestNet).
var regressionParams = Params{
GenesisBlock: &btcwire.TestNetGenesisBlock,
GenesisHash: &btcwire.TestNetGenesisHash,
PowLimit: regressionPowLimit,
PowLimitBits: BigToCompact(regressionPowLimit),
GenesisBlock: &btcwire.TestNetGenesisBlock,
GenesisHash: &btcwire.TestNetGenesisHash,
PowLimit: regressionPowLimit,
PowLimitBits: BigToCompact(regressionPowLimit),
SubsidyHalvingInterval: 150,
}
// testNetPowLimit is the highest proof of work value a bitcoin block can have
@ -61,10 +68,11 @@ var testNetPowLimit = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 224), bigOne)
// testNet3Params contains parameters specific to the test network (version 3)
// (btcwire.TestNet3).
var testNet3Params = Params{
GenesisBlock: &btcwire.TestNet3GenesisBlock,
GenesisHash: &btcwire.TestNet3GenesisHash,
PowLimit: testNetPowLimit,
PowLimitBits: BigToCompact(testNetPowLimit),
GenesisBlock: &btcwire.TestNet3GenesisBlock,
GenesisHash: &btcwire.TestNet3GenesisHash,
PowLimit: testNetPowLimit,
PowLimitBits: BigToCompact(testNetPowLimit),
SubsidyHalvingInterval: 210000,
}
// chainParams returns chain parameters specific to the bitcoin network

View file

@ -43,13 +43,8 @@ const (
serializedHeightVersion = 2
// baseSubsidy is the starting subsidy amount for mined blocks. This
// value is halved every subsidyHalvingInterval blocks.
// value is halved every SubsidyHalvingInterval blocks.
baseSubsidy = 50 * btcutil.SatoshiPerBitcoin
// subsidyHalvingInterval is the interval of blocks at which the
// baseSubsidy is continually halved. See calcBlockSubsidy for more
// details.
subsidyHalvingInterval = 210000
)
var (
@ -162,14 +157,14 @@ func isBIP0030Node(node *blockNode) bool {
// newly generated blocks awards as well as validating the coinbase for blocks
// has the expected value.
//
// The subsidy is halved every subsidyHalvingInterval blocks. Mathematically
// this is: baseSubsidy / 2^(height/subsidyHalvingInterval)
// The subsidy is halved every SubsidyHalvingInterval blocks. Mathematically
// this is: baseSubsidy / 2^(height/SubsidyHalvingInterval)
//
// At the target block generation rate this is approximately every 4
// years.
func calcBlockSubsidy(height int64) int64 {
func (b *BlockChain) calcBlockSubsidy(height int64) int64 {
// Equivalent to: baseSubsidy / 2^(height/subsidyHalvingInterval)
return baseSubsidy >> uint(height/subsidyHalvingInterval)
return baseSubsidy >> uint(height/b.chainParams().SubsidyHalvingInterval)
}
// CheckTransactionSanity performs some preliminary checks on a transaction to
@ -824,7 +819,7 @@ func (b *BlockChain) checkConnectBlock(node *blockNode, block *btcutil.Block) er
for _, txOut := range transactions[0].MsgTx().TxOut {
totalSatoshiOut += txOut.Value
}
expectedSatoshiOut := calcBlockSubsidy(node.height) + totalFees
expectedSatoshiOut := b.calcBlockSubsidy(node.height) + totalFees
if totalSatoshiOut > expectedSatoshiOut {
str := fmt.Sprintf("coinbase transaction for block pays %v "+
"which is more than expected value of %v",