OSDN Git Service

versoin1.1.9 (#594)
[bytom/vapor.git] / consensus / general.go
index 6b5a317..ec6c6cf 100644 (file)
@@ -2,8 +2,9 @@ package consensus
 
 import (
        "encoding/binary"
+       "fmt"
 
-       "github.com/vapor/protocol/bc"
+       "github.com/bytom/vapor/protocol/bc"
 )
 
 // basic constant
@@ -12,6 +13,11 @@ const (
 
        PayToWitnessPubKeyHashDataSize = 20
        PayToWitnessScriptHashDataSize = 32
+
+       CrossInForkHeight = 128957600
+
+       _ = iota
+       SoftFork001
 )
 
 // BTMAssetID is BTM's asset id, the soul asset of Bytom
@@ -71,6 +77,13 @@ type ProducerSubsidy struct {
        Subsidy    uint64
 }
 
+// MovRewardProgram is a reward address corresponding to the range of the specified block height when matching transactions
+type MovRewardProgram struct {
+       BeginBlock uint64
+       EndBlock   uint64
+       Program    string
+}
+
 // Params store the config for different network
 type Params struct {
        // Name defines a human-readable identifier for the network.
@@ -97,21 +110,14 @@ type Params struct {
 
        // ProducerSubsidys defines the producer subsidy by block height
        ProducerSubsidys []ProducerSubsidy
-}
 
-// VaporDPOSConfig return the dpos consensus config
-func VaporDPOSConfig() DPOSConfig {
-       dpos := DPOSConfig{
-               NumOfConsensusNode:      10,
-               BlockNumEachNode:        12,
-               MinConsensusNodeVoteNum: uint64(100000000000000),
-               MinVoteOutputAmount:     uint64(10000000000),
-               BlockTimeInterval:       500,
-       }
+       SoftForkPoint map[uint64]uint64
+
+       // Mov will only start when the block height is greater than this value
+       MovStartHeight uint64
 
-       dpos.RoundVoteBlockNums = uint64(uint64(dpos.NumOfConsensusNode) * dpos.BlockNumEachNode * 10)
-       dpos.MaxTimeOffsetMs = uint64(uint64(dpos.BlockTimeInterval) * dpos.BlockNumEachNode / 3)
-       return dpos
+       // Used to receive rewards for matching transactions
+       MovRewardPrograms []MovRewardProgram
 }
 
 // ActiveNetParams is the active NetParams
@@ -140,10 +146,28 @@ var MainNetParams = Params{
                CoinbasePendingBlockNumber: uint64(7200),
                CoinbaseArbitrarySizeLimit: 128,
        },
-       DPOSConfig:  VaporDPOSConfig(),
+       DPOSConfig: DPOSConfig{
+               NumOfConsensusNode:      10,
+               BlockNumEachNode:        12,
+               MinConsensusNodeVoteNum: uint64(100000000000000),
+               MinVoteOutputAmount:     uint64(100000000),
+               BlockTimeInterval:       500,
+               RoundVoteBlockNums:      1200,
+               MaxTimeOffsetMs:         2000,
+       },
        Checkpoints: []Checkpoint{},
        ProducerSubsidys: []ProducerSubsidy{
                {BeginBlock: 1, EndBlock: 63072000, Subsidy: 9512938},
+               {BeginBlock: 63072001, EndBlock: 126144000, Subsidy: 9512938},
+       },
+       SoftForkPoint:  map[uint64]uint64{SoftFork001: 10461600},
+       MovStartHeight: 42884800,
+       MovRewardPrograms: []MovRewardProgram{
+               {
+                       BeginBlock: 1,
+                       EndBlock:   126144000,
+                       Program:    "00141d00f85e220e35a23282cfc7f91fe7b34bf6dc18",
+               },
        },
 }
 
@@ -155,15 +179,23 @@ var TestNetParams = Params{
        DNSSeeds:        []string{"www.testnetseed.vapor.io"},
        BasicConfig: BasicConfig{
                MaxBlockGas:                uint64(10000000),
-               MaxGasAmount:               int64(200000),
+               MaxGasAmount:               int64(640000),
                DefaultGasCredit:           int64(160000),
                StorageGasRate:             int64(1),
                VMGasRate:                  int64(200),
-               VotePendingBlockNumber:     uint64(10000),
-               CoinbasePendingBlockNumber: uint64(1200),
+               VotePendingBlockNumber:     uint64(3456000),
+               CoinbasePendingBlockNumber: uint64(7200),
                CoinbaseArbitrarySizeLimit: 128,
        },
-       DPOSConfig:  VaporDPOSConfig(),
+       DPOSConfig: DPOSConfig{
+               NumOfConsensusNode:      10,
+               BlockNumEachNode:        12,
+               MinConsensusNodeVoteNum: uint64(100000000000000),
+               MinVoteOutputAmount:     uint64(100000000),
+               BlockTimeInterval:       500,
+               RoundVoteBlockNums:      1200,
+               MaxTimeOffsetMs:         2000,
+       },
        Checkpoints: []Checkpoint{},
        ProducerSubsidys: []ProducerSubsidy{
                {BeginBlock: 1, EndBlock: 63072000, Subsidy: 15000000},
@@ -185,7 +217,15 @@ var SoloNetParams = Params{
                CoinbasePendingBlockNumber: uint64(1200),
                CoinbaseArbitrarySizeLimit: 128,
        },
-       DPOSConfig:  VaporDPOSConfig(),
+       DPOSConfig: DPOSConfig{
+               NumOfConsensusNode:      10,
+               BlockNumEachNode:        12,
+               MinConsensusNodeVoteNum: uint64(100000000000000),
+               MinVoteOutputAmount:     uint64(100000000),
+               BlockTimeInterval:       500,
+               RoundVoteBlockNums:      1200,
+               MaxTimeOffsetMs:         2000,
+       },
        Checkpoints: []Checkpoint{},
        ProducerSubsidys: []ProducerSubsidy{
                {BeginBlock: 0, EndBlock: 0, Subsidy: 24},
@@ -207,12 +247,21 @@ func BlockSubsidy(height uint64) uint64 {
 
 // BytomMainNetParams is the config for bytom mainnet
 func BytomMainNetParams(vaporParam *Params) *Params {
-       bech32HRPSegwit := "sm"
+       bech32HRPSegwit := "sn"
        switch vaporParam.Name {
        case "main":
-               bech32HRPSegwit = "bm"
+               bech32HRPSegwit = "bn"
        case "test":
-               bech32HRPSegwit = "tm"
+               bech32HRPSegwit = "tn"
        }
        return &Params{Bech32HRPSegwit: bech32HRPSegwit}
 }
+
+// InitActiveNetParams load the config by chain ID
+func InitActiveNetParams(chainID string) error {
+       var exist bool
+       if ActiveNetParams, exist = NetParams[chainID]; !exist {
+               return fmt.Errorf("chain_id[%v] don't exist", chainID)
+       }
+       return nil
+}