Skip to content

Commit

Permalink
go/epochtime: refactor to ticker
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Jul 16, 2019
1 parent 5bb535f commit 507c75c
Show file tree
Hide file tree
Showing 58 changed files with 1,228 additions and 1,107 deletions.
53 changes: 28 additions & 25 deletions .buildkite/scripts/common_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,21 @@ EKIDEN_KM_RUNTIME_ID=${EKIDEN_KM_RUNTIME_ID:-"ffffffffffffffffffffffffffffffffff
# EKIDEN_COMMITTEE_DIR
# EKIDEN_GENESIS_FILE
# EKIDEN_IAS_PROXY_PORT
# EKIDEN_EPOCHTIME_BACKEND
# EKIDEN_VALIDATOR_SOCKET
# EKIDEN_CLIENT_SOCKET
# EKIDEN_ENTITY_PRIVATE_KEY
#
# Optional named arguments:
#
# epochtime_backend - epochtime backend (default: tendermint)
# ekiden_ticker_settable - settable ticker (default: 1)
# id - commitee identifier (default: 1)
# replica_group_size - runtime replica group size (default: 2)
# replica_group_backup_size - runtime replica group backup size (default: 1)
# storage_group_size - number of storage nodes for the runtime (default: 2)
#
run_backend_tendermint_committee() {
# Optional arguments with default values.
local epochtime_backend="tendermint"
local ekiden_ticker_settable=1
local id=1
local replica_group_size=2
local replica_group_backup_size=1
Expand Down Expand Up @@ -140,9 +139,12 @@ run_backend_tendermint_committee() {
EKIDEN_VALIDATOR_SOCKET=${base_datadir}-1/internal.sock
EKIDEN_IAS_PROXY_PORT=${ias_proxy_port}
EKIDEN_GENESIS_FILE=${genesis_file}
EKIDEN_EPOCHTIME_BACKEND=${epochtime_backend}
EKIDEN_TICKER_SETTABLE=${ekiden_ticker_settable}
EKIDEN_ENTITY_PRIVATE_KEY=${entity_dir}/entity.pem

echo "EKIDEN TICKER SETTABLE"
echo "${EKIDEN_TICKER_SETTABLE}"

# Run the seed node.
run_seed_node

Expand All @@ -161,12 +163,13 @@ run_backend_tendermint_committee() {
--log.file ${committee_dir}/validator-${idx}.log \
--grpc.log.verbose_debug \
--grpc.debug.port ${grpc_debug_port} \
--epochtime.backend ${epochtime_backend} \
--epochtime.tendermint.interval 30 \
--ticker.interval 5 \
${EKIDEN_TICKER_SETTABLE:+--ticker.debug.settable} \
${EKIDEN_BEACON_DETERMINISTIC:+--beacon.debug.deterministic} \
--metrics.mode none \
--storage.backend client \
--consensus.backend tendermint \
--tendermint.abci.epoch_interval 5 \
--genesis.file ${genesis_file} \
--tendermint.core.listen_address tcp://0.0.0.0:${tm_port} \
--tendermint.consensus.timeout_commit 250ms \
Expand Down Expand Up @@ -244,11 +247,12 @@ run_compute_node() {
--grpc.log.verbose_debug \
--storage.backend cachingclient \
--storage.cachingclient.file ${data_dir}/storage-cache \
--epochtime.backend ${EKIDEN_EPOCHTIME_BACKEND} \
--epochtime.tendermint.interval 30 \
${EKIDEN_TICKER_SETTABLE:+--ticker.debug.settable} \
--ticker.interval 5 \
${EKIDEN_BEACON_DETERMINISTIC:+--beacon.debug.deterministic} \
--metrics.mode none \
--consensus.backend tendermint \
--tendermint.abci.epoch_interval 5 \
--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 @@ -315,12 +319,13 @@ run_storage_node() {
--log.level debug \
--log.file ${log_file} \
--grpc.log.verbose_debug \
--epochtime.backend ${EKIDEN_EPOCHTIME_BACKEND} \
--epochtime.tendermint.interval 30 \
${EKIDEN_TICKER_SETTABLE:+--ticker.debug.settable} \
--ticker.interval 5 \
${EKIDEN_BEACON_DETERMINISTIC:+--beacon.debug.deterministic} \
--metrics.mode none \
--storage.backend leveldb \
--consensus.backend tendermint \
--tendermint.abci.epoch_interval 5 \
--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 @@ -372,13 +377,14 @@ run_client_node() {
--log.level debug \
--log.file ${log_file} \
--grpc.log.verbose_debug \
--epochtime.backend ${EKIDEN_EPOCHTIME_BACKEND} \
--epochtime.tendermint.interval 30 \
${EKIDEN_TICKER_SETTABLE:+--ticker.debug.settable} \
--ticker.interval 5 \
${EKIDEN_BEACON_DETERMINISTIC:+--beacon.debug.deterministic} \
--metrics.mode none \
--storage.backend cachingclient \
--storage.cachingclient.file ${data_dir}/storage-cache \
--consensus.backend tendermint \
--tendermint.abci.epoch_interval 5 \
--roothash.tendermint.index_blocks \
--genesis.file ${EKIDEN_GENESIS_FILE} \
--tendermint.core.listen_address tcp://0.0.0.0:${tm_port} \
Expand Down Expand Up @@ -408,16 +414,11 @@ wait_nodes() {
--nodes $nodes
}

# Set epoch.
# Advances epoch.
#
# Arguments:
# epoch - epoch to set
set_epoch() {
local epoch=$1

${EKIDEN_NODE} debug dummy set-epoch \
--address unix:${EKIDEN_VALIDATOR_SOCKET} \
--epoch $epoch
advance_epoch() {
${EKIDEN_NODE} debug dummy advance-epoch \
--address unix:${EKIDEN_VALIDATOR_SOCKET}
}

# Run a key manager node.
Expand Down Expand Up @@ -453,11 +454,12 @@ run_keymanager_node() {
--grpc.log.verbose_debug \
--storage.backend cachingclient \
--storage.cachingclient.file ${data_dir}/storage-cache \
--epochtime.backend ${EKIDEN_EPOCHTIME_BACKEND} \
--epochtime.tendermint.interval 30 \
${EKIDEN_TICKER_SETTABLE:+--ticker.debug.settable} \
--ticker.interval 5 \
${EKIDEN_BEACON_DETERMINISTIC:+--beacon.debug.deterministic} \
--metrics.mode none \
--consensus.backend tendermint \
--tendermint.abci.epoch_interval 5 \
--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 @@ -509,10 +511,11 @@ run_seed_node() {
--log.file ${log_file} \
--metrics.mode none \
--genesis.file ${EKIDEN_GENESIS_FILE} \
--epochtime.backend ${EKIDEN_EPOCHTIME_BACKEND} \
--epochtime.tendermint.interval 30 \
${EKIDEN_TICKER_SETTABLE:+--ticker.debug.settable} \
--ticker.interval 5 \
${EKIDEN_BEACON_DETERMINISTIC:+--beacon.debug.deterministic} \
--consensus.backend tendermint \
--tendermint.abci.epoch_interval 5 \
--tendermint.core.listen_address tcp://0.0.0.0:${EKIDEN_SEED_NODE_PORT} \
--tendermint.seed_mode \
--tendermint.debug.addr_book_lenient \
Expand Down
6 changes: 3 additions & 3 deletions .buildkite/scripts/test_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ scenario_basic() {
wait_nodes 6

# Advance epoch to elect a new committee.
set_epoch 1
advance_epoch
}

scenario_compute_discrepancy() {
Expand All @@ -72,7 +72,7 @@ scenario_compute_discrepancy() {
wait_nodes 6

# Advance epoch to elect a new committee.
set_epoch 1
advance_epoch
}

assert_compute_discrepancy_scenario_works() {
Expand All @@ -98,7 +98,7 @@ scenario_merge_discrepancy() {
wait_nodes 6

# Advance epoch to elect a new committee.
set_epoch 1
advance_epoch
}

assert_merge_discrepancy_scenario_works() {
Expand Down
8 changes: 4 additions & 4 deletions .buildkite/scripts/test_migration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test_migration() {

# Start the first network.
run_backend_tendermint_committee \
epochtime_backend=tendermint_mock \
ekiden_ticker_settable=1 \
id=1 \
replica_group_size=1 \
replica_group_backup_size=0 \
Expand All @@ -56,7 +56,7 @@ test_migration() {
# Wait for all nodes to start: 1 compute + 1 storage + key manager.
wait_nodes 3

set_epoch 1
advance_epoch
sleep 1

# Start client and do the state mutations.
Expand All @@ -83,7 +83,7 @@ test_migration() {

# Start the second network.
run_backend_tendermint_committee \
epochtime_backend=tendermint_mock \
ekiden_ticker_settable=1 \
id=2 \
replica_group_size=1 \
replica_group_backup_size=0 \
Expand All @@ -96,7 +96,7 @@ test_migration() {
# Wait for all nodes to start: 1 compute + 1 storage + key manager.
wait_nodes 3

set_epoch 2
advance_epoch

# Start client and do state verification, checking that migration succeeded.
${CLIENT} \
Expand Down
10 changes: 4 additions & 6 deletions configs/single_node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,10 @@ worker:
consensus:
backend: tendermint

# Epochtime backend.
epochtime:
backend: tendermint
tendermint:
# This makes each epoch last for 30 tendermint blocks.
interval: 30
# Ticker backend.
ticker:
# This makes tick happen every 5 blocks.
interval: 5

# Storage backend.
storage:
Expand Down
10 changes: 4 additions & 6 deletions configs/single_node_sgx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,10 @@ ias:
consensus:
backend: tendermint

# Epochtime backend.
epochtime:
backend: tendermint
tendermint:
# This makes each epoch last for 30 tendermint blocks.
interval: 30
# Ticker backend.
ticker:
# This makes tick happen every 5 blocks.
interval: 5

# Storage backend.
storage:
Expand Down
6 changes: 3 additions & 3 deletions go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ node, development, and debugging.
All sub-commands have online documentation that can be accessed via the
`--help` parameter, for example:
```
ekiden debug dummy set-epoch --help
ekiden debug dummy advance-epoch --help
```

### `debug dummy` - Control the dummy (centralized) node during tests

The `debug dummy` sub-command provides faclities for controlling the centralized
node during tests.

#### `debug dummy set-epoch` - Set the Oasis epoch
#### `debug dummy advance-epoch` - Set the Oasis epoch

The `dummy set-epoch` sub-command allows the node's Oasis epoch to be
The `dummy advance-epoch` sub-command allows the node's Oasis epoch to be
set to an arbitrary value, provided a compatible epochtime backend is
being used (`mock`, `tendermint_mock`).

Expand Down
4 changes: 2 additions & 2 deletions go/beacon/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ 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"
ticker "github.com/oasislabs/ekiden/go/ticker/api"
)

const (
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) {
func New(ctx context.Context, timeSource ticker.Backend, tmService service.TendermintService) (api.Backend, error) {
backend := commonFlags.ConsensusBackend()
switch strings.ToLower(backend) {
case tendermint.BackendName:
Expand Down
4 changes: 2 additions & 2 deletions go/beacon/tendermint/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

"github.com/oasislabs/ekiden/go/beacon/api"
"github.com/oasislabs/ekiden/go/common/logging"
epochtime "github.com/oasislabs/ekiden/go/epochtime/api"
tmapi "github.com/oasislabs/ekiden/go/tendermint/api"
app "github.com/oasislabs/ekiden/go/tendermint/apps/beacon"
"github.com/oasislabs/ekiden/go/tendermint/service"
ticker "github.com/oasislabs/ekiden/go/ticker/api"
)

// BackendName is the name of this implementation.
Expand All @@ -36,7 +36,7 @@ func (t *Backend) GetBeacon(ctx context.Context, height int64) ([]byte, error) {
}

// New constructs a new tendermint backed beacon Backend instance.
func New(ctx context.Context, timeSource epochtime.Backend, service service.TendermintService, cfg *api.Config) (api.Backend, error) {
func New(ctx context.Context, timeSource ticker.Backend, service service.TendermintService, cfg *api.Config) (api.Backend, error) {
if err := service.ForceInitialize(); err != nil {
return nil, err
}
Expand Down
9 changes: 5 additions & 4 deletions go/beacon/tests/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ import (
"github.com/stretchr/testify/require"

"github.com/oasislabs/ekiden/go/beacon/api"
epochtime "github.com/oasislabs/ekiden/go/epochtime/api"
epochtimeTests "github.com/oasislabs/ekiden/go/epochtime/tests"
scheduler "github.com/oasislabs/ekiden/go/scheduler/api"
ticker "github.com/oasislabs/ekiden/go/ticker/api"
tickerTests "github.com/oasislabs/ekiden/go/ticker/tests"
)

// BeaconImplementationTests exercises the basic functionality of a
// beacon backend.
func BeaconImplementationTests(t *testing.T, backend api.Backend, epochtime epochtime.SetableBackend) {
func BeaconImplementationTests(t *testing.T, backend api.Backend, ticker ticker.SetableBackend, scheduler scheduler.Backend) {
require := require.New(t)

beacon, err := backend.GetBeacon(context.Background(), 0)
require.NoError(err, "GetBeacon")
require.Len(beacon, api.BeaconSize, "GetBeacon - length")

_ = epochtimeTests.MustAdvanceEpoch(t, epochtime, 1)
tickerTests.MustAdvanceEpoch(t, ticker, scheduler)

newBeacon, err := backend.GetBeacon(context.Background(), 0)
require.NoError(err, "GetBeacon")
Expand Down
Loading

0 comments on commit 507c75c

Please sign in to comment.