OSDN Git Service

add mainnet seeds (#329)
[bytom/vapor.git] / consensus / general.go
1 package consensus
2
3 import (
4         "encoding/binary"
5
6         "github.com/vapor/protocol/bc"
7 )
8
9 // basic constant
10 const (
11         BTMAlias = "BTM"
12
13         PayToWitnessPubKeyHashDataSize = 20
14         PayToWitnessScriptHashDataSize = 32
15 )
16
17 // BTMAssetID is BTM's asset id, the soul asset of Bytom
18 var BTMAssetID = &bc.AssetID{
19         V0: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
20         V1: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
21         V2: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
22         V3: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
23 }
24
25 // BTMDefinitionMap is the ....
26 var BTMDefinitionMap = map[string]interface{}{
27         "name":        BTMAlias,
28         "symbol":      BTMAlias,
29         "decimals":    8,
30         "description": `Bytom Official Issue`,
31 }
32
33 // BasicConfig indicate the basic config
34 type BasicConfig struct {
35         // gas config
36         MaxBlockGas      uint64 // the max used gas for all transactions of a block
37         MaxGasAmount     int64  // the max gas for a transaction
38         DefaultGasCredit int64  // the max default credit gas for a transaction with non-BTM asset
39         VMGasRate        int64  // the gas rate for VM
40         StorageGasRate   int64  // the gas rate for storage
41
42         // utxo config
43         VotePendingBlockNumber     uint64 // the valid block interval for vote utxo after the vote transaction is confirmed
44         CoinbasePendingBlockNumber uint64 // the valid block interval for coinbase utxo after the coinbase transaction is confirmed
45         CoinbaseArbitrarySizeLimit int    // the max size for coinbase arbitrary
46 }
47
48 // DPOSConfig indicate the dpos consensus config
49 type DPOSConfig struct {
50         NumOfConsensusNode      int64  // the number of consensus node
51         BlockNumEachNode        uint64 // the number of generated continuous blocks for each node
52         RoundVoteBlockNums      uint64 // the block interval which count the vote result in a round
53         MinConsensusNodeVoteNum uint64 // the min BTM amount for becoming consensus node(the unit is neu)
54         MinVoteOutputAmount     uint64 // the min BTM amount for voting output in a transaction(the unit is neu)
55         BlockTimeInterval       uint64 // the block time interval for producting a block
56         MaxTimeOffsetMs         uint64 // the max number of seconds a block time is allowed to be ahead of the current time
57 }
58
59 // Checkpoint identifies a known good point in the block chain.  Using
60 // checkpoints allows a few optimizations for old blocks during initial download
61 // and also prevents forks from old blocks.
62 type Checkpoint struct {
63         Height uint64
64         Hash   bc.Hash
65 }
66
67 // ProducerSubsidy is a subsidy to the producer of the generated block
68 type ProducerSubsidy struct {
69         BeginBlock uint64
70         EndBlock   uint64
71         Subsidy    uint64
72 }
73
74 // Params store the config for different network
75 type Params struct {
76         // Name defines a human-readable identifier for the network.
77         Name string
78
79         // Bech32HRPSegwit defines the prefix of address for the network
80         Bech32HRPSegwit string
81
82         // DefaultPort defines the default peer-to-peer port for the network.
83         DefaultPort string
84
85         // BasicConfig defines the gas and utxo relatived paramters.
86         BasicConfig
87
88         // DPOSConfig defines the dpos consensus paramters.
89         DPOSConfig
90
91         // DNSSeeds defines a list of DNS seeds for the network that are used
92         // as one method to discover peers.
93         DNSSeeds []string
94
95         // Checkpoints defines the checkpoint blocks
96         Checkpoints []Checkpoint
97
98         // ProducerSubsidys defines the producer subsidy by block height
99         ProducerSubsidys []ProducerSubsidy
100 }
101
102 // ActiveNetParams is the active NetParams
103 var ActiveNetParams = MainNetParams
104
105 // NetParams is the correspondence between chain_id and Params
106 var NetParams = map[string]Params{
107         "mainnet": MainNetParams,
108         "testnet": TestNetParams,
109         "solonet": SoloNetParams,
110 }
111
112 // MainNetParams is the config for vapor-mainnet
113 var MainNetParams = Params{
114         Name:            "main",
115         Bech32HRPSegwit: "vp",
116         DefaultPort:     "56656",
117         DNSSeeds:        []string{"www.mainnetseed.vapor.io"},
118         BasicConfig: BasicConfig{
119                 MaxBlockGas:                uint64(10000000),
120                 MaxGasAmount:               int64(640000),
121                 DefaultGasCredit:           int64(160000),
122                 StorageGasRate:             int64(1),
123                 VMGasRate:                  int64(200),
124                 VotePendingBlockNumber:     uint64(3456000),
125                 CoinbasePendingBlockNumber: uint64(7200),
126                 CoinbaseArbitrarySizeLimit: 128,
127         },
128         DPOSConfig: DPOSConfig{
129                 NumOfConsensusNode:      10,
130                 BlockNumEachNode:        12,
131                 MinConsensusNodeVoteNum: uint64(100000000000000),
132                 MinVoteOutputAmount:     uint64(100000000),
133                 BlockTimeInterval:       500,
134                 RoundVoteBlockNums:      1200,
135                 MaxTimeOffsetMs:         2000,
136         },
137         Checkpoints: []Checkpoint{},
138         ProducerSubsidys: []ProducerSubsidy{
139                 {BeginBlock: 1, EndBlock: 63072000, Subsidy: 9512938},
140         },
141 }
142
143 // TestNetParams is the config for vapor-testnet
144 var TestNetParams = Params{
145         Name:            "test",
146         Bech32HRPSegwit: "tp",
147         DefaultPort:     "56657",
148         DNSSeeds:        []string{"www.testnetseed.vapor.io"},
149         BasicConfig: BasicConfig{
150                 MaxBlockGas:                uint64(10000000),
151                 MaxGasAmount:               int64(200000),
152                 DefaultGasCredit:           int64(160000),
153                 StorageGasRate:             int64(1),
154                 VMGasRate:                  int64(200),
155                 VotePendingBlockNumber:     uint64(10000),
156                 CoinbasePendingBlockNumber: uint64(1200),
157                 CoinbaseArbitrarySizeLimit: 128,
158         },
159         DPOSConfig: DPOSConfig{
160                 NumOfConsensusNode:      10,
161                 BlockNumEachNode:        12,
162                 MinConsensusNodeVoteNum: uint64(100000000000000),
163                 MinVoteOutputAmount:     uint64(100000000),
164                 BlockTimeInterval:       500,
165                 RoundVoteBlockNums:      1200,
166                 MaxTimeOffsetMs:         2000,
167         },
168         Checkpoints: []Checkpoint{},
169         ProducerSubsidys: []ProducerSubsidy{
170                 {BeginBlock: 1, EndBlock: 63072000, Subsidy: 15000000},
171         },
172 }
173
174 // SoloNetParams is the config for vapor solonet
175 var SoloNetParams = Params{
176         Name:            "solo",
177         Bech32HRPSegwit: "sp",
178         DefaultPort:     "56658",
179         BasicConfig: BasicConfig{
180                 MaxBlockGas:                uint64(10000000),
181                 MaxGasAmount:               int64(200000),
182                 DefaultGasCredit:           int64(160000),
183                 StorageGasRate:             int64(1),
184                 VMGasRate:                  int64(200),
185                 VotePendingBlockNumber:     uint64(10000),
186                 CoinbasePendingBlockNumber: uint64(1200),
187                 CoinbaseArbitrarySizeLimit: 128,
188         },
189         DPOSConfig: DPOSConfig{
190                 NumOfConsensusNode:      10,
191                 BlockNumEachNode:        12,
192                 MinConsensusNodeVoteNum: uint64(100000000000000),
193                 MinVoteOutputAmount:     uint64(100000000),
194                 BlockTimeInterval:       500,
195                 RoundVoteBlockNums:      1200,
196                 MaxTimeOffsetMs:         2000,
197         },
198         Checkpoints: []Checkpoint{},
199         ProducerSubsidys: []ProducerSubsidy{
200                 {BeginBlock: 0, EndBlock: 0, Subsidy: 24},
201                 {BeginBlock: 1, EndBlock: 840000, Subsidy: 24},
202                 {BeginBlock: 840001, EndBlock: 1680000, Subsidy: 12},
203                 {BeginBlock: 1680001, EndBlock: 3360000, Subsidy: 6},
204         },
205 }
206
207 // BlockSubsidy calculate the coinbase rewards on given block height
208 func BlockSubsidy(height uint64) uint64 {
209         for _, subsidy := range ActiveNetParams.ProducerSubsidys {
210                 if height >= subsidy.BeginBlock && height <= subsidy.EndBlock {
211                         return subsidy.Subsidy
212                 }
213         }
214         return 0
215 }
216
217 // BytomMainNetParams is the config for bytom mainnet
218 func BytomMainNetParams(vaporParam *Params) *Params {
219         bech32HRPSegwit := "sm"
220         switch vaporParam.Name {
221         case "main":
222                 bech32HRPSegwit = "bm"
223         case "test":
224                 bech32HRPSegwit = "tm"
225         }
226         return &Params{Bech32HRPSegwit: bech32HRPSegwit}
227 }