OSDN Git Service

Edit consensus (#116)
[bytom/vapor.git] / consensus / general.go
index a545694..910bce4 100644 (file)
@@ -18,18 +18,22 @@ const (
 
        //config parameter for coinbase reward
        CoinbasePendingBlockNumber = uint64(100)
-       subsidyReductionInterval   = uint64(840000)
-       baseSubsidy                = uint64(41250000000)
-       InitialBlockSubsidy        = uint64(140700041250000000)
 
-       // config for pow mining
-       BlocksPerRetarget     = uint64(2016)
-       TargetSecondsPerBlock = uint64(150)
-       SeedPerRetarget       = uint64(256)
+       //config parameter for vote
+       VotePendingBlockNumber = uint64(10000)
 
-       // MaxTimeOffsetSeconds is the maximum number of seconds a block time is allowed to be ahead of the current time
-       MaxTimeOffsetSeconds = uint64(60 * 60)
-       MedianTimeBlocks     = 11
+       //DPOS parameter
+       NumOfConsensusNode = 7
+       BlockNumEachNode   = 3
+       RoundVoteBlockNums = NumOfConsensusNode * BlockNumEachNode * 100
+       MinVoteNum         = 5000000
+
+       // BlockTimeInterval indicate product one block per 500 milliseconds
+       BlockTimeInterval = 500
+
+       // MaxTimeOffsetMs is the maximum number of seconds a block time is allowed to be ahead of the current time
+       MaxTimeOffsetMs  = uint64(60 * 60 * 1000)
+       MedianTimeBlocks = 11
 
        PayToWitnessPubKeyHashDataSize = 20
        PayToWitnessScriptHashDataSize = 32
@@ -46,14 +50,6 @@ var BTMAssetID = &bc.AssetID{
        V3: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
 }
 
-// InitialSeed is SHA3-256 of Byte[0^32]
-var InitialSeed = &bc.Hash{
-       V0: uint64(11412844483649490393),
-       V1: uint64(4614157290180302959),
-       V2: uint64(1780246333311066183),
-       V3: uint64(9357197556716379726),
-}
-
 // BTMDefinitionMap is the ....
 var BTMDefinitionMap = map[string]interface{}{
        "name":        BTMAlias,
@@ -64,10 +60,12 @@ var BTMDefinitionMap = map[string]interface{}{
 
 // 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
@@ -86,6 +84,13 @@ type Checkpoint struct {
        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.
@@ -96,8 +101,9 @@ type Params struct {
 
        // 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 ...
@@ -108,6 +114,7 @@ var NetParams = map[string]Params{
        "mainnet": MainNetParams,
        "wisdom":  TestNetParams,
        "solonet": SoloNetParams,
+       "vapor":   VaporNetParams,
 }
 
 // MainNetParams is the config for production
@@ -160,4 +167,20 @@ var SoloNetParams = Params{
        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
+var VaporNetParams = Params{
+       Name:            "vapor",
+       Bech32HRPSegwit: "vp",
+       Checkpoints:     []Checkpoint{},
+       ProducerSubsidys: []ProducerSubsidy{
+               {BeginBlock: 1, EndBlock: 63072000, Subsidy: 15000000},
+       },
 }