diff --git a/consensus/consensus.go b/consensus/consensus.go index 1043754f6e26118b44cdf8ee4288e64f063ca582..af8bb008da726e6573a8ab67132b2ead1ca07e9e 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -24,7 +24,7 @@ import ( definitions "github.com/eris-ltd/eris-db/definitions" ) -func LoadConsensusInPipe(moduleConfig *config.ModuleConfig, +func LoadConsensusEngineInPipe(moduleConfig *config.ModuleConfig, pipe definitions.Pipe) error { switch moduleConfig.Name { case "tendermint": @@ -34,14 +34,14 @@ func LoadConsensusInPipe(moduleConfig *config.ModuleConfig, return fmt.Errorf("Failed to load Tendermint node: %v", err) } - err = pipe.SetConsensus(tendermint) + err = pipe.SetConsensusEngine(tendermint) if err != nil { return fmt.Errorf("Failed to load Tendermint in pipe as "+ "ConsensusEngine: %v", err) } // For Tendermint we have a coupled Blockchain and ConsensusEngine - // implementation, so load it with Consensus + // implementation, so load it at the same time as ConsensusEngine err = pipe.SetBlockchain(tendermint) if err != nil { return fmt.Errorf("Failed to load Tendermint in pipe as "+ diff --git a/consensus/tendermint/tendermint.go b/consensus/tendermint/tendermint.go index c464918437edfdb18f50ef7e831241b603937ec7..a18e35311bc60c7ccc1051d2d30bd3143617dc25 100644 --- a/consensus/tendermint/tendermint.go +++ b/consensus/tendermint/tendermint.go @@ -50,7 +50,7 @@ type Tendermint struct { // Compiler checks to ensure Tendermint successfully implements // eris-db/definitions Consensus and Blockchain -var _ consensus_types.Consensus = (*Tendermint)(nil) +var _ consensus_types.ConsensusEngine = (*Tendermint)(nil) var _ blockchain_types.Blockchain = (*Tendermint)(nil) func NewTendermint(moduleConfig *config.ModuleConfig, diff --git a/consensus/types/consensus.go b/consensus/types/consensus_engine.go similarity index 94% rename from consensus/types/consensus.go rename to consensus/types/consensus_engine.go index 026903824ca11967c9086144955b8e3843b89a80..893ea85ecdbbd0504862236215bda7dcc5e09d55 100644 --- a/consensus/types/consensus.go +++ b/consensus/types/consensus_engine.go @@ -7,7 +7,7 @@ import ( tmsp_types "github.com/tendermint/tmsp/types" ) -type Consensus interface { +type ConsensusEngine interface { // Peer-2-Peer IsListening() bool Listeners() []p2p.Listener diff --git a/core/core.go b/core/core.go index 2b79d4fa366360bb11b0018dd71398498103c4f7..03f56b56a47927b09d8b2bdc9e5a2302da1fcd84 100644 --- a/core/core.go +++ b/core/core.go @@ -58,7 +58,7 @@ func NewCore(chainId string, consensusConfig *config.ModuleConfig, } log.Debug("Loaded pipe with application manager") // pass the consensus engine into the pipe - if e := consensus.LoadConsensusInPipe(consensusConfig, pipe); e != nil { + if e := consensus.LoadConsensusEngineInPipe(consensusConfig, pipe); e != nil { return nil, fmt.Errorf("Failed to load consensus engine in pipe: %v", e) } tendermintPipe, err := pipe.GetTendermintPipe() diff --git a/definitions/pipe.go b/definitions/pipe.go index 7b9e3200ffe37c48720bf21491612eade04f424d..0a045442a3fac19e655fad1e8aaf92fc24ed9d69 100644 --- a/definitions/pipe.go +++ b/definitions/pipe.go @@ -38,7 +38,7 @@ import ( type Pipe interface { Accounts() Accounts Blockchain() blockchain_types.Blockchain - Consensus() consensus_types.Consensus + Consensus() consensus_types.ConsensusEngine Events() event.EventEmitter NameReg() NameReg Net() Net @@ -47,8 +47,8 @@ type Pipe interface { GenesisHash() []byte // NOTE: [ben] added to Pipe interface on 0.12 refactor GetApplication() manager_types.Application - SetConsensus(consensus consensus_types.Consensus) error - GetConsensus() consensus_types.Consensus + SetConsensusEngine(consensusEngine consensus_types.ConsensusEngine) error + GetConsensusEngine() consensus_types.ConsensusEngine SetBlockchain(blockchain blockchain_types.Blockchain) error GetBlockchain() blockchain_types.Blockchain // Support for Tendermint RPC diff --git a/manager/eris-mint/pipe.go b/manager/eris-mint/pipe.go index 61ec36cad66d8157f95459043c469521d89b782a..2c6b5c3bec037ebf5545354cf093814f6be2d723 100644 --- a/manager/eris-mint/pipe.go +++ b/manager/eris-mint/pipe.go @@ -47,19 +47,19 @@ import ( ) type erisMintPipe struct { - erisMintState *state.State - erisMint *ErisMint + erisMintState *state.State + erisMint *ErisMint // Pipe implementations - accounts *accounts - blockchain blockchain_types.Blockchain - consensus consensus_types.Consensus - events edb_event.EventEmitter - namereg *namereg - network *network - transactor *transactor + accounts *accounts + blockchain blockchain_types.Blockchain + consensusEngine consensus_types.ConsensusEngine + events edb_event.EventEmitter + namereg *namereg + network *network + transactor *transactor // Genesis cache - genesisDoc *state_types.GenesisDoc - genesisState *state.State + genesisDoc *state_types.GenesisDoc + genesisState *state.State } // NOTE [ben] Compiler check to ensure erisMintPipe successfully implements @@ -115,7 +115,7 @@ func NewErisMintPipe(moduleConfig *config.ModuleConfig, network: newNetwork(), // consensus and blockchain should both be loaded into the pipe by a higher // authority - this is a sort of dependency injection pattern - consensus: nil, + consensusEngine: nil, blockchain: nil, }, nil } @@ -181,8 +181,8 @@ func (pipe *erisMintPipe) Blockchain() blockchain_types.Blockchain { return pipe.blockchain } -func (pipe *erisMintPipe) Consensus() consensus_types.Consensus { - return pipe.consensus +func (pipe *erisMintPipe) Consensus() consensus_types.ConsensusEngine { + return pipe.consensusEngine } func (pipe *erisMintPipe) Events() edb_event.EventEmitter { @@ -219,18 +219,18 @@ func (pipe *erisMintPipe) GetBlockchain() blockchain_types.Blockchain { return pipe.blockchain } -func (pipe *erisMintPipe) SetConsensus( - consensus consensus_types.Consensus) error { - if pipe.consensus == nil { - pipe.consensus = consensus +func (pipe *erisMintPipe) SetConsensusEngine( + consensusEngine consensus_types.ConsensusEngine) error { + if pipe.consensusEngine == nil { + pipe.consensusEngine = consensusEngine } else { return fmt.Errorf("Failed to set consensus engine for pipe; already set") } return nil } -func (pipe *erisMintPipe) GetConsensus() consensus_types.Consensus { - return pipe.consensus +func (pipe *erisMintPipe) GetConsensusEngine() consensus_types.ConsensusEngine { + return pipe.consensusEngine } func (pipe *erisMintPipe) GetTendermintPipe() (definitions.TendermintPipe, @@ -241,7 +241,7 @@ func (pipe *erisMintPipe) GetTendermintPipe() (definitions.TendermintPipe, func (pipe *erisMintPipe) consensusAndManagerEvents() edb_event.EventEmitter { // NOTE: [Silas] We could initialise this lazily and use the cached instance, // but for the time being that feels like a premature optimisation - return edb_event.Multiplex(pipe.events, pipe.consensus.Events()) + return edb_event.Multiplex(pipe.events, pipe.consensusEngine.Events()) } //------------------------------------------------------------------------------ @@ -288,7 +288,7 @@ func (pipe *erisMintPipe) GenesisHash() []byte { } func (pipe *erisMintPipe) Status() (*rpc_tm_types.ResultStatus, error) { - if pipe.consensus == nil { + if pipe.consensusEngine == nil { return nil, fmt.Errorf("Consensus Engine is not set in pipe.") } latestHeight := pipe.blockchain.Height() @@ -303,21 +303,21 @@ func (pipe *erisMintPipe) Status() (*rpc_tm_types.ResultStatus, error) { latestBlockTime = latestBlockMeta.Header.Time.UnixNano() } return &rpc_tm_types.ResultStatus{ - NodeInfo: pipe.consensus.NodeInfo(), + NodeInfo: pipe.consensusEngine.NodeInfo(), GenesisHash: pipe.GenesisHash(), - PubKey: pipe.consensus.PublicValidatorKey(), + PubKey: pipe.consensusEngine.PublicValidatorKey(), LatestBlockHash: latestBlockHash, LatestBlockHeight: latestHeight, LatestBlockTime: latestBlockTime}, nil } func (pipe *erisMintPipe) NetInfo() (*rpc_tm_types.ResultNetInfo, error) { - listening := pipe.consensus.IsListening() + listening := pipe.consensusEngine.IsListening() listeners := []string{} - for _, listener := range pipe.consensus.Listeners() { + for _, listener := range pipe.consensusEngine.Listeners() { listeners = append(listeners, listener.String()) } - peers := pipe.consensus.Peers() + peers := pipe.consensusEngine.Peers() return &rpc_tm_types.ResultNetInfo{ Listening: listening, Listeners: listeners, @@ -514,7 +514,7 @@ func (pipe *erisMintPipe) ListNames() (*rpc_tm_types.ResultListNames, error) { // NOTE: txs must be signed func (pipe *erisMintPipe) BroadcastTxAsync(tx txs.Tx) ( *rpc_tm_types.ResultBroadcastTx, error) { - err := pipe.consensus.BroadcastTransaction(txs.EncodeTx(tx), nil) + err := pipe.consensusEngine.BroadcastTransaction(txs.EncodeTx(tx), nil) if err != nil { return nil, fmt.Errorf("Error broadcasting txs: %v", err) } @@ -524,7 +524,7 @@ func (pipe *erisMintPipe) BroadcastTxAsync(tx txs.Tx) ( func (pipe *erisMintPipe) BroadcastTxSync(tx txs.Tx) (*rpc_tm_types.ResultBroadcastTx, error) { responseChannel := make(chan *tmsp_types.Response, 1) - err := pipe.consensus.BroadcastTransaction(txs.EncodeTx(tx), + err := pipe.consensusEngine.BroadcastTransaction(txs.EncodeTx(tx), func(res *tmsp_types.Response) { responseChannel <- res }) diff --git a/test/mock/pipe.go b/test/mock/pipe.go index 3f72055bcd1a548fd572eedc71412b8227c7d70a..78ba9d38783445c94f85e70f6871ca71dffd91c6 100644 --- a/test/mock/pipe.go +++ b/test/mock/pipe.go @@ -22,21 +22,21 @@ import ( // Base struct. type MockPipe struct { - testData *td.TestData - accounts definitions.Accounts - blockchain blockchain_types.Blockchain - consensus consensus_types.Consensus - events event.EventEmitter - namereg definitions.NameReg - net definitions.Net - transactor definitions.Transactor + testData *td.TestData + accounts definitions.Accounts + blockchain blockchain_types.Blockchain + consensusEngine consensus_types.ConsensusEngine + events event.EventEmitter + namereg definitions.NameReg + net definitions.Net + transactor definitions.Transactor } // Create a new mock tendermint pipe. func NewMockPipe(td *td.TestData) definitions.Pipe { accounts := &accounts{td} blockchain := &blockchain{td} - consensus := &consensus{td} + consensusEngine := &consensusEngine{td} eventer := &eventer{td} namereg := &namereg{td} net := &net{td} @@ -45,7 +45,7 @@ func NewMockPipe(td *td.TestData) definitions.Pipe { td, accounts, blockchain, - consensus, + consensusEngine, eventer, namereg, net, @@ -66,8 +66,8 @@ func (this *MockPipe) Blockchain() blockchain_types.Blockchain { return this.blockchain } -func (this *MockPipe) Consensus() consensus_types.Consensus { - return this.consensus +func (this *MockPipe) Consensus() consensus_types.ConsensusEngine { + return this.consensusEngine } func (this *MockPipe) Events() event.EventEmitter { @@ -91,12 +91,12 @@ func (this *MockPipe) GetApplication() manager_types.Application { return nil } -func (this *MockPipe) SetConsensus(_ consensus_types.Consensus) error { +func (this *MockPipe) SetConsensusEngine(_ consensus_types.ConsensusEngine) error { // TODO: [ben] mock consensus engine return nil } -func (this *MockPipe) GetConsensus() consensus_types.Consensus { +func (this *MockPipe) GetConsensusEngine() consensus_types.ConsensusEngine { return nil } @@ -170,32 +170,32 @@ func (this *blockchain) BlockMeta(height int) *mintTypes.BlockMeta { } // Consensus -type consensus struct { +type consensusEngine struct { testData *td.TestData } -func (cons *consensus) BroadcastTransaction(transaction []byte, +func (cons *consensusEngine) BroadcastTransaction(transaction []byte, callback func(*tmsp_types.Response)) error { return nil } -func (cons *consensus) IsListening() bool { +func (cons *consensusEngine) IsListening() bool { return true } -func (cons *consensus) Listeners() []p2p.Listener { +func (cons *consensusEngine) Listeners() []p2p.Listener { return make([]p2p.Listener, 0) } -func (cons *consensus) NodeInfo() *p2p.NodeInfo { +func (cons *consensusEngine) NodeInfo() *p2p.NodeInfo { return &p2p.NodeInfo{} } -func (cons *consensus) Peers() []consensus_types.Peer { +func (cons *consensusEngine) Peers() []consensus_types.Peer { return make([]consensus_types.Peer, 0) } -func (cons *consensus) PublicValidatorKey() crypto.PubKey { +func (cons *consensusEngine) PublicValidatorKey() crypto.PubKey { return crypto.PubKeyEd25519{ 1,2,3,4,5,6,7,8, 1,2,3,4,5,6,7,8, @@ -204,7 +204,7 @@ func (cons *consensus) PublicValidatorKey() crypto.PubKey { } } -func (cons *consensus) Events() event.EventEmitter { +func (cons *consensusEngine) Events() event.EventEmitter { return nil }