OSDN Git Service

aad4c781522d35b5b16634e4cfe0551cede0b20d
[bytom/vapor.git] / consensus / general.go
1 package consensus
2
3 import (
4         "encoding/binary"
5         "strings"
6
7         "github.com/vapor/crypto/ed25519/chainkd"
8         "github.com/vapor/protocol/bc"
9 )
10
11 //consensus variables
12 const (
13         // Max gas that one block contains
14         MaxBlockGas      = uint64(10000000)
15         VMGasRate        = int64(200)
16         StorageGasRate   = int64(1)
17         MaxGasAmount     = int64(200000)
18         DefaultGasCredit = int64(30000)
19
20         //config parameter for coinbase reward
21         CoinbasePendingBlockNumber = uint64(100)
22         subsidyReductionInterval   = uint64(840000)
23         baseSubsidy                = uint64(0)
24         //baseSubsidy                = uint64(41250000000)
25         //InitialBlockSubsidy        = uint64(140700041250000000)
26         InitialBlockSubsidy = uint64(0)
27
28         // config for pow mining
29         BlocksPerRetarget     = uint64(2016)
30         TargetSecondsPerBlock = uint64(150)
31         SeedPerRetarget       = uint64(256)
32
33         // MaxTimeOffsetSeconds is the maximum number of seconds a block time is allowed to be ahead of the current time
34         MaxTimeOffsetSeconds = uint64(60 * 60)
35         MedianTimeBlocks     = 11
36
37         PayToWitnessPubKeyHashDataSize = 20
38         PayToWitnessScriptHashDataSize = 32
39         CoinbaseArbitrarySizeLimit     = 128
40
41         BTMAlias = "BTM"
42 )
43
44 // BTMAssetID is BTM's asset id, the soul asset of Bytom
45 var BTMAssetID = &bc.AssetID{
46         V0: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
47         V1: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
48         V2: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
49         V3: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
50 }
51
52 // InitialSeed is SHA3-256 of Byte[0^32]
53 var InitialSeed = &bc.Hash{
54         V0: uint64(11412844483649490393),
55         V1: uint64(4614157290180302959),
56         V2: uint64(1780246333311066183),
57         V3: uint64(9357197556716379726),
58 }
59
60 // BTMDefinitionMap is the ....
61 var BTMDefinitionMap = map[string]interface{}{
62         "name":        BTMAlias,
63         "symbol":      BTMAlias,
64         "decimals":    8,
65         "description": `Bytom Official Issue`,
66 }
67
68 const (
69         Coin     = 100000000
70         MaxMoney = 2100000000 * Coin
71 )
72
73 func MoneyRange(nValue uint64) bool { return nValue >= 0 && nValue <= MaxMoney }
74
75 // BlockSubsidy calculate the coinbase rewards on given block height
76 func BlockSubsidy(height uint64) uint64 {
77         if height == 0 {
78                 return InitialBlockSubsidy
79         }
80         return baseSubsidy >> uint(height/subsidyReductionInterval)
81 }
82
83 // IsBech32SegwitPrefix returns whether the prefix is a known prefix for segwit
84 // addresses on any default or registered network.  This is used when decoding
85 // an address string into a specific address type.
86 func IsBech32SegwitPrefix(prefix string, params *Params) bool {
87         prefix = strings.ToLower(prefix)
88         return prefix == params.Bech32HRPSegwit+"1"
89 }
90
91 func IsBytomBech32SegwitPrefix(prefix string, params *Params) bool {
92         prefix = strings.ToLower(prefix)
93         return prefix == params.BytomBech32HRPSegwit+"1"
94 }
95
96 // Checkpoint identifies a known good point in the block chain.  Using
97 // checkpoints allows a few optimizations for old blocks during initial download
98 // and also prevents forks from old blocks.
99 type Checkpoint struct {
100         Height uint64
101         Hash   bc.Hash
102 }
103
104 // Params store the config for different network
105 type Params struct {
106         // Name defines a human-readable identifier for the network.
107         Name                   string
108         Bech32HRPSegwit        string
109         BytomBech32HRPSegwit   string
110         Checkpoints            []Checkpoint
111         FedpegXPubs            []chainkd.XPub
112         SignBlockXPubs         []chainkd.XPub
113         PeginMinDepth          uint64
114         ParentGenesisBlockHash string
115         Signer                 string
116 }
117
118 // ActiveNetParams is ...
119 var ActiveNetParams = MainNetParams
120
121 // NetParams is the correspondence between chain_id and Params
122 var NetParams = map[string]Params{
123         "mainnet": MainNetParams,
124         "wisdom":  TestNetParams,
125         "solonet": SoloNetParams,
126 }
127
128 // BytomMainNetParams is the config for production
129 var MainNetParams = Params{
130         Name:                 "main",
131         Bech32HRPSegwit:      "vbm",
132         BytomBech32HRPSegwit: "bm",
133         Checkpoints: []Checkpoint{
134                 {10000, bc.NewHash([32]byte{0x93, 0xe1, 0xeb, 0x78, 0x21, 0xd2, 0xb4, 0xad, 0x0f, 0x5b, 0x1c, 0xea, 0x82, 0xe8, 0x43, 0xad, 0x8c, 0x09, 0x9a, 0xb6, 0x5d, 0x8f, 0x70, 0xc5, 0x84, 0xca, 0xa2, 0xdd, 0xf1, 0x74, 0x65, 0x2c})},
135                 {20000, bc.NewHash([32]byte{0x7d, 0x38, 0x61, 0xf3, 0x2c, 0xc0, 0x03, 0x81, 0xbb, 0xcd, 0x9a, 0x37, 0x6f, 0x10, 0x5d, 0xfe, 0x6f, 0xfe, 0x2d, 0xa5, 0xea, 0x88, 0xa5, 0xe3, 0x42, 0xed, 0xa1, 0x17, 0x9b, 0xa8, 0x0b, 0x7c})},
136                 {30000, bc.NewHash([32]byte{0x32, 0x36, 0x06, 0xd4, 0x27, 0x2e, 0x35, 0x24, 0x46, 0x26, 0x7b, 0xe0, 0xfa, 0x48, 0x10, 0xa4, 0x3b, 0xb2, 0x40, 0xf1, 0x09, 0x51, 0x5b, 0x22, 0x9f, 0xf3, 0xc3, 0x83, 0x28, 0xaa, 0x4a, 0x00})},
137                 {40000, bc.NewHash([32]byte{0x7f, 0xe2, 0xde, 0x11, 0x21, 0xf3, 0xa9, 0xa0, 0xee, 0x60, 0x8d, 0x7d, 0x4b, 0xea, 0xcc, 0x33, 0xfe, 0x41, 0x25, 0xdc, 0x2f, 0x26, 0xc2, 0xf2, 0x9c, 0x07, 0x17, 0xf9, 0xe4, 0x4f, 0x9d, 0x46})},
138                 {50000, bc.NewHash([32]byte{0x5e, 0xfb, 0xdf, 0xf5, 0x35, 0x38, 0xa6, 0x0b, 0x75, 0x32, 0x02, 0x61, 0x83, 0x54, 0x34, 0xff, 0x3e, 0x82, 0x2e, 0xf8, 0x64, 0xae, 0x2d, 0xc7, 0x6c, 0x9d, 0x5e, 0xbd, 0xa3, 0xd4, 0x50, 0xcf})},
139                 {62000, bc.NewHash([32]byte{0xd7, 0x39, 0x8f, 0x23, 0x57, 0xf9, 0x4c, 0xa0, 0x28, 0xa7, 0x00, 0x2b, 0x53, 0x9e, 0x51, 0x2d, 0x3e, 0xca, 0xc9, 0x22, 0x59, 0xfc, 0xd0, 0x3f, 0x67, 0x1a, 0x0a, 0xb1, 0x02, 0xbf, 0x2b, 0x03})},
140                 {72000, bc.NewHash([32]byte{0x66, 0x02, 0x31, 0x19, 0xf1, 0x60, 0x35, 0x61, 0xa4, 0xf1, 0x38, 0x04, 0xcc, 0xe4, 0x59, 0x8f, 0x55, 0x39, 0xba, 0x22, 0xf2, 0x6d, 0x90, 0xbf, 0xc1, 0x87, 0xef, 0x98, 0xcc, 0x70, 0x4d, 0x94})},
141                 {83700, bc.NewHash([32]byte{0x7f, 0x26, 0xc9, 0x11, 0xe8, 0x46, 0xd0, 0x6e, 0x36, 0xbb, 0xac, 0xce, 0x99, 0xa2, 0x19, 0x89, 0x3f, 0xf7, 0x84, 0x2a, 0xcb, 0x44, 0x7f, 0xbb, 0x0e, 0x3b, 0xa3, 0x68, 0xd6, 0x2b, 0xe8, 0x0d})},
142         },
143 }
144
145 // BytomTestNetParams is the config for test-net
146 var TestNetParams = Params{
147         Name:                 "test",
148         Bech32HRPSegwit:      "vtm",
149         BytomBech32HRPSegwit: "tm",
150         Checkpoints: []Checkpoint{
151                 {10303, bc.NewHash([32]byte{0x3e, 0x94, 0x5d, 0x35, 0x70, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c})},
152                 {40000, bc.NewHash([32]byte{0x6b, 0x13, 0x9a, 0x5b, 0x76, 0x77, 0x9b, 0xd4, 0x1c, 0xec, 0x53, 0x68, 0x44, 0xbf, 0xf4, 0x48, 0x94, 0x3d, 0x16, 0xe3, 0x9b, 0x2e, 0xe8, 0xa1, 0x0f, 0xa0, 0xbc, 0x7d, 0x2b, 0x17, 0x55, 0xfc})},
153         },
154 }
155
156 // BytomSoloNetParams is the config for test-net
157 var SoloNetParams = Params{
158         Name:                 "solo",
159         Bech32HRPSegwit:      "vsm",
160         BytomBech32HRPSegwit: "sm",
161         Checkpoints:          []Checkpoint{},
162 }