OSDN Git Service

Merge pull request #564 from Bytom/dev
[bytom/bytom-spv.git] / consensus / general.go
1 package consensus
2
3 import (
4         "strings"
5
6         "github.com/bytom/protocol/bc"
7 )
8
9 //consensus variables
10 const (
11         // define the Max transaction size and Max block size
12         MaxTxSize   = uint64(1048576)
13         MaxBlockGas = uint64(100000000)
14
15         //config parameter for coinbase reward
16         CoinbasePendingBlockNumber = uint64(6)
17         subsidyReductionInterval   = uint64(560640)
18         baseSubsidy                = uint64(624000000000)
19         InitialBlockSubsidy        = uint64(1470000000000000000)
20
21         // config for pow mining
22         PowMinBits            = uint64(2305843009213861724)
23         BlocksPerRetarget     = uint64(1024)
24         TargetSecondsPerBlock = uint64(60)
25         SeedPerRetarget       = uint64(128)
26
27         // MaxTimeOffsetSeconds is the maximum number of seconds a block time is allowed to be ahead of the current time
28         MaxTimeOffsetSeconds = uint64(60 * 60)
29         MedianTimeBlocks     = 11
30
31         PayToWitnessPubKeyHashDataSize = 20
32         PayToWitnessScriptHashDataSize = 32
33
34         CoinbaseArbitrarySizeLimit = 128
35
36         VMGasRate        = int64(1000)
37         StorageGasRate   = int64(0)
38         MaxGasAmount     = int64(100000)
39         DefaultGasCredit = int64(80000)
40
41         BTMAlias       = "BTM"
42         BTMSymbol      = "BTM"
43         BTMDecimals    = 8
44         BTMDescription = `Bytom Official Issue`
45 )
46
47 // BTMAssetID is BTM's asset id, the soul asset of Bytom
48 var BTMAssetID = &bc.AssetID{
49         V0: uint64(18446744073709551615),
50         V1: uint64(18446744073709551615),
51         V2: uint64(18446744073709551615),
52         V3: uint64(18446744073709551615),
53 }
54
55 // InitialSeed is SHA3-256 of Byte[0^32]
56 var InitialSeed = &bc.Hash{
57         V0: uint64(11412844483649490393),
58         V1: uint64(4614157290180302959),
59         V2: uint64(1780246333311066183),
60         V3: uint64(9357197556716379726),
61 }
62
63 // BTMDefinitionMap is the ....
64 var BTMDefinitionMap = map[string]interface{}{
65         "name":        BTMAlias,
66         "symbol":      BTMSymbol,
67         "decimals":    BTMDecimals,
68         "description": BTMDescription,
69 }
70
71 // BlockSubsidy calculate the coinbase rewards on given block height
72 func BlockSubsidy(height uint64) uint64 {
73         if height == 0 {
74                 return InitialBlockSubsidy
75         }
76         return baseSubsidy >> uint(height/subsidyReductionInterval)
77 }
78
79 // IsBech32SegwitPrefix returns whether the prefix is a known prefix for segwit
80 // addresses on any default or registered network.  This is used when decoding
81 // an address string into a specific address type.
82 func IsBech32SegwitPrefix(prefix string, params *Params) bool {
83         prefix = strings.ToLower(prefix)
84         return prefix == params.Bech32HRPSegwit+"1"
85 }
86
87 // Params store the config for different network
88 type Params struct {
89         // Name defines a human-readable identifier for the network.
90         Name            string
91         Bech32HRPSegwit string
92 }
93
94 // MainNetParams is the config for production
95 var MainNetParams = Params{
96         Name:            "main",
97         Bech32HRPSegwit: "bm",
98 }
99
100 // TestNetParams is the config for test-net
101 var TestNetParams = Params{
102         Name:            "test",
103         Bech32HRPSegwit: "tm",
104 }