forked from aergoio/aergo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
89 lines (71 loc) · 1.82 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* @file
* @copyright defined in aergo/LICENSE.txt
*/
package chain
import (
"errors"
"math/big"
"github.com/aergoio/aergo/internal/enc"
"github.com/aergoio/aergo/types"
)
const pubNetMaxBlockSize = 4000000
var (
CoinbaseAccount []byte
MaxAnchorCount int
UseFastSyncer bool
VerifierCount int
coinbaseFee *big.Int
// MaxBlockSize is the upper limit of block size.
maxBlockSize uint32
pubNet bool
)
var (
ErrInvalidCoinbaseAccount = errors.New("invalid coinbase account in config")
)
// Init initializes the blockchain-related parameters.
func Init(maxBlkSize uint32, coinbaseAccountStr string, isBp bool, maxAnchorCount int, useFastSyncer bool, verifierCount int) error {
var err error
maxBlockSize = maxBlkSize
if isBp {
if len(coinbaseAccountStr) != 0 {
CoinbaseAccount, err = types.DecodeAddress(coinbaseAccountStr)
if err != nil {
return ErrInvalidCoinbaseAccount
}
logger.Info().Str("account", enc.ToString(CoinbaseAccount)).Str("str", coinbaseAccountStr).
Msg("set coinbase account")
} else {
logger.Info().Msg("Coinbase Account is nil, so BP reward will be discarded")
}
}
MaxAnchorCount = maxAnchorCount
UseFastSyncer = useFastSyncer
VerifierCount = verifierCount
return nil
}
// IsPublic reports whether the block chain is public or not.
func IsPublic() bool {
return pubNet
}
func initChainEnv(genesis *types.Genesis) {
pubNet = genesis.ID.PublicNet
if pubNet {
setMaxBlockSize(pubNetMaxBlockSize)
}
fee, _ := genesis.ID.GetCoinbaseFee() // no failure
setCoinbaseFee(fee)
}
// MaxBlockSize returns (kind of) the upper limit of block size.
func MaxBlockSize() uint32 {
return maxBlockSize
}
func setMaxBlockSize(size uint32) {
maxBlockSize = size
}
func setCoinbaseFee(fee *big.Int) {
coinbaseFee = fee
}
func CoinbaseFee() *big.Int {
return coinbaseFee
}