8 log "github.com/sirupsen/logrus"
10 "github.com/bytom/bytom/crypto/ed25519/chainkd"
11 "github.com/bytom/bytom/protocol/bc"
14 // consensus variables
16 // Max gas that one block contains
17 MaxBlockGas = uint64(10000000)
18 VMGasRate = int64(200)
19 StorageGasRate = int64(1)
20 MaxGasAmount = int64(300000)
22 // These configs need add to casper config in elegant way
23 MaxNumOfValidators = int(10)
24 InitBTMSupply = 169290721678579697
26 BlockReward = uint64(570776255)
28 // config parameter for coinbase reward
29 CoinbasePendingBlockNumber = uint64(10)
30 MinVoteOutputAmount = uint64(100000000)
32 PayToWitnessPubKeyHashDataSize = 20
33 PayToWitnessScriptHashDataSize = 32
34 BCRPContractHashDataSize = 32
35 CoinbaseArbitrarySizeLimit = 128
37 BCRPRequiredBTMAmount = uint64(100000000)
42 type CasperConfig struct {
43 // BlockTimeInterval, milliseconds, the block time interval for producing a block
44 BlockTimeInterval uint64
46 // MaxTimeOffsetMs represent the max number of seconds a block time is allowed to be ahead of the current time
47 MaxTimeOffsetMs uint64
49 // BlocksOfEpoch represent the block num in one epoch
52 // MinValidatorVoteNum is the minimum vote number of become validator
53 MinValidatorVoteNum uint64
55 // VotePendingBlockNumber is the locked block number of vote utxo
56 VotePendingBlockNumber uint64
58 FederationXpubs []chainkd.XPub
61 // BTMAssetID is BTM's asset id, the soul asset of Bytom
62 var BTMAssetID = &bc.AssetID{
63 V0: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
64 V1: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
65 V2: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
66 V3: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
69 // BTMDefinitionMap is the ....
70 var BTMDefinitionMap = map[string]interface{}{
74 "description": `Bytom Official Issue`,
77 // IsBech32SegwitPrefix returns whether the prefix is a known prefix for segwit
78 // addresses on any default or registered network. This is used when decoding
79 // an address string into a specific address type.
80 func IsBech32SegwitPrefix(prefix string, params *Params) bool {
81 prefix = strings.ToLower(prefix)
82 return prefix == params.Bech32HRPSegwit+"1"
85 // Params store the config for different network
87 // Name defines a human-readable identifier for the network.
89 Bech32HRPSegwit string
90 // DefaultPort defines the default peer-to-peer port for the network.
93 // DNSSeeds defines a list of DNS seeds for the network that are used
94 // as one method to discover peers.
97 // CasperConfig defines the casper consensus parameters
101 // ActiveNetParams is ...
102 var ActiveNetParams = MainNetParams
104 // NetParams is the correspondence between chain_id and Params
105 var NetParams = map[string]Params{
106 "mainnet": MainNetParams,
107 "wisdom": TestNetParams,
108 "solonet": SoloNetParams,
111 // MainNetParams is the config for production
112 var MainNetParams = Params{
114 Bech32HRPSegwit: "bn",
115 DefaultPort: "46657",
116 DNSSeeds: []string{},
117 CasperConfig: CasperConfig{
118 BlockTimeInterval: 6000,
119 MaxTimeOffsetMs: 3000,
121 MinValidatorVoteNum: 1e14,
122 VotePendingBlockNumber: 14400,
123 FederationXpubs: []chainkd.XPub{
124 xpub("f9003633ccbd8cc37e034f4dbe70d9fae980d437948d8cb908d0cab7909780d74a324b4decb5dfcd43fbc6b896ac066b7e02c733a1537360e933278a101a850c"),
125 xpub("d301fee5d4ba7eb5b9d41ca13ec56c19daceb5f6b752d91d49777fd1fc7c45891e5773cafb3b6d6ab764ef2794e8ba953c8bdb9dc77a3af51e979f96885f96b2"),
126 xpub("2ba14bdd29fd84c73f67d6025d2a98292dbdd46b90a2af29c8669dd88dacb1cec62a3e9448d8b731a448f0454b0aa367748659d6c01ad7125d395ffda972da54"),
127 xpub("1313379b05c38ff2d171d512f23f199f0f068a67d77b9d5b6db040f2da1edc0c35c68a21b068956f448fed6441b9c27294f1ca6aaedc2c580de322f3f0260c1f"),
132 // TestNetParams is the config for test-net
133 var TestNetParams = Params{
135 Bech32HRPSegwit: "tn",
136 DefaultPort: "46656",
137 DNSSeeds: []string{},
138 CasperConfig: CasperConfig{
139 BlockTimeInterval: 6000,
140 MaxTimeOffsetMs: 3000,
142 MinValidatorVoteNum: 1e8,
143 VotePendingBlockNumber: 10,
144 FederationXpubs: []chainkd.XPub{
145 xpub("7732fac62320799ff5e4eec1dc4ba7b07dc0e5a647850bf0bc34cb9aca195a05a1118b57d377947d7936156c831c87b700ed945a82cae63aff14905beb39d001"),
146 xpub("08543fef8c3ca27483954f80eee6d461c307b6aa564aafaf235a4bd2740debbc71b14af78715c94cbc1d16fa84da97a3eabc5b21f003ab49882e4af7f9f00bbd"),
147 xpub("0dd00fe3880c1cb5d5b0b5d03993c004e7fbe3697a47ff60c3bc12950bead964843dfe45b2bab5d01ae32fb23a4b0460049e822d7787a9a15b76d8bb9dfcec74"),
148 xpub("b0584ecaefc02d3c367f280e128ec310c9f9198d44cd76b6726cd6c06c002770a1a7dc069ddd06f7a821a176931573d40e63b015ce88b6de01a61205d719567f"),
153 // SoloNetParams is the config for test-net
154 var SoloNetParams = Params{
156 Bech32HRPSegwit: "sn",
157 CasperConfig: CasperConfig{
158 BlockTimeInterval: 6000,
159 MaxTimeOffsetMs: 24000,
161 MinValidatorVoteNum: 1e8,
162 VotePendingBlockNumber: 10,
163 FederationXpubs: []chainkd.XPub{},
167 // InitActiveNetParams load the config by chain ID
168 func InitActiveNetParams(chainID string) error {
170 if ActiveNetParams, exist = NetParams[chainID]; !exist {
171 return fmt.Errorf("chain_id[%v] don't exist", chainID)
176 func xpub(str string) (xpub chainkd.XPub) {
177 if err := xpub.UnmarshalText([]byte(str)); err != nil {
178 log.Panicf("Fail converts a string to xpub")