OSDN Git Service

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