OSDN Git Service

eb25bc4a794f659b6f10516ac977fb7f669c2a20
[bytom/bytom.git] / consensus / general.go
1 package consensus
2
3 import (
4         "encoding/binary"
5         "strings"
6
7         "github.com/bytom/bytom/protocol/bc"
8 )
9
10 // consensus variables
11 const (
12         // Max gas that one block contains
13         MaxBlockGas    = uint64(10000000)
14         VMGasRate      = int64(200)
15         StorageGasRate = int64(1)
16         MaxGasAmount   = int64(300000)
17
18         // These configs need add to casper config in elegant way
19         MaxNumOfValidators = int(10)
20         InitBTMSupply      = 15.66 * 1e16
21         RewardThreshold    = 0.5
22         BlockReward        = uint64(570776255)
23
24         // config parameter for coinbase reward
25         CoinbasePendingBlockNumber = uint64(10)
26         MinVoteOutputAmount        = uint64(100000000)
27
28         PayToWitnessPubKeyHashDataSize = 20
29         PayToWitnessScriptHashDataSize = 32
30         BCRPContractHashDataSize       = 32
31         CoinbaseArbitrarySizeLimit     = 128
32
33         BCRPRequiredBTMAmount = uint64(100000000)
34
35         BTMAlias = "BTM"
36 )
37
38 type CasperConfig struct {
39         // BlockTimeInterval, milliseconds, the block time interval for producing a block
40         BlockTimeInterval uint64
41
42         // MaxTimeOffsetMs represent the max number of seconds a block time is allowed to be ahead of the current time
43         MaxTimeOffsetMs uint64
44
45         // BlocksOfEpoch represent the block num in one epoch
46         BlocksOfEpoch uint64
47
48         // MinValidatorVoteNum is the minimum vote number of become validator
49         MinValidatorVoteNum uint64
50
51         // VotePendingBlockNumber is the locked block number of vote utxo
52         VotePendingBlockNumber uint64
53 }
54
55 // BTMAssetID is BTM's asset id, the soul asset of Bytom
56 var BTMAssetID = &bc.AssetID{
57         V0: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
58         V1: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
59         V2: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
60         V3: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
61 }
62
63 // BTMDefinitionMap is the ....
64 var BTMDefinitionMap = map[string]interface{}{
65         "name":        BTMAlias,
66         "symbol":      BTMAlias,
67         "decimals":    8,
68         "description": `Bytom Official Issue`,
69 }
70
71 // IsBech32SegwitPrefix returns whether the prefix is a known prefix for segwit
72 // addresses on any default or registered network.  This is used when decoding
73 // an address string into a specific address type.
74 func IsBech32SegwitPrefix(prefix string, params *Params) bool {
75         prefix = strings.ToLower(prefix)
76         return prefix == params.Bech32HRPSegwit+"1"
77 }
78
79 // Params store the config for different network
80 type Params struct {
81         // Name defines a human-readable identifier for the network.
82         Name            string
83         Bech32HRPSegwit string
84         // DefaultPort defines the default peer-to-peer port for the network.
85         DefaultPort string
86
87         // DNSSeeds defines a list of DNS seeds for the network that are used
88         // as one method to discover peers.
89         DNSSeeds []string
90
91         // CasperConfig defines the casper consensus parameters
92         CasperConfig
93 }
94
95 // ActiveNetParams is ...
96 var ActiveNetParams = MainNetParams
97
98 // NetParams is the correspondence between chain_id and Params
99 var NetParams = map[string]Params{
100         "mainnet": MainNetParams,
101         "wisdom":  TestNetParams,
102         "solonet": SoloNetParams,
103 }
104
105 // MainNetParams is the config for production
106 var MainNetParams = Params{
107         Name:            "main",
108         Bech32HRPSegwit: "bm",
109         DefaultPort:     "46657",
110         DNSSeeds:        []string{"www.mainnetseed.bytom.io"},
111         CasperConfig: CasperConfig{
112                 BlockTimeInterval:      6000,
113                 MaxTimeOffsetMs:        2400,
114                 BlocksOfEpoch:          100,
115                 MinValidatorVoteNum:    1e14,
116                 VotePendingBlockNumber: 181440,
117         },
118 }
119
120 // TestNetParams is the config for test-net
121 var TestNetParams = Params{
122         Name:            "test",
123         Bech32HRPSegwit: "tm",
124         DefaultPort:     "46656",
125         DNSSeeds:        []string{"www.testnetseed.bytom.io"},
126         CasperConfig: CasperConfig{
127                 BlockTimeInterval:      6000,
128                 MaxTimeOffsetMs:        24000,
129                 BlocksOfEpoch:          100,
130                 MinValidatorVoteNum:    1e8,
131                 VotePendingBlockNumber: 10,
132         },
133 }
134
135 // SoloNetParams is the config for test-net
136 var SoloNetParams = Params{
137         Name:            "solo",
138         Bech32HRPSegwit: "sm",
139         CasperConfig: CasperConfig{
140                 BlockTimeInterval:      6000,
141                 MaxTimeOffsetMs:        24000,
142                 BlocksOfEpoch:          100,
143                 MinValidatorVoteNum:    1e8,
144                 VotePendingBlockNumber: 10,
145         },
146 }