7 "github.com/vapor/protocol/bc"
14 PayToWitnessPubKeyHashDataSize = 20
15 PayToWitnessScriptHashDataSize = 32
18 // BTMAssetID is BTM's asset id, the soul asset of Bytom
19 var BTMAssetID = &bc.AssetID{
20 V0: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
21 V1: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
22 V2: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
23 V3: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
26 // BTMDefinitionMap is the ....
27 var BTMDefinitionMap = map[string]interface{}{
31 "description": `Bytom Official Issue`,
34 // BasicConfig indicate the basic config
35 type BasicConfig struct {
37 MaxBlockGas uint64 // the max used gas for all transactions of a block
38 MaxGasAmount int64 // the max gas for a transaction
39 DefaultGasCredit int64 // the max default credit gas for a transaction with non-BTM asset
40 VMGasRate int64 // the gas rate for VM
41 StorageGasRate int64 // the gas rate for storage
44 VotePendingBlockNumber uint64 // the valid block interval for vote utxo after the vote transaction is confirmed
45 CoinbasePendingBlockNumber uint64 // the valid block interval for coinbase utxo after the coinbase transaction is confirmed
46 CoinbaseArbitrarySizeLimit int // the max size for coinbase arbitrary
49 // DPOSConfig indicate the dpos consensus config
50 type DPOSConfig struct {
51 NumOfConsensusNode int64 // the number of consensus node
52 BlockNumEachNode uint64 // the number of generated continuous blocks for each node
53 RoundVoteBlockNums uint64 // the block interval which count the vote result in a round
54 MinConsensusNodeVoteNum uint64 // the min BTM amount for becoming consensus node(the unit is neu)
55 MinVoteOutputAmount uint64 // the min BTM amount for voting output in a transaction(the unit is neu)
56 BlockTimeInterval uint64 // the block time interval for producting a block
57 MaxTimeOffsetMs uint64 // the max number of seconds a block time is allowed to be ahead of the current time
60 // Checkpoint identifies a known good point in the block chain. Using
61 // checkpoints allows a few optimizations for old blocks during initial download
62 // and also prevents forks from old blocks.
63 type Checkpoint struct {
68 // ProducerSubsidy is a subsidy to the producer of the generated block
69 type ProducerSubsidy struct {
75 // Params store the config for different network
77 // Name defines a human-readable identifier for the network.
80 // Bech32HRPSegwit defines the prefix of address for the network
81 Bech32HRPSegwit string
83 // DefaultPort defines the default peer-to-peer port for the network.
86 // BasicConfig defines the gas and utxo relatived paramters.
89 // DPOSConfig defines the dpos consensus paramters.
92 // DNSSeeds defines a list of DNS seeds for the network that are used
93 // as one method to discover peers.
96 // Checkpoints defines the checkpoint blocks
97 Checkpoints []Checkpoint
99 // ProducerSubsidys defines the producer subsidy by block height
100 ProducerSubsidys []ProducerSubsidy
103 // ActiveNetParams is the active NetParams
104 var ActiveNetParams = MainNetParams
106 // NetParams is the correspondence between chain_id and Params
107 var NetParams = map[string]Params{
108 "mainnet": MainNetParams,
109 "testnet": TestNetParams,
110 "solonet": SoloNetParams,
113 // MainNetParams is the config for vapor-mainnet
114 var MainNetParams = Params{
116 Bech32HRPSegwit: "vp",
117 DefaultPort: "56656",
118 DNSSeeds: []string{"www.mainnetseed.vapor.io"},
119 BasicConfig: BasicConfig{
120 MaxBlockGas: uint64(10000000),
121 MaxGasAmount: int64(640000),
122 DefaultGasCredit: int64(160000),
123 StorageGasRate: int64(1),
124 VMGasRate: int64(200),
125 VotePendingBlockNumber: uint64(3456000),
126 CoinbasePendingBlockNumber: uint64(7200),
127 CoinbaseArbitrarySizeLimit: 128,
129 DPOSConfig: DPOSConfig{
130 NumOfConsensusNode: 10,
131 BlockNumEachNode: 12,
132 MinConsensusNodeVoteNum: uint64(100000000000000),
133 MinVoteOutputAmount: uint64(100000000),
134 BlockTimeInterval: 500,
135 RoundVoteBlockNums: 1200,
136 MaxTimeOffsetMs: 2000,
138 Checkpoints: []Checkpoint{},
139 ProducerSubsidys: []ProducerSubsidy{
140 {BeginBlock: 1, EndBlock: 63072000, Subsidy: 9512938},
144 // TestNetParams is the config for vapor-testnet
145 var TestNetParams = Params{
147 Bech32HRPSegwit: "tp",
148 DefaultPort: "56657",
149 DNSSeeds: []string{"www.testnetseed.vapor.io"},
150 BasicConfig: BasicConfig{
151 MaxBlockGas: uint64(10000000),
152 MaxGasAmount: int64(200000),
153 DefaultGasCredit: int64(160000),
154 StorageGasRate: int64(1),
155 VMGasRate: int64(200),
156 VotePendingBlockNumber: uint64(10000),
157 CoinbasePendingBlockNumber: uint64(1200),
158 CoinbaseArbitrarySizeLimit: 128,
160 DPOSConfig: DPOSConfig{
161 NumOfConsensusNode: 10,
162 BlockNumEachNode: 12,
163 MinConsensusNodeVoteNum: uint64(100000000000000),
164 MinVoteOutputAmount: uint64(100000000),
165 BlockTimeInterval: 500,
166 RoundVoteBlockNums: 1200,
167 MaxTimeOffsetMs: 2000,
169 Checkpoints: []Checkpoint{},
170 ProducerSubsidys: []ProducerSubsidy{
171 {BeginBlock: 1, EndBlock: 63072000, Subsidy: 15000000},
175 // SoloNetParams is the config for vapor solonet
176 var SoloNetParams = Params{
178 Bech32HRPSegwit: "sp",
179 DefaultPort: "56658",
180 BasicConfig: BasicConfig{
181 MaxBlockGas: uint64(10000000),
182 MaxGasAmount: int64(200000),
183 DefaultGasCredit: int64(160000),
184 StorageGasRate: int64(1),
185 VMGasRate: int64(200),
186 VotePendingBlockNumber: uint64(10000),
187 CoinbasePendingBlockNumber: uint64(1200),
188 CoinbaseArbitrarySizeLimit: 128,
190 DPOSConfig: DPOSConfig{
191 NumOfConsensusNode: 10,
192 BlockNumEachNode: 12,
193 MinConsensusNodeVoteNum: uint64(100000000000000),
194 MinVoteOutputAmount: uint64(100000000),
195 BlockTimeInterval: 500,
196 RoundVoteBlockNums: 1200,
197 MaxTimeOffsetMs: 2000,
199 Checkpoints: []Checkpoint{},
200 ProducerSubsidys: []ProducerSubsidy{
201 {BeginBlock: 0, EndBlock: 0, Subsidy: 24},
202 {BeginBlock: 1, EndBlock: 840000, Subsidy: 24},
203 {BeginBlock: 840001, EndBlock: 1680000, Subsidy: 12},
204 {BeginBlock: 1680001, EndBlock: 3360000, Subsidy: 6},
208 // BlockSubsidy calculate the coinbase rewards on given block height
209 func BlockSubsidy(height uint64) uint64 {
210 for _, subsidy := range ActiveNetParams.ProducerSubsidys {
211 if height >= subsidy.BeginBlock && height <= subsidy.EndBlock {
212 return subsidy.Subsidy
218 // BytomMainNetParams is the config for bytom mainnet
219 func BytomMainNetParams(vaporParam *Params) *Params {
220 bech32HRPSegwit := "sm"
221 switch vaporParam.Name {
223 bech32HRPSegwit = "bm"
225 bech32HRPSegwit = "tm"
227 return &Params{Bech32HRPSegwit: bech32HRPSegwit}
230 func InitActiveNetParams(chainID string) error {
232 if ActiveNetParams, exist = NetParams[chainID]; !exist {
233 return fmt.Errorf("chain_id[%v] don't exist", chainID)