-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package byzantine | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/oasislabs/ekiden/go/common/logging" | ||
"github.com/oasislabs/ekiden/go/ekiden/cmd/common" | ||
"github.com/oasislabs/ekiden/go/genesis" | ||
"github.com/oasislabs/ekiden/go/tendermint" | ||
) | ||
|
||
var ( | ||
logger = logging.GetLogger("cmd/byzantine") | ||
byzantineCmd = &cobra.Command{ | ||
Use: "byzantine", | ||
Short: "run some node behaviors for testing, often not honest", | ||
} | ||
computeHonestCmd = &cobra.Command{ | ||
Use: "compute-honest", | ||
Short: "act as an honest compute worker", | ||
Run: doComputeHonest, | ||
} | ||
) | ||
|
||
func doComputeHonest(cmd *cobra.Command, args []string) { | ||
if err := common.Init(); err != nil { | ||
common.EarlyLogAndExit(err) | ||
} | ||
|
||
startHonestTendermint() | ||
defer stopHonestTendermint() | ||
logger.Debug("compute honest: ok %%%") | ||
} | ||
|
||
// Register registers the byzantine sub-command and all of its children. | ||
func Register(parentCmd *cobra.Command) { | ||
byzantineCmd.AddCommand(computeHonestCmd) | ||
parentCmd.AddCommand(byzantineCmd) | ||
} | ||
|
||
func init() { | ||
computeHonestCmd.Flags().AddFlagSet(genesis.Flags) | ||
computeHonestCmd.Flags().AddFlagSet(tendermint.Flags) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package byzantine | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
beacon "github.com/oasislabs/ekiden/go/beacon/api" | ||
"github.com/oasislabs/ekiden/go/common/crypto/signature" | ||
fileSigner "github.com/oasislabs/ekiden/go/common/crypto/signature/signers/file" | ||
"github.com/oasislabs/ekiden/go/common/identity" | ||
"github.com/oasislabs/ekiden/go/common/pubsub" | ||
"github.com/oasislabs/ekiden/go/ekiden/cmd/common" | ||
"github.com/oasislabs/ekiden/go/epochtime/api" | ||
"github.com/oasislabs/ekiden/go/genesis" | ||
registry "github.com/oasislabs/ekiden/go/registry/api" | ||
scheduler "github.com/oasislabs/ekiden/go/scheduler/api" | ||
"github.com/oasislabs/ekiden/go/tendermint" | ||
beaconapp "github.com/oasislabs/ekiden/go/tendermint/apps/beacon" | ||
keymanagerapp "github.com/oasislabs/ekiden/go/tendermint/apps/keymanager" | ||
registryapp "github.com/oasislabs/ekiden/go/tendermint/apps/registry" | ||
roothashapp "github.com/oasislabs/ekiden/go/tendermint/apps/roothash" | ||
schedulerapp "github.com/oasislabs/ekiden/go/tendermint/apps/scheduler" | ||
stakingapp "github.com/oasislabs/ekiden/go/tendermint/apps/staking" | ||
"github.com/oasislabs/ekiden/go/tendermint/service" | ||
) | ||
|
||
var ( | ||
honestTendermint service.TendermintService | ||
|
||
_ api.Backend = (*fakeTimeBackend)(nil) | ||
) | ||
|
||
// fakeTimeBackend is like TendermintBackend (of epochtime), but without | ||
// any workers. | ||
// TODO: come up with an acceptable way to do this | ||
type fakeTimeBackend struct{} | ||
|
||
// GetEpoch implements epochtime Backend. | ||
func (*fakeTimeBackend) GetEpoch(ctx context.Context, height int64) (api.EpochTime, error) { | ||
if height == 0 { | ||
panic("0 height not supported") | ||
} | ||
return api.EpochTime(height / 30), nil | ||
} | ||
|
||
// GetEpochBlock implements epochtime Backend. | ||
func (*fakeTimeBackend) GetEpochBlock(ctx context.Context, epoch api.EpochTime) (int64, error) { | ||
panic("GetEpochBlock not supported") | ||
// return int64(epoch) * 30, nil | ||
} | ||
|
||
// WatchEpochs implements epochtime Backend. | ||
func (*fakeTimeBackend) WatchEpochs() (<-chan api.EpochTime, *pubsub.Subscription) { | ||
panic("WatchEpochs not supported") | ||
} | ||
|
||
func startHonestTendermint() { | ||
if honestTendermint != nil { | ||
panic("honest Tendermint service already started") | ||
} | ||
|
||
dataDir := common.DataDir() | ||
signerFactory := fileSigner.NewFactory(dataDir, signature.SignerNode, signature.SignerP2P, signature.SignerEntity) | ||
identity, err := identity.LoadOrGenerate(dataDir, signerFactory) | ||
if err != nil { | ||
panic("identity.LoadOrGenerate: " + err.Error()) | ||
} | ||
genesis, err := genesis.New(identity) | ||
if err != nil { | ||
panic("genesis.New: " + err.Error()) | ||
} | ||
honestTendermint = tendermint.New(context.Background(), dataDir, identity, genesis) | ||
logger.Debug("honest Tendermint service instantiated %%%", "honestTendermint", honestTendermint) | ||
|
||
if err := honestTendermint.ForceInitialize(); err != nil { | ||
panic("honestTendermint.ForceInitialize: " + err.Error()) | ||
} | ||
logger.Debug("honest Tendermint service force initialized %%%") | ||
|
||
// Register honest mux apps. | ||
// This isn't very flexible. It's configured to match what we use in end-to-end tests. | ||
// And we do that mostly by hardcoding options. We could make this more flexible with command | ||
// line flags in future work. | ||
timeSource := &fakeTimeBackend{} | ||
// Tendermint epochtime has no registration | ||
if err := honestTendermint.RegisterApplication(beaconapp.New(timeSource, &beacon.Config{ | ||
DebugDeterministic: true, | ||
})); err != nil { | ||
panic("honestTendermint.RegisterApplication beacon: " + err.Error()) | ||
} | ||
if err := honestTendermint.RegisterApplication(stakingapp.New(nil)); err != nil { | ||
panic("honestTendermint.RegisterApplication staking: " + err.Error()) | ||
} | ||
if err := honestTendermint.RegisterApplication(registryapp.New(timeSource, ®istry.Config{ | ||
DebugAllowRuntimeRegistration: false, | ||
DebugBypassStake: false, | ||
})); err != nil { | ||
panic("honestTendermint.RegisterApplication registry: " + err.Error()) | ||
} | ||
if err := honestTendermint.RegisterApplication(keymanagerapp.New(timeSource)); err != nil { | ||
panic("honestTendermint.RegisterApplication keymanager: " + err.Error()) | ||
} | ||
if err := honestTendermint.RegisterApplication(schedulerapp.New(timeSource, &scheduler.Config{ | ||
DebugBypassStake: false, | ||
})); err != nil { | ||
panic("honestTendermint.RegisterApplication scheduler: " + err.Error()) | ||
} | ||
// storage has no registration | ||
if err := honestTendermint.RegisterApplication(roothashapp.New(context.Background(), timeSource, nil, 10*time.Second)); err != nil { | ||
panic("honestTendermint.RegisterApplication roothash: " + err.Error()) | ||
} | ||
|
||
if err := honestTendermint.Start(); err != nil { | ||
panic("honestTendermint.Start: " + err.Error()) | ||
} | ||
logger.Debug("honest Tendermint service start returned %%%") | ||
<-honestTendermint.Started() | ||
logger.Debug("honest Tendermint service start channel closed %%%") | ||
<-honestTendermint.Synced() | ||
logger.Debug("honest Tendermint service sync channel closed %%%") | ||
} | ||
|
||
func stopHonestTendermint() { | ||
if honestTendermint == nil { | ||
panic("honest Tendermint service not started") | ||
} | ||
|
||
honestTendermint.Stop() | ||
logger.Debug("honest Tendermint service stop returned %%%") | ||
<-honestTendermint.Quit() | ||
logger.Debug("honest Tendermint service quit channel closed %%%") | ||
honestTendermint = nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters