OSDN Git Service

Merge pull request #99 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(1024)
13         MaxBlockSzie = uint64(16384)
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(2161727821138738707)
23         BlocksPerRetarget     = uint64(1024)
24         targetSecondsPerBlock = uint64(60)
25 )
26
27 // BTMAssetID is BTM's asset id, the soul asset of Bytom
28 var BTMAssetID = &bc.AssetID{
29         V0: uint64(18446744073709551615),
30         V1: uint64(18446744073709551615),
31         V2: uint64(18446744073709551615),
32         V3: uint64(18446744073709551615),
33 }
34
35 // BlockSubsidy calculate the coinbase rewards on given block height
36 func BlockSubsidy(height uint64) uint64 {
37         if height == 1 {
38                 return initialBlockSubsidy
39         }
40         return baseSubsidy >> uint(height/subsidyReductionInterval)
41 }
42
43 // InitBlock record the byte init block
44 func InitBlock() []byte {
45         return []byte("0301010000000000000000000000000000000000000000000000000000000000000000cecccaebf42b406b03545ed2b38a578e5e6b0796d4ebdd8a6dd72210873fcc026c7319de578ffc492159980684155da19e87de0d1b37b35c1a1123770ec1dcc710aabe77607cced7bb1993fcb680808080801e0107010700cecccaebf42b000001012cffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8080ccdee2a69fb314010151000000")
46 }
47
48 // IsBech32SegwitPrefix returns whether the prefix is a known prefix for segwit
49 // addresses on any default or registered network.  This is used when decoding
50 // an address string into a specific address type.
51 func IsBech32SegwitPrefix(prefix string, params *Params) bool {
52         prefix = strings.ToLower(prefix)
53         return prefix == params.Bech32HRPSegwit+"1"
54 }
55
56 // Params store the config for different network
57 type Params struct {
58         // Name defines a human-readable identifier for the network.
59         Name            string
60         Bech32HRPSegwit string
61 }
62
63 // MainNetParams is the config for production
64 var MainNetParams = Params{
65         Name:            "main",
66         Bech32HRPSegwit: "bm",
67 }
68
69 // TestNetParams is the config for test-net
70 var TestNetParams = Params{
71         Name:            "test",
72         Bech32HRPSegwit: "tm",
73 }