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/p2p"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/tmstore"
"github.com/tendermint/tendermint/store"
"github.com/tendermint/tendermint/types"
)
@ -61,7 +61,7 @@ type BlockchainReactor struct {
initialState sm.State
blockExec *sm.BlockExecutor
store *tmstore.BlockStore
store *store.BlockStore
pool *BlockPool
fastSync bool
@ -70,7 +70,7 @@ type BlockchainReactor struct {
}
// 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 {
if state.LastBlockHeight != store.Height() {

View File

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

View File

@ -11,7 +11,7 @@ import (
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/p2p"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/tmstore"
"github.com/tendermint/tendermint/store"
"github.com/tendermint/tendermint/types"
)
@ -54,7 +54,7 @@ type BlockchainReactor struct {
state sm.State
blockExec *sm.BlockExecutor
store *tmstore.BlockStore
store *store.BlockStore
fastSync bool
@ -74,7 +74,7 @@ type BlockchainReactor struct {
}
// 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 {
if state.LastBlockHeight != store.Height() {

View File

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

View File

@ -671,7 +671,7 @@ type FastSyncParamsConfig struct {
// DefaultFastSyncParamsConfig returns a default configuration for the fast sync service
func DefaultFastSyncParamsConfig() *FastSyncParamsConfig {
return &FastSyncParamsConfig{
Version: "legacy",
Version: "v0",
}
}
@ -682,12 +682,12 @@ func TestFastSyncParamsConfig() *FastSyncParamsConfig {
func (cfg *FastSyncParamsConfig) ValidateBasic() error {
switch cfg.Version {
case "legacy":
case "v0":
return nil
case "experimental":
case "v1":
return nil
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
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]
@ -356,15 +364,6 @@ max_open_connections = {{ .Instrumentation.MaxOpenConnections }}
# 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 ***********/

View File

@ -30,7 +30,7 @@ import (
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/privval"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/tmstore"
"github.com/tendermint/tendermint/store"
"github.com/tendermint/tendermint/types"
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 {
// Get BlockStore
blockStore := tmstore.NewBlockStore(blockDB)
blockStore := store.NewBlockStore(blockDB)
// one for mempool, one for consensus
mtx := new(sync.Mutex)

View File

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

View File

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

View File

@ -20,7 +20,7 @@ import (
"github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/proxy"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/tmstore"
"github.com/tendermint/tendermint/store"
"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
sm.SaveState(stateDB, state)
blockStore := tmstore.NewBlockStore(blockStoreDB)
blockStore := store.NewBlockStore(blockStoreDB)
proxyApp := proxy.NewAppConns(proxy.NewLocalClientCreator(app))
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
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]

View File

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

View File

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

View File

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

View File

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