OSDN Git Service

fix the bug (#399)
[bytom/vapor.git] / consensus / general.go
index 0a399c2..b34f19d 100644 (file)
@@ -2,6 +2,7 @@ package consensus
 
 import (
        "encoding/binary"
+       "fmt"
 
        "github.com/vapor/protocol/bc"
 )
@@ -12,6 +13,9 @@ const (
 
        PayToWitnessPubKeyHashDataSize = 20
        PayToWitnessScriptHashDataSize = 32
+
+       _ = iota
+       SoftFork001
 )
 
 // BTMAssetID is BTM's asset id, the soul asset of Bytom
@@ -97,21 +101,8 @@ 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(100000000),
-               BlockTimeInterval:       500,
-       }
 
-       dpos.RoundVoteBlockNums = uint64(uint64(dpos.NumOfConsensusNode) * dpos.BlockNumEachNode * 10)
-       dpos.MaxTimeOffsetMs = uint64(uint64(dpos.BlockTimeInterval) * dpos.BlockNumEachNode / 3)
-       return dpos
+       SoftForkPoint map[uint64]uint64
 }
 
 // ActiveNetParams is the active NetParams
@@ -132,7 +123,7 @@ var MainNetParams = Params{
        DNSSeeds:        []string{"www.mainnetseed.vapor.io"},
        BasicConfig: BasicConfig{
                MaxBlockGas:                uint64(10000000),
-               MaxGasAmount:               int64(200000),
+               MaxGasAmount:               int64(640000),
                DefaultGasCredit:           int64(160000),
                StorageGasRate:             int64(1),
                VMGasRate:                  int64(200),
@@ -140,11 +131,20 @@ 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: 15000000},
+               {BeginBlock: 1, EndBlock: 63072000, Subsidy: 9512938},
        },
+       SoftForkPoint: map[uint64]uint64{SoftFork001: 10461600},
 }
 
 // TestNetParams is the config for vapor-testnet
@@ -163,7 +163,15 @@ var TestNetParams = 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: 1, EndBlock: 63072000, Subsidy: 15000000},
@@ -185,7 +193,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},
@@ -216,3 +232,11 @@ func BytomMainNetParams(vaporParam *Params) *Params {
        }
        return &Params{Bech32HRPSegwit: bech32HRPSegwit}
 }
+
+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
+}