-
Notifications
You must be signed in to change notification settings - Fork 109
/
tendermint.go
67 lines (57 loc) · 1.89 KB
/
tendermint.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
package tendermint
import (
"context"
"fmt"
flag "github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/oasisprotocol/oasis-core/go/common/identity"
consensusAPI "github.com/oasisprotocol/oasis-core/go/consensus/api"
"github.com/oasisprotocol/oasis-core/go/consensus/tendermint/common"
"github.com/oasisprotocol/oasis-core/go/consensus/tendermint/full"
"github.com/oasisprotocol/oasis-core/go/consensus/tendermint/seed"
genesisAPI "github.com/oasisprotocol/oasis-core/go/genesis/api"
upgradeAPI "github.com/oasisprotocol/oasis-core/go/upgrade/api"
)
const (
// CfgMode configures the consensus backend mode.
CfgMode = "consensus.tendermint.mode"
)
// Flags has the configuration flags.
var Flags = flag.NewFlagSet("", flag.ContinueOnError)
// Mode returns the configured tendermint mode.
func Mode() (mode consensusAPI.Mode, err error) {
err = mode.UnmarshalText([]byte(viper.GetString(CfgMode)))
return
}
// New creates a new Tendermint consensus backend.
func New(
ctx context.Context,
dataDir string,
identity *identity.Identity,
upgrader upgradeAPI.Backend,
genesisProvider genesisAPI.Provider,
) (consensusAPI.Backend, error) {
var mode consensusAPI.Mode
if err := mode.UnmarshalText([]byte(viper.GetString(CfgMode))); err != nil {
return nil, err
}
switch mode {
case consensusAPI.ModeFull:
// Full node.
return full.New(ctx, dataDir, identity, upgrader, genesisProvider)
case consensusAPI.ModeSeed:
// Seed-only node.
return seed.New(dataDir, identity, genesisProvider)
case consensusAPI.ModeArchive:
// Archive node.
return full.NewArchive(ctx, dataDir, identity, genesisProvider)
default:
return nil, fmt.Errorf("tendermint: unsupported mode: %s", mode)
}
}
func init() {
Flags.String(CfgMode, consensusAPI.ModeFull.String(), "tendermint mode (full, seed, archive)")
_ = viper.BindPFlags(Flags)
Flags.AddFlagSet(common.Flags)
Flags.AddFlagSet(full.Flags)
}