diff --git a/erisdb/pipe/consensus.go b/erisdb/pipe/consensus.go index 1ca1f47206d56bc43526983aa344b172bd4b3123..2d5ecdf2489afb568500610d0237309357f92334 100644 --- a/erisdb/pipe/consensus.go +++ b/erisdb/pipe/consensus.go @@ -23,7 +23,7 @@ func (this *consensus) State() (*ConsensusState, error) { peerRoundStates := []string{} for _, peer := range this.p2pSwitch.Peers().List() { // TODO: clean this up? - peerState := peer.Data.Get(cm.PeerStateKey).(*cm.PeerState) + peerState := peer.Data.Get(types.PeerStateKey).(*cm.PeerState) peerRoundState := peerState.GetRoundState() peerRoundStateStr := peer.Key + ":" + string(wire.JSONBytes(peerRoundState)) peerRoundStates = append(peerRoundStates, peerRoundStateStr) diff --git a/erisdb/serve.go b/erisdb/serve.go index 5727c4a402c8ad4b04c43d50f431a057e2517afc..adf5c4d8e0696e5d6179ff415afd4dfd844fece5 100644 --- a/erisdb/serve.go +++ b/erisdb/serve.go @@ -3,15 +3,24 @@ package erisdb import ( + "encoding/hex" + "fmt" + "path" + "strings" + + ep "github.com/eris-ltd/eris-db/erisdb/pipe" + "github.com/eris-ltd/eris-db/server" + + "github.com/eris-ltd/mint-client/mintx/core" + "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/log15" + acm "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/account" . "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/common" cfg "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/config" tmcfg "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/config/tendermint" "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/node" "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/p2p" - ep "github.com/eris-ltd/eris-db/erisdb/pipe" - "github.com/eris-ltd/eris-db/server" - "path" + "github.com/eris-ltd/eris-db/Godeps/_workspace/src/github.com/tendermint/tendermint/types" ) const ERISDB_VERSION = "0.11.5" @@ -56,9 +65,28 @@ func ServeErisDB(workDir string) (*server.ServeProcess, error) { tmConfig.Set("version", TENDERMINT_VERSION) cfg.ApplyConfig(tmConfig) // Notify modules of new config + // load the priv validator + privVal := types.LoadPrivValidator(tmConfig.GetString("priv_validator_file")) + + // possibly set the signer to use eris-keys + signerCfg := tmConfig.GetString("signer") + if !(signerCfg == "default" || signerCfg == "") { + spl := strings.Split(signerCfg, ":") + if len(spl) != 2 { + panic(`"signer" field in config.toml should be "default" or "ERIS_KEYS_HOST:ERIS_KEYS_PORT"`) + } + + // TODO: if a privKey is found in the privVal, warn the user that we want to import it to eris-keys and delete it + + host := signerCfg + addr := hex.EncodeToString(privVal.Address) + signer := NewErisSigner(host, addr) + privVal.SetSigner(signer) + } + // Set the node up. nodeRd := make(chan struct{}) - nd := node.NewNode() + nd := node.NewNode(privVal) // Load the supporting objects. pipe := ep.NewPipe(nd) codec := &TCodec{} @@ -103,3 +131,25 @@ func startNode(nd *node.Node, ready chan struct{}, shutDown <-chan struct{}) { <-shutDown nd.Stop() } + +type ErisSigner struct { + Host string + Address string + SessionKey string +} + +func NewErisSigner(host, address string) *ErisSigner { + if !strings.HasPrefix(host, "http://") { + host = fmt.Sprintf("http://%s", host) + } + return &ErisSigner{Host: host, Address: address} +} + +func (es *ErisSigner) Sign(msg []byte) acm.SignatureEd25519 { + msgHex := hex.EncodeToString(msg) + sig, err := core.Sign(msgHex, es.Address, es.Host) + if err != nil { + panic(err) + } + return acm.SignatureEd25519(sig) +}