move both reactor versions under blockchain

This commit is contained in:
Anca Zamfir
2019-06-19 11:32:26 +02:00
parent f0559a05b0
commit 7bf1683077
25 changed files with 78 additions and 55 deletions

View File

@ -11,7 +11,7 @@ import (
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/tmstore" "github.com/tendermint/tendermint/store"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
@ -61,7 +61,7 @@ type BlockchainReactor struct {
initialState sm.State initialState sm.State
blockExec *sm.BlockExecutor blockExec *sm.BlockExecutor
store *tmstore.BlockStore store *store.BlockStore
pool *BlockPool pool *BlockPool
fastSync bool fastSync bool
@ -70,7 +70,7 @@ type BlockchainReactor struct {
} }
// NewBlockchainReactor returns new reactor instance. // NewBlockchainReactor returns new reactor instance.
func NewBlockchainReactor(state sm.State, blockExec *sm.BlockExecutor, store *tmstore.BlockStore, func NewBlockchainReactor(state sm.State, blockExec *sm.BlockExecutor, store *store.BlockStore,
fastSync bool) *BlockchainReactor { fastSync bool) *BlockchainReactor {
if state.LastBlockHeight != store.Height() { if state.LastBlockHeight != store.Height() {

View File

@ -6,7 +6,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/tendermint/tendermint/tmstore" "github.com/tendermint/tendermint/store"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -83,7 +83,7 @@ func newBlockchainReactor(logger log.Logger, genDoc *types.GenesisDoc, privVals
blockDB := dbm.NewMemDB() blockDB := dbm.NewMemDB()
stateDB := dbm.NewMemDB() stateDB := dbm.NewMemDB()
blockStore := tmstore.NewBlockStore(blockDB) blockStore := store.NewBlockStore(blockDB)
state, err := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc) state, err := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
if err != nil { if err != nil {

View File

@ -11,7 +11,7 @@ import (
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/tmstore" "github.com/tendermint/tendermint/store"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
@ -54,7 +54,7 @@ type BlockchainReactor struct {
state sm.State state sm.State
blockExec *sm.BlockExecutor blockExec *sm.BlockExecutor
store *tmstore.BlockStore store *store.BlockStore
fastSync bool fastSync bool
@ -74,7 +74,7 @@ type BlockchainReactor struct {
} }
// NewBlockchainReactor returns new reactor instance. // NewBlockchainReactor returns new reactor instance.
func NewBlockchainReactor(state sm.State, blockExec *sm.BlockExecutor, store *tmstore.BlockStore, func NewBlockchainReactor(state sm.State, blockExec *sm.BlockExecutor, store *store.BlockStore,
fastSync bool) *BlockchainReactor { fastSync bool) *BlockchainReactor {
if state.LastBlockHeight != store.Height() { if state.LastBlockHeight != store.Height() {

View File

@ -18,7 +18,7 @@ import (
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/tmstore" "github.com/tendermint/tendermint/store"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time" tmtime "github.com/tendermint/tendermint/types/time"
) )
@ -83,7 +83,7 @@ func newBlockchainReactor(logger log.Logger, genDoc *types.GenesisDoc, privVals
blockDB := dbm.NewMemDB() blockDB := dbm.NewMemDB()
stateDB := dbm.NewMemDB() stateDB := dbm.NewMemDB()
blockStore := tmstore.NewBlockStore(blockDB) blockStore := store.NewBlockStore(blockDB)
state, err := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc) state, err := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
if err != nil { if err != nil {

View File

@ -671,7 +671,7 @@ type FastSyncParamsConfig struct {
// DefaultFastSyncParamsConfig returns a default configuration for the fast sync service // DefaultFastSyncParamsConfig returns a default configuration for the fast sync service
func DefaultFastSyncParamsConfig() *FastSyncParamsConfig { func DefaultFastSyncParamsConfig() *FastSyncParamsConfig {
return &FastSyncParamsConfig{ return &FastSyncParamsConfig{
Version: "legacy", Version: "v0",
} }
} }
@ -682,12 +682,12 @@ func TestFastSyncParamsConfig() *FastSyncParamsConfig {
func (cfg *FastSyncParamsConfig) ValidateBasic() error { func (cfg *FastSyncParamsConfig) ValidateBasic() error {
switch cfg.Version { switch cfg.Version {
case "legacy": case "v0":
return nil return nil
case "experimental": case "v1":
return nil return nil
default: default:
return errors.New("unknown fast sync version") return fmt.Errorf("unknown fastsync version %s", cfg.Version)
} }
} }

View File

@ -286,6 +286,14 @@ max_txs_bytes = {{ .Mempool.MaxTxsBytes }}
# Size of the cache (used to filter transactions we saw earlier) in transactions # Size of the cache (used to filter transactions we saw earlier) in transactions
cache_size = {{ .Mempool.CacheSize }} cache_size = {{ .Mempool.CacheSize }}
##### fast sync configuration options #####
[fastsync]
# Fast Sync version to use:
# 1) "v0" (default) - the legacy fast sync implementation
# 2) "v1" - refactor of v0 version for better testability
version = "{{ .FastSyncParams.Version }}"
##### consensus configuration options ##### ##### consensus configuration options #####
[consensus] [consensus]
@ -356,15 +364,6 @@ max_open_connections = {{ .Instrumentation.MaxOpenConnections }}
# Instrumentation namespace # Instrumentation namespace
namespace = "{{ .Instrumentation.Namespace }}" namespace = "{{ .Instrumentation.Namespace }}"
##### fast sync configuration options #####
[fastsync]
# Fast Sync version to use:
# 1) "experimental"
# 2) "legacy" (default)
version = "{{ .FastSyncParams.Version }}"
` `
/****** these are for test settings ***********/ /****** these are for test settings ***********/

View File

@ -30,7 +30,7 @@ import (
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/privval"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/tmstore" "github.com/tendermint/tendermint/store"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time" tmtime "github.com/tendermint/tendermint/types/time"
) )
@ -280,7 +280,7 @@ func newConsensusStateWithConfig(thisConfig *cfg.Config, state sm.State, pv type
func newConsensusStateWithConfigAndBlockStore(thisConfig *cfg.Config, state sm.State, pv types.PrivValidator, app abci.Application, blockDB dbm.DB) *ConsensusState { func newConsensusStateWithConfigAndBlockStore(thisConfig *cfg.Config, state sm.State, pv types.PrivValidator, app abci.Application, blockDB dbm.DB) *ConsensusState {
// Get BlockStore // Get BlockStore
blockStore := tmstore.NewBlockStore(blockDB) blockStore := store.NewBlockStore(blockDB)
// one for mempool, one for consensus // one for mempool, one for consensus
mtx := new(sync.Mutex) mtx := new(sync.Mutex)

View File

@ -24,7 +24,7 @@ import (
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/p2p/mock" "github.com/tendermint/tendermint/p2p/mock"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/tmstore" "github.com/tendermint/tendermint/store"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
@ -133,7 +133,7 @@ func TestReactorWithEvidence(t *testing.T) {
// css[i] = newConsensusStateWithConfig(thisConfig, state, privVals[i], app) // css[i] = newConsensusStateWithConfig(thisConfig, state, privVals[i], app)
blockDB := dbm.NewMemDB() blockDB := dbm.NewMemDB()
blockStore := tmstore.NewBlockStore(blockDB) blockStore := store.NewBlockStore(blockDB)
// one for mempool, one for consensus // one for mempool, one for consensus
mtx := new(sync.Mutex) mtx := new(sync.Mutex)

View File

@ -18,7 +18,7 @@ import (
"github.com/tendermint/tendermint/mock" "github.com/tendermint/tendermint/mock"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/tmstore" "github.com/tendermint/tendermint/store"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
@ -280,7 +280,7 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo
dbType := dbm.DBBackendType(config.DBBackend) dbType := dbm.DBBackendType(config.DBBackend)
// Get BlockStore // Get BlockStore
blockStoreDB := dbm.NewDB("blockstore", dbType, config.DBDir()) blockStoreDB := dbm.NewDB("blockstore", dbType, config.DBDir())
blockStore := tmstore.NewBlockStore(blockStoreDB) blockStore := store.NewBlockStore(blockStoreDB)
// Get State // Get State
stateDB := dbm.NewDB("state", dbType, config.DBDir()) stateDB := dbm.NewDB("state", dbType, config.DBDir())

View File

@ -20,7 +20,7 @@ import (
"github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/tmstore" "github.com/tendermint/tendermint/store"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
@ -55,7 +55,7 @@ func WALGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int) (err error) {
} }
state.Version.Consensus.App = kvstore.ProtocolVersion state.Version.Consensus.App = kvstore.ProtocolVersion
sm.SaveState(stateDB, state) sm.SaveState(stateDB, state)
blockStore := tmstore.NewBlockStore(blockStoreDB) blockStore := store.NewBlockStore(blockStoreDB)
proxyApp := proxy.NewAppConns(proxy.NewLocalClientCreator(app)) proxyApp := proxy.NewAppConns(proxy.NewLocalClientCreator(app))
proxyApp.SetLogger(logger.With("module", "proxy")) proxyApp.SetLogger(logger.With("module", "proxy"))

View File

@ -232,6 +232,14 @@ max_txs_bytes = 1073741824
# Size of the cache (used to filter transactions we saw earlier) in transactions # Size of the cache (used to filter transactions we saw earlier) in transactions
cache_size = 10000 cache_size = 10000
##### fast sync configuration options #####
[fastsync]
# Fast Sync version to use:
# 1) "v0" (default) - the legacy fast sync implementation
# 2) "v1" - refactor of v0 version for better testability
version = "v0"
##### consensus configuration options ##### ##### consensus configuration options #####
[consensus] [consensus]

View File

@ -18,8 +18,8 @@ import (
amino "github.com/tendermint/go-amino" amino "github.com/tendermint/go-amino"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
bc "github.com/tendermint/tendermint/blockchain" bcv0 "github.com/tendermint/tendermint/blockchain/v0"
bcexp "github.com/tendermint/tendermint/blockchainexp" bcv1 "github.com/tendermint/tendermint/blockchain/v1"
cfg "github.com/tendermint/tendermint/config" cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/consensus" "github.com/tendermint/tendermint/consensus"
cs "github.com/tendermint/tendermint/consensus" cs "github.com/tendermint/tendermint/consensus"
@ -42,7 +42,7 @@ import (
"github.com/tendermint/tendermint/state/txindex" "github.com/tendermint/tendermint/state/txindex"
"github.com/tendermint/tendermint/state/txindex/kv" "github.com/tendermint/tendermint/state/txindex/kv"
"github.com/tendermint/tendermint/state/txindex/null" "github.com/tendermint/tendermint/state/txindex/null"
"github.com/tendermint/tendermint/tmstore" "github.com/tendermint/tendermint/store"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time" tmtime "github.com/tendermint/tendermint/types/time"
"github.com/tendermint/tendermint/version" "github.com/tendermint/tendermint/version"
@ -160,7 +160,7 @@ type Node struct {
// services // services
eventBus *types.EventBus // pub/sub for services eventBus *types.EventBus // pub/sub for services
stateDB dbm.DB stateDB dbm.DB
blockStore *tmstore.BlockStore // store the blockchain to disk blockStore *store.BlockStore // store the blockchain to disk
bcReactor p2p.Reactor // for fast-syncing bcReactor p2p.Reactor // for fast-syncing
mempoolReactor *mempl.Reactor // for gossipping transactions mempoolReactor *mempl.Reactor // for gossipping transactions
mempool mempl.Mempool mempool mempl.Mempool
@ -175,13 +175,13 @@ type Node struct {
prometheusSrv *http.Server prometheusSrv *http.Server
} }
func initDBs(config *cfg.Config, dbProvider DBProvider) (blockStore *tmstore.BlockStore, stateDB dbm.DB, err error) { func initDBs(config *cfg.Config, dbProvider DBProvider) (blockStore *store.BlockStore, stateDB dbm.DB, err error) {
var blockStoreDB dbm.DB var blockStoreDB dbm.DB
blockStoreDB, err = dbProvider(&DBContext{"blockstore", config}) blockStoreDB, err = dbProvider(&DBContext{"blockstore", config})
if err != nil { if err != nil {
return return
} }
blockStore = tmstore.NewBlockStore(blockStoreDB) blockStore = store.NewBlockStore(blockStoreDB)
stateDB, err = dbProvider(&DBContext{"state", config}) stateDB, err = dbProvider(&DBContext{"state", config})
if err != nil { if err != nil {
@ -322,6 +322,26 @@ func createEvidenceReactor(config *cfg.Config, dbProvider DBProvider,
return evidenceReactor, evidencePool, nil return evidenceReactor, evidencePool, nil
} }
func createBlockchainReactor(config *cfg.Config,
state sm.State,
blockExec *sm.BlockExecutor,
blockStore *store.BlockStore,
fastSync bool,
logger log.Logger) (bcReactor p2p.Reactor, err error) {
switch config.FastSyncParams.Version {
case "v0":
bcReactor = bcv0.NewBlockchainReactor(state.Copy(), blockExec, blockStore, fastSync)
case "v1":
bcReactor = bcv1.NewBlockchainReactor(state.Copy(), blockExec, blockStore, fastSync)
default:
return nil, fmt.Errorf("unknown fastsync version %s", config.FastSyncParams.Version)
}
bcReactor.SetLogger(logger.With("module", "blockchain"))
return bcReactor, nil
}
func createConsensusReactor(config *cfg.Config, func createConsensusReactor(config *cfg.Config,
state sm.State, state sm.State,
blockExec *sm.BlockExecutor, blockExec *sm.BlockExecutor,
@ -566,17 +586,11 @@ func NewNode(config *cfg.Config,
) )
// Make BlockchainReactor // Make BlockchainReactor
var bcReactor p2p.Reactor bcReactor, err := createBlockchainReactor(config, state, blockExec, blockStore, fastSync, logger)
// Make BlockchainReactor if err != nil {
switch config.FastSyncParams.Version { return nil, errors.Wrap(err, "could not create blockchain reactor")
case "experimental":
bcReactor = bcexp.NewBlockchainReactor(state.Copy(), blockExec, blockStore, fastSync)
default:
bcReactor = bc.NewBlockchainReactor(state.Copy(), blockExec, blockStore, fastSync)
} }
bcReactor.SetLogger(logger.With("module", "blockchain"))
// Make ConsensusReactor // Make ConsensusReactor
consensusReactor, consensusState := createConsensusReactor( consensusReactor, consensusState := createConsensusReactor(
config, state, blockExec, blockStore, mempool, evidencePool, config, state, blockExec, blockStore, mempool, evidencePool,
@ -895,7 +909,7 @@ func (n *Node) Switch() *p2p.Switch {
} }
// BlockStore returns the Node's BlockStore. // BlockStore returns the Node's BlockStore.
func (n *Node) BlockStore() *tmstore.BlockStore { func (n *Node) BlockStore() *store.BlockStore {
return n.blockStore return n.blockStore
} }
@ -986,10 +1000,12 @@ func makeNodeInfo(
var bcChannel byte var bcChannel byte
switch config.FastSyncParams.Version { switch config.FastSyncParams.Version {
case "experimental": case "v0":
bcChannel = bcexp.BlockchainChannel bcChannel = bcv0.BlockchainChannel
case "v1":
bcChannel = bcv1.BlockchainChannel
default: default:
bcChannel = bc.BlockchainChannel return nil, fmt.Errorf("unknown fastsync version %s", config.FastSyncParams.Version)
} }
nodeInfo := p2p.DefaultNodeInfo{ nodeInfo := p2p.DefaultNodeInfo{

View File

@ -1,4 +1,4 @@
package tmstore package store
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package tmstore package store
import ( import (
"bytes" "bytes"

View File

@ -1,4 +1,4 @@
package tmstore package store
import ( import (
amino "github.com/tendermint/go-amino" amino "github.com/tendermint/go-amino"