Browse Source

remove viper from blockchain and state

pull/484/head
Ethan Buchman 7 years ago
parent
commit
29c0e6e4f4
4 changed files with 10 additions and 12 deletions
  1. +2
    -6
      blockchain/reactor.go
  2. +2
    -2
      node/node.go
  3. +2
    -3
      state/state.go
  4. +4
    -1
      types/block.go

+ 2
- 6
blockchain/reactor.go View File

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


+ 2
- 2
node/node.go View File

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


+ 2
- 3
state/state.go View File

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


+ 4
- 1
types/block.go View File

@ -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"`


Loading…
Cancel
Save