diff --git a/blockchain/reactor.go b/blockchain/reactor.go index bfa671d0..4a7f21d0 100644 --- a/blockchain/reactor.go +++ b/blockchain/reactor.go @@ -242,7 +242,7 @@ FOR_LOOP: // NOTE: we could improve performance if we // didn't make the app commit to disk every block // ... but we would need a way to get the hash without it persisting - err := bcR.state.ApplyBlock(bcR.evsw, bcR.proxyAppConn, first, firstPartsHeader, sm.MockMempool{}) + err := bcR.state.ApplyBlock(bcR.evsw, bcR.proxyAppConn, first, firstPartsHeader, types.MockMempool{}) if err != nil { // TODO This is bad, are we zombie? PanicQ(Fmt("Failed to process committed block (%d:%X): %v", first.Height, first.Hash(), err)) diff --git a/consensus/replay.go b/consensus/replay.go index 2ab84dc2..07308bf1 100644 --- a/consensus/replay.go +++ b/consensus/replay.go @@ -175,8 +175,8 @@ func makeHeightSearchFunc(height int) auto.SearchFunc { // we were last and using the WAL to recover there // Replay the last block through the consensus and return the AppHash from after Commit. -func replayLastBlock(config cfg.Config, state *sm.State, proxyApp proxy.AppConnConsensus, blockStore sm.BlockStore) ([]byte, error) { - mempool := sm.MockMempool{} +func replayLastBlock(config cfg.Config, state *sm.State, proxyApp proxy.AppConnConsensus, blockStore types.BlockStore) ([]byte, error) { + mempool := types.MockMempool{} cs := NewConsensusState(config, state, proxyApp, blockStore, mempool) evsw := types.NewEventSwitch() @@ -196,12 +196,12 @@ func replayLastBlock(config cfg.Config, state *sm.State, proxyApp proxy.AppConnC type Handshaker struct { config cfg.Config state *sm.State - store sm.BlockStore + store types.BlockStore nBlocks int // number of blocks applied to the state } -func NewHandshaker(config cfg.Config, state *sm.State, store sm.BlockStore) *Handshaker { +func NewHandshaker(config cfg.Config, state *sm.State, store types.BlockStore) *Handshaker { return &Handshaker{config, state, store, 0} } diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 3016f104..2d812de9 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -254,7 +254,7 @@ func testReplayCrashBeforeWriteVote(t *testing.T, thisCase *testCase, lineNum in var ( NUM_BLOCKS = 6 // number of blocks in the test_data/many_blocks.cswal - mempool = sm.MockMempool{} + mempool = types.MockMempool{} testPartSize int ) diff --git a/consensus/state.go b/consensus/state.go index dc1324e3..882d5c87 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -224,8 +224,8 @@ type ConsensusState struct { config cfg.Config proxyAppConn proxy.AppConnConsensus - blockStore sm.BlockStore - mempool sm.Mempool + blockStore types.BlockStore + mempool types.Mempool privValidator PrivValidator // for signing votes @@ -253,7 +253,7 @@ type ConsensusState struct { done chan struct{} } -func NewConsensusState(config cfg.Config, state *sm.State, proxyAppConn proxy.AppConnConsensus, blockStore sm.BlockStore, mempool sm.Mempool) *ConsensusState { +func NewConsensusState(config cfg.Config, state *sm.State, proxyAppConn proxy.AppConnConsensus, blockStore types.BlockStore, mempool types.Mempool) *ConsensusState { cs := &ConsensusState{ config: config, proxyAppConn: proxyAppConn, diff --git a/rpc/core/pipe.go b/rpc/core/pipe.go index fb06c3ff..40ef7081 100644 --- a/rpc/core/pipe.go +++ b/rpc/core/pipe.go @@ -5,36 +5,19 @@ import ( "github.com/tendermint/go-crypto" "github.com/tendermint/go-p2p" - abci "github.com/tendermint/abci/types" "github.com/tendermint/tendermint/consensus" "github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/types" ) -//----------------------------------------------------- -// Interfaces for use by RPC -// NOTE: these methods must be thread safe! - -type BlockStore interface { - Height() int - LoadBlockMeta(height int) *types.BlockMeta - LoadBlock(height int) *types.Block - LoadSeenCommit(height int) *types.Commit - LoadBlockCommit(height int) *types.Commit -} +//---------------------------------------------- +// These interfaces are used by RPC and must be thread safe type Consensus interface { GetValidators() (int, []*types.Validator) GetRoundState() *consensus.RoundState } -type Mempool interface { - Size() int - CheckTx(types.Tx, func(*abci.Response)) error - Reap(int) types.Txs - Flush() -} - type P2P interface { Listeners() []p2p.Listener Peers() p2p.IPeerSet @@ -44,16 +27,18 @@ type P2P interface { DialSeeds([]string) } +//---------------------------------------------- + var ( // external, thread safe interfaces eventSwitch types.EventSwitch proxyAppQuery proxy.AppConnQuery config cfg.Config - // interfaces defined above - blockStore BlockStore + // interfaces defined in types and above + blockStore types.BlockStore + mempool types.Mempool consensusState Consensus - mempool Mempool p2pSwitch P2P // objects @@ -69,18 +54,18 @@ func SetEventSwitch(evsw types.EventSwitch) { eventSwitch = evsw } -func SetBlockStore(bs BlockStore) { +func SetBlockStore(bs types.BlockStore) { blockStore = bs } +func SetMempool(mem types.Mempool) { + mempool = mem +} + func SetConsensusState(cs Consensus) { consensusState = cs } -func SetMempool(mem Mempool) { - mempool = mem -} - func SetSwitch(sw P2P) { p2pSwitch = sw } diff --git a/state/execution.go b/state/execution.go index 3e7ad91b..aa911301 100644 --- a/state/execution.go +++ b/state/execution.go @@ -223,7 +223,7 @@ func (s *State) validateBlock(block *types.Block) error { // Execute and commit block against app, save block and state func (s *State) ApplyBlock(eventCache types.Fireable, proxyAppConn proxy.AppConnConsensus, - block *types.Block, partsHeader types.PartSetHeader, mempool Mempool) error { + block *types.Block, partsHeader types.PartSetHeader, mempool types.Mempool) error { // Run the block on the State: // + update validator sets @@ -244,7 +244,7 @@ func (s *State) ApplyBlock(eventCache types.Fireable, proxyAppConn proxy.AppConn // mempool must be locked during commit and update // because state is typically reset on Commit and old txs must be replayed // against committed state before new txs are run in the mempool, lest they be invalid -func (s *State) CommitStateUpdateMempool(proxyAppConn proxy.AppConnConsensus, block *types.Block, mempool Mempool) error { +func (s *State) CommitStateUpdateMempool(proxyAppConn proxy.AppConnConsensus, block *types.Block, mempool types.Mempool) error { mempool.Lock() defer mempool.Unlock() @@ -288,40 +288,3 @@ func ApplyBlock(appConnConsensus proxy.AppConnConsensus, block *types.Block) ([] } return res.Data, nil } - -//------------------------------------------------------ -// blockchain services types - -// Updates to the mempool need to be synchronized with committing a block -// so apps can reset their transient state on Commit -type Mempool interface { - Lock() - Unlock() - - CheckTx(types.Tx, func(*abci.Response)) error - Reap(int) types.Txs - Update(height int, txs types.Txs) -} - -type MockMempool struct { -} - -func (m MockMempool) Lock() {} -func (m MockMempool) Unlock() {} -func (m MockMempool) CheckTx(tx types.Tx, cb func(*abci.Response)) error { return nil } -func (m MockMempool) Reap(n int) types.Txs { return types.Txs{} } -func (m MockMempool) Update(height int, txs types.Txs) {} - -// TODO: Should we move blockchain/store.go to its own package? -type BlockStore interface { - Height() int - - LoadBlockMeta(height int) *types.BlockMeta - LoadBlock(height int) *types.Block - LoadBlockPart(height int, index int) *types.Part - - SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) - - LoadBlockCommit(height int) *types.Commit - LoadSeenCommit(height int) *types.Commit -} diff --git a/types/services.go b/types/services.go new file mode 100644 index 00000000..ee20487e --- /dev/null +++ b/types/services.go @@ -0,0 +1,56 @@ +package types + +import ( + abci "github.com/tendermint/abci/types" +) + +//------------------------------------------------------ +// blockchain services types +// NOTE: Interfaces used by RPC must be thread safe! +//------------------------------------------------------ + +//------------------------------------------------------ +// mempool + +// Updates to the mempool need to be synchronized with committing a block +// so apps can reset their transient state on Commit +type Mempool interface { + Lock() + Unlock() + + Size() int + CheckTx(Tx, func(*abci.Response)) error + Reap(int) Txs + Update(height int, txs Txs) + Flush() +} + +type MockMempool struct { +} + +func (m MockMempool) Lock() {} +func (m MockMempool) Unlock() {} +func (m MockMempool) Size() int { return 0 } +func (m MockMempool) CheckTx(tx Tx, cb func(*abci.Response)) error { return nil } +func (m MockMempool) Reap(n int) Txs { return Txs{} } +func (m MockMempool) Update(height int, txs Txs) {} +func (m MockMempool) Flush() {} + +//------------------------------------------------------ +// blockstore + +type BlockStoreRPC interface { + Height() int + + LoadBlockMeta(height int) *BlockMeta + LoadBlock(height int) *Block + LoadBlockPart(height int, index int) *Part + + LoadBlockCommit(height int) *Commit + LoadSeenCommit(height int) *Commit +} + +type BlockStore interface { + BlockStoreRPC + SaveBlock(block *Block, blockParts *PartSet, seenCommit *Commit) +}