Skip to content

Commit

Permalink
Merge pull request #1878 from oasislabs/ptrus/feature/cleanup-consens…
Browse files Browse the repository at this point in the history
…us-backends

go/node: add consensus.backend flag
  • Loading branch information
ptrus authored Jul 1, 2019
2 parents c6a9957 + 731a96d commit d33c9a5
Show file tree
Hide file tree
Showing 26 changed files with 78 additions and 819 deletions.
36 changes: 6 additions & 30 deletions .buildkite/scripts/common_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,10 @@ run_backend_tendermint_committee() {
--grpc.debug.port ${grpc_debug_port} \
--epochtime.backend ${epochtime_backend} \
--epochtime.tendermint.interval 30 \
--beacon.backend tendermint \
${EKIDEN_BEACON_DETERMINISTIC:+--beacon.debug.deterministic} \
--metrics.mode none \
--storage.backend client \
--scheduler.backend tendermint \
--registry.backend tendermint \
--roothash.backend tendermint \
--keymanager.backend tendermint \
--consensus.backend tendermint \
--genesis.file ${genesis_file} \
--tendermint.core.listen_address tcp://0.0.0.0:${tm_port} \
--tendermint.consensus.timeout_commit 250ms \
Expand Down Expand Up @@ -250,13 +246,9 @@ run_compute_node() {
--storage.cachingclient.file ${data_dir}/storage-cache \
--epochtime.backend ${EKIDEN_EPOCHTIME_BACKEND} \
--epochtime.tendermint.interval 30 \
--beacon.backend tendermint \
${EKIDEN_BEACON_DETERMINISTIC:+--beacon.debug.deterministic} \
--metrics.mode none \
--scheduler.backend tendermint \
--registry.backend tendermint \
--roothash.backend tendermint \
--keymanager.backend tendermint \
--consensus.backend tendermint \
--genesis.file ${EKIDEN_GENESIS_FILE} \
--tendermint.core.listen_address tcp://0.0.0.0:${tm_port} \
--tendermint.consensus.timeout_commit 250ms \
Expand Down Expand Up @@ -325,14 +317,10 @@ run_storage_node() {
--grpc.log.verbose_debug \
--epochtime.backend ${EKIDEN_EPOCHTIME_BACKEND} \
--epochtime.tendermint.interval 30 \
--beacon.backend tendermint \
${EKIDEN_BEACON_DETERMINISTIC:+--beacon.debug.deterministic} \
--metrics.mode none \
--storage.backend leveldb \
--scheduler.backend tendermint \
--registry.backend tendermint \
--roothash.backend tendermint \
--keymanager.backend tendermint \
--consensus.backend tendermint \
--genesis.file ${EKIDEN_GENESIS_FILE} \
--tendermint.core.listen_address tcp://0.0.0.0:${tm_port} \
--tendermint.consensus.timeout_commit 250ms \
Expand Down Expand Up @@ -386,16 +374,12 @@ run_client_node() {
--grpc.log.verbose_debug \
--epochtime.backend ${EKIDEN_EPOCHTIME_BACKEND} \
--epochtime.tendermint.interval 30 \
--beacon.backend tendermint \
${EKIDEN_BEACON_DETERMINISTIC:+--beacon.debug.deterministic} \
--metrics.mode none \
--storage.backend cachingclient \
--storage.cachingclient.file ${data_dir}/storage-cache \
--scheduler.backend tendermint \
--registry.backend tendermint \
--roothash.backend tendermint \
--consensus.backend tendermint \
--roothash.tendermint.index_blocks \
--keymanager.backend tendermint \
--genesis.file ${EKIDEN_GENESIS_FILE} \
--tendermint.core.listen_address tcp://0.0.0.0:${tm_port} \
--tendermint.consensus.timeout_commit 250ms \
Expand Down Expand Up @@ -471,13 +455,9 @@ run_keymanager_node() {
--storage.cachingclient.file ${data_dir}/storage-cache \
--epochtime.backend ${EKIDEN_EPOCHTIME_BACKEND} \
--epochtime.tendermint.interval 30 \
--beacon.backend tendermint \
${EKIDEN_BEACON_DETERMINISTIC:+--beacon.debug.deterministic} \
--metrics.mode none \
--scheduler.backend tendermint \
--registry.backend tendermint \
--roothash.backend tendermint \
--keymanager.backend tendermint \
--consensus.backend tendermint \
--genesis.file ${EKIDEN_GENESIS_FILE} \
--tendermint.core.listen_address tcp://0.0.0.0:${tm_port} \
--tendermint.consensus.timeout_commit 250ms \
Expand Down Expand Up @@ -531,12 +511,8 @@ run_seed_node() {
--genesis.file ${EKIDEN_GENESIS_FILE} \
--epochtime.backend ${EKIDEN_EPOCHTIME_BACKEND} \
--epochtime.tendermint.interval 30 \
--beacon.backend tendermint \
${EKIDEN_BEACON_DETERMINISTIC:+--beacon.debug.deterministic} \
--scheduler.backend tendermint \
--registry.backend tendermint \
--roothash.backend tendermint \
--keymanager.backend tendermint \
--consensus.backend tendermint \
--tendermint.core.listen_address tcp://0.0.0.0:${EKIDEN_SEED_NODE_PORT} \
--tendermint.seed_mode \
--tendermint.debug.addr_book_lenient \
Expand Down
21 changes: 4 additions & 17 deletions configs/single_node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,25 @@ worker:
binary: target/debug/ekiden-keymanager-runtime
loader: target/debug/ekiden-runtime-loader

# Consensus backend.
consensus:
backend: tendermint

# Epochtime backend.
epochtime:
backend: tendermint
tendermint:
# This makes each epoch last for 30 tendermint blocks.
interval: 30

# Random beacon backend.
beacon:
backend: tendermint

# Storage backend.
storage:
backend: leveldb
debug:
mock_signing_key: true

# Scheduler backend.
scheduler:
backend: tendermint

# Registry backend.
registry:
backend: tendermint

# Roothash backend.
roothash:
backend: tendermint
tendermint:
index_blocks: true

Expand All @@ -102,10 +93,6 @@ tendermint:
consensus:
timeout_commit: 1s

# Key manager backend configuration.
keymanager:
backend: tendermint

# Client configuration.
client:
indexer:
Expand Down
21 changes: 4 additions & 17 deletions configs/single_node_sgx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,34 +73,25 @@ worker:
ias:
proxy_addr: "127.0.0.1:9001"

# Consensus backend.
consensus:
backend: tendermint

# Epochtime backend.
epochtime:
backend: tendermint
tendermint:
# This makes each epoch last for 30 tendermint blocks.
interval: 30

# Random beacon backend.
beacon:
backend: tendermint

# Storage backend.
storage:
backend: leveldb
debug:
mock_signing_key: true

# Scheduler backend.
scheduler:
backend: tendermint

# Registry backend.
registry:
backend: tendermint

# Roothash backend.
roothash:
backend: tendermint
tendermint:
index_blocks: true

Expand All @@ -109,10 +100,6 @@ tendermint:
consensus:
timeout_commit: 1s

# Key manager backend configuration.
keymanager:
backend: tendermint

# Client configuration.
client:
indexer:
Expand Down
6 changes: 2 additions & 4 deletions go/beacon/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import (

"github.com/oasislabs/ekiden/go/beacon/api"
"github.com/oasislabs/ekiden/go/beacon/tendermint"
commonFlags "github.com/oasislabs/ekiden/go/ekiden/cmd/common/flags"
epochtime "github.com/oasislabs/ekiden/go/epochtime/api"
"github.com/oasislabs/ekiden/go/tendermint/service"
)

const (
cfgBackend = "beacon.backend"
cfgDebugDeterministic = "beacon.debug.deterministic"
)

// New constructs a new Backend based on the configuration flags.
func New(ctx context.Context, timeSource epochtime.Backend, tmService service.TendermintService) (api.Backend, error) {
debugDeterministic := viper.GetBool(cfgDebugDeterministic)

backend := viper.GetString(cfgBackend)
backend := commonFlags.ConsensusBackend()
switch strings.ToLower(backend) {
case tendermint.BackendName:
return tendermint.New(ctx, timeSource, tmService, debugDeterministic)
Expand All @@ -37,12 +37,10 @@ func New(ctx context.Context, timeSource epochtime.Backend, tmService service.Te
// command.
func RegisterFlags(cmd *cobra.Command) {
if !cmd.Flags().Parsed() {
cmd.Flags().String(cfgBackend, tendermint.BackendName, "Random beacon backend")
cmd.Flags().Bool(cfgDebugDeterministic, false, "enable deterministic beacon output (UNSAFE)")
}

for _, v := range []string{
cfgBackend,
cfgDebugDeterministic,
} {
viper.BindPFlag(v, cmd.Flags().Lookup(v)) //nolint: errcheck
Expand Down
2 changes: 1 addition & 1 deletion go/beacon/tendermint/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

// BackendName is the name of this implementation.
const BackendName = "tendermint"
const BackendName = tmapi.BackendName

var _ api.Backend = (*Backend)(nil)

Expand Down
28 changes: 28 additions & 0 deletions go/ekiden/cmd/common/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
package flags

import (
"fmt"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"

tmapi "github.com/oasislabs/ekiden/go/tendermint/api"
)

const (
cfgVerbose = "verbose"
cfgForce = "force"
cfgRetries = "retries"

cfgConsensusBackend = "consensus.backend"

cfgDebugTestEntity = "debug.test_entity"
)

Expand Down Expand Up @@ -57,6 +64,27 @@ func RegisterRetries(cmd *cobra.Command) {
_ = viper.BindPFlag(cfgRetries, cmd.Flags().Lookup(cfgRetries))
}

// ConsensusBackend returns the set consensus backend.
func ConsensusBackend() string {
backend := viper.GetString(cfgConsensusBackend)

switch strings.ToLower(backend) {
case tmapi.BackendName:
return tmapi.BackendName
default:
panic(fmt.Sprintf("consensus: unsupported backend: '%v'", backend))
}
}

// RegisterConsensusBackend registers the consensus backend flag for the provided command.
func RegisterConsensusBackend(cmd *cobra.Command) {
if !cmd.Flags().Parsed() {
cmd.Flags().String(cfgConsensusBackend, tmapi.BackendName, "force")
}

_ = viper.BindPFlag(cfgConsensusBackend, cmd.Flags().Lookup(cfgConsensusBackend))
}

// DebugTestEntity returns true iff the test entity enable flag is set.
func DebugTestEntity() bool {
return viper.GetBool(cfgDebugTestEntity)
Expand Down
1 change: 1 addition & 0 deletions go/ekiden/cmd/debug/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func registerBootstrapFlags(cmd *cobra.Command) {
}

flags.RegisterDebugTestEntity(cmd)
flags.RegisterConsensusBackend(cmd)
}

// Register registers the bootstrap sub-command and all of it's children.
Expand Down
1 change: 1 addition & 0 deletions go/ekiden/cmd/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ func registerInitGenesisFlags(cmd *cobra.Command) {
}

flags.RegisterDebugTestEntity(cmd)
flags.RegisterConsensusBackend(cmd)
}

// Register registers the genesis sub-command and all of it's children.
Expand Down
1 change: 1 addition & 0 deletions go/ekiden/cmd/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,5 @@ func RegisterFlags(cmd *cobra.Command) {
}

flags.RegisterDebugTestEntity(cmd)
flags.RegisterConsensusBackend(cmd)
}
1 change: 1 addition & 0 deletions go/ekiden/cmd/registry/entity/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ func Register(parentCmd *cobra.Command) {
deregisterCmd,
} {
cmdFlags.RegisterDebugTestEntity(v)
cmdFlags.RegisterConsensusBackend(v)
}

for _, v := range []*cobra.Command{
Expand Down
3 changes: 3 additions & 0 deletions go/ekiden/cmd/registry/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var (
Short: "initialize a runtime for genesis",
PreRun: func(cmd *cobra.Command, args []string) {
cmdFlags.RegisterDebugTestEntity(cmd)
cmdFlags.RegisterConsensusBackend(cmd)
registerRuntimeFlags(cmd)
registerOutputFlag(cmd)
},
Expand All @@ -71,6 +72,7 @@ var (
PreRun: func(cmd *cobra.Command, args []string) {
cmdGrpc.RegisterClientFlags(cmd, false)
cmdFlags.RegisterDebugTestEntity(cmd)
cmdFlags.RegisterConsensusBackend(cmd)
cmdFlags.RegisterRetries(cmd)
registerRuntimeFlags(cmd)
},
Expand Down Expand Up @@ -437,6 +439,7 @@ func Register(parentCmd *cobra.Command) {
registerCmd,
} {
cmdFlags.RegisterDebugTestEntity(v)
cmdFlags.RegisterConsensusBackend(v)
}

registerRuntimeFlags(initGenesisCmd)
Expand Down
7 changes: 1 addition & 6 deletions go/ekiden/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,10 @@ var (
}{
{"log.level.default", "DEBUG"},
{"epochtime.backend", "tendermint_mock"},
{"beacon.backend", "tendermint"},
{"keymanager.backend", "tendermint"},
{"registry.backend", "tendermint"},
{"roothash.backend", "tendermint"},
{"consensus.backend", "tendermint"},
{"roothash.tendermint.index_blocks", true},
{"scheduler.backend", "tendermint"},
{"storage.backend", "leveldb"},
{"storage.debug.mock_signing_key", true},
{"staking.backend", "tendermint"},
{"staking.debug.genesis_state", stakingTests.DebugGenesisState},
{"tendermint.consensus.timeout_commit", 1 * time.Millisecond},
{"tendermint.consensus.skip_timeout_commit", true},
Expand Down
3 changes: 2 additions & 1 deletion go/epochtime/tendermint/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import (
"github.com/oasislabs/ekiden/go/common/logging"
"github.com/oasislabs/ekiden/go/common/pubsub"
"github.com/oasislabs/ekiden/go/epochtime/api"
tmapi "github.com/oasislabs/ekiden/go/tendermint/api"
"github.com/oasislabs/ekiden/go/tendermint/service"
)

const (
// BackendName is the name of this implementation.
BackendName = "tendermint"
BackendName = tmapi.BackendName
)

var _ api.Backend = (*tendermintBackend)(nil)
Expand Down
Loading

0 comments on commit d33c9a5

Please sign in to comment.