9 log "github.com/sirupsen/logrus"
11 "github.com/bytom/bytom/crypto/ed25519/chainkd"
12 "github.com/bytom/bytom/protocol/bc"
15 // consensus variables
17 // Max gas that one block contains
18 MaxBlockGas = uint64(10000000)
19 VMGasRate = int64(200)
20 StorageGasRate = int64(1)
21 MaxGasAmount = int64(300000)
23 // These configs need add to casper config in elegant way
24 MaxNumOfValidators = int(10)
25 InitBTMSupply = 169290721678579170 + 50000000000
27 BlockReward = uint64(570776255)
29 // config parameter for coinbase reward
30 CoinbasePendingBlockNumber = uint64(10)
31 MinVoteOutputAmount = uint64(100000000)
33 PayToWitnessPubKeyHashDataSize = 20
34 PayToWitnessScriptHashDataSize = 32
35 BCRPContractHashDataSize = 32
36 CoinbaseArbitrarySizeLimit = 128
38 BCRPRequiredBTMAmount = uint64(100000000)
41 defaultVotePendingNum = 302400
44 type CasperConfig struct {
45 // BlockTimeInterval, milliseconds, the block time interval for producing a block
46 BlockTimeInterval uint64
48 // MaxTimeOffsetMs represent the max number of seconds a block time is allowed to be ahead of the current time
49 MaxTimeOffsetMs uint64
51 // BlocksOfEpoch represent the block num in one epoch
54 // MinValidatorVoteNum is the minimum vote number of become validator
55 MinValidatorVoteNum uint64
57 // VotePendingBlockNumber is the locked block number of vote utxo
58 VotePendingBlockNums []VotePendingBlockNum
60 FederationXpubs []chainkd.XPub
63 type VotePendingBlockNum struct {
69 // BTMAssetID is BTM's asset id, the soul asset of Bytom
70 var BTMAssetID = &bc.AssetID{
71 V0: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
72 V1: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
73 V2: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
74 V3: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
77 // BTMDefinitionMap is the ....
78 var BTMDefinitionMap = map[string]interface{}{
82 "description": `Bytom Official Issue`,
85 // IsBech32SegwitPrefix returns whether the prefix is a known prefix for segwit
86 // addresses on any default or registered network. This is used when decoding
87 // an address string into a specific address type.
88 func IsBech32SegwitPrefix(prefix string, params *Params) bool {
89 prefix = strings.ToLower(prefix)
90 return prefix == params.Bech32HRPSegwit+"1"
93 // Params store the config for different network
95 // Name defines a human-readable identifier for the network.
97 Bech32HRPSegwit string
98 // DefaultPort defines the default peer-to-peer port for the network.
101 // DNSSeeds defines a list of DNS seeds for the network that are used
102 // as one method to discover peers.
105 // CasperConfig defines the casper consensus parameters
109 // ActiveNetParams is ...
110 var ActiveNetParams = MainNetParams
112 // NetParams is the correspondence between chain_id and Params
113 var NetParams = map[string]Params{
114 "mainnet": MainNetParams,
115 "wisdom": TestNetParams,
116 "solonet": SoloNetParams,
119 // MainNetParams is the config for production
120 var MainNetParams = Params{
122 Bech32HRPSegwit: "bn",
123 DefaultPort: "46657",
124 DNSSeeds: []string{},
125 CasperConfig: CasperConfig{
126 BlockTimeInterval: 6000,
127 MaxTimeOffsetMs: 3000,
129 MinValidatorVoteNum: 1e14,
130 VotePendingBlockNums: []VotePendingBlockNum{
131 {BeginBlock: 0, EndBlock: 432000, Num: 14400},
132 {BeginBlock: 432000, EndBlock: math.MaxUint64, Num: defaultVotePendingNum},
134 FederationXpubs: []chainkd.XPub{
135 xpub("f9003633ccbd8cc37e034f4dbe70d9fae980d437948d8cb908d0cab7909780d74a324b4decb5dfcd43fbc6b896ac066b7e02c733a1537360e933278a101a850c"),
136 xpub("d301fee5d4ba7eb5b9d41ca13ec56c19daceb5f6b752d91d49777fd1fc7c45891e5773cafb3b6d6ab764ef2794e8ba953c8bdb9dc77a3af51e979f96885f96b2"),
137 xpub("2ba14bdd29fd84c73f67d6025d2a98292dbdd46b90a2af29c8669dd88dacb1cec62a3e9448d8b731a448f0454b0aa367748659d6c01ad7125d395ffda972da54"),
138 xpub("1313379b05c38ff2d171d512f23f199f0f068a67d77b9d5b6db040f2da1edc0c35c68a21b068956f448fed6441b9c27294f1ca6aaedc2c580de322f3f0260c1f"),
143 // TestNetParams is the config for test-net
144 var TestNetParams = Params{
146 Bech32HRPSegwit: "tn",
147 DefaultPort: "46656",
148 DNSSeeds: []string{},
149 CasperConfig: CasperConfig{
150 BlockTimeInterval: 6000,
151 MaxTimeOffsetMs: 3000,
153 MinValidatorVoteNum: 1e8,
154 VotePendingBlockNums: []VotePendingBlockNum{{BeginBlock: 0, EndBlock: math.MaxUint64, Num: 10}},
155 FederationXpubs: []chainkd.XPub{
156 xpub("7732fac62320799ff5e4eec1dc4ba7b07dc0e5a647850bf0bc34cb9aca195a05a1118b57d377947d7936156c831c87b700ed945a82cae63aff14905beb39d001"),
157 xpub("08543fef8c3ca27483954f80eee6d461c307b6aa564aafaf235a4bd2740debbc71b14af78715c94cbc1d16fa84da97a3eabc5b21f003ab49882e4af7f9f00bbd"),
158 xpub("0dd00fe3880c1cb5d5b0b5d03993c004e7fbe3697a47ff60c3bc12950bead964843dfe45b2bab5d01ae32fb23a4b0460049e822d7787a9a15b76d8bb9dfcec74"),
159 xpub("b0584ecaefc02d3c367f280e128ec310c9f9198d44cd76b6726cd6c06c002770a1a7dc069ddd06f7a821a176931573d40e63b015ce88b6de01a61205d719567f"),
164 // SoloNetParams is the config for test-net
165 var SoloNetParams = Params{
167 Bech32HRPSegwit: "sn",
168 CasperConfig: CasperConfig{
169 BlockTimeInterval: 6000,
170 MaxTimeOffsetMs: 24000,
172 MinValidatorVoteNum: 1e8,
173 VotePendingBlockNums: []VotePendingBlockNum{{BeginBlock: 0, EndBlock: math.MaxUint64, Num: 10}},
174 FederationXpubs: []chainkd.XPub{},
178 func VotePendingBlockNums(height uint64) uint64 {
179 for _, pendingNum := range ActiveNetParams.VotePendingBlockNums {
180 if height >= pendingNum.BeginBlock && height < pendingNum.EndBlock {
181 return pendingNum.Num
184 return defaultVotePendingNum
187 // InitActiveNetParams load the config by chain ID
188 func InitActiveNetParams(chainID string) error {
190 if ActiveNetParams, exist = NetParams[chainID]; !exist {
191 return fmt.Errorf("chain_id[%v] don't exist", chainID)
196 func xpub(str string) (xpub chainkd.XPub) {
197 if err := xpub.UnmarshalText([]byte(str)); err != nil {
198 log.Panicf("Fail converts a string to xpub")