types.NewCoinbaseInput(coinbaseInput[:]),
},
Outputs: []*types.TxOutput{
- types.NewIntraChainOutput(*consensus.BTMAssetID, consensus.InitialBlockSubsidy, contract),
+ types.NewIntraChainOutput(*consensus.BTMAssetID, consensus.BlockSubsidy(0), contract),
},
}
return types.NewTx(txData)
//config parameter for coinbase reward
CoinbasePendingBlockNumber = uint64(100)
- subsidyReductionInterval = uint64(840000)
- baseSubsidy = uint64(41250000000)
- InitialBlockSubsidy = uint64(140700041250000000)
//config parameter for vote
VotePendingBlockNumber = uint64(10000)
// BlockSubsidy calculate the coinbase rewards on given block height
func BlockSubsidy(height uint64) uint64 {
- if height == 0 {
- return InitialBlockSubsidy
+ for _, subsidy := range ActiveNetParams.ProducerSubsidys {
+ if height >= subsidy.BeginBlock && height <= subsidy.EndBlock {
+ return subsidy.Subsidy
+ }
}
- return baseSubsidy >> uint(height/subsidyReductionInterval)
+ return 0
}
// IsBech32SegwitPrefix returns whether the prefix is a known prefix for segwit
Hash bc.Hash
}
+// ProducerSubsidy is a subsidy to the producer of the generated block
+type ProducerSubsidy struct {
+ BeginBlock uint64
+ EndBlock uint64
+ Subsidy uint64
+}
+
// Params store the config for different network
type Params struct {
// Name defines a human-readable identifier for the network.
// DNSSeeds defines a list of DNS seeds for the network that are used
// as one method to discover peers.
- DNSSeeds []string
- Checkpoints []Checkpoint
+ DNSSeeds []string
+ Checkpoints []Checkpoint
+ ProducerSubsidys []ProducerSubsidy
}
// ActiveNetParams is ...
Name: "solo",
Bech32HRPSegwit: "sm",
Checkpoints: []Checkpoint{},
+ ProducerSubsidys: []ProducerSubsidy{
+ {BeginBlock: 0, EndBlock: 0, Subsidy: 24},
+ {BeginBlock: 1, EndBlock: 840000, Subsidy: 24},
+ {BeginBlock: 840001, EndBlock: 1680000, Subsidy: 12},
+ {BeginBlock: 1680001, EndBlock: 3360000, Subsidy: 6},
+ },
}
// VaporNetParams is the config for vapor-net
Name: "vapor",
Bech32HRPSegwit: "vp",
Checkpoints: []Checkpoint{},
+ ProducerSubsidys: []ProducerSubsidy{
+ {BeginBlock: 1, EndBlock: 63072000, Subsidy: 15000000},
+ },
}
import "testing"
func TestSubsidy(t *testing.T) {
+ ActiveNetParams = Params{
+ ProducerSubsidys: []ProducerSubsidy{
+ {BeginBlock: 0, EndBlock: 0, Subsidy: 24},
+ {BeginBlock: 1, EndBlock: 840000, Subsidy: 24},
+ {BeginBlock: 840001, EndBlock: 1680000, Subsidy: 12},
+ {BeginBlock: 1680001, EndBlock: 3360000, Subsidy: 6},
+ },
+ }
+ subsidyReductionInterval := uint64(840000)
cases := []struct {
subsidy uint64
height uint64
}{
{
- subsidy: baseSubsidy,
+ subsidy: 24,
height: 1,
},
{
- subsidy: baseSubsidy,
+ subsidy: 24,
height: subsidyReductionInterval - 1,
},
{
- subsidy: baseSubsidy / 2,
+ subsidy: 24,
height: subsidyReductionInterval,
},
{
- subsidy: baseSubsidy / 2,
+ subsidy: 12,
height: subsidyReductionInterval + 1,
},
{
- subsidy: baseSubsidy / 1024,
+ subsidy: 0,
height: subsidyReductionInterval * 10,
},
}
package proposal
-import "testing"
+import (
+ "testing"
+
+ "github.com/vapor/consensus"
+)
func TestCreateCoinbaseTx(t *testing.T) {
+ consensus.ActiveNetParams = consensus.Params{
+ ProducerSubsidys: []consensus.ProducerSubsidy{
+ {BeginBlock: 0, EndBlock: 0, Subsidy: 24},
+ {BeginBlock: 1, EndBlock: 840000, Subsidy: 24},
+ {BeginBlock: 840001, EndBlock: 1680000, Subsidy: 12},
+ {BeginBlock: 1680001, EndBlock: 3360000, Subsidy: 6},
+ },
+ }
reductionInterval := uint64(840000)
- baseSubsidy := uint64(41250000000)
cases := []struct {
height uint64
txFee uint64
{
height: reductionInterval - 1,
txFee: 100000000,
- subsidy: baseSubsidy + 100000000,
+ subsidy: 24 + 100000000,
},
{
height: reductionInterval,
txFee: 2000000000,
- subsidy: baseSubsidy/2 + 2000000000,
+ subsidy: 24 + 2000000000,
},
{
height: reductionInterval + 1,
txFee: 0,
- subsidy: baseSubsidy / 2,
+ subsidy: 12,
},
{
height: reductionInterval * 2,
txFee: 100000000,
- subsidy: baseSubsidy/4 + 100000000,
+ subsidy: 12 + 100000000,
},
}
- for _, c := range cases {
+ for index, c := range cases {
coinbaseTx, err := createCoinbaseTx(nil, c.txFee, c.height)
if err != nil {
t.Fatal(err)
outputAmount := coinbaseTx.Outputs[0].OutputCommitment().Amount
if outputAmount != c.subsidy {
- t.Fatalf("coinbase tx reward dismatch, expected: %d, have: %d", c.subsidy, outputAmount)
+ t.Fatalf("index:%d,coinbase tx reward dismatch, expected: %d, have: %d", index, c.subsidy, outputAmount)
}
}
}
Version: 1,
SerializedSize: 1,
Inputs: []*types.TxInput{types.NewCoinbaseInput(nil)},
- Outputs: []*types.TxOutput{types.NewIntraChainOutput(*consensus.BTMAssetID, 41250000000, cp)},
+ Outputs: []*types.TxOutput{types.NewIntraChainOutput(*consensus.BTMAssetID, consensus.BlockSubsidy(0), cp)},
}),
},
},
Version: 1,
SerializedSize: 1,
Inputs: []*types.TxInput{types.NewCoinbaseInput(nil)},
- Outputs: []*types.TxOutput{types.NewIntraChainOutput(*consensus.BTMAssetID, 41250000000, cp)},
+ Outputs: []*types.TxOutput{types.NewIntraChainOutput(*consensus.BTMAssetID, consensus.BlockSubsidy(0), cp)},
}),
},
},
Height: 1,
Timestamp: 1523352601000,
PreviousBlockId: &bc.Hash{V0: 0},
- TransactionsRoot: &bc.Hash{V0: 10011341401654852692, V1: 8144266100226420640, V2: 18332298251154128538, V3: 7663092454615786384},
+ TransactionsRoot: &bc.Hash{V0: 12212572290317752069, V1: 8979003395977198825, V2: 3978010681554327084, V3: 12322462500143540195},
TransactionStatusHash: &bc.Hash{V0: 8682965660674182538, V1: 8424137560837623409, V2: 6979974817894224946, V3: 4673809519342015041},
},
Transactions: []*bc.Tx{
Version: 1,
SerializedSize: 1,
Inputs: []*types.TxInput{types.NewCoinbaseInput(nil)},
- Outputs: []*types.TxOutput{types.NewIntraChainOutput(*consensus.BTMAssetID, 41449998224, cp)},
+ Outputs: []*types.TxOutput{types.NewIntraChainOutput(*consensus.BTMAssetID, 199998224, cp)},
}),
types.MapTx(&types.TxData{
Version: 1,