This repository has been archived by the owner on May 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 346
/
config.go
140 lines (118 loc) · 4.66 KB
/
config.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package core
import (
"fmt"
"github.com/go-kit/kit/log"
"github.com/hyperledger/burrow/config"
"github.com/hyperledger/burrow/consensus/abci"
"github.com/hyperledger/burrow/consensus/tendermint"
"github.com/hyperledger/burrow/execution"
"github.com/hyperledger/burrow/execution/registry"
"github.com/hyperledger/burrow/keys"
"github.com/hyperledger/burrow/logging/logconfig"
"github.com/hyperledger/burrow/logging/structure"
"github.com/hyperledger/burrow/project"
tmConfig "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/node"
tmTypes "github.com/tendermint/tendermint/types"
)
// LoadKeysFromConfig sets the keyClient & keyStore based on the given config
func (kern *Kernel) LoadKeysFromConfig(conf *keys.KeysConfig) (err error) {
kern.keyStore = keys.NewFilesystemKeyStore(conf.KeysDirectory, conf.AllowBadFilePermissions)
if conf.RemoteAddress != "" {
kern.keyClient, err = keys.NewRemoteKeyClient(conf.RemoteAddress, kern.Logger)
if err != nil {
return err
}
} else {
kern.keyClient = keys.NewLocalKeyClient(kern.keyStore, kern.Logger)
}
return nil
}
// LoadLoggerFromConfig adds a logging configuration to the kernel
func (kern *Kernel) LoadLoggerFromConfig(conf *logconfig.LoggingConfig) error {
logger, err := conf.Logger()
kern.SetLogger(logger)
return err
}
// LoadExecutionOptionsFromConfig builds the execution options for the kernel
func (kern *Kernel) LoadExecutionOptionsFromConfig(conf *execution.ExecutionConfig) error {
if conf != nil {
exeOptions, err := conf.ExecutionOptions()
if err != nil {
return err
}
kern.exeOptions = exeOptions
kern.timeoutFactor = conf.TimeoutFactor
}
return nil
}
// LoadTendermintFromConfig loads our consensus engine into the kernel
func (kern *Kernel) LoadTendermintFromConfig(conf *config.BurrowConfig, privVal tmTypes.PrivValidator) (err error) {
if conf.Tendermint == nil || !conf.Tendermint.Enabled {
return nil
}
authorizedPeersProvider := conf.Tendermint.DefaultAuthorizedPeersProvider()
if conf.Tendermint.IdentifyPeers {
authorizedPeersProvider = registry.NewNodeFilter(kern.State)
}
kern.database.Stats()
pubKey, err := privVal.GetPubKey()
if err != nil {
return err
}
kern.info = fmt.Sprintf("Burrow_%s_%s_ValidatorID:%X", project.History.CurrentVersion().String(),
kern.Blockchain.ChainID(), pubKey.Address())
app := abci.NewApp(kern.info, kern.Blockchain, kern.State, kern.checker, kern.committer, kern.txCodec,
authorizedPeersProvider, kern.Panic, kern.Logger)
// We could use this to provide/register our own metrics (though this will register them with us). Unfortunately
// Tendermint currently ignores the metrics passed unless its own server is turned on.
metricsProvider := node.DefaultMetricsProvider(&tmConfig.InstrumentationConfig{
Prometheus: false,
PrometheusListenAddr: "",
})
genesisDoc := kern.Blockchain.GenesisDoc()
tmGenesisDoc := tendermint.DeriveGenesisDoc(&genesisDoc, kern.Blockchain.AppHashAfterLastBlock())
heightValuer := log.Valuer(func() interface{} { return kern.Blockchain.LastBlockHeight() })
tmLogger := kern.Logger.With(structure.CallerKey, log.Caller(LoggingCallerDepth+1)).With("height", heightValuer)
tmConf, err := conf.TendermintConfig()
if err != nil {
return fmt.Errorf("could not build Tendermint config: %v", err)
}
kern.Node, err = tendermint.NewNode(tmConf, privVal, tmGenesisDoc, app, metricsProvider, tmLogger)
return err
}
// LoadKernelFromConfig builds and returns a Kernel based solely on the supplied configuration
func LoadKernelFromConfig(conf *config.BurrowConfig) (*Kernel, error) {
kern, err := NewKernel(conf.BurrowDir)
if err != nil {
return nil, fmt.Errorf("could not create initial kernel: %v", err)
}
if err = kern.LoadLoggerFromConfig(conf.Logging); err != nil {
return nil, fmt.Errorf("could not configure logger: %v", err)
}
err = kern.LoadKeysFromConfig(conf.Keys)
if err != nil {
return nil, fmt.Errorf("could not configure keys: %v", err)
}
err = kern.LoadExecutionOptionsFromConfig(conf.Execution)
if err != nil {
return nil, fmt.Errorf("could not add execution options: %v", err)
}
err = kern.LoadState(conf.GenesisDoc)
if err != nil {
return nil, fmt.Errorf("could not load state: %v", err)
}
if conf.ValidatorAddress == nil {
return nil, fmt.Errorf("Address must be set")
}
privVal, err := kern.PrivValidator(*conf.ValidatorAddress)
if err != nil {
return nil, fmt.Errorf("could not form PrivValidator from Address: %v", err)
}
err = kern.LoadTendermintFromConfig(conf, privVal)
if err != nil {
return nil, fmt.Errorf("could not configure Tendermint: %v", err)
}
kern.AddProcesses(DefaultProcessLaunchers(kern, conf.RPC, conf.Keys)...)
return kern, nil
}