Browse Source

move some interfaces to types/services.go

pull/408/head
Ethan Buchman 7 years ago
parent
commit
f9df4294f3
7 changed files with 79 additions and 75 deletions
  1. +1
    -1
      blockchain/reactor.go
  2. +4
    -4
      consensus/replay.go
  3. +1
    -1
      consensus/replay_test.go
  4. +3
    -3
      consensus/state.go
  5. +12
    -27
      rpc/core/pipe.go
  6. +2
    -39
      state/execution.go
  7. +56
    -0
      types/services.go

+ 1
- 1
blockchain/reactor.go View File

@ -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))


+ 4
- 4
consensus/replay.go View File

@ -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}
}


+ 1
- 1
consensus/replay_test.go View File

@ -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
)


+ 3
- 3
consensus/state.go View File

@ -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,


+ 12
- 27
rpc/core/pipe.go View File

@ -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,16 +54,16 @@ func SetEventSwitch(evsw types.EventSwitch) {
eventSwitch = evsw
}
func SetBlockStore(bs BlockStore) {
func SetBlockStore(bs types.BlockStore) {
blockStore = bs
}
func SetConsensusState(cs Consensus) {
consensusState = cs
func SetMempool(mem types.Mempool) {
mempool = mem
}
func SetMempool(mem Mempool) {
mempool = mem
func SetConsensusState(cs Consensus) {
consensusState = cs
}
func SetSwitch(sw P2P) {


+ 2
- 39
state/execution.go View File

@ -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
}

+ 56
- 0
types/services.go View File

@ -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)
}

Loading…
Cancel
Save