From 29c0e6e4f49c664c8c708085c7ad7541c2daf2f6 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Fri, 28 Apr 2017 23:50:24 -0400 Subject: [PATCH] remove viper from blockchain and state --- blockchain/reactor.go | 8 ++------ node/node.go | 4 ++-- state/state.go | 5 ++--- types/block.go | 5 ++++- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/blockchain/reactor.go b/blockchain/reactor.go index 1ea5650ed..0d51d124c 100644 --- a/blockchain/reactor.go +++ b/blockchain/reactor.go @@ -6,8 +6,6 @@ import ( "reflect" "time" - "github.com/spf13/viper" - "github.com/tendermint/go-wire" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/proxy" @@ -44,7 +42,6 @@ type consensusReactor interface { type BlockchainReactor struct { p2p.BaseReactor - config *viper.Viper state *sm.State proxyAppConn proxy.AppConnConsensus // same as consensus.proxyAppConn store *BlockStore @@ -58,7 +55,7 @@ type BlockchainReactor struct { } // NewBlockchainReactor returns new reactor instance. -func NewBlockchainReactor(config *viper.Viper, state *sm.State, proxyAppConn proxy.AppConnConsensus, store *BlockStore, fastSync bool) *BlockchainReactor { +func NewBlockchainReactor(state *sm.State, proxyAppConn proxy.AppConnConsensus, store *BlockStore, fastSync bool) *BlockchainReactor { if state.LastBlockHeight == store.Height()-1 { store.height-- // XXX HACK, make this better } @@ -73,7 +70,6 @@ func NewBlockchainReactor(config *viper.Viper, state *sm.State, proxyAppConn pro timeoutsCh, ) bcR := &BlockchainReactor{ - config: config, state: state, proxyAppConn: proxyAppConn, store: store, @@ -226,7 +222,7 @@ FOR_LOOP: // We need both to sync the first block. break SYNC_LOOP } - firstParts := first.MakePartSet(bcR.config.GetInt("block_part_size")) // TODO: put part size in parts header? + firstParts := first.MakePartSet(types.DefaultPartSetSize) firstPartsHeader := firstParts.Header() // Finally, verify the first block using the second's commit // NOTE: we can probably make this more efficient, but note that calling diff --git a/node/node.go b/node/node.go index e34f8c726..0471bf3c7 100644 --- a/node/node.go +++ b/node/node.go @@ -73,7 +73,7 @@ func NewNode(config *viper.Viper, privValidator *types.PrivValidator, clientCrea // Get State stateDB := dbm.NewDB("state", config.GetString("db_backend"), config.GetString("db_dir")) - state := sm.GetState(config, stateDB) + state := sm.GetState(stateDB, config.GetString("genesis_file")) // add the chainid and number of validators to the global config config.Set("chain_id", state.ChainID) @@ -121,7 +121,7 @@ func NewNode(config *viper.Viper, privValidator *types.PrivValidator, clientCrea } // Make BlockchainReactor - bcReactor := bc.NewBlockchainReactor(config, state.Copy(), proxyApp.Consensus(), blockStore, fastSync) + bcReactor := bc.NewBlockchainReactor(state.Copy(), proxyApp.Consensus(), blockStore, fastSync) // Make MempoolReactor mempool := mempl.NewMempool(config, proxyApp.Mempool()) diff --git a/state/state.go b/state/state.go index 2625cbc71..bacde0ab5 100644 --- a/state/state.go +++ b/state/state.go @@ -6,7 +6,6 @@ import ( "sync" "time" - "github.com/spf13/viper" abci "github.com/tendermint/abci/types" cmn "github.com/tendermint/tmlibs/common" dbm "github.com/tendermint/tmlibs/db" @@ -169,10 +168,10 @@ func (s *State) GetValidators() (*types.ValidatorSet, *types.ValidatorSet) { // Load the most recent state from "state" db, // or create a new one (and save) from genesis. -func GetState(config *viper.Viper, stateDB dbm.DB) *State { +func GetState(stateDB dbm.DB, genesisFile string) *State { state := LoadState(stateDB) if state == nil { - state = MakeGenesisStateFromFile(stateDB, config.GetString("genesis_file")) + state = MakeGenesisStateFromFile(stateDB, genesisFile) state.Save() } diff --git a/types/block.go b/types/block.go index 65d4031da..afa3be4e7 100644 --- a/types/block.go +++ b/types/block.go @@ -14,7 +14,10 @@ import ( "github.com/tendermint/tmlibs/merkle" ) -const MaxBlockSize = 22020096 // 21MB TODO make it configurable +const ( + MaxBlockSize = 22020096 // 21MB TODO make it configurable + DefaultPartSetSize = 65536 // 64kB TODO: put part size in parts header? +) type Block struct { *Header `json:"header"`